Skip to content

serialMenu speed-up #1188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
modified: ../app/src/processing/app/Editor.java
Changed Editor.java to add optional rescan of serial ports.
Original behavior of Tools menu would rescan serial ports every time it is
opened.  This can be time consuming when you have an abundance of virtual
or bluetooth serial devices.  New behavior adds a check button to serialMenu
to disable the automatic scanning and a button to manually scan ports.
  • Loading branch information
oroszwj committed Dec 26, 2012
commit af8207aa434bf7935c93c44abd4cc4dcce64b6f1
59 changes: 52 additions & 7 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ public class Editor extends JFrame implements RunnerListener {
*/
boolean untitled;

/**
* true if ports are to be scanned automatically
*/
static boolean autoscanSerial = false;
static JCheckBoxMenuItem JCMIautoscanSerial;
static JMenuItem JMIrescanSerial;

PageFormat pageFormat;
PrinterJob printerJob;

Expand Down Expand Up @@ -709,7 +716,9 @@ public void menuCanceled(MenuEvent e) {}
public void menuDeselected(MenuEvent e) {}
public void menuSelected(MenuEvent e) {
//System.out.println("Tools menu selected.");
populateSerialMenu();
if(autoscanSerial | (serialMenu == null) ) {
populateSerialMenu();
}
}
});

Expand Down Expand Up @@ -902,8 +911,21 @@ class SerialMenuListener implements ActionListener {
//public SerialMenuListener() { }

public void actionPerformed(ActionEvent e) {
selectSerialPort(((JCheckBoxMenuItem)e.getSource()).getText());
base.onBoardOrPortChange();
System.out.print("Serial Menu Action\n");
if(e.getSource() == JCMIautoscanSerial) {
//setAutoscan(!autoscanSerial);
System.out.print("toggle\n");
toggleAutoscan();
}
else if(e.getSource() == JMIrescanSerial) {
System.out.print("rescan\n");
populateSerialMenu();
}
else {
System.out.print("port\n");
selectSerialPort(((JMenuItem)e.getSource()).getText());
base.onBoardOrPortChange();
}
}

/*
Expand All @@ -917,7 +939,20 @@ public void actionPerformed(ActionEvent e) {
}
*/
}


protected void setAutoscan(boolean enabled) {
autoscanSerial = enabled;
JCMIautoscanSerial.setState(enabled);
JMIrescanSerial.setEnabled(!enabled);
}

protected void toggleAutoscan() {
System.out.print(_("toggling Autoscan..."));
autoscanSerial = !autoscanSerial;
JCMIautoscanSerial.setState(autoscanSerial);
JMIrescanSerial.setEnabled(!autoscanSerial);
}

protected void selectSerialPort(String name) {
if(serialMenu == null) {
System.out.println(_("serialMenu is null"));
Expand All @@ -928,7 +963,7 @@ protected void selectSerialPort(String name) {
return;
}
JCheckBoxMenuItem selection = null;
for (int i = 0; i < serialMenu.getItemCount(); i++) {
for (int i = 0; i < serialMenu.getItemCount()-3; i++) {
JCheckBoxMenuItem item = ((JCheckBoxMenuItem)serialMenu.getItem(i));
if (item == null) {
System.out.println(_("name is null"));
Expand Down Expand Up @@ -988,10 +1023,20 @@ protected void populateSerialMenu() {
}

if (serialMenu.getItemCount() == 0) {
serialMenu.setEnabled(false);
//serialMenu.setEnabled(false);
rbMenuItem = new JMenuItem("(No serial ports detected)");
rbMenuItem.setEnabled(false);
serialMenu.add(rbMenuItem);
}

//serialMenu.addSeparator();
serialMenu.addSeparator();
JCMIautoscanSerial = new JCheckBoxMenuItem("Auto-Scan", autoscanSerial);
JCMIautoscanSerial.addActionListener(serialMenuListener);
serialMenu.add(JCMIautoscanSerial);
JMIrescanSerial = new JMenuItem("Rescan Ports");
JMIrescanSerial.setEnabled(!autoscanSerial);
JMIrescanSerial.addActionListener(serialMenuListener);
serialMenu.add(JMIrescanSerial);
//serialMenu.add(item);
}

Expand Down