@@ -269,40 +269,30 @@ static private void createAndShowGUI(String[] args) {
269
269
// https://github.com/processing/processing/issues/4997
270
270
static private void checkDriverBug () {
271
271
if (System .getProperty ("os.name" ).contains ("Windows 10" )) {
272
- new Thread (new Runnable () {
273
- public void run () {
274
- try {
275
- Process p = Runtime .getRuntime ().exec ("powershell Get-WmiObject Win32_PnPSignedDriver| select devicename, driverversion | where {$_.devicename -like \\ \" *nvidia*\\ \" }" );
276
- BufferedReader reader = PApplet .createReader (p .getInputStream ());
277
- String line = null ;
278
- while ((line = reader .readLine ()) != null ) {
279
- if (line .contains ("3.7849" )) {
280
- EventQueue .invokeLater (new Runnable () {
281
- public void run () {
282
- Messages .showWarning ("NVIDIA screwed up" ,
283
- "Due to an NVIDIA bug, you need to update your graphics drivers,\n " +
284
- "otherwise you won't be able to run any sketches. Update here:\n " +
285
- "http://nvidia.custhelp.com/app/answers/detail/a_id/4378\n " +
286
- "or read background about the issue at this link:\n " +
287
- "https://github.com/processing/processing/issues/4853" );
288
- }
289
- });
290
- } else if (line .contains ("3.8165" )) {
291
- EventQueue .invokeLater (new Runnable () {
292
- public void run () {
293
- Messages .showWarning ("NVIDIA screwed up again" ,
294
- "Due to an NVIDIA bug, you need to update your graphics drivers,\n " +
295
- "otherwise you won't be able to run any sketches. Update here:\n " +
296
- "http://nvidia.custhelp.com/app/answers/detail/a_id/4453/\n " +
297
- "or read background about the issue at this link:\n " +
298
- "https://github.com/processing/processing/issues/4997" );
299
- }
300
- });
301
- }
272
+ new Thread (() -> {
273
+ try {
274
+ Process p = Runtime .getRuntime ().exec ("powershell Get-WmiObject Win32_PnPSignedDriver| select devicename, driverversion | where {$_.devicename -like \\ \" *nvidia*\\ \" }" );
275
+ BufferedReader reader = PApplet .createReader (p .getInputStream ());
276
+ String line ;
277
+ while ((line = reader .readLine ()) != null ) {
278
+ if (line .contains ("3.7849" )) {
279
+ EventQueue .invokeLater (() -> Messages .showWarning ("NVIDIA screwed up" ,
280
+ "Due to an NVIDIA bug, you need to update your graphics drivers,\n " +
281
+ "otherwise you won't be able to run any sketches. Update here:\n " +
282
+ "http://nvidia.custhelp.com/app/answers/detail/a_id/4378\n " +
283
+ "or read background about the issue at this link:\n " +
284
+ "https://github.com/processing/processing/issues/4853" ));
285
+ } else if (line .contains ("3.8165" )) {
286
+ EventQueue .invokeLater (() -> Messages .showWarning ("NVIDIA screwed up again" ,
287
+ "Due to an NVIDIA bug, you need to update your graphics drivers,\n " +
288
+ "otherwise you won't be able to run any sketches. Update here:\n " +
289
+ "http://nvidia.custhelp.com/app/answers/detail/a_id/4453/\n " +
290
+ "or read background about the issue at this link:\n " +
291
+ "https://github.com/processing/processing/issues/4997" ));
302
292
}
303
- } catch (Exception e ) {
304
- Messages .loge ("Problem checking NVIDIA driver" , e );
305
293
}
294
+ } catch (Exception e ) {
295
+ Messages .loge ("Problem checking NVIDIA driver" , e );
306
296
}
307
297
}).start ();
308
298
}
@@ -436,36 +426,19 @@ public JMenu initDefaultFileMenu() {
436
426
defaultFileMenu = new JMenu (Language .text ("menu.file" ));
437
427
438
428
JMenuItem item = Toolkit .newJMenuItem (Language .text ("menu.file.new" ), 'N' );
439
- item .addActionListener (new ActionListener () {
440
- public void actionPerformed (ActionEvent e ) {
441
- handleNew ();
442
- }
443
- });
429
+ item .addActionListener (e -> handleNew ());
444
430
defaultFileMenu .add (item );
445
431
446
432
item = Toolkit .newJMenuItem (Language .text ("menu.file.open" ), 'O' );
447
- item .addActionListener (new ActionListener () {
448
- public void actionPerformed (ActionEvent e ) {
449
- handleOpenPrompt ();
450
- }
451
- });
433
+ item .addActionListener (e -> handleOpenPrompt ());
452
434
defaultFileMenu .add (item );
453
435
454
436
item = Toolkit .newJMenuItemShift (Language .text ("menu.file.sketchbook" ), 'K' );
455
- item .addActionListener (new ActionListener () {
456
- @ Override
457
- public void actionPerformed (ActionEvent e ) {
458
- getNextMode ().showSketchbookFrame ();
459
- }
460
- });
437
+ item .addActionListener (e -> getNextMode ().showSketchbookFrame ());
461
438
defaultFileMenu .add (item );
462
439
463
440
item = Toolkit .newJMenuItemShift (Language .text ("menu.file.examples" ), 'O' );
464
- item .addActionListener (new ActionListener () {
465
- public void actionPerformed (ActionEvent e ) {
466
- thinkDifferentExamples ();
467
- }
468
- });
441
+ item .addActionListener (e -> thinkDifferentExamples ());
469
442
defaultFileMenu .add (item );
470
443
471
444
return defaultFileMenu ;
@@ -516,12 +489,9 @@ void rebuildContribModes() {
516
489
if (!known .containsKey (folder )) {
517
490
try {
518
491
contribModes .add (new ModeContribution (this , folder , null ));
519
- } catch (NoSuchMethodError nsme ) {
492
+ } catch (NoSuchMethodError | NoClassDefFoundError ne ) {
520
493
System .err .println (folder .getName () + " is not compatible with this version of Processing" );
521
- if (DEBUG ) nsme .printStackTrace ();
522
- } catch (NoClassDefFoundError ncdfe ) {
523
- System .err .println (folder .getName () + " is not compatible with this version of Processing" );
524
- if (DEBUG ) ncdfe .printStackTrace ();
494
+ if (DEBUG ) ne .printStackTrace ();
525
495
} catch (InvocationTargetException ite ) {
526
496
System .err .println (folder .getName () + " could not be loaded and may not compatible with this version of Processing" );
527
497
if (DEBUG ) ite .printStackTrace ();
@@ -837,11 +807,7 @@ public void populateToolsMenu(JMenu toolsMenu) {
837
807
}
838
808
839
809
JMenuItem item = new JMenuItem (Language .text ("menu.tools.add_tool" ));
840
- item .addActionListener (new ActionListener () {
841
- public void actionPerformed (ActionEvent e ) {
842
- ContributionManager .openTools ();
843
- }
844
- });
810
+ item .addActionListener (e -> ContributionManager .openTools ());
845
811
toolsMenu .add (item );
846
812
}
847
813
@@ -872,24 +838,21 @@ static public void addTools(JMenu menu, List<Tool> tools) {
872
838
JMenuItem createToolItem (final Tool tool ) { //, Map<String, JMenuItem> toolItems) {
873
839
String title = tool .getMenuTitle ();
874
840
final JMenuItem item = new JMenuItem (title );
875
- item .addActionListener (new ActionListener () {
841
+ item .addActionListener (e -> {
842
+ try {
843
+ tool .run ();
876
844
877
- public void actionPerformed (ActionEvent e ) {
878
- try {
879
- tool .run ();
880
-
881
- } catch (NoSuchMethodError | java .lang .NoClassDefFoundError ne ) {
882
- Messages .showWarning ("Tool out of date" ,
883
- tool .getMenuTitle () + " is not compatible with this version of Processing.\n " +
884
- "Try updating the Mode or contact its author for a new version." , ne );
885
- Messages .loge ("Incompatible tool found during tool.run()" , ne );
886
- item .setEnabled (false );
887
-
888
- } catch (Exception ex ) {
889
- activeEditor .statusError ("An error occurred inside \" " + tool .getMenuTitle () + "\" " );
890
- ex .printStackTrace ();
891
- item .setEnabled (false );
892
- }
845
+ } catch (NoSuchMethodError | NoClassDefFoundError ne ) {
846
+ Messages .showWarning ("Tool out of date" ,
847
+ tool .getMenuTitle () + " is not compatible with this version of Processing.\n " +
848
+ "Try updating the Mode or contact its author for a new version." , ne );
849
+ Messages .loge ("Incompatible tool found during tool.run()" , ne );
850
+ item .setEnabled (false );
851
+
852
+ } catch (Exception ex ) {
853
+ activeEditor .statusError ("An error occurred inside \" " + tool .getMenuTitle () + "\" " );
854
+ ex .printStackTrace ();
855
+ item .setEnabled (false );
893
856
}
894
857
});
895
858
//toolItems.put(title, item);
@@ -906,8 +869,7 @@ public List<ModeContribution> getModeContribs() {
906
869
907
870
908
871
public List <Mode > getModeList () {
909
- List <Mode > allModes = new ArrayList <>();
910
- allModes .addAll (Arrays .asList (coreModes ));
872
+ List <Mode > allModes = new ArrayList <>(Arrays .asList (coreModes ));
911
873
if (modeContribs != null ) {
912
874
for (ModeContribution contrib : modeContribs ) {
913
875
allModes .add (contrib .getMode ());
@@ -923,10 +885,8 @@ public List<ExamplesContribution> getExampleContribs() {
923
885
924
886
925
887
private List <Contribution > getInstalledContribs () {
926
- List <Contribution > contributions = new ArrayList <>();
927
-
928
888
List <ModeContribution > modeContribs = getModeContribs ();
929
- contributions . addAll (modeContribs );
889
+ List < Contribution > contributions = new ArrayList <> (modeContribs );
930
890
931
891
for (ModeContribution modeContrib : modeContribs ) {
932
892
Mode mode = modeContrib .getMode ();
@@ -1169,8 +1129,8 @@ protected Mode findMode(String id) {
1169
1129
*/
1170
1130
public void handleNew () {
1171
1131
try {
1172
- File newbieDir = null ;
1173
- String newbieName = null ;
1132
+ File newbieDir ;
1133
+ String newbieName ;
1174
1134
1175
1135
// In 0126, untitled sketches will begin in the temp folder,
1176
1136
// and then moved to a new location because Save will default to Save As.
@@ -1182,7 +1142,7 @@ public void handleNew() {
1182
1142
// Use a generic name like sketch_031008a, the date plus a char
1183
1143
int index = 0 ;
1184
1144
String format = Preferences .get ("editor.untitled.suffix" );
1185
- String suffix = null ;
1145
+ String suffix ;
1186
1146
if (format == null ) {
1187
1147
Calendar cal = Calendar .getInstance ();
1188
1148
int day = cal .get (Calendar .DAY_OF_MONTH ); // 1..31
@@ -1269,16 +1229,14 @@ public void handleOpenPrompt() {
1269
1229
new FileDialog (activeEditor , prompt , FileDialog .LOAD );
1270
1230
1271
1231
// Only show .pde files as eligible bachelors
1272
- openDialog .setFilenameFilter (new FilenameFilter () {
1273
- public boolean accept (File dir , String name ) {
1274
- // confirmed to be working properly [fry 110128]
1275
- for (String ext : extensions ) {
1276
- if (name .toLowerCase ().endsWith ("." + ext )) { //$NON-NLS-1$
1277
- return true ;
1278
- }
1232
+ openDialog .setFilenameFilter ((dir , name ) -> {
1233
+ // confirmed to be working properly [fry 110128]
1234
+ for (String ext : extensions ) {
1235
+ if (name .toLowerCase ().endsWith ("." + ext )) { //$NON-NLS-1$
1236
+ return true ;
1279
1237
}
1280
- return false ;
1281
1238
}
1239
+ return false ;
1282
1240
});
1283
1241
1284
1242
openDialog .setVisible (true );
@@ -1630,11 +1588,7 @@ protected boolean handleQuitEach() {
1630
1588
* to prevent the interface from locking up until the menus are done.
1631
1589
*/
1632
1590
protected void rebuildSketchbookMenusAsync () {
1633
- EventQueue .invokeLater (new Runnable () {
1634
- public void run () {
1635
- rebuildSketchbookMenus ();
1636
- }
1637
- });
1591
+ EventQueue .invokeLater (this ::rebuildSketchbookMenus );
1638
1592
}
1639
1593
1640
1594
@@ -1738,27 +1692,21 @@ protected boolean addSketches(JMenu menu, File folder,
1738
1692
// Alphabetize the list, since it's not always alpha order
1739
1693
Arrays .sort (list , String .CASE_INSENSITIVE_ORDER );
1740
1694
1741
- ActionListener listener = new ActionListener () {
1742
- public void actionPerformed (ActionEvent e ) {
1743
- String path = e .getActionCommand ();
1744
- if (new File (path ).exists ()) {
1745
- boolean replace = replaceExisting ;
1746
- if ((e .getModifiers () & ActionEvent .SHIFT_MASK ) != 0 ) {
1747
- replace = !replace ;
1748
- }
1749
- // if (replace) {
1750
- // handleOpenReplace(path);
1751
- // } else {
1752
- handleOpen (path );
1753
- // }
1754
- } else {
1755
- Messages .showWarning ("Sketch Disappeared" ,
1756
- "The selected sketch no longer exists.\n " +
1757
- "You may need to restart Processing to update\n " +
1758
- "the sketchbook menu." , null );
1759
- }
1695
+ ActionListener listener = e -> {
1696
+ String path = e .getActionCommand ();
1697
+ if (new File (path ).exists ()) {
1698
+ boolean replace = replaceExisting ;
1699
+ if ((e .getModifiers () & ActionEvent .SHIFT_MASK ) != 0 ) {
1700
+ replace = !replace ;
1760
1701
}
1761
- };
1702
+ handleOpen (path );
1703
+ } else {
1704
+ Messages .showWarning ("Sketch Disappeared" ,
1705
+ "The selected sketch no longer exists.\n " +
1706
+ "You may need to restart Processing to update\n " +
1707
+ "the sketchbook menu." , null );
1708
+ }
1709
+ };
1762
1710
// offers no speed improvement
1763
1711
//menu.addActionListener(listener);
1764
1712
0 commit comments