We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProcessing DevelopmentLibraries,  Tool Development › Hacking Processing guts
Page Index Toggle Pages: 1
Hacking Processing guts (Read 2119 times)
Hacking Processing guts
Sep 23rd, 2005, 6:32pm
 
I don't know if this is the right place to post a Subject like this.
First of all a piece of advice: this is a funny experiment (unreliable source). At the same time I've learned some about java and processing (thanks BEN/CASEY and all the people of this forum).

Some time ago I wrote up some about posting messages and the YaBB tags. Some people seems to have the same problem (is it a general problem?).
I had an simple idea: use processing IDE to solve it (interaction IDE-webBoard).

Originally I thought about a library, but I couldn't find out a way to read the sketchcode from a library without import or creating a new sketch (any idea, please?). That's the reason why I tried to hack PDE's source (may be it's a sin...).

This source creates a new menu option on the mouse's (right-button) popup menu called "Format for discourse".
And the new menu option lets you to format the sketchcode from the actual tab of the editor, according to the YaBB Bulletin Board Code (YaBBC color and b).
It uses mouse only (right click, Select All and copy). No editable.
No macs or keyboard support (I've tested only with windowsXP and Processing 0091).
Another features can be added: formatting selected text with a determined tag (|url|selected text|/url|).

I hope you enjoy this.
One Saludo.

Using CODE (you know...)
***********************
Code:


// This is a comment line
int a = 12;

void setup()
{
println(a);
}

void draw() {
}

class example
{
this.nothing = 0;
}


Using hacking-discourse (quote
instead because code tag cancels other YaBB tags)
***************************************************
Quote:


// This is a comment line
int a = 12;

void setup()
{
 println(a);
}

void draw() {
}

class example
{
 this.nothing = 0;
}



YaBB Tags (broken for read)
**************************
[color=#777755]// This is a comment line [/color[color=#993300][b]draw[/b [color


And the source (Eclipse workspace):
Discourse.zip
Re: Hacking Processing guts
Reply #1 - Sep 26th, 2005, 11:08pm
 
neato, this is exactly the sort of thing that we have planned for the "Tools" menu, that you'll be able to add something like this without having to hack the source, but instead it'll just be a teeny jar file that talks to processing.app.Editor & friends so that you can implement this kind of thing.

to make this work for you, what sort of things did you have to change in the editor object, and what sort of methods do you need from the Editor object so that you won't have to hack on it directly?

i see that you're grabbing the painter and some stuff like that, were there things that you had to make public and whatnot that had not been previously?
Re: Hacking Processing guts
Reply #2 - Sep 30th, 2005, 7:33am
 
That sounds funny (teeny jar)!
Inside the Discourse.zip there is a readme.txt with the points you're refering to (if I've understood you correctly). Sorry: it's a bit hidden (ProcessingStyle/readme.txt).


¯ "were there things that you had to make public and whatnot that had not been previously":
It was necessary to read from outside (Discourse.java > String codeFormated() )

package processing.app.syntax
1.-- TextAreaPainter.java

 // package-private members
 // Changed to public <<<<
 public int currentLineIndex;
 public Token currentLineTokens;
 public Segment currentLine;


¯ "what sort of things did you have to change in the editor object":
Mouse button: a bridge to read and define (parent) Editor's textarea

package processing.app
2.-- Editor.java

----- At public TextAreaPopup() added:

this.addSeparator();

item = new JMenuItem("Format for discourse");
item.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
    Discourse.formatDiscourse(textarea);
  }
});
this.add(item);


¯ And "what sort of methods do you need from the Editor object":

Uf! Well... this is more complicated.
May be I got the hardest way for Proccesing runtime, but the easiest for me and my limits. It can be changed for best running. Anyway...
The objective is SyntaxStyle[] styles (getFontMetrics and getColor). I've used the same Processing method, that is, first read code, put it into segment, get the Editor.textarea TextAreaPainter, the TokenMarker etc...
Then it creates a new window and paint the formated code.

Methods?
- To create a button (and may be a submenu) in the "Tools" as you say using that "teeny jar".
- To "get" the Editor object and its textarea.
- And your opinion about those private members in the TextAreaPainter.

Any other idea or suggestion are welcome.
Re: Hacking Processing guts
Reply #3 - Mar 10th, 2006, 11:54pm
 
i've just cleaned this up and modded it for the latest release, how would you feel about having it released as GPL with the next rev (with attribution to you)? we probably won't keep it in there by default, but i'm working on getting the "tools" menu to work, and need some test cases.. and in the meantime, it'd be fun to have it in general use.
Re: Hacking Processing guts
Reply #4 - Mar 12th, 2006, 6:20pm
 
Sure!
Feel free to do what you want.
I have another version without hack TextAreaPainter creating a new DiscourseTextAreaPainter (paralel TextAreaPainter) thinking about tools... But actually I have not much time.
Thank you for your hard work (and all the people who keep on helping-teaching!).

Keep on Smiley!

Nach.
Page Index Toggle Pages: 1