19
19
package processing .app ;
20
20
21
21
import processing .app .debug .MessageConsumer ;
22
+ import processing .core .*;
22
23
23
24
import java .awt .*;
24
25
import java .awt .event .*;
@@ -127,7 +128,7 @@ public void actionPerformed(ActionEvent event) {
127
128
Preferences .set ("serial.debug_rate" , rateString );
128
129
closeSerialPort ();
129
130
try {
130
- openSerialPort ();
131
+ openSerialPort ();
131
132
} catch (SerialException e ) {
132
133
System .err .println (e );
133
134
}
@@ -144,8 +145,40 @@ public void actionPerformed(ActionEvent event) {
144
145
getContentPane ().add (pane , BorderLayout .SOUTH );
145
146
146
147
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
+ }
147
163
}
148
164
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
+
149
182
private void send (String s ) {
150
183
if (serial != null ) {
151
184
switch (lineEndings .getSelectedIndex ()) {
@@ -166,6 +199,9 @@ public void openSerialPort() throws SerialException {
166
199
167
200
public void closeSerialPort () {
168
201
if (serial != null ) {
202
+ int [] location = getPlacement ();
203
+ String locationStr = PApplet .join (PApplet .str (location ), "," );
204
+ Preferences .set ("last.serial.location" , locationStr );
169
205
textArea .setText ("" );
170
206
serial .dispose ();
171
207
serial = null ;
0 commit comments