mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-19 08:52:15 +01:00
Added BoardPort.protocolLabel and simplified port menu rendering
This commit is contained in:
parent
c03a8bc175
commit
349af4b5cf
@ -52,7 +52,6 @@ import java.net.URLClassLoader;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -147,9 +146,6 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static List<String> BOARD_PROTOCOLS_ORDER = Arrays.asList("serial", "network");
|
|
||||||
private final static List<String> BOARD_PROTOCOLS_ORDER_TRANSLATIONS = Arrays.asList(tr("Serial ports"), tr("Network ports"));
|
|
||||||
|
|
||||||
final Base base;
|
final Base base;
|
||||||
|
|
||||||
// otherwise, if the window is resized with the message label
|
// otherwise, if the window is resized with the message label
|
||||||
@ -1062,6 +1058,9 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void populatePortMenu() {
|
private void populatePortMenu() {
|
||||||
|
final List<String> PROTOCOLS_ORDER = Arrays.asList("serial", "network");
|
||||||
|
final List<String> PROTOCOLS_LABELS = Arrays.asList(tr("Serial ports"), tr("Network ports"));
|
||||||
|
|
||||||
portMenu.removeAll();
|
portMenu.removeAll();
|
||||||
|
|
||||||
String selectedPort = PreferencesData.get("serial.port");
|
String selectedPort = PreferencesData.get("serial.port");
|
||||||
@ -1070,31 +1069,43 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
|
|
||||||
ports = platform.filterPorts(ports, PreferencesData.getBoolean("serial.ports.showall"));
|
ports = platform.filterPorts(ports, PreferencesData.getBoolean("serial.ports.showall"));
|
||||||
|
|
||||||
Collections.sort(ports, new Comparator<BoardPort>() {
|
ports.stream() //
|
||||||
@Override
|
.filter(port -> port.getProtocolLabel() == null || port.getProtocolLabel().isEmpty())
|
||||||
public int compare(BoardPort o1, BoardPort o2) {
|
.forEach(port -> {
|
||||||
return (BOARD_PROTOCOLS_ORDER.indexOf(o1.getProtocol()) - BOARD_PROTOCOLS_ORDER.indexOf(o2.getProtocol())) * 10 +
|
int labelIdx = PROTOCOLS_ORDER.indexOf(port.getProtocol());
|
||||||
o1.getAddress().compareTo(o2.getAddress());
|
if (labelIdx != -1) {
|
||||||
}
|
port.setProtocolLabel(PROTOCOLS_LABELS.get(labelIdx));
|
||||||
|
} else {
|
||||||
|
port.setProtocolLabel(port.getProtocol());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Collections.sort(ports, (port1, port2) -> {
|
||||||
|
String pr1 = port1.getProtocol();
|
||||||
|
String pr2 = port2.getProtocol();
|
||||||
|
int prIdx1 = PROTOCOLS_ORDER.contains(pr1) ? PROTOCOLS_ORDER.indexOf(pr1) : 999;
|
||||||
|
int prIdx2 = PROTOCOLS_ORDER.contains(pr2) ? PROTOCOLS_ORDER.indexOf(pr2) : 999;
|
||||||
|
int r = prIdx1 - prIdx2;
|
||||||
|
if (r != 0)
|
||||||
|
return r;
|
||||||
|
r = port1.getProtocolLabel().compareTo(port2.getProtocolLabel());
|
||||||
|
if (r != 0)
|
||||||
|
return r;
|
||||||
|
return port1.getAddress().compareTo(port2.getAddress());
|
||||||
});
|
});
|
||||||
|
|
||||||
String lastProtocol = null;
|
String lastProtocol = "";
|
||||||
String lastProtocolTranslated;
|
String lastProtocolLabel = "";
|
||||||
for (BoardPort port : ports) {
|
for (BoardPort port : ports) {
|
||||||
if (lastProtocol == null || !port.getProtocol().equals(lastProtocol)) {
|
if (!port.getProtocol().equals(lastProtocol) || !port.getProtocolLabel().equals(lastProtocolLabel)) {
|
||||||
if (lastProtocol != null) {
|
if (!lastProtocol.isEmpty()) {
|
||||||
portMenu.addSeparator();
|
portMenu.addSeparator();
|
||||||
}
|
}
|
||||||
lastProtocol = port.getProtocol();
|
lastProtocol = port.getProtocol();
|
||||||
|
lastProtocolLabel = port.getProtocolLabel();
|
||||||
if (BOARD_PROTOCOLS_ORDER.indexOf(port.getProtocol()) != -1) {
|
JMenuItem item = new JMenuItem(tr(lastProtocolLabel));
|
||||||
lastProtocolTranslated = BOARD_PROTOCOLS_ORDER_TRANSLATIONS.get(BOARD_PROTOCOLS_ORDER.indexOf(port.getProtocol()));
|
item.setEnabled(false);
|
||||||
} else {
|
portMenu.add(item);
|
||||||
lastProtocolTranslated = port.getProtocol();
|
|
||||||
}
|
|
||||||
JMenuItem lastProtocolMenuItem = new JMenuItem(tr(lastProtocolTranslated));
|
|
||||||
lastProtocolMenuItem.setEnabled(false);
|
|
||||||
portMenu.add(lastProtocolMenuItem);
|
|
||||||
}
|
}
|
||||||
String address = port.getAddress();
|
String address = port.getAddress();
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ public class BoardPort {
|
|||||||
|
|
||||||
private String address; // unique name for this port, used by Preferences
|
private String address; // unique name for this port, used by Preferences
|
||||||
private String protocol; // how to communicate, used for Ports menu sections
|
private String protocol; // how to communicate, used for Ports menu sections
|
||||||
|
private String protocolLabel; // protocol extended name to display on GUI
|
||||||
private String boardName;
|
private String boardName;
|
||||||
private String label; // friendly name shown in Ports menu
|
private String label; // friendly name shown in Ports menu
|
||||||
private final PreferencesMap identificationPrefs; // data to match with boards.txt
|
private final PreferencesMap identificationPrefs; // data to match with boards.txt
|
||||||
@ -76,6 +77,14 @@ public class BoardPort {
|
|||||||
this.protocol = protocol;
|
this.protocol = protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getProtocolLabel() {
|
||||||
|
return protocolLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProtocolLabel(String protocolLabel) {
|
||||||
|
this.protocolLabel = protocolLabel;
|
||||||
|
}
|
||||||
|
|
||||||
public String getBoardName() {
|
public String getBoardName() {
|
||||||
return boardName;
|
return boardName;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user