Skip to content

Commit 9e81ab6

Browse files
author
Federico Fissore
committed
Editor: serialMenu -> portMenu, and some cleanup
1 parent f255319 commit 9e81ab6

File tree

2 files changed

+24
-34
lines changed

2 files changed

+24
-34
lines changed

app/src/processing/app/Base.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ protected void onIndexesUpdated() throws Exception {
13171317
}
13181318

13191319
public void rebuildBoardsMenu() throws Exception {
1320-
boardsCustomMenus = new LinkedList<JMenu>();
1320+
boardsCustomMenus = new LinkedList<>();
13211321

13221322
// The first custom menu is the "Board" selection submenu
13231323
JMenu boardMenu = new JMenu(_("Board"));

app/src/processing/app/Editor.java

+23-33
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public boolean apply(Sketch sketch) {
134134
static JMenu examplesMenu;
135135
static JMenu importMenu;
136136

137-
private static JMenu serialMenu;
137+
private static JMenu portMenu;
138138

139139
static AbstractMonitor serialMonitor;
140140

@@ -223,7 +223,7 @@ public void windowDeactivated(WindowEvent e) {
223223
for (Component menuItem : toolsMenuItemsToRemove) {
224224
toolsMenu.remove(menuItem);
225225
}
226-
toolsMenu.remove(serialMenu);
226+
toolsMenu.remove(portMenu);
227227
}
228228
});
229229

