FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

cleaning up this town · ishit/processing@677b41a · GitHub

Repository navigation

Commit 677b41a

Browse files
committed
cleaning up this town
1 parent a90823f commit 677b41a

16 files changed

Lines changed: 630 additions & 684 deletions

‎app/src/antlr/java/JavaLexer.java‎

Lines changed: 70 additions & 127 deletions
Large diffs are not rendered by default.

‎app/src/antlr/java/JavaRecognizer.java‎

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,18 @@
22

33
package antlr.java;
44

5-
import antlr.TokenBuffer;
6-
import antlr.TokenStreamException;
7-
import antlr.TokenStreamIOException;
8-
import antlr.ANTLRException;
9-
import antlr.LLkParser;
10-
import antlr.Token;
11-
import antlr.TokenStream;
12-
import antlr.RecognitionException;
5+
import antlr.ASTFactory;
6+
import antlr.ASTPair;
137
import antlr.NoViableAltException;
14-
import antlr.MismatchedTokenException;
15-
import antlr.SemanticException;
168
import antlr.ParserSharedInputState;
17-
import antlr.collections.impl.BitSet;
9+
import antlr.RecognitionException;
10+
import antlr.Token;
11+
import antlr.TokenBuffer;
12+
import antlr.TokenStream;
13+
import antlr.TokenStreamException;
1814
import antlr.collections.AST;
19-
import java.util.Hashtable;
20-
import antlr.ASTFactory;
21-
import antlr.ASTPair;
2215
import antlr.collections.impl.ASTArray;
16+
import antlr.collections.impl.BitSet;
2317

2418
/** Java 1.3 Recognizer
2519
* <PRE>

‎app/src/processing/app/Base.java‎

Lines changed: 205 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
//import javax.swing.text.*;
3737
//import javax.swing.undo.*;
3838

39-
import com.apple.mrj.*;
39+
//import com.apple.mrj.*;
4040
import com.ice.jni.registry.*;
4141

4242
import processing.core.*;
@@ -61,8 +61,9 @@ public class Base {
6161
* Path of filename opened on the command line,
6262
* or via the MRJ open document handler.
6363
*/
64-
static String openedAtStartup;
64+
//static String openedAtStartup;
6565

66+
Sketchbook sketchbook;
6667
Editor editor;
6768

6869

@@ -170,7 +171,12 @@ public Base() {
170171
// show the window
171172
editor.show();
172173
*/
174+
175+
if (PApplet.platform == PConstants.MACOSX) {
176+
registerMacOS();
177+
}
173178

179+
/*
174180
if (PApplet.platform == PConstants.MACOSX) {
175181
MRJOpenDocumentHandler startupOpen = new MRJOpenDocumentHandler() {
176182
public void handleOpenFile(File file) {
@@ -217,26 +223,92 @@ public void run() {
217223
}
218224
});
219225
}
226+
*/
220227

221228
// Create a new empty window (will be replaced with any files to be opened)
222-
new Editor(this, null);
229+
//new Editor(this, null);
230+
try {
231+
String path = Sketchbook.handleNewUntitled();
232+
handleOpen(path);
233+
} catch (IOException e) {
234+
e.printStackTrace();
235+
}
236+
}
237+
238+
239+
protected void registerMacOS() {
240+
try {
241+
Class osxAdapter = ClassLoader.getSystemClassLoader().loadClass("BaseMacOS");
242+
243+
Class[] defArgs = { Base.class };
244+
Method registerMethod = osxAdapter.getDeclaredMethod("register", defArgs);
245+
if (registerMethod != null) {
246+
Object[] args = { this };
247+
registerMethod.invoke(osxAdapter, args);
248+
}
249+
} catch (NoClassDefFoundError e) {
250+
// This will be thrown first if the OSXAdapter is loaded on a system without the EAWT
251+
// because OSXAdapter extends ApplicationAdapter in its def
252+
System.err.println("This version of Mac OS X does not support the Apple EAWT." +
253+
"Application Menu handling has been disabled (" + e + ")");
254+
255+
} catch (ClassNotFoundException e) {
256+
// This shouldn't be reached; if there's a problem with the OSXAdapter
257+
// we should get the above NoClassDefFoundError first.
258+
System.err.println("This version of Mac OS X does not support the Apple EAWT. " +
259+
"Application Menu handling has been disabled (" + e + ")");
260+
} catch (Exception e) {
261+
System.err.println("Exception while loading BaseOSX:");
262+
e.printStackTrace();
263+
}
223264
}
224265

