new keywords class

This commit is contained in:
benfry
2003-11-09 23:10:56 +00:00
parent 3361c31139
commit e3484f553b
6 changed files with 464 additions and 251 deletions
+26 -15
View File
@@ -89,7 +89,6 @@ public class PdeBase /*extends JFrame implements ActionListener*/
// build the editor object
editor = new PdeEditor();
editor.pack();
// figure out which operating system
@@ -141,6 +140,7 @@ public class PdeBase /*extends JFrame implements ActionListener*/
// read in the keywords for the reference
//final String KEYWORDS = "pde_keywords.properties";
/*
keywords = new Properties();
try {
@@ -157,11 +157,12 @@ public class PdeBase /*extends JFrame implements ActionListener*/
System.err.println(e.toString());
e.printStackTrace();
}
*/
// get things rawkin
editor.restorePreferences();
//editor.restorePreferences(); // done at end of constructor
editor.pack();
editor.show();
@@ -306,16 +307,21 @@ public class PdeBase /*extends JFrame implements ActionListener*/
}
}
//
/**
* "No cookie for you" type messages. Nothing fatal or all that
* much of a bummer, but something to notify the user about.
*/
static public void showMessage(String title, String message) {
if (title == null) title = "Message";
JOptionPane.showMessageDialog(new Frame(), message, title,
JOptionPane.INFORMATION_MESSAGE);
}
//
/**
* Non-fatal error message with optional stack trace side dish.
*/
static public void showWarning(String title, String message,
Exception e) {
if (title == null) title = "Warning";
@@ -326,8 +332,12 @@ public class PdeBase /*extends JFrame implements ActionListener*/
if (e != null) e.printStackTrace();
}
//
/**
* Show an error message that's actually fatal to the program.
* This is an error that can't be recovered. Use showWarning()
* for errors that allow P5 to continue running.
*/
static public void showError(String title, String message,
Exception e) {
if (title == null) title = "Error";
@@ -335,19 +345,19 @@ public class PdeBase /*extends JFrame implements ActionListener*/
JOptionPane.ERROR_MESSAGE);
if (e != null) e.printStackTrace();
System.exit(1);
}
//
// ...................................................................
static public Image getImage(String name, Component who) {
Image image = null;
Toolkit tk = Toolkit.getDefaultToolkit();
if (PdeBase.platform == PdeBase.MACOSX) {
//String pkg = "Proce55ing.app/Contents/Resources/Java/";
//image = tk.getImage(pkg + name);
image = tk.getImage("lib/" + name);
} else if (PdeBase.platform == PdeBase.MACOS9) {
if ((PdeBase.platform == PdeBase.MACOSX) ||
(PdeBase.platform == PdeBase.MACOS9)) {
image = tk.getImage("lib/" + name);
} else {
image = tk.getImage(who.getClass().getResource(name));
@@ -366,9 +376,9 @@ public class PdeBase /*extends JFrame implements ActionListener*/
return image;
}
//
public InputStream getStream(String filename) throws IOException {
static public InputStream getStream(/*Class cls,*/ String filename)
throws IOException {
if ((PdeBase.platform == PdeBase.MACOSX) ||
(PdeBase.platform == PdeBase.MACOS9)) {
// macos doesn't seem to think that files in the lib folder
@@ -380,7 +390,8 @@ public class PdeBase /*extends JFrame implements ActionListener*/
}
// all other, more reasonable operating systems
return getClass().getResource(filename).openStream();
//return cls.getResource(filename).openStream();
return PdeBase.class.getResource(filename).openStream();
}
+8 -4
View File
@@ -128,7 +128,7 @@ public class PdeEditor extends JFrame
PdeHistory history;
PdeSketchbook sketchbook;
PdePreferences preferences;
static Properties keywords; // keyword -> reference html lookup
//static Properties keywords; // keyword -> reference html lookup
public PdeEditor() { //PdeBase base) {
@@ -161,6 +161,7 @@ public class PdeEditor extends JFrame
//this.addWindowListener(windowListener);
PdeKeywords keywords = new PdeKeywords();
history = new PdeHistory(this);
sketchbook = new PdeSketchbook(this);
preferences = new PdePreferences();
@@ -196,7 +197,7 @@ public class PdeEditor extends JFrame
textarea = new JEditTextArea();
textarea.setRightClickPopup(new TextAreaPopup(this));
textarea.setTokenMarker(new PdeTokenMarker());
textarea.setTokenMarker(new PdeKeywords());
// assemble console panel, consisting of status area and the console itself
consolePanel = new JPanel();
@@ -326,6 +327,9 @@ public class PdeEditor extends JFrame
}
}
});
// can this happen here?
restorePreferences();
}
@@ -788,7 +792,7 @@ public class PdeEditor extends JFrame
message("First select a word to find in the reference.");
} else {
String referenceFile = (String) PdeBase.keywords.get(text);
String referenceFile = PdeKeywords.getReference(text);
if (referenceFile == null) {
message("No reference available for \"" + text + "\"");
} else {
@@ -2511,7 +2515,7 @@ public class PdeEditor extends JFrame
cutItem.setEnabled(true);
copyItem.setEnabled(true);
referenceFile = PdeBase.keywords.get(getSelectedText());
referenceFile = PdeKeywords.get(getSelectedText());
if (referenceFile != null) {
referenceItem.setEnabled(true);
}
+5 -5
View File
@@ -51,7 +51,7 @@ public class PdeHistory {
File historyFile;
//OutputStream historyStream;
//PrintWriter historyWriter;
//String historyLast;
//String lastRecorded;
String lastRecorded;
ActionListener menuListener;
@@ -96,8 +96,8 @@ public class PdeHistory {
public void record(String program, int mode) {
if (!PdePreferences.getBoolean("history.recording")) return;
if ((historyLast != null) &&
(historyLast.equals(program))) return;
if ((lastRecorded != null) &&
(lastRecorded.equals(program))) return;
String modeStr = null;
switch (mode) {
@@ -167,7 +167,7 @@ public class PdeHistory {
historyWriter.println();
historyWriter.println(program);
historyWriter.flush(); // ??
historyLast = program;
lastRecorded = program;
//JMenuItem menuItem = new JMenuItem(modeStr + " - " + readableDate);
JMenuItem menuItem = new JMenuItem(modeStr + " - " + readableDate);
@@ -230,7 +230,7 @@ public class PdeHistory {
}
//textarea.editorSetText(buffer.toString());
editor.changeText(buffer.toString(), true);
historyLast = editor.textarea.getText();
lastRecorded = editor.textarea.getText();
editor.setSketchModified(false);
} else {
+95
View File
@@ -0,0 +1,95 @@
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
PdeKeywords - handles text coloring and links to html reference
Part of the Processing project - http://Proce55ing.net
Copyright (c) 2001-03
Ben Fry, Massachusetts Institute of Technology and
Casey Reas, Interaction Design Institute Ivrea
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.util.*;
public class PdeKeywords extends CTokenMarker {
// lookup table for the TokenMarker subclass, handles coloring
static KeywordMap keywordColoring;
// lookup table that maps keywords to their html reference pages
static Hashtable keywordToReference;
public PdeKeywords() {
super(false, getKeywords());
}
/**
* Handles loading of keywords file. uses getKeywords() method
* because that's part of the TokenMarker classes.
*/
static public KeywordMap getKeywords() {
if (keywordColoring == null) {
try {
keywords = new KeywordMap(false);
keywordToReference = new Hashtable();
InputStream input = PdeBase.getStream("keywords.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line = null;
while ((line = reader.readLine()) != null) {
int tab = line.indexOf('\t');
if (tab == -1) continue;
String keyword = line.substring(0, tab);
String second = line.substring(tab + 1);
tab = second.indexOf('\t');
String coloring = second.substring(0, tab);
String htmlFilename = second.substring(tab + 1);
if (coloring.length() > 0) {
// text will be KEYWORD or LITERAL
boolean isKeyword = (coloring.charAt(0) == 'K');
// KEYWORD1 -> 0, KEYWORD2 -> 1, etc
int num = coloring.charAt(coloring.length() - 1) - '1';
int constant = (isKeyword ? KEYWORD : LITERAL) + num;
keywordColoring.add(keyword, constant);
}
if (htmlFilename.length() > 0) {
keywordToReference.put(keyword, htmlFilename);
}
}
} catch (Exception e) {
PdeBase.showError("Problem loading keywords",
"Could not find keywords.txt,\n" +
"please re-install Processing.", e);
System.exit(1);
}
reader.close();
}
return keywordColoring;
}
static public String getReference(String keyword) {
return (String) keywordToReference.get(keyword);
}
}
+330
View File
@@ -0,0 +1,330 @@
! logicalNOT
!= inequality
% modulo
&& logicalAND
( parentheses
) parentheses
* multiply
*/ multilinecomment
+ add
++ increment
+= addassign
, comma
- negation
-- decrement
-= subtractassign
. dot
/ divide
/* multilinecomment
// comment
; semicolon
< lessthan
<= lessthanorequalto
> greaterthan
>= greaterthanorequalto
ADD LITERAL1
ALIGN_CENTER LITERAL1
ALIGN_LEFT LITERAL1
ALIGN_RIGHT LITERAL1
ALPHA LITERAL1
ALT LITERAL1
ARROW LITERAL1
BEVELED_JOIN LITERAL1
BFont KEYWORD1 BFont
BImage KEYWORD1 BImage
BLEND LITERAL1
BSound KEYWORD1 BSound
Boolean KEYWORD1
Byte KEYWORD1
CENTER_DIAMETER LITERAL1
CENTER_RADIUS LITERAL1
CONCAVE_POLYGON LITERAL1
CONTROL LITERAL1
CONVEX_POLYGON LITERAL1
CORNER LITERAL1
CORNERS LITERAL1
CROSS LITERAL1
Character KEYWORD1
Class KEYWORD1
DARKEST LITERAL1
DEG_TO_RAD LITERAL1
DISABLE_TEXT_SMOOTH LITERAL1
DOWN LITERAL1
Double KEYWORD1
Float KEYWORD1
HALF_PI LITERAL1 HALF_PI
HAND LITERAL1
HSB LITERAL1
IMAGE_SPACE LITERAL1
Integer KEYWORD1
LEFT LITERAL1
LIGHTEST LITERAL1
LINES LITERAL1
LINE_LOOP LITERAL1
LINE_STRIP LITERAL1
MITERED_JOIN LITERAL1
MOVE LITERAL1
Math KEYWORD1
NORMAL_SPACE LITERAL1
OBJECT_SPACE LITERAL1
PI LITERAL1 PI
POINTS LITERAL1
POLYGON LITERAL1
PROJECTED_ENDCAP LITERAL1
QUADS LITERAL1
QUAD_STRIP LITERAL1
QUARTER_PI LITERAL1
RAD_TO_DEG LITERAL1
REPLACE LITERAL1
RGB LITERAL1
RIGHT LITERAL1
ROUND_ENDCAP LITERAL1
ROUND_JOIN LITERAL1
SCREEN_SPACE LITERAL1
SHIFT LITERAL1
SQUARE_ENDCAP LITERAL1
SUBSTRACT LITERAL1
String KEYWORD1
StringBuffer KEYWORD1
TEXT LITERAL1
THIRD_PI LITERAL1
TRAINGLES LITERAL1
TRIANGLE_STRIP LITERAL1
TWO_PI LITERAL1 TWO_PI
Thread KEYWORD1
UP LITERAL1
WAIT LITERAL1
[ arrayaccess
= assign
== equality
] arrayaccess
abs KEYWORD2 abs_
abstract KEYWORD1
alpha KEYWORD2
atan2 KEYWORD2 atan2_
background KEYWORD2 background_
beginNet KEYWORD2
beginSerial KEYWORD2 beginSerial_
beginShape KEYWORD2 beginShape_
beginSound KEYWORD2 beginSound_
bezier KEYWORD2 bezier_
bezierPoint KEYWORD2
bezierSegments KEYWORD2
bezierTangent KEYWORD2
bezierVertex KEYWORD2 bezierVertex_
blendMode KEYWORD2
blue KEYWORD2 blue_
boolean KEYWORD1 boolean_
box KEYWORD2 box_
break KEYWORD1
brightness KEYWORD2 brightness_
byte KEYWORD1 byte_
cache KEYWORD2 cache_
case KEYWORD1
catch KEYWORD1
ceil KEYWORD2
char KEYWORD1 char_
class KEYWORD1
color KEYWORD1 color_
colorMode KEYWORD2 colorMode_
continue KEYWORD1
copy KEYWORD2
cos KEYWORD2 cos_
cursor KEYWORD2
curve KEYWORD2 curve_
curvePoint KEYWORD2
curveSegments KEYWORD2
curveTangent KEYWORD2
curveTightness KEYWORD2
curveVertex KEYWORD2 curveVertex_
day KEYWORD2 day_
default KEYWORD1
degrees KEYWORD2 degrees_
delay KEYWORD2 delay_
do KEYWORD1
double KEYWORD1 double_
draw KEYWORD3
ellipse KEYWORD2 ellipse_
ellipseMode KEYWORD2 ellipseMode_
else KEYWORD1 else
endNet KEYWORD2
endSerial KEYWORD2 endSerial_
endShape KEYWORD2 endShape_
extends KEYWORD1
false LITERAL1
fill KEYWORD2 fill_
final KEYWORD1
finally KEYWORD1
float KEYWORD1 float_
floor KEYWORD2
for KEYWORD1 for_
framerate KEYWORD2 framerate_
frequency KEYWORD2 frequency_
generate KEYWORD2 generate_
get KEYWORD2
getPixel getPixel_
green KEYWORD2 green_
height LITERAL2 height
hint KEYWORD2
hour KEYWORD2 hour_
hue KEYWORD2 hue_
if KEYWORD1 if_
image KEYWORD2 image_
imageMode KEYWORD2 imageMode_
implements KEYWORD1
import KEYWORD1
in KEYWORD2 in_
instanceof KEYWORD1
int KEYWORD1 int_
interface KEYWORD1
key LITERAL2 key
keyPressed LITERAL2 keyPressed_
keyReleased LITERAL2 keyReleased_
keyTyped LITERAL2 keyTyped_
length LITERAL2
light light_
lights KEYWORD2 lights_
line KEYWORD2 line_
loadBytes KEYWORD2 loadBytes_
loadFont KEYWORD2 loadFont_
loadImage KEYWORD2 loadImage_
loadSound KEYWORD2 loadSound_
loadStream KEYWORD2 loadStream_
loadStrings KEYWORD2 loadStrings_
long KEYWORD1
loop KEYWORD3 loop_
max KEYWORD2 max_
microphone KEYWORD2 microphone_
millis KEYWORD2 millis_
min KEYWORD2 min_
minute KEYWORD2 minute_
month KEYWORD2 month_
mouseClicked LITERAL2 mouseClicked_
mouseDragged LITERAL2 mouseDragged_
mouseEntered LITERAL2
mouseExited LITERAL2 mouseExited_
mouseMoved LITERAL2 mouseMoved_
mousePressed LITERAL2 mousePressed_
mouseReleased LITERAL2 mouseReleased_
mouseX LITERAL2 mouseX
mouseY LITERAL2 mouseY
native KEYWORD1
net LITERAL2
netWrite KEYWORD2
new KEYWORD1 new
nf nf_
noBackground noBackground_
noCursor KEYWORD2
noFill KEYWORD2 noFill_
noLights KEYWORD2 noLights_
noSmooth KEYWORD2 noSmooth_
noStroke KEYWORD2 noStroke_
noTint KEYWORD2
normal KEYWORD2
null LITERAL1
online KEYWORD2
out KEYWORD2 out_
package KEYWORD1
param KEYWORD2
pause KEYWORD2 pause_
pixels LITERAL2 pixels
play KEYWORD2 play_
pmouseX LITERAL2 pmouseX
pmouseY LITERAL2 pmouseY
point KEYWORD2 point_
pop KEYWORD2 pop_
pow KEYWORD2 pow_
print KEYWORD2 print_
println KEYWORD2 println_
private KEYWORD1
project KEYWORD2 project_
protected KEYWORD1
public KEYWORD1
push KEYWORD2 push_
quad KEYWORD2 quad_
radians KEYWORD2 radians_
random KEYWORD2 random_
rect KEYWORD2 rect_
rectMode KEYWORD2 rectMode_
red KEYWORD2 red_
repeat KEYWORD2 repeat_
replicate KEYWORD2
return KEYWORD1
rotate KEYWORD2 rotate_
rotateX KEYWORD2 rotateX_
rotateY KEYWORD2 rotateY_
rotateZ KEYWORD2 rotateZ_
samples LITERAL2
saturation KEYWORD2 saturation_
save KEYWORD2
saveBytes KEYWORD2
saveFrame KEYWORD2
saveStrings KEYWORD2
scale KEYWORD2 scale_
screenGrab screenGrab_
second KEYWORD2 second_
seek KEYWORD2 seek_
serial LITERAL2 serial
serialEvent LITERAL2 serialEvent_
serialWrite KEYWORD2 serialWrite_
set KEYWORD2
setFont setFont_
setPixel setPixel_
setup KEYWORD3 setup_
short KEYWORD1
sin KEYWORD2 sin_
size KEYWORD2 size_
smooth KEYWORD2 smooth_
soundEvent LITERAL2 soundEvent_
sphere KEYWORD2 sphere_
splitFloats KEYWORD2 splitFloats_
splitInts KEYWORD2 splitInts_
splitStrings KEYWORD2 splitStrings_
sq KEYWORD2 sq_
sqrt KEYWORD2 sqrt_
static KEYWORD1
status KEYWORD2
stop KEYWORD2 stop_
stroke KEYWORD2 stroke_
strokeJoin KEYWORD2
strokeMiter KEYWORD2
strokeMode strokeMode_
strokeWeight KEYWORD2
strokeWidth strokeWidth_
super LITERAL1
switch KEYWORD1
synchronized KEYWORD1
synthesize KEYWORD2 synthesize_
tan KEYWORD2 tan_
text KEYWORD2 text_
textFont KEYWORD2
textLeading KEYWORD2
textMode KEYWORD2
textSize KEYWORD2
textSpace KEYWORD2
texture KEYWORD2
textureImage textureImage_
textureMode KEYWORD2
this LITERAL1
throw KEYWORD1
throws KEYWORD1
tint KEYWORD2
transform KEYWORD2 transform_
transient KEYWORD1
translate KEYWORD2 translate_
triangle KEYWORD2 triangle_
true LITERAL1
try KEYWORD1
unhint KEYWORD2
vertex KEYWORD2 vertex_
vertexNormal vertexNormal_
vertexTexture vertexTexture_
void KEYWORD1 void
volatile KEYWORD1
volume KEYWORD2 volume_
while KEYWORD1 while_
width LITERAL2 width
year KEYWORD2 year_
{ curlybraces
|| logicalOR
} curlybraces
@@ -1,227 +0,0 @@
# p r o c e s s i n g keyword reference mapping
#
# format:
# token=filename
#
# description:
# token is the text string to be linked from the processing editor
# filename is the base filename (without .html extension) in the
# "reference" directory
#
# note that some characters, such as "=", have to be escaped by "\"
else=else
for=for_
if=if_
while=while_
setup=setup_
loop=loop_
serialEvent=serialEvent_
soundEvent=soundEvent_
keyTyped=keyTyped_
keyPressed=keyPressed_
keyReleased=keyReleased_
mouseMoved=mouseMoved_
mouseDragged=mouseDragged_
mouseExited=mouseExited_
mouseReleased=mouseReleased_
mousePressed=mousePressed_
mouseClicked=mouseClicked_
beginShape=beginShape_
textureImage=textureImage_
vertexTexture=vertexTexture_
vertexNormal=vertexNormal_
vertex=vertex_
bezierVertex=bezierVertex_
curveVertex=curveVertex_
endShape=endShape_
point=point_
line=line_
triangle=triangle_
quad=quad_
rectMode=rectMode_
rect=rect_
ellipseMode=ellipseMode_
ellipse=ellipse_
box=box_
sphere=sphere_
bezier=bezier_
curve=curve_
loadImage=loadImage_
image=image_
imageMode=imageMode_
cache=cache_
loadSound=loadSound_
microphone=microphone_
generate=generate_
synthesize=synthesize_
volume=volume_
play=play_
repeat=repeat_
pause=pause_
stop=stop_
seek=seek_
in=in_
out=out_
loadFont=loadFont_
setFont=setFont_
text=text_
push=push_
pop=pop_
project=project_
translate=translate_
rotate=rotate_
rotateX=rotateX_
rotateY=rotateY_
rotateZ=rotateZ_
scale=scale_
transform=transform_
smooth=smooth_
noSmooth=noSmooth_
colorMode=colorMode_
noFill=noFill_
fill=fill_
strokeWidth=strokeWidth_
strokeMode=strokeMode_
noStroke=noStroke_
stroke=stroke_
noBackground=noBackground_
background=background_
light=light_
lights=lights_
noLights=noLights_
loadStream=loadStream_
loadBytes=loadBytes_
loadStrings=loadStrings_
getPixel=getPixel_
setPixel=setPixel_
color=color_
red=red_
green=green_
blue=blue_
hue=hue_
saturation=saturation_
brightness=brightness_
size=size_
;=semicolon
\==assign
(=parentheses
)=parentheses
,=comma
//=comment
/*=multilinecomment
*/=multilinecomment
new=new
{=curlybraces
}=curlybraces
[=arrayaccess
]=arrayaccess
.=dot
print=print_
println=println_
screenGrab=screenGrab_
millis=millis_
second=second_
minute=minute_
hour=hour_
day=day_
month=month_
year=year_
delay=delay_
framerate=framerate_
frequency=frequency_
beginSerial=beginSerial_
endSerial=endSerial_
serialWrite=serialWrite_
beginSound=beginSound_
print=print_
println=println_
splitInts=splitInts_
splitStrings=splitStrings_
splitFloats=splitFloats_
abs=abs_
sq=sq_
sqrt=sqrt_
pow=pow_
min=min_
max=max_
sin=sin_
cos=cos_
tan=tan_
atan2=atan2_
degrees=degrees_
radians=radians_
random=random_
byte=byte_
char=char_
int=int_
color=color_
float=float_
double=double_
boolean=boolean_
void=void
BImage=BImage
BFont=BFont
BSound=BSound
PI=PI
HALF_PI=HALF_PI
TWO_PI=TWO_PI
mouseX=mouseX
mouseY=mouseY
pmouseX=pmouseX
pmouseY=pmouseY
serial=serial
key=key
width=width
height=height
pixels=pixels
nf=nf_
+=add
-=subtract
*=multiply
/=divide
++=increment
--=decrement
%=modulo
+\==addassign
-\==subtractassign
-=negation
||=logicalOR
&&=logicalAND
!=logicalNOT
>=greaterthan
<=lessthan
>\==greaterthanorequalto
<\==lessthanorequalto
\=\==equality
!\==inequality