2323
2424package processing .app ;
2525
26+ import java .awt .*;
27+ import java .awt .event .ActionListener ;
28+ import java .io .*;
29+ import java .lang .reflect .InvocationTargetException ;
30+ import java .util .*;
31+ import java .util .List ;
32+ import java .util .Map .Entry ;
33+
34+ import javax .swing .*;
35+ import javax .swing .tree .DefaultMutableTreeNode ;
36+
2637import com .formdev .flatlaf .FlatDarkLaf ;
2738import com .formdev .flatlaf .FlatLaf ;
2839import com .formdev .flatlaf .FlatLightLaf ;
3445import processing .core .PApplet ;
3546import processing .data .StringList ;
3647
37- import javax .swing .*;
38- import javax .swing .tree .DefaultMutableTreeNode ;
39- import java .awt .*;
40- import java .awt .event .ActionListener ;
41- import java .io .File ;
42- import java .io .FileInputStream ;
43- import java .io .IOException ;
44- import java .io .InputStream ;
45- import java .lang .reflect .InvocationTargetException ;
46- import java .util .*;
47- import java .util .List ;
48- import java .util .Map .Entry ;
49-
5048/**
5149 * The base class for the main processing application.
5250 * Primary role of this class is for platform identification and
@@ -231,7 +229,7 @@ static private void createAndShowGUI(String[] args) {
231229 Messages .log ("Base() constructor succeeded" );
232230
233231 // Prevent more than one copy of the PDE from running.
234- SingleInstance .startServer (base );
232+ new Thread (() -> { SingleInstance .startServer (base ); } ). start ( );
235233
236234 handleWelcomeScreen (base );
237235 handleCrustyDisplay ();
@@ -850,7 +848,7 @@ public List<ToolContribution> getContribTools() {
850848 return contribTools ;
851849 }
852850
853-
851+ private List < Tool > toolsToInit = new ArrayList <>();
854852 public void rebuildToolList () {
855853 // Only do these once because the list of internal tools will never change
856854 if (internalTools == null ) {
@@ -870,43 +868,12 @@ public void rebuildToolList() {
870868 // Only init() these the first time they're loaded
871869 if (coreTools == null ) {
872870 coreTools = ToolContribution .loadAll (Base .getToolsFolder ());
873- for (Tool tool : coreTools ) {
874- tool .init (this );
875- }
871+ toolsToInit .addAll (coreTools );
876872 }
877873
878874 // Reset the contributed tools and re-init() all of them.
879875 contribTools = ToolContribution .loadAll (Base .getSketchbookToolsFolder ());
880- for (Tool tool : contribTools ) {
881- try {
882- tool .init (this );
883-
884- // With the exceptions, we can't call statusError because the window
885- // isn't completely set up yet. Also not gonna pop up a warning because
886- // people may still be running different versions of Processing.
887-
888- } catch (VerifyError | AbstractMethodError ve ) {
889- System .err .println ("\" " + tool .getMenuTitle () + "\" is not " +
890- "compatible with this version of Processing" );
891- Messages .err ("Incompatible Tool found during tool.init()" , ve );
892-
893- } catch (NoSuchMethodError nsme ) {
894- System .err .println ("\" " + tool .getMenuTitle () + "\" is not " +
895- "compatible with this version of Processing" );
896- System .err .println ("The " + nsme .getMessage () + " method no longer exists." );
897- Messages .err ("Incompatible Tool found during tool.init()" , nsme );
898-
899- } catch (NoClassDefFoundError ncdfe ) {
900- System .err .println ("\" " + tool .getMenuTitle () + "\" is not " +
901- "compatible with this version of Processing" );
902- System .err .println ("The " + ncdfe .getMessage () + " class is no longer available." );
903- Messages .err ("Incompatible Tool found during tool.init()" , ncdfe );
904-
905- } catch (Error | Exception e ) {
906- System .err .println ("An error occurred inside \" " + tool .getMenuTitle () + "\" " );
907- e .printStackTrace ();
908- }
909- }
876+ toolsToInit .addAll (contribTools );
910877 }
911878
912879
@@ -915,7 +882,7 @@ protected void initInternalTool(Class<?> toolClass) {
915882 final Tool tool = (Tool )
916883 toolClass .getDeclaredConstructor ().newInstance ();
917884
918- tool . init ( this );
885+ toolsToInit . add ( tool );
919886 internalTools .add (tool );
920887
921888 } catch (Exception e ) {
@@ -963,12 +930,40 @@ public void populateToolsMenu(JMenu toolsMenu) {
963930 toolsMenu .add (manageTools );
964931 }
965932
933+ void initTool (Tool tool ) {
934+ if (!toolsToInit .contains (tool )) {return ;}
935+ try {
936+ tool .init (this );
937+ toolsToInit .remove (tool );
938+ } catch (VerifyError | AbstractMethodError ve ) {
939+ System .err .println ("\" " + tool .getMenuTitle () + "\" is not " +
940+ "compatible with this version of Processing" );
941+ Messages .err ("Incompatible Tool found during tool.init()" , ve );
942+
943+ } catch (NoSuchMethodError nsme ) {
944+ System .err .println ("\" " + tool .getMenuTitle () + "\" is not " +
945+ "compatible with this version of Processing" );
946+ System .err .println ("The " + nsme .getMessage () + " method no longer exists." );
947+ Messages .err ("Incompatible Tool found during tool.init()" , nsme );
948+
949+ } catch (NoClassDefFoundError ncdfe ) {
950+ System .err .println ("\" " + tool .getMenuTitle () + "\" is not " +
951+ "compatible with this version of Processing" );
952+ System .err .println ("The " + ncdfe .getMessage () + " class is no longer available." );
953+ Messages .err ("Incompatible Tool found during tool.init()" , ncdfe );
954+
955+ } catch (Error | Exception e ) {
956+ System .err .println ("An error occurred inside \" " + tool .getMenuTitle () + "\" " );
957+ e .printStackTrace ();
958+ }
959+ }
966960
967961 JMenuItem createToolItem (final Tool tool ) { //, Map<String, JMenuItem> toolItems) {
968962 String title = tool .getMenuTitle ();
969963 final JMenuItem item = new JMenuItem (title );
970964 item .addActionListener (e -> {
971965 try {
966+ initTool (tool );
972967 tool .run ();
973968
974969 } catch (NoSuchMethodError | NoClassDefFoundError ne ) {
0 commit comments