@@ -552,16 +552,16 @@ public void menuSelected(MenuEvent e) {
552552
toolsMenu.addMenuListener(new StubMenuListener() {
553553
@Override
554554
public void menuSelected(MenuEvent e) {
555-
List<Component> components = Arrays.asList(fileMenu.getComponents());
555+
List<Component> components = Arrays.asList(toolsMenu.getComponents());
556556
int offset = 0;
557557
for (JMenu menu : base.getBoardsCustomMenus()) {
558558
if (!components.contains(menu)) {
559559
toolsMenu.insert(menu, numTools + offset);
560560
offset++;
561561
}
562562
}
563-
if (!components.contains(serialMenu)) {
564-
toolsMenu.insert(serialMenu, numTools + offset);
563+
if (!components.contains(portMenu)) {
564+
toolsMenu.insert(portMenu, numTools + offset);
565565
}
566566
toolsMenu.revalidate();
567567
validate();
@@ -780,11 +780,7 @@ private JMenu buildToolsMenu() {
780780
addInternalTools(toolsMenu);
781781

782782
JMenuItem item = newJMenuItemShift(_("Serial Monitor"), 'M');
783-
item.addActionListener(new ActionListener() {
784-
public void actionPerformed(ActionEvent e) {
785-
handleSerial();
786-
}
787-
});
783+
item.addActionListener(e -> handleSerial());
788784
toolsMenu.add(item);
789785

790786
addTools(toolsMenu, BaseNoGui.getToolsFolder());
@@ -798,26 +794,20 @@ public void actionPerformed(ActionEvent e) {
798794
// XXX: DAM: these should probably be implemented using the Tools plugin
799795
// API, if possible (i.e. if it supports custom actions, etc.)
800796

801-
for (JMenu menu : base.getBoardsCustomMenus()) {
802-
toolsMenu.add(menu);
803-
}
797+
base.getBoardsCustomMenus().stream().forEach(toolsMenu::add);
804798

805-
if (serialMenu == null)
806-
serialMenu = new JMenu(_("Port"));
799+
if (portMenu == null)
800+
portMenu = new JMenu(_("Port"));
807801
populatePortMenu();
808-
toolsMenu.add(serialMenu);
802+
toolsMenu.add(portMenu);
809803
toolsMenu.addSeparator();
810804

811805
JMenu programmerMenu = new JMenu(_("Programmer"));
812806
base.rebuildProgrammerMenu(programmerMenu);
813807
toolsMenu.add(programmerMenu);
814808

815809
item = new JMenuItem(_("Burn Bootloader"));
816-
item.addActionListener(new ActionListener() {
817-
public void actionPerformed(ActionEvent e) {
818-
handleBurnBootloader();
819-
}
820-
});
810+
item.addActionListener(e -> handleBurnBootloader());
821811
toolsMenu.add(item);
822812

823813
toolsMenu.addMenuListener(new StubMenuListener() {
@@ -1098,7 +1088,7 @@ public void actionPerformed(ActionEvent e) {
10981088
}
10991089

11001090
private void selectSerialPort(String name) {
1101-
if(serialMenu == null) {
1091+
if(portMenu == null) {
11021092
System.out.println(_("serialMenu is null"));
11031093
return;
11041094
}
@@ -1107,8 +1097,8 @@ private void selectSerialPort(String name) {
11071097
return;
11081098
}
11091099
JCheckBoxMenuItem selection = null;
1110-
for (int i = 0; i < serialMenu.getItemCount(); i++) {
1111-
JMenuItem menuItem = serialMenu.getItem(i);
1100+
for (int i = 0; i < portMenu.getItemCount(); i++) {
1101+
JMenuItem menuItem = portMenu.getItem(i);
11121102
if (!(menuItem instanceof JCheckBoxMenuItem)) {
11131103
continue;
11141104
}
@@ -1135,7 +1125,7 @@ private void selectSerialPort(String name) {
11351125

11361126

11371127
private void populatePortMenu() {
1138-
serialMenu.removeAll();
1128+
portMenu.removeAll();
11391129

11401130
String selectedPort = PreferencesData.get("serial.port");
11411131

@@ -1155,7 +1145,7 @@ public int compare(BoardPort o1, BoardPort o2) {
11551145
for (BoardPort port : ports) {
11561146
if (lastProtocol == null || !port.getProtocol().equals(lastProtocol)) {
11571147
if (lastProtocol != null) {
1158-
serialMenu.addSeparator();
1148+
portMenu.addSeparator();
11591149
}
11601150
lastProtocol = port.getProtocol();
11611151

@@ -1166,17 +1156,17 @@ public int compare(BoardPort o1, BoardPort o2) {
11661156
}
11671157
JMenuItem lastProtocolMenuItem = new JMenuItem(_(lastProtocolTranslated));
11681158
lastProtocolMenuItem.setEnabled(false);
1169-
serialMenu.add(lastProtocolMenuItem);
1159+
portMenu.add(lastProtocolMenuItem);
11701160
}
11711161
String address = port.getAddress();
11721162
String label = port.getLabel();
11731163

11741164
JCheckBoxMenuItem item = new JCheckBoxMenuItem(label, address.equals(selectedPort));
11751165
item.addActionListener(new SerialMenuListener(address));
1176-
serialMenu.add(item);
1166+
portMenu.add(item);
11771167
}
11781168

1179-
serialMenu.setEnabled(serialMenu.getMenuComponentCount() > 0);
1169+
portMenu.setEnabled(portMenu.getMenuComponentCount() > 0);
11801170
}
11811171

11821172

@@ -2320,10 +2310,10 @@ public boolean handleSaveAs() {
23202310

23212311

23222312
private boolean serialPrompt() {
2323-
int count = serialMenu.getItemCount();
2313+
int count = portMenu.getItemCount();
23242314
Object[] names = new Object[count];
23252315
for (int i = 0; i < count; i++) {
2326-
names[i] = serialMenu.getItem(i).getText();
2316+
names[i] = portMenu.getItem(i).getText();
23272317
}
23282318

23292319
String result = (String)
@@ -2390,7 +2380,7 @@ public void run() {
23902380
statusNotice(_("Done uploading."));
23912381
}
23922382
} catch (SerialNotFoundException e) {
2393-
if (serialMenu.getItemCount() == 0) statusError(e);
2383+
if (portMenu.getItemCount() == 0) statusError(e);
23942384
else if (serialPrompt()) run();
23952385
else statusNotice(_("Upload canceled."));
23962386
} catch (PreferencesMapException e) {
@@ -2460,7 +2450,7 @@ public void run() {
24602450
statusNotice(_("Done uploading."));
24612451
}
24622452
} catch (SerialNotFoundException e) {
2463-
if (serialMenu.getItemCount() == 0) statusError(e);
2453+
if (portMenu.getItemCount() == 0) statusError(e);
24642454
else if (serialPrompt()) run();
24652455
else statusNotice(_("Upload canceled."));
24662456
} catch (PreferencesMapException e) {

0 commit comments

Comments
 (0)