diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 077ce6ce1..92d6dd83d 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -898,23 +898,7 @@ public class Editor extends JFrame implements RunnerListener { //public SerialMenuListener() { } public void actionPerformed(ActionEvent e) { - if(serialMenu == null) { - System.out.println("serialMenu is null"); - return; - } - int count = serialMenu.getItemCount(); - for (int i = 0; i < count; i++) { - ((JCheckBoxMenuItem)serialMenu.getItem(i)).setState(false); - } - JCheckBoxMenuItem item = (JCheckBoxMenuItem)e.getSource(); - item.setState(true); - String name = item.getText(); - //System.out.println(item.getLabel()); - Preferences.set("serial.port", name); - serialMonitor.closeSerialPort(); - serialMonitor.setVisible(false); - serialMonitor = new SerialMonitor(Preferences.get("serial.port")); - //System.out.println("set to " + get("serial.port")); + selectSerialPort(((JCheckBoxMenuItem)e.getSource()).getText()); } /* @@ -929,7 +913,35 @@ public class Editor extends JFrame implements RunnerListener { */ } - + protected void selectSerialPort(String name) { + if(serialMenu == null) { + System.out.println("serialMenu is null"); + return; + } + if (name == null) { + System.out.println("name is null"); + return; + } + JCheckBoxMenuItem selection = null; + for (int i = 0; i < serialMenu.getItemCount(); i++) { + JCheckBoxMenuItem item = ((JCheckBoxMenuItem)serialMenu.getItem(i)); + if (item == null) { + System.out.println("name is null"); + continue; + } + item.setState(false); + if (name.equals(item.getText())) selection = item; + } + if (selection != null) selection.setState(true); + //System.out.println(item.getLabel()); + Preferences.set("serial.port", name); + serialMonitor.closeSerialPort(); + serialMonitor.setVisible(false); + serialMonitor = new SerialMonitor(Preferences.get("serial.port")); + //System.out.println("set to " + get("serial.port")); + } + + protected void populateSerialMenu() { // getting list of ports @@ -2218,6 +2230,31 @@ public class Editor extends JFrame implements RunnerListener { return true; } + + + public boolean serialPrompt() { + populateSerialMenu(); + int count = serialMenu.getItemCount(); + Object[] names = new Object[count]; + for (int i = 0; i < count; i++) { + names[i] = ((JCheckBoxMenuItem)serialMenu.getItem(i)).getText(); + } + + String result = (String) + JOptionPane.showInputDialog(this, + "Serial port " + + Preferences.get("serial.port") + + " not found.\n" + + "Retry the upload with another serial port?", + "Serial port not found", + JOptionPane.PLAIN_MESSAGE, + null, + names, + 0); + if (result == null) return false; + selectSerialPort(result); + return true; + } /** @@ -2260,6 +2297,9 @@ public class Editor extends JFrame implements RunnerListener { } else { // error message will already be visible } + } catch (SerialNotFoundException e) { + if (serialPrompt()) run(); + else statusNotice("Upload canceled."); } catch (RunnerException e) { //statusError("Error during upload."); //e.printStackTrace(); diff --git a/app/src/processing/app/Serial.java b/app/src/processing/app/Serial.java index ea08110e7..c84c949cd 100755 --- a/app/src/processing/app/Serial.java +++ b/app/src/processing/app/Serial.java @@ -150,7 +150,7 @@ public class Serial implements SerialPortEventListener { } if (port == null) { - throw new SerialException("Serial port '" + iname + "' not found. Did you select the right one from the Tools > Serial Port menu?"); + throw new SerialNotFoundException("Serial port '" + iname + "' not found. Did you select the right one from the Tools > Serial Port menu?"); } } diff --git a/app/src/processing/app/SerialNotFoundException.java b/app/src/processing/app/SerialNotFoundException.java new file mode 100644 index 000000000..a3ab755b8 --- /dev/null +++ b/app/src/processing/app/SerialNotFoundException.java @@ -0,0 +1,39 @@ +/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Copyright (c) 2007 David A. Mellis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package processing.app; + +public class SerialNotFoundException extends SerialException { + public SerialNotFoundException() { + super(); + } + + public SerialNotFoundException(String message) { + super(message); + } + + public SerialNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public SerialNotFoundException(Throwable cause) { + super(cause); + } +} diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index c6a9d769f..801067c5e 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -1518,8 +1518,8 @@ public class Sketch { } return null; } - - + + protected boolean exportApplet(boolean verbose) throws Exception { return exportApplet(tempBuildFolder.getAbsolutePath(), verbose); } @@ -1529,7 +1529,7 @@ public class Sketch { * Handle export to applet. */ public boolean exportApplet(String appletPath, boolean verbose) - throws RunnerException, IOException { + throws RunnerException, IOException, SerialException { // Make sure the user didn't hide the sketch folder ensureExistence(); @@ -1566,7 +1566,7 @@ public class Sketch { // } upload(appletFolder.getPath(), foundName, verbose); - + return true; } @@ -1593,7 +1593,7 @@ public class Sketch { protected String upload(String buildPath, String suggestedClassName, boolean verbose) - throws RunnerException { + throws RunnerException, SerialException { Uploader uploader; diff --git a/app/src/processing/app/debug/AvrdudeUploader.java b/app/src/processing/app/debug/AvrdudeUploader.java index 877d24f73..97ef91a20 100755 --- a/app/src/processing/app/debug/AvrdudeUploader.java +++ b/app/src/processing/app/debug/AvrdudeUploader.java @@ -29,6 +29,7 @@ package processing.app.debug; import processing.app.Base; import processing.app.Preferences; import processing.app.Serial; +import processing.app.SerialException; import java.io.*; import java.util.*; @@ -43,7 +44,7 @@ public class AvrdudeUploader extends Uploader { // XXX: add support for uploading sketches using a programmer public boolean uploadUsingPreferences(String buildPath, String className, boolean verbose) - throws RunnerException { + throws RunnerException, SerialException { this.verbose = verbose; Map boardPreferences = Base.getBoardPreferences(); String uploadUsing = boardPreferences.get("upload.using"); @@ -71,7 +72,7 @@ public class AvrdudeUploader extends Uploader { } private boolean uploadViaBootloader(String buildPath, String className) - throws RunnerException { + throws RunnerException, SerialException { Map boardPreferences = Base.getBoardPreferences(); List commandDownloader = new ArrayList(); String protocol = boardPreferences.get("upload.protocol"); diff --git a/app/src/processing/app/debug/Uploader.java b/app/src/processing/app/debug/Uploader.java index 0be757f5a..16e3d33d8 100755 --- a/app/src/processing/app/debug/Uploader.java +++ b/app/src/processing/app/debug/Uploader.java @@ -29,6 +29,8 @@ package processing.app.debug; import processing.app.Base; import processing.app.Preferences; import processing.app.Serial; +import processing.app.SerialException; +import processing.app.SerialNotFoundException; import java.io.*; import java.util.*; @@ -63,11 +65,11 @@ public abstract class Uploader implements MessageConsumer { } public abstract boolean uploadUsingPreferences(String buildPath, String className, boolean verbose) - throws RunnerException; + throws RunnerException, SerialException; public abstract boolean burnBootloader(String target, String programmer) throws RunnerException; - protected void flushSerialBuffer() throws RunnerException { + protected void flushSerialBuffer() throws RunnerException, SerialException { // Cleanup the serial buffer try { Serial serialPort = new Serial(); @@ -90,6 +92,8 @@ public abstract class Uploader implements MessageConsumer { serialPort.setRTS(true); serialPort.dispose(); + } catch (SerialNotFoundException e) { + throw e; } catch(Exception e) { e.printStackTrace(); throw new RunnerException(e.getMessage());