225266

226267
// .................................................................
227268

228269

229270
int editorCount;
271+
Editor[] editors;
230272
Editor activeEditor;
231273

274+
232275
// Because of variations in native windowing systems, no guarantees about
233276
// changes to the focused and active Windows can be made. Developers must
234277
// never assume that this Window is the focused or active Window until this
235278
// Window receives a WINDOW_GAINED_FOCUS or WINDOW_ACTIVATED event.
236279
public void handleActivated(Editor whichEditor) {
237280
activeEditor = whichEditor;
238281
}
282+
283+
284+
/*
285+
public Editor getActiveEditor() {
286+
return activeEditor;
287+
}
288+
*/
289+
290+
291+
public boolean handleQuit() {
292+
boolean canceled = false;
293+
for (int i = 0; i < editorCount; i++) {
294+
if (!handleClose(editors[i])) {
295+
canceled = true;
296+
break;
297+
}
298+
}
299+
return !canceled;
300+
}
301+
302+
/*
303+
storePreferences();
304+
Preferences.save();
305+
306+
sketchbook.clean();
307+
console.handleQuit();
239308
309+
//System.out.println("exiting here");
310+
System.exit(0);
311+
*/
240312

241313
/*
242314
public void handleNew() {
@@ -266,12 +338,33 @@ public void handleNew() {
266338
public void handleNewPrompt() {
267339
}
268340
*/
341+
342+
343+
/**
344+
* Asynchronous version of menu rebuild to be used on 'new' and 'save',
345+
* to prevent the interface from locking up until the menus are done.
346+
*/
347+
public void rebuildMenusAsync() {
348+
// disabling the async option for actual release, this hasn't been tested
349+
/*
350+
SwingUtilities.invokeLater(new Runnable() {
351+
public void run() {
352+
rebuildMenus();
353+
}
354+
});
355+
*/
356+
for (int i = 0; i < editorCount; i++) {
357+
editors[i].sketchbookChanged = true; //sketchbook.rebuildMenus();
358+
}
359+
sketchbook.rebuildMenus();
360+
}
269361

270362

