3030import javax .swing .border .EmptyBorder ;
3131import javax .swing .text .DefaultCaret ;
3232
33+ import cc .arduino .packages .BoardPort ;
3334import processing .app .debug .TextAreaFIFO ;
3435import processing .app .legacy .PApplet ;
3536
@@ -50,8 +51,11 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
5051 private Timer updateTimer ;
5152 private StringBuffer updateBuffer ;
5253
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 ;
5559
5660 addWindowListener (new WindowAdapter () {
5761 public void windowClosing (WindowEvent event ) {
@@ -136,10 +140,7 @@ public void actionPerformed(ActionEvent event) {
136140 }
137141 lineEndings .setMaximumSize (lineEndings .getMinimumSize ());
138142
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" };
143144
144145 serialRates = new JComboBox ();
145146 for (String rate : serialRateStrings ) {
@@ -185,8 +186,7 @@ public void actionPerformed(ActionEvent event) {
185186 closed = false ;
186187 }
187188
188- public void enableWindow (boolean enable )
189- {
189+ public void enableWindow (boolean enable ) {
190190 textArea .setEnabled (enable );
191191 scrollPane .setEnabled (enable );
192192 textField .setEnabled (enable );
@@ -200,33 +200,24 @@ public void enableWindow(boolean enable)
200200
201201 // Puts the window in suspend state, closing the serial port
202202 // 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 );
213205
206+ close ();
214207 }
215208
216- public void resume () throws SerialException
217- {
209+ public void resume (BoardPort boardPort ) throws Exception {
210+ setBoardPort (boardPort );
211+
218212 // Enable the window
219213 enableWindow (true );
220214
221215 // 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+ }
229219
220+ open ();
230221 }
231222
232223 public void onSerialRateChange (ActionListener listener ) {
@@ -275,12 +266,25 @@ public String getAuthorizationKey() {
275266 }
276267
277268 public boolean isClosed () {
278- return closed ;
269+ return closed ;
270+ }
271+
272+ public void open () throws Exception {
273+ closed = false ;
279274 }
280275
281- public abstract void open () throws Exception ;
276+ public void close () throws Exception {
277+ closed = true ;
278+ }
282279
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+ }
284288
285289 public synchronized void addToUpdateBuffer (char buff [], int n ) {
286290 updateBuffer .append (buff , 0 , n );
@@ -293,15 +297,18 @@ private synchronized String consumeUpdateBuffer() {
293297 }
294298
295299 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 );
305312 }
306313 }
307314
0 commit comments