From 1cac73c254b0851f91abe7aa10c90791afdfa76c Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sun, 7 Nov 2010 22:25:02 -0500 Subject: [PATCH] Saving and restoring location of the serial monitor. --- app/src/processing/app/Base.java | 2 ++ app/src/processing/app/Editor.java | 4 +-- app/src/processing/app/SerialMonitor.java | 38 ++++++++++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 48ab3aca4..c939e0f2f 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -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 diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index b4fedbc74..05431dbcd 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -2341,10 +2341,10 @@ public class Editor extends JFrame implements RunnerListener { if (uploading) return; try { - serialMonitor.openSerialPort(); + serialMonitor.openSerialPort(); serialMonitor.setVisible(true); } catch (SerialException e) { - statusError(e); + statusError(e); } } diff --git a/app/src/processing/app/SerialMonitor.java b/app/src/processing/app/SerialMonitor.java index 14aed74bb..264748855 100644 --- a/app/src/processing/app/SerialMonitor.java +++ b/app/src/processing/app/SerialMonitor.java @@ -19,6 +19,7 @@ package processing.app; import processing.app.debug.MessageConsumer; +import processing.core.*; import java.awt.*; import java.awt.event.*; @@ -127,7 +128,7 @@ public class SerialMonitor extends JFrame implements MessageConsumer { Preferences.set("serial.debug_rate", rateString); closeSerialPort(); try { - openSerialPort(); + openSerialPort(); } catch (SerialException e) { System.err.println(e); } @@ -144,8 +145,40 @@ 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) { if (serial != null) { switch (lineEndings.getSelectedIndex()) { @@ -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;