Skip to content

Commit 36ffdec

Browse files
committed
cleaning up warnings/doing lambdas
1 parent 9f2b0fd commit 36ffdec

1 file changed

Lines changed: 22 additions & 42 deletions

File tree

app/src/processing/app/Mode.java

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,13 @@ public abstract class Mode {
5656
protected Map<String, String> keywordToReference = new HashMap<>();
5757

5858
protected Settings theme;
59-
// protected Formatter formatter;
60-
// protected Tool formatter;
6159

6260
// maps imported packages to their library folder
6361
protected Map<String, List<Library>> importToLibraryTable;
6462

6563
// these menus are shared so that they needn't be rebuilt for all windows
6664
// each time a sketch is created, renamed, or moved.
67-
protected JMenu examplesMenu; // this is for the menubar, not the toolbar
65+
// protected JMenu examplesMenu; // this is for the menubar, not the toolbar
6866
protected JMenu importMenu;
6967

7068
protected ExamplesFrame examplesFrame;
@@ -91,9 +89,9 @@ public abstract class Mode {
9189
*/
9290
protected ClassLoader classLoader;
9391

94-
static final int BACKGROUND_WIDTH = 1025;
95-
static final int BACKGROUND_HEIGHT = 65;
96-
protected Image backgroundImage;
92+
// static final int BACKGROUND_WIDTH = 1025;
93+
// static final int BACKGROUND_HEIGHT = 65;
94+
// protected Image backgroundImage;
9795

9896
// public Mode(Base base, File folder) {
9997
// this(base, folder, base.getSketchbookLibrariesFolder());
@@ -140,10 +138,11 @@ protected void loadKeywords(File keywordFile) throws IOException {
140138
}
141139

142140

141+
@SuppressWarnings("SameParameterValue")
143142
protected void loadKeywords(File keywordFile,
144143
String commentPrefix) throws IOException {
145144
BufferedReader reader = PApplet.createReader(keywordFile);
146-
String line = null;
145+
String line;
147146
while ((line = reader.readLine()) != null) {
148147
if (!line.trim().startsWith(commentPrefix)) {
149148
// Was difficult to make sure that mode authors were properly doing
@@ -169,7 +168,7 @@ protected void loadKeywords(File keywordFile,
169168
// for StringList.size() and others, but not vice-versa.
170169
// https://github.com/processing/processing/issues/4224
171170
boolean seen = keywordToReference.containsKey(keyword);
172-
if (!seen || (seen && keyword.equals(htmlFilename))) {
171+
if (!seen || keyword.equals(htmlFilename)) {
173172
keywordToReference.put(keyword, htmlFilename);
174173
}
175174
}
@@ -466,29 +465,17 @@ protected void rebuildToolbarMenu() { //JMenu menu) {
466465
//System.out.println("rebuilding toolbar menu");
467466
// Add the single "Open" item
468467
item = Toolkit.newJMenuItem("Open...", 'O');
469-
item.addActionListener(new ActionListener() {
470-
public void actionPerformed(ActionEvent e) {
471-
base.handleOpenPrompt();
472-
}
473-
});
468+
item.addActionListener(e -> base.handleOpenPrompt());
474469
toolbarMenu.add(item);
475470

476471
insertToolbarRecentMenu();
477472

478473
item = Toolkit.newJMenuItemShift("Examples...", 'O');
479-
item.addActionListener(new ActionListener() {
480-
public void actionPerformed(ActionEvent e) {
481-
showExamplesFrame();
482-
}
483-
});
474+
item.addActionListener(e -> showExamplesFrame());
484475
toolbarMenu.add(item);
485476

486477
item = new JMenuItem(Language.text("examples.add_examples"));
487-
item.addActionListener(new ActionListener() {
488-
public void actionPerformed(ActionEvent e) {
489-
ContributionManager.openExamples();
490-
}
491-
});
478+
item.addActionListener(e -> ContributionManager.openExamples());
492479
toolbarMenu.add(item);
493480

494481
// Add a list of all sketches and subfolders
@@ -560,21 +547,13 @@ public void rebuildImportMenu() { //JMenu importMenu) {
560547
}
561548

562549
JMenuItem addLib = new JMenuItem(Language.text("menu.library.add_library"));
563-
addLib.addActionListener(new ActionListener() {
564-
public void actionPerformed(ActionEvent e) {
565-
ContributionManager.openLibraries();
566-
}
567-
});
550+
addLib.addActionListener(e -> ContributionManager.openLibraries());
568551
importMenu.add(addLib);
569552
importMenu.addSeparator();
570553

571554
rebuildLibraryList();
572555

573-
ActionListener listener = new ActionListener() {
574-
public void actionPerformed(ActionEvent e) {
575-
base.activeEditor.handleImportLibrary(e.getActionCommand());
576-
}
577-
};
556+
ActionListener listener = e -> base.activeEditor.handleImportLibrary(e.getActionCommand());
578557

579558
// try {
580559
// pw = new PrintWriter(new FileWriter(System.getProperty("user.home") + "/Desktop/libs.csv"));
@@ -647,11 +626,7 @@ public boolean requireExampleCompatibility() {
647626
* and how they appear in the examples window.
648627
*/
649628
public File[] getExampleCategoryFolders() {
650-
return examplesFolder.listFiles(new FilenameFilter() {
651-
public boolean accept(File dir, String name) {
652-
return dir.isDirectory() && name.charAt(0) != '.';
653-
}
654-
});
629+
return examplesFolder.listFiles((dir, name) -> dir.isDirectory() && name.charAt(0) != '.');
655630
}
656631

657632

@@ -789,6 +764,7 @@ public String lookupReference(String keyword) {
789764
* @since 3.2
790765
* @param code the code for which we need a TokenMarker
791766
*/
767+
@SuppressWarnings("unused")
792768
public TokenMarker getTokenMarker(SketchCode code) {
793769
return getTokenMarker();
794770
}
@@ -863,7 +839,7 @@ public SyntaxStyle getStyle(String attribute) {
863839
Color color = new Color(Integer.parseInt(s, 16));
864840

865841
s = st.nextToken();
866-
boolean bold = (s.indexOf("bold") != -1);
842+
boolean bold = s.contains("bold");
867843
// boolean italic = (s.indexOf("italic") != -1);
868844

869845
// return new SyntaxStyle(color, italic, bold);
@@ -966,8 +942,8 @@ public boolean canEdit(Sketch sketch) {
966942
*/
967943
public boolean validExtension(String what) {
968944
String[] ext = getExtensions();
969-
for (int i = 0; i < ext.length; i++) {
970-
if (ext[i].equals(what)) return true;
945+
for (String s : ext) {
946+
if (s.equals(what)) return true;
971947
}
972948
return false;
973949
}
@@ -1044,7 +1020,11 @@ public void prepareExportFolder(File targetFolder) {
10441020
}
10451021
}
10461022
// Create a fresh output folder (needed before preproc is run next)
1047-
targetFolder.mkdirs();
1023+
if (!targetFolder.exists()) {
1024+
if (!targetFolder.mkdirs()) {
1025+
Messages.loge("Could not create " + targetFolder);
1026+
}
1027+
}
10481028
}
10491029
}
10501030

0 commit comments

Comments
 (0)