Skip to content

Commit

Permalink
Split ports in menu, grouping boards by their protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Fissore committed Feb 11, 2015
1 parent 5128a06 commit fea3848
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
@SuppressWarnings("serial")
public class Editor extends JFrame implements RunnerListener {

private final static List<String> BOARD_PROTOCOLS_ORDER = Arrays.asList(new String[]{"serial", "network"});
private final static List<String> BOARD_PROTOCOLS_ORDER_TRANSLATIONS = Arrays.asList(new String[]{_("Serial ports"), _("Network ports")});

Base base;

// otherwise, if the window is resized with the message label
Expand Down Expand Up @@ -441,7 +444,7 @@ protected void applyPreferences() {
textarea.setEditable(!external);
saveMenuItem.setEnabled(!external);
saveAsMenuItem.setEnabled(!external);

textarea.setDisplayLineNumbers(Preferences.getBoolean("editor.linenumbers"));

TextAreaPainter painter = textarea.getPainter();
Expand Down Expand Up @@ -996,7 +999,30 @@ protected void populatePortMenu() {
String selectedPort = Preferences.get("serial.port");

List<BoardPort> ports = Base.getDiscoveryManager().discovery();

Collections.sort(ports, new Comparator<BoardPort>() {
@Override
public int compare(BoardPort o1, BoardPort o2) {
return BOARD_PROTOCOLS_ORDER.indexOf(o1.getProtocol()) - BOARD_PROTOCOLS_ORDER.indexOf(o2.getProtocol());
}
});

String lastProtocol = null;
String lastProtocolTranslated;
for (BoardPort port : ports) {
if (lastProtocol == null || !port.getProtocol().equals(lastProtocol)) {
if (lastProtocol != null) {
serialMenu.addSeparator();
}
lastProtocol = port.getProtocol();

if (BOARD_PROTOCOLS_ORDER.indexOf(port.getProtocol()) != -1) {
lastProtocolTranslated = BOARD_PROTOCOLS_ORDER_TRANSLATIONS.get(BOARD_PROTOCOLS_ORDER.indexOf(port.getProtocol()));
} else {
lastProtocolTranslated = port.getProtocol();
}
serialMenu.add(new JMenuItem(_(lastProtocolTranslated)));
}
String address = port.getAddress();
String label = port.getLabel();

Expand Down Expand Up @@ -1646,7 +1672,7 @@ protected void setCode(SketchCodeDocument codeDoc) {
if (document == null) { // this document not yet inited
document = new SyntaxDocument();
codeDoc.setDocument(document);

// turn on syntax highlighting
document.setTokenMarker(new PdeKeywords());

Expand Down Expand Up @@ -1870,7 +1896,7 @@ protected String getCurrentKeyword() {

} catch (BadLocationException bl) {
bl.printStackTrace();
}
}
return text;
}

Expand Down

0 comments on commit fea3848

Please sign in to comment.