Skip to content

Commit 1cac73c

Browse files
committed
Saving and restoring location of the serial monitor.
1 parent b3c92d8 commit 1cac73c

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

app/src/processing/app/Base.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ public boolean handleClose(Editor editor) {
788788

789789
// This will store the sketch count as zero
790790
editors.remove(editor);
791+
Editor.serialMonitor.closeSerialPort();
791792
storeSketches();
792793

793794
// Save out the current prefs state
@@ -825,6 +826,7 @@ public boolean handleQuit() {
825826
// If quit is canceled, this will be replaced anyway
826827
// by a later handleQuit() that is not canceled.
827828
storeSketches();
829+
Editor.serialMonitor.closeSerialPort();
828830

829831
if (handleQuitEach()) {
830832
// make sure running sketches close before quitting

app/src/processing/app/Editor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,10 +2341,10 @@ public void handleSerial() {
23412341
if (uploading) return;
23422342

23432343
try {
2344-
serialMonitor.openSerialPort();
2344+
serialMonitor.openSerialPort();
23452345
serialMonitor.setVisible(true);
23462346
} catch (SerialException e) {
2347-
statusError(e);
2347+
statusError(e);
23482348
}
23492349
}
23502350

app/src/processing/app/SerialMonitor.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package processing.app;
2020

2121
import processing.app.debug.MessageConsumer;
22+
import processing.core.*;
2223

2324
import java.awt.*;
2425
import java.awt.event.*;
@@ -127,7 +128,7 @@ public void actionPerformed(ActionEvent event) {
127128
Preferences.set("serial.debug_rate", rateString);
128129
closeSerialPort();
129130
try {
130-
openSerialPort();
131+
openSerialPort();
131132
} catch (SerialException e) {
132133
System.err.println(e);
133134
}
@@ -144,8 +145,40 @@ public void actionPerformed(ActionEvent event) {
144145
getContentPane().add(pane, BorderLayout.SOUTH);
145146

146147
pack();
148+
149+
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
150+
if (Preferences.get("last.screen.height") != null) {
151+
// if screen size has changed, the window coordinates no longer
152+
// make sense, so don't use them unless they're identical
153+
int screenW = Preferences.getInteger("last.screen.width");
154+
int screenH = Preferences.getInteger("last.screen.height");
155+
if ((screen.width == screenW) && (screen.height == screenH)) {
156+
String locationStr = Preferences.get("last.serial.location");
157+
if (locationStr != null) {
158+
int[] location = PApplet.parseInt(PApplet.split(locationStr, ','));
159+
setPlacement(location);
160+
}
161+
}
162+
}
147163
}
148164

165+
protected void setPlacement(int[] location) {
166+
setBounds(location[0], location[1], location[2], location[3]);
167+
}
168+
169+
protected int[] getPlacement() {
170+
int[] location = new int[4];
171+
172+
// Get the dimensions of the Frame
173+
Rectangle bounds = getBounds();
174+
location[0] = bounds.x;
175+
location[1] = bounds.y;
176+
location[2] = bounds.width;
177+
location[3] = bounds.height;
178+
179+
return location;
180+
}
181+
149182
private void send(String s) {
150183
if (serial != null) {
151184
switch (lineEndings.getSelectedIndex()) {
@@ -166,6 +199,9 @@ public void openSerialPort() throws SerialException {
166199

167200
public void closeSerialPort() {
168201
if (serial != null) {
202+
int[] location = getPlacement();
203+
String locationStr = PApplet.join(PApplet.str(location), ",");
204+
Preferences.set("last.serial.location", locationStr);
169205
textArea.setText("");
170206
serial.dispose();
171207
serial = null;

0 commit comments

Comments
 (0)