mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-20 21:01:25 +03:00
Moving serial error messages into the serial monitor (out of the editor).
This commit is contained in:
@ -101,8 +101,6 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
static SerialMenuListener serialMenuListener;
|
||||
static SerialMonitor serialMonitor;
|
||||
|
||||
static Editor activeEditor;
|
||||
|
||||
EditorHeader header;
|
||||
EditorStatus status;
|
||||
EditorConsole console;
|
||||
@ -162,8 +160,6 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
// When bringing a window to front, let the Base know
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowActivated(WindowEvent e) {
|
||||
activeEditor = Editor.this;
|
||||
|
||||
base.handleActivated(Editor.this);
|
||||
|
||||
// re-add the sub-menus that are shared by all windows
|
||||
@ -856,7 +852,7 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
//System.out.println(item.getLabel());
|
||||
Preferences.set("serial.port", name);
|
||||
//System.out.println("set to " + get("serial.port"));
|
||||
activeEditor.handleSerial(false);
|
||||
handleSerial(false);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2215,17 +2211,10 @@ public class Editor extends JFrame implements RunnerListener {
|
||||
|
||||
|
||||
public void handleSerial(boolean showSerialMonitor) {
|
||||
statusEmpty();
|
||||
|
||||
if (!showSerialMonitor && !serialMonitor.isVisible()) return;
|
||||
|
||||
try {
|
||||
serialMonitor.openSerialPort(Preferences.get("serial.port"));
|
||||
serialMonitor.setVisible(true);
|
||||
} catch (SerialException e) {
|
||||
statusError(e.getMessage());
|
||||
serialMonitor.setVisible(false);
|
||||
}
|
||||
serialMonitor.setVisible(true);
|
||||
serialMonitor.openSerialPort(Preferences.get("serial.port"));
|
||||
}
|
||||
|
||||
|
||||
|
@ -33,6 +33,7 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
|
||||
private JTextField textField;
|
||||
private JButton sendButton;
|
||||
private JComboBox serialRates;
|
||||
private JLabel statusLabel;
|
||||
|
||||
public SerialMonitor() {
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@ -73,7 +74,12 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
|
||||
|
||||
getContentPane().add(pane, BorderLayout.NORTH);
|
||||
|
||||
pane = new JPanel(new FlowLayout(FlowLayout.TRAILING, 4, 4));
|
||||
pane = new JPanel(new BorderLayout(4, 0));
|
||||
pane.setBorder(new EmptyBorder(4, 4, 4, 4));
|
||||
|
||||
statusLabel = new JLabel();
|
||||
|
||||
pane.add(statusLabel, BorderLayout.CENTER);
|
||||
|
||||
String[] serialRateStrings = {
|
||||
"300","1200","2400","4800","9600","14400",
|
||||
@ -91,11 +97,12 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
|
||||
String rateString = wholeString.substring(0, wholeString.indexOf(' '));
|
||||
int rate = Integer.parseInt(rateString);
|
||||
Preferences.set("serial.debug_rate", rateString);
|
||||
String port = SerialMonitor.this.port;
|
||||
closeSerialPort();
|
||||
Editor.activeEditor.handleSerial(true);
|
||||
openSerialPort(port);
|
||||
}});
|
||||
|
||||
pane.add(serialRates);
|
||||
pane.add(serialRates, BorderLayout.EAST);
|
||||
|
||||
getContentPane().add(pane, BorderLayout.SOUTH);
|
||||
|
||||
@ -107,25 +114,32 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
|
||||
serial.write(s);
|
||||
}
|
||||
|
||||
public void openSerialPort(String port) throws SerialException {
|
||||
public void openSerialPort(String port) {
|
||||
if (port.equals(this.port))
|
||||
return;
|
||||
|
||||
closeSerialPort();
|
||||
|
||||
serial = new Serial(port);
|
||||
serial.addListener(this);
|
||||
setTitle(port);
|
||||
this.port = port;
|
||||
try {
|
||||
statusLabel.setText("opening...");
|
||||
serial = new Serial(port);
|
||||
serial.addListener(this);
|
||||
setTitle(port);
|
||||
this.port = port;
|
||||
statusLabel.setText("");
|
||||
} catch (SerialException e) {
|
||||
statusLabel.setText(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void closeSerialPort() {
|
||||
if (serial != null) {
|
||||
setTitle("closing...");
|
||||
statusLabel.setText("closing...");
|
||||
textArea.setText("");
|
||||
serial.dispose();
|
||||
serial = null;
|
||||
port = null;
|
||||
statusLabel.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user