diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 61051f93c97..7d74af54728 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -2374,8 +2374,7 @@ class DefaultExportHandler implements Runnable { public void run() { try { - serialMonitor.closeSerialPort(); - serialMonitor.setVisible(false); + serialMonitor.suspend(); uploading = true; @@ -2402,6 +2401,14 @@ public void run() { uploading = false; //toolbar.clear(); toolbar.deactivate(EditorToolbar.EXPORT); + + // Return the serial monitor window to its initial state + try { + serialMonitor.resume(); + } + catch (SerialException e) { + statusError(e); + } } } @@ -2476,12 +2483,9 @@ protected boolean handleExportCheckModified() { } - public void handleSerial() { - if (uploading) return; - + public void handleSerial() { try { - serialMonitor.openSerialPort(); - serialMonitor.setVisible(true); + serialMonitor.openSerialMonitor(); } catch (SerialException e) { statusError(e); } diff --git a/app/src/processing/app/SerialMonitor.java b/app/src/processing/app/SerialMonitor.java index 1f34e8f7e55..dff4f5b643f 100644 --- a/app/src/processing/app/SerialMonitor.java +++ b/app/src/processing/app/SerialMonitor.java @@ -40,10 +40,11 @@ public class SerialMonitor extends JFrame implements MessageConsumer { private JComboBox lineEndings; private JComboBox serialRates; private int serialRate; + private boolean serialMonitorEnabled; + public SerialMonitor(String port) { super(port); - this.port = port; addWindowListener(new WindowAdapter() { @@ -171,6 +172,8 @@ public void actionPerformed(ActionEvent event) { } } } + + serialMonitorEnabled = true; } protected void setPlacement(int[] location) { @@ -228,4 +231,50 @@ public void run() { } }}); } + + public void enableWindow(boolean enable) + { + textArea.setEnabled(enable); + scrollPane.setEnabled(enable); + textField.setEnabled(enable); + sendButton.setEnabled(enable); + autoscrollBox.setEnabled(enable); + lineEndings.setEnabled(enable); + serialRates.setEnabled(enable); + + serialMonitorEnabled = enable; + } + + // Make the serial monitor window operational + public void openSerialMonitor() throws SerialException + { + // If the serial monitor is not currently disabled, open + // the serial port + if (serialMonitorEnabled) + openSerialPort(); + + // Make the window visible + setVisible(true); + } + + // Puts the window in suspend state, closing the serial port + // to allow other entity (the programmer) to use it + public void suspend() + { + if (serial != null) + // Serial is opened. Record this fact and close it + closeSerialPort(); + + enableWindow(false); + } + + public void resume() throws SerialException + { + // Enable the window + enableWindow(true); + + // If the window is visible, try to open the serial port + if (isVisible()) + openSerialPort(); + } }