Saving and restoring location of the serial monitor.

This commit is contained in:
David A. Mellis 2010-11-07 22:25:02 -05:00
parent b3c92d834f
commit 1cac73c254
3 changed files with 41 additions and 3 deletions

View File

@ -788,6 +788,7 @@ public class Base {
// This will store the sketch count as zero
editors.remove(editor);
Editor.serialMonitor.closeSerialPort();
storeSketches();
// Save out the current prefs state
@ -825,6 +826,7 @@ public class Base {
// If quit is canceled, this will be replaced anyway
// by a later handleQuit() that is not canceled.
storeSketches();
Editor.serialMonitor.closeSerialPort();
if (handleQuitEach()) {
// make sure running sketches close before quitting

View File

@ -19,6 +19,7 @@
package processing.app;
import processing.app.debug.MessageConsumer;
import processing.core.*;
import java.awt.*;
import java.awt.event.*;
@ -144,6 +145,38 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
getContentPane().add(pane, BorderLayout.SOUTH);
pack();
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
if (Preferences.get("last.screen.height") != null) {
// if screen size has changed, the window coordinates no longer
// make sense, so don't use them unless they're identical
int screenW = Preferences.getInteger("last.screen.width");
int screenH = Preferences.getInteger("last.screen.height");
if ((screen.width == screenW) && (screen.height == screenH)) {
String locationStr = Preferences.get("last.serial.location");
if (locationStr != null) {
int[] location = PApplet.parseInt(PApplet.split(locationStr, ','));
setPlacement(location);
}
}
}
}
protected void setPlacement(int[] location) {
setBounds(location[0], location[1], location[2], location[3]);
}
protected int[] getPlacement() {
int[] location = new int[4];
// Get the dimensions of the Frame
Rectangle bounds = getBounds();
location[0] = bounds.x;
location[1] = bounds.y;
location[2] = bounds.width;
location[3] = bounds.height;
return location;
}
private void send(String s) {
@ -166,6 +199,9 @@ public class SerialMonitor extends JFrame implements MessageConsumer {
public void closeSerialPort() {
if (serial != null) {
int[] location = getPlacement();
String locationStr = PApplet.join(PApplet.str(location), ",");
Preferences.set("last.serial.location", locationStr);
textArea.setText("");
serial.dispose();
serial = null;