30
30
import javax .swing .border .EmptyBorder ;
31
31
import javax .swing .text .DefaultCaret ;
32
32
33
+ import cc .arduino .packages .BoardPort ;
33
34
import processing .app .debug .TextAreaFIFO ;
34
35
import processing .app .legacy .PApplet ;
35
36
@@ -50,8 +51,11 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
50
51
private Timer updateTimer ;
51
52
private StringBuffer updateBuffer ;
52
53
53
- public AbstractMonitor (String title ) {
54
- super (title );
54
+ private BoardPort boardPort ;
55
+
56
+ public AbstractMonitor (BoardPort boardPort ) {
57
+ super (boardPort .getLabel ());
58
+ this .boardPort = boardPort ;
55
59
56
60
addWindowListener (new WindowAdapter () {
57
61
public void windowClosing (WindowEvent event ) {
@@ -136,10 +140,7 @@ public void actionPerformed(ActionEvent event) {
136
140
}
137
141
lineEndings .setMaximumSize (lineEndings .getMinimumSize ());
138
142
139
- String [] serialRateStrings = {
140
- "300" , "1200" , "2400" , "4800" , "9600" ,
141
- "19200" , "38400" , "57600" , "115200" , "230400" , "250000"
142
- };
143
+ String [] serialRateStrings = {"300" , "1200" , "2400" , "4800" , "9600" , "19200" , "38400" , "57600" , "115200" , "230400" , "250000" };
143
144
144
145
serialRates = new JComboBox ();
145
146
for (String rate : serialRateStrings ) {
@@ -185,8 +186,7 @@ public void actionPerformed(ActionEvent event) {
185
186
closed = false ;
186
187
}
187
188
188
- public void enableWindow (boolean enable )
189
- {
189
+ public void enableWindow (boolean enable ) {
190
190
textArea .setEnabled (enable );
191
191
scrollPane .setEnabled (enable );
192
192
textField .setEnabled (enable );
@@ -200,33 +200,24 @@ public void enableWindow(boolean enable)
200
200
201
201
// Puts the window in suspend state, closing the serial port
202
202
// to allow other entity (the programmer) to use it
203
- public void suspend ()
204
- {
205
- enableWindow (false );
206
-
207
- try {
208
- close ();
209
- }
210
- catch (Exception e ) {
211
- //throw new SerialException("Failed closing the port");
212
- }
203
+ public void suspend () throws Exception {
204
+ enableWindow (false );
213
205
206
+ close ();
214
207
}
215
208
216
- public void resume () throws SerialException
217
- {
209
+ public void resume (BoardPort boardPort ) throws Exception {
210
+ setBoardPort (boardPort );
211
+
218
212
// Enable the window
219
213
enableWindow (true );
220
214
221
215
// If the window is visible, try to open the serial port
222
- if (isVisible ())
223
- try {
224
- open ();
225
- }
226
- catch (Exception e ) {
227
- throw new SerialException ("Failed opening the port" );
228
- }
216
+ if (!isVisible ()) {
217
+ return ;
218
+ }
229
219
220
+ open ();
230
221
}
231
222
232
223
public void onSerialRateChange (ActionListener listener ) {
@@ -275,12 +266,25 @@ public String getAuthorizationKey() {
275
266
}
276
267
277
268
public boolean isClosed () {
278
- return closed ;
269
+ return closed ;
270
+ }
271
+
272
+ public void open () throws Exception {
273
+ closed = false ;
279
274
}
280
275
281
- public abstract void open () throws Exception ;
276
+ public void close () throws Exception {
277
+ closed = true ;
278
+ }
282
279
283
- public abstract void close () throws Exception ;
280
+ public BoardPort getBoardPort () {
281
+ return boardPort ;
282
+ }
283
+
284
+ public void setBoardPort (BoardPort boardPort ) {
285
+ setTitle (boardPort .getLabel ());
286
+ this .boardPort = boardPort ;
287
+ }
284
288
285
289
public synchronized void addToUpdateBuffer (char buff [], int n ) {
286
290
updateBuffer .append (buff , 0 , n );
@@ -293,15 +297,18 @@ private synchronized String consumeUpdateBuffer() {
293
297
}
294
298
295
299
public void actionPerformed (ActionEvent e ) {
296
- final String s = consumeUpdateBuffer ();
297
- if (s .length () > 0 ) {
298
- //System.out.println("gui append " + s.length());
299
- if (autoscrollBox .isSelected ()) {
300
- textArea .appendTrim (s );
301
- textArea .setCaretPosition (textArea .getDocument ().getLength ());
302
- } else {
303
- textArea .appendNoTrim (s );
304
- }
300
+ String s = consumeUpdateBuffer ();
301
+
302
+ if (s .isEmpty ()) {
303
+ return ;
304
+ }
305
+
306
+ //System.out.println("gui append " + s.length());
307
+ if (autoscrollBox .isSelected ()) {
308
+ textArea .appendTrim (s );
309
+ textArea .setCaretPosition (textArea .getDocument ().getLength ());
310
+ } else {
311
+ textArea .appendNoTrim (s );
305
312
}
306
313
}
307
314
0 commit comments