271-
public void handleClose(Editor editor) {
363+
public boolean handleClose(Editor editor) {
272364
// check if modified
273365
// if not canceled, the check if this is the last open window
274366
// if this is the last open window, just do a 'new' instead
367+
return false;
275368
}
276369

277370

@@ -426,10 +519,106 @@ protected boolean checkModified() {
426519
}
427520
*/
428521

522+
523+
// ...................................................................
524+
525+
526+
/**
527+
* Show the About box.
528+
*/
529+
public void handleAbout() {
530+
final Image image = Base.getImage("about.jpg", activeEditor);
531+
final Window window = new Window(activeEditor) {
532+
public void paint(Graphics g) {
533+
g.drawImage(image, 0, 0, null);
534+
535+
Graphics2D g2 = (Graphics2D) g;
536+
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
537+
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
538+
539+
g.setFont(new Font("SansSerif", Font.PLAIN, 11));
540+
g.setColor(Color.white);
541+
g.drawString(Base.VERSION_NAME, 50, 30);
542+
}
543+
};
544+
window.addMouseListener(new MouseAdapter() {
545+
public void mousePressed(MouseEvent e) {
546+
window.dispose();
547+
}
548+
});
549+
int w = image.getWidth(activeEditor);
550+
int h = image.getHeight(activeEditor);
551+
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
552+
window.setBounds((screen.width-w)/2, (screen.height-h)/2, w, h);
553+
window.setVisible(true);
554+
}
555+
556+
557+
/**
558+
* Show the preferences window.
559+
*/
560+
public void handlePrefs() {
561+
Preferences preferences = new Preferences();
562+
preferences.showFrame(activeEditor);
563+
}
564+
429565

430566
// ...................................................................
431567

432568

569+
/**
570+
* New was called (by buttons or by menu), first check modified
571+
* and if things work out ok, handleNew2() will be called.
572+
* <p/>
573+
* If shift is pressed when clicking the toolbar button, then
574+
* force the opposite behavior from sketchbook.prompt's setting
575+
* @param editor TODO
576+
* @param shiftDown TODO
577+
*/
578+
/*
579+
public void handleNew(final boolean shift) {
580+
buttons.activate(EditorButtons.NEW);
581+
582+
SwingUtilities.invokeLater(new Runnable() {
583+
public void run() {
584+
doStop();
585+
handleNewShift = shift;
586+
checkModified(HANDLE_NEW);
587+
}});
588+
}
589+
*/
590+
591+
592+
public void handleNew(boolean shiftDown) {
593+
boolean prompt = Preferences.getBoolean("sketchbook.prompt");
594+
if (shiftDown) prompt = !prompt; // reverse behavior if shift is down
595+
596+
// no sketch has been started, don't prompt for the name if it's
597+
// starting up, just make the farker. otherwise if the person hits
598+
// 'cancel' i'd have to add a thing to make p5 quit, which is silly.
599+
// instead give them an empty sketch, and they can look at examples.
600+
// i hate it when imovie makes you start with that goofy dialog box.
601+
// unless, ermm, they user tested it and people preferred that as
602+
// a way to get started. shite. now i hate myself.
603+
//if (disablePrompt) prompt = false;
604+
605+
try {
606+
String path = null;
607+
if (prompt) {
608+
path = Sketchbook.handleNewPrompt(activeEditor);
609+
} else {
610+
path = Sketchbook.handleNewUntitled();
611+
}
612+
if (path != null) {
613+
rebuildMenusAsync();
614+
handleOpen(path);
615+
}
616+
} catch (IOException e) {
617+
// TODO Auto-generated catch block
618+
e.printStackTrace();
619+
}
620+
}
621+
433622

434623
/**
435624
* returns true if the Processing is running on a Mac OS machine,
@@ -459,13 +648,15 @@ static public boolean isLinux() {
459648
// .................................................................
460649

461650

651+
/*
462652
static final int kDocumentsFolderType =
463653
('d' << 24) | ('o' << 16) | ('c' << 8) | 's';
464654
static final int kPreferencesFolderType =
465655
('p' << 24) | ('r' << 16) | ('e' << 8) | 'f';
466656
static final int kDomainLibraryFolderType =
467657
('d' << 24) | ('l' << 16) | ('i' << 8) | 'b';
468658
static final short kUserDomain = -32763;
659+
*/
469660

470661

471662
static public File getSettingsFolder() {
@@ -475,7 +666,7 @@ static public File getSettingsFolder() {
475666
if (pref != null) {
476667
dataFolder = new File(pref);
477668

478-
} else if (Base.isMacOS()) {
669+
} else if (PApplet.platform == PConstants.MACOSX) {
479670
// carbon folder constants
480671
// http://developer.apple.com/documentation/Carbon/Reference
481672
// /Folder_Manager/folder_manager_ref/constant_6.html#/
@@ -500,7 +691,8 @@ static public File getSettingsFolder() {
500691
}
501692
*/
502693

503-
// this method has to be dynamically loaded, because
694+
695+
/*
504696
MRJOSType domainLibrary = new MRJOSType("dlib");
505697
Method findFolderMethod =
506698
MRJFileUtils.class.getMethod("findFolder",
@@ -510,6 +702,9 @@ static public File getSettingsFolder() {
510702
findFolderMethod.invoke(null, new Object[] { new Short(kUserDomain),
511703
domainLibrary });
512704
705+
*/
706+
// TODO load this dynamically
707+
File libraryFolder = new File(BaseMacOS.getLibraryFolder());
513708
dataFolder = new File(libraryFolder, "Processing");
514709

515710
} catch (Exception e) {
@@ -666,6 +861,7 @@ static public File getDefaultSketchbookFolder() {
666861

667862
// not clear if i can write to this folder tho..
668863
try {
864+
/*
669865
MRJOSType domainDocuments = new MRJOSType("docs");
670866
//File libraryFolder = MRJFileUtils.findFolder(domainDocuments);
671867
@@ -677,6 +873,8 @@ static public File getDefaultSketchbookFolder() {
677873
File documentsFolder = (File)
678874
findFolderMethod.invoke(null, new Object[] { new Short(kUserDomain),
679875
domainDocuments });
876+
*/
877+
File documentsFolder = new File(BaseMacOS.getDocumentsFolder());
680878
sketchbookFolder = new File(documentsFolder, "Processing");
681879

682880
/*
@@ -1011,7 +1209,7 @@ static public void openURL(String url) {
10111209
url = sb.toString();
10121210
}
10131211
}
1014-
com.apple.mrj.MRJFileUtils.openURL(url);
1212+
com.apple.eio.FileManager.openURL(url);
10151213

10161214
} else if (Base.isLinux()) {
10171215
// how's mozilla sound to ya, laddie?

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL