| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,24 +2,18 @@ | |||
| 2 | 2 | ||
| 3 | 3 | package antlr.java; | |
| 4 | 4 | ||
| 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; | ||
| 13 | 7 | import antlr.NoViableAltException; | |
| 14 | - import antlr.MismatchedTokenException; | ||
| 15 | - import antlr.SemanticException; | ||
| 16 | 8 | 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; | ||
| 18 | 14 | import antlr.collections.AST; | |
| 19 | - import java.util.Hashtable; | ||
| 20 | - import antlr.ASTFactory; | ||
| 21 | - import antlr.ASTPair; | ||
| 22 | 15 | import antlr.collections.impl.ASTArray; | |
| 16 | + import antlr.collections.impl.BitSet; | ||
| 23 | 17 | ||
| 24 | 18 | /** Java 1.3 Recognizer | |
| 25 | 19 | * <PRE> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ | |||
| 36 | 36 | //import javax.swing.text.*; | |
| 37 | 37 | //import javax.swing.undo.*; | |
| 38 | 38 | ||
| 39 | - import com.apple.mrj.*; | ||
| 39 | + //import com.apple.mrj.*; | ||
| 40 | 40 | import com.ice.jni.registry.*; | |
| 41 | 41 | ||
| 42 | 42 | import processing.core.*; | |
@@ -61,8 +61,9 @@ public class Base { | |||
| 61 | 61 | * Path of filename opened on the command line, | |
| 62 | 62 | * or via the MRJ open document handler. | |
| 63 | 63 | */ | |
| 64 | - static String openedAtStartup; | ||
| 64 | + //static String openedAtStartup; | ||
| 65 | 65 | ||
| 66 | + Sketchbook sketchbook; | ||
| 66 | 67 | Editor editor; | |
| 67 | 68 | ||
| 68 | 69 | ||
@@ -170,7 +171,12 @@ public Base() { | |||
| 170 | 171 | // show the window | |
| 171 | 172 | editor.show(); | |
| 172 | 173 | */ | |
| 174 | + | ||
| 175 | + if (PApplet.platform == PConstants.MACOSX) { | ||
| 176 | + registerMacOS(); | ||
| 177 | + } | ||
| 173 | 178 | ||
| 179 | + /* | ||
| 174 | 180 | if (PApplet.platform == PConstants.MACOSX) { | |
| 175 | 181 | MRJOpenDocumentHandler startupOpen = new MRJOpenDocumentHandler() { | |
| 176 | 182 | public void handleOpenFile(File file) { | |
@@ -217,26 +223,92 @@ public void run() { | |||
| 217 | 223 | } | |
| 218 | 224 | }); | |
| 219 | 225 | } | |
| 226 | + */ | ||
| 220 | 227 | ||
| 221 | 228 | // 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 | + } | ||
| 223 | 264 | } | |
| 224 | 265 | ||
| 225 | 266 | ||
| 226 | 267 | // ................................................................. | |
| 227 | 268 | ||
| 228 | 269 | ||
| 229 | 270 | int editorCount; | |
| 271 | + Editor[] editors; | ||
| 230 | 272 | Editor activeEditor; | |
| 231 | 273 | ||
| 274 | + | ||
| 232 | 275 | // Because of variations in native windowing systems, no guarantees about | |
| 233 | 276 | // changes to the focused and active Windows can be made. Developers must | |
| 234 | 277 | // never assume that this Window is the focused or active Window until this | |
| 235 | 278 | // Window receives a WINDOW_GAINED_FOCUS or WINDOW_ACTIVATED event. | |
| 236 | 279 | public void handleActivated(Editor whichEditor) { | |
| 237 | 280 | activeEditor = whichEditor; | |
| 238 | 281 | } | |
| 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(); | ||
| 239 | 308 | ||
| 309 | + //System.out.println("exiting here"); | ||
| 310 | + System.exit(0); | ||
| 311 | + */ | ||
| 240 | 312 | ||
| 241 | 313 | /* | |
| 242 | 314 | public void handleNew() { | |
@@ -266,12 +338,33 @@ public void handleNew() { | |||
| 266 | 338 | public void handleNewPrompt() { | |
| 267 | 339 | } | |
| 268 | 340 | */ | |
| 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 | + } | ||
| 269 | 361 | ||
| 270 | 362 | ||
| 271 | - public void handleClose(Editor editor) { | ||
| 363 | + public boolean handleClose(Editor editor) { | ||
| 272 | 364 | // check if modified | |
| 273 | 365 | // if not canceled, the check if this is the last open window | |
| 274 | 366 | // if this is the last open window, just do a 'new' instead | |
| 367 | + return false; | ||
| 275 | 368 | } | |
| 276 | 369 | ||
| 277 | 370 | ||
@@ -426,10 +519,106 @@ protected boolean checkModified() { | |||
| 426 | 519 | } | |
| 427 | 520 | */ | |
| 428 | 521 | ||
| 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 | + | ||
| 429 | 565 | ||
| 430 | 566 | // ................................................................... | |
| 431 | 567 | ||
| 432 | 568 | ||
| 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 | + | ||
| 433 | 622 | ||
| 434 | 623 | /** | |
| 435 | 624 | * returns true if the Processing is running on a Mac OS machine, | |
@@ -459,13 +648,15 @@ static public boolean isLinux() { | |||
| 459 | 648 | // ................................................................. | |
| 460 | 649 | ||
| 461 | 650 | ||
| 651 | + /* | ||
| 462 | 652 | static final int kDocumentsFolderType = | |
| 463 | 653 | ('d' << 24) | ('o' << 16) | ('c' << 8) | 's'; | |
| 464 | 654 | static final int kPreferencesFolderType = | |
| 465 | 655 | ('p' << 24) | ('r' << 16) | ('e' << 8) | 'f'; | |
| 466 | 656 | static final int kDomainLibraryFolderType = | |
| 467 | 657 | ('d' << 24) | ('l' << 16) | ('i' << 8) | 'b'; | |
| 468 | 658 | static final short kUserDomain = -32763; | |
| 659 | + */ | ||
| 469 | 660 | ||
| 470 | 661 | ||
| 471 | 662 | static public File getSettingsFolder() { | |
@@ -475,7 +666,7 @@ static public File getSettingsFolder() { | |||
| 475 | 666 | if (pref != null) { | |
| 476 | 667 | dataFolder = new File(pref); | |
| 477 | 668 | ||
| 478 | - } else if (Base.isMacOS()) { | ||
| 669 | + } else if (PApplet.platform == PConstants.MACOSX) { | ||
| 479 | 670 | // carbon folder constants | |
| 480 | 671 | // http://developer.apple.com/documentation/Carbon/Reference | |
| 481 | 672 | // /Folder_Manager/folder_manager_ref/constant_6.html#/ | |
@@ -500,7 +691,8 @@ static public File getSettingsFolder() { | |||
| 500 | 691 | } | |
| 501 | 692 | */ | |
| 502 | 693 | ||
| 503 | - // this method has to be dynamically loaded, because | ||
| 694 | + | ||
| 695 | + /* | ||
| 504 | 696 | MRJOSType domainLibrary = new MRJOSType("dlib"); | |
| 505 | 697 | Method findFolderMethod = | |
| 506 | 698 | MRJFileUtils.class.getMethod("findFolder", | |
@@ -510,6 +702,9 @@ static public File getSettingsFolder() { | |||
| 510 | 702 | findFolderMethod.invoke(null, new Object[] { new Short(kUserDomain), | |
| 511 | 703 | domainLibrary }); | |
| 512 | 704 | ||
| 705 | + */ | ||
| 706 | + // TODO load this dynamically | ||
| 707 | + File libraryFolder = new File(BaseMacOS.getLibraryFolder()); | ||
| 513 | 708 | dataFolder = new File(libraryFolder, "Processing"); | |
| 514 | 709 | ||
| 515 | 710 | } catch (Exception e) { | |
@@ -666,6 +861,7 @@ static public File getDefaultSketchbookFolder() { | |||
| 666 | 861 | ||
| 667 | 862 | // not clear if i can write to this folder tho.. | |
| 668 | 863 | try { | |
| 864 | + /* | ||
| 669 | 865 | MRJOSType domainDocuments = new MRJOSType("docs"); | |
| 670 | 866 | //File libraryFolder = MRJFileUtils.findFolder(domainDocuments); | |
| 671 | 867 | ||
@@ -677,6 +873,8 @@ static public File getDefaultSketchbookFolder() { | |||
| 677 | 873 | File documentsFolder = (File) | |
| 678 | 874 | findFolderMethod.invoke(null, new Object[] { new Short(kUserDomain), | |
| 679 | 875 | domainDocuments }); | |
| 876 | + */ | ||
| 877 | + File documentsFolder = new File(BaseMacOS.getDocumentsFolder()); | ||
| 680 | 878 | sketchbookFolder = new File(documentsFolder, "Processing"); | |
| 681 | 879 | ||
| 682 | 880 | /* | |
@@ -1011,7 +1209,7 @@ static public void openURL(String url) { | |||
| 1011 | 1209 | url = sb.toString(); | |
| 1012 | 1210 | } | |
| 1013 | 1211 | } | |
| 1014 | - com.apple.mrj.MRJFileUtils.openURL(url); | ||
| 1212 | + com.apple.eio.FileManager.openURL(url); | ||
| 1015 | 1213 | ||
| 1016 | 1214 | } else if (Base.isLinux()) { | |
| 1017 | 1215 | // how's mozilla sound to ya, laddie? | |
| Back | FazBrowse Home | New Git URL |
0 commit comments