Skip to content

Commit 64e5929

Browse files
committed
lambda city, population: this source file
1 parent 832cc07 commit 64e5929

File tree

1 file changed

+69
-121
lines changed

1 file changed

+69
-121
lines changed

app/src/processing/app/Base.java

Lines changed: 69 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -269,40 +269,30 @@ static private void createAndShowGUI(String[] args) {
269269
// https://github.com/processing/processing/issues/4997
270270
static private void checkDriverBug() {
271271
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"));
302292
}
303-
} catch (Exception e) {
304-
Messages.loge("Problem checking NVIDIA driver", e);
305293
}
294+
} catch (Exception e) {
295+
Messages.loge("Problem checking NVIDIA driver", e);
306296
}
307297
}).start();
308298
}
@@ -436,36 +426,19 @@ public JMenu initDefaultFileMenu() {
436426
defaultFileMenu = new JMenu(Language.text("menu.file"));
437427

438428
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());
444430
defaultFileMenu.add(item);
445431

446432
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());
452434
defaultFileMenu.add(item);
453435

454436
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());
461438
defaultFileMenu.add(item);
462439

463440
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());
469442
defaultFileMenu.add(item);
470443

471444
return defaultFileMenu;
@@ -516,12 +489,9 @@ void rebuildContribModes() {
516489
if (!known.containsKey(folder)) {
517490
try {
518491
contribModes.add(new ModeContribution(this, folder, null));
519-
} catch (NoSuchMethodError nsme) {
492+
} catch (NoSuchMethodError | NoClassDefFoundError ne) {
520493
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();
525495
} catch (InvocationTargetException ite) {
526496
System.err.println(folder.getName() + " could not be loaded and may not compatible with this version of Processing");
527497
if (DEBUG) ite.printStackTrace();
@@ -837,11 +807,7 @@ public void populateToolsMenu(JMenu toolsMenu) {
837807
}
838808

839809
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());
845811
toolsMenu.add(item);
846812
}
847813

@@ -872,24 +838,21 @@ static public void addTools(JMenu menu, List<Tool> tools) {
872838
JMenuItem createToolItem(final Tool tool) { //, Map<String, JMenuItem> toolItems) {
873839
String title = tool.getMenuTitle();
874840
final JMenuItem item = new JMenuItem(title);
875-
item.addActionListener(new ActionListener() {
841+
item.addActionListener(e -> {
842+
try {
843+
tool.run();
876844

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);
893856
}
894857
});
895858
//toolItems.put(title, item);
@@ -906,8 +869,7 @@ public List<ModeContribution> getModeContribs() {
906869

907870

908871
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));
911873
if (modeContribs != null) {
912874
for (ModeContribution contrib : modeContribs) {
913875
allModes.add(contrib.getMode());
@@ -923,10 +885,8 @@ public List<ExamplesContribution> getExampleContribs() {
923885

924886

925887
private List<Contribution> getInstalledContribs() {
926-
List<Contribution> contributions = new ArrayList<>();
927-
928888
List<ModeContribution> modeContribs = getModeContribs();
929-
contributions.addAll(modeContribs);
889+
List<Contribution> contributions = new ArrayList<>(modeContribs);
930890

931891
for (ModeContribution modeContrib : modeContribs) {
932892
Mode mode = modeContrib.getMode();
@@ -1169,8 +1129,8 @@ protected Mode findMode(String id) {
11691129
*/
11701130
public void handleNew() {
11711131
try {
1172-
File newbieDir = null;
1173-
String newbieName = null;
1132+
File newbieDir;
1133+
String newbieName;
11741134

11751135
// In 0126, untitled sketches will begin in the temp folder,
11761136
// and then moved to a new location because Save will default to Save As.
@@ -1182,7 +1142,7 @@ public void handleNew() {
11821142
// Use a generic name like sketch_031008a, the date plus a char
11831143
int index = 0;
11841144
String format = Preferences.get("editor.untitled.suffix");
1185-
String suffix = null;
1145+
String suffix;
11861146
if (format == null) {
11871147
Calendar cal = Calendar.getInstance();
11881148
int day = cal.get(Calendar.DAY_OF_MONTH); // 1..31
@@ -1269,16 +1229,14 @@ public void handleOpenPrompt() {
12691229
new FileDialog(activeEditor, prompt, FileDialog.LOAD);
12701230

12711231
// 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;
12791237
}
1280-
return false;
12811238
}
1239+
return false;
12821240
});
12831241

12841242
openDialog.setVisible(true);
@@ -1630,11 +1588,7 @@ protected boolean handleQuitEach() {
16301588
* to prevent the interface from locking up until the menus are done.
16311589
*/
16321590
protected void rebuildSketchbookMenusAsync() {
1633-
EventQueue.invokeLater(new Runnable() {
1634-
public void run() {
1635-
rebuildSketchbookMenus();
1636-
}
1637-
});
1591+
EventQueue.invokeLater(this::rebuildSketchbookMenus);
16381592
}
16391593

16401594

@@ -1738,27 +1692,21 @@ protected boolean addSketches(JMenu menu, File folder,
17381692
// Alphabetize the list, since it's not always alpha order
17391693
Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
17401694

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;
17601701
}
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+
};
17621710
// offers no speed improvement
17631711
//menu.addActionListener(listener);
17641712

0 commit comments

Comments
 (0)