GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — processing/java/src/processing/mode/java/JavaEditor.java at master · ErikssonM/processing Expand file tree/ Copy pathJavaEditor.javaMore file actions 2808 lines (2353 loc) · 89.9 KB / Copy pathJavaEditor.javaFile metadata and controls2808 lines (2353 loc) · 89.9 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 package processing.mode.java; import java.awt.*; import java.awt.event.*; import java.beans.*; import java.io.*; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; import javax.swing.text.BadLocationException; import javax.swing.text.Document; import processing.core.PApplet; import processing.data.StringList; import processing.app.*; import processing.app.contrib.*; import processing.app.syntax.JEditTextArea; import processing.app.syntax.PdeTextArea; import processing.app.syntax.PdeTextAreaDefaults; import processing.app.ui.*; import processing.app.ui.Toolkit; import processing.mode.java.debug.LineBreakpoint; import processing.mode.java.debug.LineHighlight; import processing.mode.java.debug.LineID; import processing.mode.java.pdex.PreprocessingService; import processing.mode.java.pdex.ImportStatement; import processing.mode.java.pdex.JavaTextArea; import processing.mode.java.pdex.PDEX; import processing.mode.java.pdex.JavaProblem; import processing.mode.java.pdex.SourceUtils; import processing.mode.java.preproc.PdePreprocessor; import processing.mode.java.runner.Runner; import processing.mode.java.tweak.ColorControlBox; import processing.mode.java.tweak.Handle; import processing.mode.java.tweak.SketchParser; import processing.mode.java.tweak.TweakClient; public class JavaEditor extends Editor { JavaMode jmode; // Runner associated with this editor window private Runner runtime; private boolean runtimeLaunchRequested; private final Object runtimeLock = new Object[0]; // Need to sort through the rest of these additions [fry] protected final List<LineHighlight> breakpointedLines = new ArrayList<>(); protected LineHighlight currentLine; // where the debugger is suspended protected final String breakpointMarkerComment = " //<>//"; protected JMenu debugMenu; protected JMenuItem debugItem; protected Debugger debugger; protected boolean debugEnabled; protected VariableInspector inspector; protected JMenuItem inspectorItem; static final int ERROR_TAB_INDEX = 0; private boolean hasJavaTabs; private boolean javaTabWarned; protected PreprocessingService preprocessingService; protected PDEX pdex; protected JavaEditor(Base base, String path, EditorState state, Mode mode) throws EditorException { super(base, path, state, mode); jmode = (JavaMode) mode; debugger = new Debugger(this); inspector = new VariableInspector(this); // set breakpoints from marker comments for (LineID lineID : stripBreakpointComments()) { //System.out.println("setting: " + lineID); debugger.setBreakpoint(lineID); } // setting breakpoints will flag sketch as modified, so override this here getSketch().setModified(false); hasJavaTabs = checkForJavaTabs(); /* // hack to add a JPanel to the right-hand side of the text area JPanel textAndError = new JPanel(); // parent is a vertical box with the toolbar, the header, and the text area Box box = (Box) textarea.getParent(); // remove the text area temporarily box.remove(2); textAndError.setLayout(new BorderLayout()); errorColumn = new MarkerColumn(this, textarea.getMinimumSize().height); textAndError.add(errorColumn, BorderLayout.EAST); textarea.setBounds(0, 0, errorColumn.getX() - 1, textarea.getHeight()); textAndError.add(textarea); // add our hacked version back to the editor box.add(textAndError); */ preprocessingService = new PreprocessingService(this); pdex = new PDEX(this, preprocessingService); Toolkit.setMenuMnemonics(textarea.getRightClickPopup()); // ensure completion is hidden when editor loses focus addWindowFocusListener(new WindowFocusListener() { public void windowLostFocus(WindowEvent e) { getJavaTextArea().hideSuggestion(); } public void windowGainedFocus(WindowEvent e) { } }); } public PdePreprocessor createPreprocessor(final String sketchName) { return new PdePreprocessor(sketchName); } protected JEditTextArea createTextArea() { return new JavaTextArea(new PdeTextAreaDefaults(mode), this); } public EditorToolbar createToolbar() { return new JavaToolbar(this); } private int previousTabCount = 1; // TODO: this is a clumsy way to get notified when tabs get added/deleted // Override the parent call to add hook to the rebuild() method public EditorHeader createHeader() { return new EditorHeader(this) { public void rebuild() { super.rebuild(); // after Rename and New Tab, we may have new .java tabs boolean newHasJavaTabs = checkForJavaTabs(); boolean hasJavaTabsChanged = hasJavaTabs != newHasJavaTabs; hasJavaTabs = newHasJavaTabs; if (preprocessingService != null) { if (hasJavaTabsChanged) { preprocessingService.handleHasJavaTabsChange(hasJavaTabs); pdex.hasJavaTabsChanged(hasJavaTabs); if (hasJavaTabs) { setProblemList(Collections.emptyList()); } } int currentTabCount = sketch.getCodeCount(); if (currentTabCount != previousTabCount) { previousTabCount = currentTabCount; pdex.sketchChanged(); } } } }; } @Override public EditorFooter createFooter() { EditorFooter footer = super.createFooter(); addErrorTable(footer); return footer; } public Formatter createFormatter() { return new AutoFormat(); } // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . public JMenu buildFileMenu() { //String appTitle = JavaToolbar.getTitle(JavaToolbar.EXPORT, false); String appTitle = Language.text("menu.file.export_application"); JMenuItem exportApplication = Toolkit.newJMenuItemShift(appTitle, 'E'); exportApplication.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleExportApplication(); } }); return buildFileMenu(new JMenuItem[] { exportApplication }); } public JMenu buildSketchMenu() { JMenuItem runItem = Toolkit.newJMenuItem(Language.text("menu.sketch.run"), 'R'); runItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleRun(); } }); JMenuItem presentItem = Toolkit.newJMenuItemShift(Language.text("menu.sketch.present"), 'R'); presentItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handlePresent(); } }); JMenuItem stopItem = new JMenuItem(Language.text("menu.sketch.stop")); stopItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (isDebuggerEnabled()) { Messages.log("Invoked 'Stop' menu item"); debugger.stopDebug(); } else { handleStop(); } } }); JMenuItem tweakItem = Toolkit.newJMenuItemShift(Language.text("menu.sketch.tweak"), 'T'); // tweakItem.setSelected(JavaMode.enableTweak); tweakItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // JavaMode.enableTweak = true; // handleRun(); handleTweak(); } }); return buildSketchMenu(new JMenuItem[] { runItem, presentItem, tweakItem, stopItem }); } public JMenu buildHelpMenu() { JMenu menu = new JMenu(Language.text("menu.help")); JMenuItem item; // macosx already has its own about menu if (!Platform.isMacOS()) { item = new JMenuItem(Language.text("menu.help.about")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new About(JavaEditor.this); } }); menu.add(item); } item = new JMenuItem(Language.text("menu.help.welcome")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { new Welcome(base, Preferences.getSketchbookPath().equals(Preferences.getOldSketchbookPath())); } catch (IOException ioe) { Messages.showWarning("Unwelcome Error", "Please report this error to\n" + "https://github.com/processing/processing/issues", ioe); } } }); menu.add(item); item = new JMenuItem(Language.text("menu.help.environment")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showReference("environment" + File.separator + "index.html"); } }); menu.add(item); item = new JMenuItem(Language.text("menu.help.reference")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showReference("index.html"); } }); menu.add(item); item = Toolkit.newJMenuItemShift(Language.text("menu.help.find_in_reference"), 'F'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (textarea.isSelectionActive()) { handleFindReference(); } else { statusNotice(Language.text("editor.status.find_reference.select_word_first")); } } }); menu.add(item); menu.addSeparator(); final JMenu libRefSubmenu = new JMenu(Language.text("menu.help.libraries_reference")); // Populate only when sub-menu is opened, to avoid having spurious menu // options if a library is deleted, or a missing menu option if a library is added libRefSubmenu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { // Adding this in case references are included in a core library, // or other core libraries are included in the future boolean isCoreLibMenuItemAdded = addLibReferencesToSubMenu(mode.coreLibraries, libRefSubmenu); if (isCoreLibMenuItemAdded && !mode.contribLibraries.isEmpty()) { libRefSubmenu.addSeparator(); } boolean isContribLibMenuItemAdded = addLibReferencesToSubMenu(mode.contribLibraries, libRefSubmenu); if (!isContribLibMenuItemAdded && !isCoreLibMenuItemAdded) { JMenuItem emptyMenuItem = new JMenuItem(Language.text("menu.help.empty")); emptyMenuItem.setEnabled(false); emptyMenuItem.setFocusable(false); emptyMenuItem.setFocusPainted(false); libRefSubmenu.add(emptyMenuItem); } else if (!isContribLibMenuItemAdded && !mode.coreLibraries.isEmpty()) { //re-populate the menu to get rid of terminal separator libRefSubmenu.removeAll(); addLibReferencesToSubMenu(mode.coreLibraries, libRefSubmenu); } } @Override public void menuDeselected(MenuEvent e) { libRefSubmenu.removeAll(); } @Override public void menuCanceled(MenuEvent e) { menuDeselected(e); } }); menu.add(libRefSubmenu); final JMenu toolRefSubmenu = new JMenu(Language.text("menu.help.tools_reference")); // Populate only when sub-menu is opened, to avoid having spurious menu // options if a tool is deleted, or a missing menu option if a library is added toolRefSubmenu.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { boolean isCoreToolMenuItemAdded = false; boolean isContribToolMenuItemAdded = false; List<ToolContribution> contribTools = base.getToolContribs(); // Adding this in in case a reference folder is added for MovieMaker, or in case // other core tools are introduced later isCoreToolMenuItemAdded = addToolReferencesToSubMenu(base.getCoreTools(), toolRefSubmenu); if (isCoreToolMenuItemAdded && !contribTools.isEmpty()) toolRefSubmenu.addSeparator(); isContribToolMenuItemAdded = addToolReferencesToSubMenu(contribTools, toolRefSubmenu); if (!isContribToolMenuItemAdded && !isCoreToolMenuItemAdded) { toolRefSubmenu.removeAll(); // in case a separator was added final JMenuItem emptyMenuItem = new JMenuItem(Language.text("menu.help.empty")); emptyMenuItem.setEnabled(false); emptyMenuItem.setBorderPainted(false); emptyMenuItem.setFocusable(false); emptyMenuItem.setFocusPainted(false); toolRefSubmenu.add(emptyMenuItem); } else if (!isContribToolMenuItemAdded && !contribTools.isEmpty()) { // re-populate the menu to get rid of terminal separator toolRefSubmenu.removeAll(); addToolReferencesToSubMenu(base.getCoreTools(), toolRefSubmenu); } } @Override public void menuDeselected(MenuEvent e) { toolRefSubmenu.removeAll(); } @Override public void menuCanceled(MenuEvent e) { menuDeselected(e); } }); menu.add(toolRefSubmenu); menu.addSeparator(); item = new JMenuItem(Language.text("menu.help.online")); item.setEnabled(false); menu.add(item); item = new JMenuItem(Language.text("menu.help.getting_started")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Platform.openURL(Language.text("menu.help.getting_started.url")); } }); menu.add(item); item = new JMenuItem(Language.text("menu.help.troubleshooting")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Platform.openURL(Language.text("menu.help.troubleshooting.url")); } }); menu.add(item); item = new JMenuItem(Language.text("menu.help.faq")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Platform.openURL(Language.text("menu.help.faq.url")); } }); menu.add(item); item = new JMenuItem(Language.text("menu.help.foundation")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Platform.openURL(Language.text("menu.help.foundation.url")); } }); menu.add(item); item = new JMenuItem(Language.text("menu.help.visit")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Platform.openURL(Language.text("menu.help.visit.url")); } }); menu.add(item); return menu; } //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . /** * Populates the JMenu with JMenuItems, one for each Library that has a * reference accompanying it. The JMenuItems open the index.htm/index.html * file of the reference in the user's default browser, or the readme.txt in * the user's default text editor. * * @param libsList * A list of the Libraries to be added * @param subMenu * The JMenu to which the JMenuItems corresponding to the Libraries * are to be added * @return true if and only if any JMenuItems were added; false otherwise */ private boolean addLibReferencesToSubMenu(List<Library> libsList, JMenu subMenu) { boolean isItemAdded = false; Iterator<Library> iter = libsList.iterator(); while (iter.hasNext()) { final Library libContrib = iter.next(); if (libContrib.hasReference()) { JMenuItem libRefItem = new JMenuItem(libContrib.getName()); libRefItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { showReferenceFile(libContrib.getReferenceIndexFile()); } }); subMenu.add(libRefItem); isItemAdded = true; } } return isItemAdded; } /** * Populates the JMenu with JMenuItems, one for each Tool that has a reference * accompanying it. The JMenuItems open the index.htm/index.html file of the * reference in the user's default browser, or the readme.txt in the user's * default text editor. * * @param toolsList * A list of Tools to be added * @param subMenu * The JMenu to which the JMenuItems corresponding to the Tools are * to be added * @return true if and only if any JMenuItems were added; false otherwise */ private boolean addToolReferencesToSubMenu(List<ToolContribution> toolsList, JMenu subMenu) { boolean isItemAdded = false; Iterator<ToolContribution> iter = toolsList.iterator(); while (iter.hasNext()) { final ToolContribution toolContrib = iter.next(); final File toolRef = new File(toolContrib.getFolder(), "reference/index.html"); if (toolRef.exists()) { JMenuItem libRefItem = new JMenuItem(toolContrib.getName()); libRefItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { showReferenceFile(toolRef); } }); subMenu.add(libRefItem); isItemAdded = true; } } return isItemAdded; } // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . public String getCommentPrefix() { return "//"; } // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . /** * Called by Sketch → Export. * Handles calling the export() function on sketch, and * queues all the gui status stuff that comes along with it. * <p/> * Made synchronized to (hopefully) avoid problems of people * hitting export twice, quickly, and horking things up. */ /* public void handleExportApplet() { if (handleExportCheckModified()) { toolbar.activate(JavaToolbar.EXPORT); try { boolean success = jmode.handleExportApplet(sketch); if (success) { File appletFolder = new File(sketch.getFolder(), "applet"); Base.openFolder(appletFolder); statusNotice("Done exporting."); } else { // error message will already be visible } } catch (Exception e) { statusError(e); } toolbar.deactivate(JavaToolbar.EXPORT); } } */ /** * Handler for Sketch → Export Application */ public void handleExportApplication() { // toolbar.activate(JavaToolbar.EXPORT); if (handleExportCheckModified()) { statusNotice(Language.text("export.notice.exporting")); try { if (exportApplicationPrompt()) { Platform.openFolder(sketch.getFolder()); statusNotice(Language.text("export.notice.exporting.done")); } else { // error message will already be visible // or there was no error, in which case it was canceled. } } catch (Exception e) { statusNotice(Language.text("export.notice.exporting.error")); e.printStackTrace(); } } // toolbar.deactivate(JavaToolbar.EXPORT); } // Can't be .windows because that'll be stripped off as a per-platform pref static final String EXPORT_PREFIX = "export.application.platform_"; static final String EXPORT_MACOSX = EXPORT_PREFIX + "macosx"; static final String EXPORT_WINDOWS = EXPORT_PREFIX + "windows"; static final String EXPORT_LINUX = EXPORT_PREFIX + "linux"; final JButton exportButton = new JButton(Language.text("prompt.export")); final JButton cancelButton = new JButton(Language.text("prompt.cancel")); final JCheckBox windowsButton = new JCheckBox("Windows"); final JCheckBox macosxButton = new JCheckBox("Mac OS X"); final JCheckBox linuxButton = new JCheckBox("Linux"); protected void updateExportButton() { exportButton.setEnabled(windowsButton.isSelected() || macosxButton.isSelected() || linuxButton.isSelected()); } protected boolean exportApplicationPrompt() throws IOException, SketchException { JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.add(Box.createVerticalStrut(6)); // Box panel = Box.createVerticalBox(); // Box labelBox = Box.createHorizontalBox(); // String msg = "<html>Click Export to Application to create a standalone, " + // "double-clickable application for the selected plaforms."; // String msg = "Export to Application creates a standalone, \n" + // "double-clickable application for the selected plaforms."; String line1 = Language.text("export.description.line1"); String line2 = Language.text("export.description.line2"); //String line2 = "standalone application for the current plaform."; JLabel label1 = new JLabel(line1, SwingConstants.CENTER); JLabel label2 = new JLabel(line2, SwingConstants.CENTER); label1.setAlignmentX(Component.LEFT_ALIGNMENT); label2.setAlignmentX(Component.LEFT_ALIGNMENT); panel.add(label1); panel.add(label2); // The longer line is different between Windows and OS X. // int wide = Math.max(label1.getPreferredSize().width, // label2.getPreferredSize().width); panel.add(Box.createVerticalStrut(12)); // final JCheckBox windowsButton = new JCheckBox("Windows"); // final JCheckBox macosxButton = new JCheckBox("Mac OS X"); // final JCheckBox linuxButton = new JCheckBox("Linux"); windowsButton.setSelected(Preferences.getBoolean(EXPORT_WINDOWS)); windowsButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { Preferences.setBoolean(EXPORT_WINDOWS, windowsButton.isSelected()); updateExportButton(); } }); // Only possible to export OS X applications on OS X if (!Platform.isMacOS()) { // Make sure they don't have a previous 'true' setting for this Preferences.setBoolean(EXPORT_MACOSX, false); } macosxButton.setSelected(Preferences.getBoolean(EXPORT_MACOSX)); macosxButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { Preferences.setBoolean(EXPORT_MACOSX, macosxButton.isSelected()); updateExportButton(); } }); if (!Platform.isMacOS()) { macosxButton.setEnabled(false); macosxButton.setToolTipText(Language.text("export.tooltip.macosx")); } linuxButton.setSelected(Preferences.getBoolean(EXPORT_LINUX)); linuxButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { Preferences.setBoolean(EXPORT_LINUX, linuxButton.isSelected()); updateExportButton(); } }); updateExportButton(); // do the initial enable/disable based on prefs.txt JPanel platformPanel = new JPanel(); //platformPanel.setLayout(new BoxLayout(platformPanel, BoxLayout.X_AXIS)); platformPanel.add(windowsButton); platformPanel.add(Box.createHorizontalStrut(6)); platformPanel.add(macosxButton); platformPanel.add(Box.createHorizontalStrut(6)); platformPanel.add(linuxButton); platformPanel.setBorder(new TitledBorder(Language.text("export.platforms"))); //Dimension goodIdea = new Dimension(wide, platformPanel.getPreferredSize().height); //platformPanel.setMaximumSize(goodIdea); // wide = Math.max(wide, platformPanel.getPreferredSize().width); platformPanel.setAlignmentX(Component.LEFT_ALIGNMENT); panel.add(platformPanel); int divWidth = platformPanel.getPreferredSize().width; //int indent = new JCheckBox().getPreferredSize().width; int indent = 0; final JCheckBox showStopButton = new JCheckBox(Language.text("export.options.show_stop_button")); showStopButton.setSelected(Preferences.getBoolean("export.application.stop")); showStopButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { Preferences.setBoolean("export.application.stop", showStopButton.isSelected()); } }); showStopButton.setEnabled(Preferences.getBoolean("export.application.present")); showStopButton.setBorder(new EmptyBorder(3, 13 + indent, 6, 13)); final JCheckBox presentButton = new JCheckBox(Language.text("export.options.present")); presentButton.setSelected(Preferences.getBoolean("export.application.present")); presentButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { boolean sal = presentButton.isSelected(); Preferences.setBoolean("export.application.present", sal); showStopButton.setEnabled(sal); } }); presentButton.setBorder(new EmptyBorder(3, 13, 3, 13)); JPanel presentPanel = new JPanel(); presentPanel.setLayout(new BoxLayout(presentPanel, BoxLayout.Y_AXIS)); Box fullScreenBox = Box.createHorizontalBox(); fullScreenBox.add(presentButton); /* //run.present.stop.color // presentColorPanel = new JTextField(); // presentColorPanel.setFocusable(false); // presentColorPanel.setEnabled(false); presentColorPanel = new JPanel() { public void paintComponent(Graphics g) { g.setColor(Preferences.getColor("run.present.bgcolor")); Dimension size = getSize(); g.fillRect(0, 0, size.width, size.height); } }; presentColorPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); // presentColorPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); presentColorPanel.setMaximumSize(new Dimension(30, 20)); fullScreenBox.add(presentColorPanel); */ fullScreenBox.add(new ColorPreference("run.present.bgcolor")); //presentPanel.add(fullScreenButton); fullScreenBox.add(Box.createHorizontalStrut(10)); fullScreenBox.add(Box.createHorizontalGlue()); presentPanel.add(fullScreenBox); // presentColorPanel.addMouseListener(new MouseAdapter() { // public void mousePressed(MouseEvent e) { // new ColorListener("run.present.bgcolor"); // } // }); Box showStopBox = Box.createHorizontalBox(); showStopBox.add(showStopButton); showStopBox.add(new ColorPreference("run.present.stop.color")); showStopBox.add(Box.createHorizontalStrut(10)); showStopBox.add(Box.createHorizontalGlue()); presentPanel.add(showStopBox); //presentPanel.add(showStopButton); // presentPanel.add(Box.createHorizontalStrut(10)); // presentPanel.add(Box.createHorizontalGlue()); presentPanel.setBorder(new TitledBorder(Language.text("export.full_screen"))); // wide = Math.max(wide, platformPanel.getPreferredSize().width); presentPanel.setAlignmentX(Component.LEFT_ALIGNMENT); panel.add(presentPanel); // Dimension good; // good = new Dimension(wide, label1.getPreferredSize().height); // label1.setMaximumSize(good); // good = new Dimension(wide, label2.getPreferredSize().height); // label2.setMaximumSize(good); // good = new Dimension(wide, presentPanel.getPreferredSize().height); // JPanel embedPanel = new JPanel(); embedPanel.setLayout(new BoxLayout(embedPanel, BoxLayout.Y_AXIS)); String platformName = null; if (Platform.isMacOS()) { platformName = "Mac OS X"; } else if (Platform.isWindows()) { platformName = "Windows (" + Platform.getNativeBits() + "-bit)"; } else if (Platform.isLinux()) { platformName = "Linux (" + Platform.getNativeBits() + "-bit)"; } boolean embed = Preferences.getBoolean("export.application.embed_java"); final String embedWarning = "<html><div width=\"" + divWidth + "\"><font size=\"2\">" + // "<html><body><font size=2>" + "Embedding Java will make the " + platformName + " application " + "larger, but it will be far more likely to work. " + "Users on other platforms will need to " + "<a href=\"\">install Java " + PApplet.javaPlatform + "</a>."; final String nopeWarning = "<html><div width=\"" + divWidth + "\"><font size=\"2\">" + // "<html><body><font size=2>" + "Users on all platforms will have to install the latest " + "version of Java " + PApplet.javaPlatform + " from <a href=\"\">http://java.com/download</a>. " + "<br/> "; //"from <a href=\"http://java.com/download\">java.com/download</a>."; final JLabel warningLabel = new JLabel(embed ? embedWarning : nopeWarning); warningLabel.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent event) { Platform.openURL("http://java.com/download"); } }); warningLabel.setBorder(new EmptyBorder(3, 13 + indent, 3, 13)); final JCheckBox embedJavaButton = new JCheckBox(Language.text("export.embed_java.for") + " " + platformName); embedJavaButton.setSelected(embed); embedJavaButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { boolean selected = embedJavaButton.isSelected(); Preferences.setBoolean("export.application.embed_java", selected); if (selected) { warningLabel.setText(embedWarning); } else { warningLabel.setText(nopeWarning); } } }); embedJavaButton.setBorder(new EmptyBorder(3, 13, 3, 13)); embedPanel.add(embedJavaButton); embedPanel.add(warningLabel); embedPanel.setBorder(new TitledBorder(Language.text("export.embed_java"))); panel.add(embedPanel); // if (Platform.isMacOS()) { JPanel signPanel = new JPanel(); signPanel.setLayout(new BoxLayout(signPanel, BoxLayout.Y_AXIS)); signPanel.setBorder(new TitledBorder(Language.text("export.code_signing"))); // gatekeeper: http://support.apple.com/kb/ht5290 // for developers: https://developer.apple.com/developer-id/ String thePain = //"<html><body><font size=2>" + "In recent versions of OS X, Apple has introduced the \u201CGatekeeper\u201D system, " + "which makes it more difficult to run applications like those exported from Processing. "; if (new File("/usr/bin/codesign_allocate").exists()) { thePain += "This application will be \u201Cself-signed\u201D which means that Finder may report that the " + "application is from an \u201Cunidentified developer\u201D. If the application will not " + "run, try right-clicking the app and selecting Open from the pop-up menu. Or you can visit " + "System Preferences \u2192 Security & Privacy and select Allow apps downloaded from: anywhere. "; } else { thePain += "Gatekeeper requires applications to be \u201Csigned\u201D, or they will be reported as damaged. " + "To prevent this message, install Xcode (and the Command Line Tools) from the App Store, or visit " + "System Preferences \u2192 Security & Privacy and select Allow apps downloaded from: anywhere. "; } thePain += "To avoid the messages entirely, manually code sign your app. " + "For more information: <a href=\"\">https://developer.apple.com/developer-id/</a>"; // xattr -d com.apple.quarantine thesketch.app //signPanel.add(new JLabel(thePain)); //JEditorPane area = new JEditorPane("text/html", thePain); //JTextPane area = new JEditorPane("text/html", thePain); // JTextArea area = new JTextArea(thePain); // area.setBackground(null); // area.setFont(new Font("Dialog", Font.PLAIN, 10)); // area.setLineWrap(true); // area.setWrapStyleWord(true); // Are you f-king serious, Java API developers? JLabel area = new JLabel("<html><div width=\"" + divWidth + "\"><font size=\"2\">" + thePain + "</div></html>"); area.setBorder(new EmptyBorder(3, 13, 3, 13)); // area.setPreferredSize(new Dimension(embedPanel.getPreferredSize().width, 100)); // area.setPreferredSize(new Dimension(300, 200)); signPanel.add(area); // signPanel.add(Box.createHorizontalGlue()); signPanel.setAlignmentX(Component.LEFT_ALIGNMENT); area.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent event) { Platform.openURL("https://developer.apple.com/developer-id/"); } }); panel.add(signPanel); } // //String[] options = { Language.text("prompt.export"), Language.text("prompt.cancel") }; final JButton[] options = { exportButton, cancelButton }; final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, exportButton); //options[0]); final JDialog dialog = new JDialog(this, Language.text("export"), true); dialog.setContentPane(optionPane); exportButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { optionPane.setValue(exportButton); } }); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { optionPane.setValue(cancelButton); } }); optionPane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if (dialog.isVisible() && (e.getSource() == optionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY))) { // If you were going to check something before // closing the window, you'd do it here. dialog.setVisible(false); } } }); dialog.pack(); // System.out.println("after pack: " + panel.getPreferredSize()); // dialog.setSize(optionPane.getPreferredSize()); dialog.setResizable(false); // Center the window in the middle of the editor Rectangle bounds = getBounds(); dialog.setLocation(bounds.x + (bounds.width - dialog.getSize().width) / 2, bounds.y + (bounds.height - dialog.getSize().height) / 2); dialog.setVisible(true); Object value = optionPane.getValue(); if (value.equals(exportButton)) { return jmode.handleExportApplication(sketch); } else if (value.equals(cancelButton) || value.equals(-1)) { // closed window by hitting Cancel or ESC statusNotice(Language.text("export.notice.exporting.cancel")); } return false; } class ColorPreference extends JPanel implements ActionListener { ColorChooser chooser; String prefName; public ColorPreference(String pref) { prefName = pref; setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); setPreferredSize(new Dimension(30, 20)); setMaximumSize(new Dimension(30, 20)); addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { Color color = Preferences.getColor(prefName); chooser = new ColorChooser(JavaEditor.this, true, color, Language.text("color_chooser.select"), ColorPreference.this); chooser.show(); } }); } public void paintComponent(Graphics g) { g.setColor(Preferences.getColor(prefName)); Dimension size = getSize(); g.fillRect(0, 0, size.width, size.height); } public void actionPerformed(ActionEvent e) { Color color = chooser.getColor(); Preferences.setColor(prefName, color); //presentColorPanel.repaint(); repaint(); chooser.hide(); } } // protected void selectColor(String prefName) { // Color color = Preferences.getColor(prefName); // final ColorChooser chooser = new ColorChooser(JavaEditor.this, true, color, // "Select", new ActionListener() { // // @Override // public void actionPerformed(ActionEvent e) { // Preferences.setColor(prefName, c.getColor()); // } // }); // } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |