added retry option at failed simulation reload

This commit is contained in:
fros4943 2007-05-11 10:55:07 +00:00
parent ca6b1d4bf8
commit fd53ff57dd
3 changed files with 105 additions and 59 deletions

View File

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: GUI.java,v 1.44 2007/05/10 17:08:44 fros4943 Exp $ * $Id: GUI.java,v 1.45 2007/05/11 10:55:07 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -1848,13 +1848,13 @@ public class GUI {
progressDialog.dispose(); progressDialog.dispose();
} }
} catch (UnsatisfiedLinkError e) { } catch (UnsatisfiedLinkError e) {
showErrorDialog(frame, "Simulation load error", e); showErrorDialog(frame, "Simulation load error", e, false);
if (progressDialog != null && progressDialog.isDisplayable()) if (progressDialog != null && progressDialog.isDisplayable())
progressDialog.dispose(); progressDialog.dispose();
newSim = null; newSim = null;
} catch (SimulationCreationException e) { } catch (SimulationCreationException e) {
showErrorDialog(frame, "Simulation load error", e); showErrorDialog(frame, "Simulation load error", e, false);
if (progressDialog != null && progressDialog.isDisplayable()) if (progressDialog != null && progressDialog.isDisplayable())
progressDialog.dispose(); progressDialog.dispose();
@ -1982,25 +1982,27 @@ public class GUI {
} }
// Reload altered simulation config // Reload altered simulation config
try { boolean shouldRetry = false;
myGUI.doRemoveSimulation(false); do {
Simulation newSim = loadSimulationConfig(new StringReader(configXML), true); try {
myGUI.setSimulation(newSim); shouldRetry = false;
myGUI.doRemoveSimulation(false);
Simulation newSim = loadSimulationConfig(new StringReader(configXML), true);
myGUI.setSimulation(newSim);
} catch (UnsatisfiedLinkError e) {
shouldRetry = showErrorDialog(frame, "Simulation reload error", e, true);
} catch (UnsatisfiedLinkError e) { myGUI.doRemoveSimulation(false);
showErrorDialog(frame, "Simulation reload error", e); } catch (SimulationCreationException e) {
shouldRetry = showErrorDialog(frame, "Simulation reload error", e, true);
myGUI.doRemoveSimulation(false); myGUI.doRemoveSimulation(false);
} catch (SimulationCreationException e) {
showErrorDialog(frame, "Simulation reload error", e);
myGUI.doRemoveSimulation(false);
} finally {
if (progressDialog != null && progressDialog.isDisplayable()) {
progressDialog.dispose();
} }
} } while (shouldRetry);
if (progressDialog != null && progressDialog.isDisplayable()) {
progressDialog.dispose();
}
} }
}); });
@ -3015,16 +3017,31 @@ public class GUI {
} }
} }
public static void showErrorDialog(Component parentComponent, final String title, Throwable exception) { /**
* Shows a simple dialog with information about the thrown exception. A user
* may watch the stack trace and, if the exception is a
* MoteTypeCreationException, watch compilation output.
*
* @param parentComponent
* Parent component
* @param title
* Title of error window
* @param exception
* Exception causing window to be shown
* @param retryAvailable
* If true, a retry option is available
*/
public static boolean showErrorDialog(Component parentComponent,
final String title, Throwable exception, boolean retryAvailable) {
MessageList compilationOutput = null; MessageList compilationOutput = null;
MessageList stackTrace = null; MessageList stackTrace = null;
String message = title; String message = title;
// Create message // Create message
if (exception != null) if (exception != null)
message = exception.getMessage(); message = exception.getMessage();
// Create stack trace message list // Create stack trace message list
if (exception != null) { if (exception != null) {
stackTrace = new MessageList(); stackTrace = new MessageList();
@ -3033,15 +3050,17 @@ public class GUI {
} }
// Create compilation out message list (if available) // Create compilation out message list (if available)
if (exception != null if (exception != null && exception instanceof MoteTypeCreationException
&& exception instanceof MoteTypeCreationException
&& ((MoteTypeCreationException) exception).hasCompilationOutput()) { && ((MoteTypeCreationException) exception).hasCompilationOutput()) {
compilationOutput = ((MoteTypeCreationException) exception).getCompilationOutput(); compilationOutput = ((MoteTypeCreationException) exception)
} else if (exception != null .getCompilationOutput();
&& exception.getCause() != null } else if (exception != null
&& exception.getCause() instanceof MoteTypeCreationException && exception.getCause() != null
&& ((MoteTypeCreationException) exception.getCause()).hasCompilationOutput()) { && exception.getCause() instanceof MoteTypeCreationException
compilationOutput = ((MoteTypeCreationException) exception.getCause()).getCompilationOutput(); && ((MoteTypeCreationException) exception.getCause())
.hasCompilationOutput()) {
compilationOutput = ((MoteTypeCreationException) exception.getCause())
.getCompilationOutput();
} }
// Create error dialog // Create error dialog
@ -3051,20 +3070,21 @@ public class GUI {
else if (parentComponent instanceof Frame) else if (parentComponent instanceof Frame)
errorDialog = new JDialog((Frame) parentComponent, title, true); errorDialog = new JDialog((Frame) parentComponent, title, true);
else if (parentComponent instanceof Window) else if (parentComponent instanceof Window)
errorDialog = new JDialog((Window) parentComponent, title, ModalityType.APPLICATION_MODAL); errorDialog = new JDialog((Window) parentComponent, title,
ModalityType.APPLICATION_MODAL);
else { else {
logger.fatal("Bad parent for error dialog"); logger.fatal("Bad parent for error dialog");
errorDialog = new JDialog((Frame) null, title + " (Java stack trace)"); errorDialog = new JDialog((Frame) null, title + " (Java stack trace)");
return;
} }
final JPanel errorPanel = new JPanel(); final JPanel errorPanel = new JPanel();
errorPanel.setLayout(new BoxLayout(errorPanel, BoxLayout.Y_AXIS)); errorPanel.setLayout(new BoxLayout(errorPanel, BoxLayout.Y_AXIS));
errorPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); errorPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
Box messageBox = Box.createHorizontalBox(); Box messageBox = Box.createHorizontalBox();
// Icon myIcon = (Icon)DefaultLookup.get(errorPanel, null, "OptionPane.errorIcon"); // Icon myIcon = (Icon)DefaultLookup.get(errorPanel, null,
// messageBox.add(new JLabel(myIcon)); // "OptionPane.errorIcon");
// messageBox.add(new JLabel(myIcon));
messageBox.add(Box.createHorizontalGlue()); messageBox.add(Box.createHorizontalGlue());
messageBox.add(new JLabel(message)); messageBox.add(new JLabel(message));
messageBox.add(Box.createHorizontalGlue()); messageBox.add(Box.createHorizontalGlue());
@ -3077,11 +3097,13 @@ public class GUI {
showCompilationButton.addActionListener(new ActionListener() { showCompilationButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
JDialog messageListDialog = new JDialog(errorDialog, titleToDisplay); JDialog messageListDialog = new JDialog(errorDialog, titleToDisplay);
JPanel messageListPanel = new JPanel(new BorderLayout()); JPanel messageListPanel = new JPanel(new BorderLayout());
messageListPanel.add(BorderLayout.CENTER, new JScrollPane(listToDisplay)); messageListPanel.add(BorderLayout.CENTER, new JScrollPane(
messageListPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); listToDisplay));
messageListPanel.setBorder(BorderFactory.createEmptyBorder(20, 20,
20, 20));
messageListPanel.setVisible(true); messageListPanel.setVisible(true);
messageListDialog.getContentPane().add(messageListPanel); messageListDialog.getContentPane().add(messageListPanel);
@ -3089,13 +3111,16 @@ public class GUI {
messageListDialog.pack(); messageListDialog.pack();
messageListDialog.setLocationRelativeTo(errorDialog); messageListDialog.setLocationRelativeTo(errorDialog);
Rectangle maxSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); Rectangle maxSize = GraphicsEnvironment.getLocalGraphicsEnvironment()
if (maxSize != null && .getMaximumWindowBounds();
(messageListDialog.getSize().getWidth() > maxSize.getWidth() if (maxSize != null
|| messageListDialog.getSize().getHeight() > maxSize.getHeight())) { && (messageListDialog.getSize().getWidth() > maxSize.getWidth() || messageListDialog
.getSize().getHeight() > maxSize.getHeight())) {
Dimension newSize = new Dimension(); Dimension newSize = new Dimension();
newSize.height = Math.min((int) maxSize.getHeight(), (int) messageListDialog.getSize().getHeight()); newSize.height = Math.min((int) maxSize.getHeight(),
newSize.width = Math.min((int) maxSize.getWidth(), (int) messageListDialog.getSize().getWidth()); (int) messageListDialog.getSize().getHeight());
newSize.width = Math.min((int) maxSize.getWidth(),
(int) messageListDialog.getSize().getWidth());
messageListDialog.setSize(newSize); messageListDialog.setSize(newSize);
} }
@ -3104,7 +3129,7 @@ public class GUI {
}); });
buttonBox.add(showCompilationButton); buttonBox.add(showCompilationButton);
} }
if (stackTrace != null) { if (stackTrace != null) {
final MessageList listToDisplay = stackTrace; final MessageList listToDisplay = stackTrace;
final String titleToDisplay = title + " (Java stack trace)"; final String titleToDisplay = title + " (Java stack trace)";
@ -3112,11 +3137,13 @@ public class GUI {
showTraceButton.addActionListener(new ActionListener() { showTraceButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
JDialog messageListDialog = new JDialog(errorDialog, titleToDisplay); JDialog messageListDialog = new JDialog(errorDialog, titleToDisplay);
JPanel messageListPanel = new JPanel(new BorderLayout()); JPanel messageListPanel = new JPanel(new BorderLayout());
messageListPanel.add(BorderLayout.CENTER, new JScrollPane(listToDisplay)); messageListPanel.add(BorderLayout.CENTER, new JScrollPane(
messageListPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); listToDisplay));
messageListPanel.setBorder(BorderFactory.createEmptyBorder(20, 20,
20, 20));
messageListPanel.setVisible(true); messageListPanel.setVisible(true);
messageListDialog.getContentPane().add(messageListPanel); messageListDialog.getContentPane().add(messageListPanel);
@ -3124,22 +3151,36 @@ public class GUI {
messageListDialog.pack(); messageListDialog.pack();
messageListDialog.setLocationRelativeTo(errorDialog); messageListDialog.setLocationRelativeTo(errorDialog);
Rectangle maxSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds(); Rectangle maxSize = GraphicsEnvironment.getLocalGraphicsEnvironment()
if (maxSize != null && .getMaximumWindowBounds();
(messageListDialog.getSize().getWidth() > maxSize.getWidth() if (maxSize != null
|| messageListDialog.getSize().getHeight() > maxSize.getHeight())) { && (messageListDialog.getSize().getWidth() > maxSize.getWidth() || messageListDialog
.getSize().getHeight() > maxSize.getHeight())) {
Dimension newSize = new Dimension(); Dimension newSize = new Dimension();
newSize.height = Math.min((int) maxSize.getHeight(), (int) messageListDialog.getSize().getHeight()); newSize.height = Math.min((int) maxSize.getHeight(),
newSize.width = Math.min((int) maxSize.getWidth(), (int) messageListDialog.getSize().getWidth()); (int) messageListDialog.getSize().getHeight());
newSize.width = Math.min((int) maxSize.getWidth(),
(int) messageListDialog.getSize().getWidth());
messageListDialog.setSize(newSize); messageListDialog.setSize(newSize);
} }
messageListDialog.setVisible(true); messageListDialog.setVisible(true);
} }
}); });
buttonBox.add(showTraceButton); buttonBox.add(showTraceButton);
} }
if (retryAvailable) {
JButton retryButton = new JButton("Retry");
retryButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
errorDialog.dispose();
errorDialog.setTitle("-RETRY-");
}
});
buttonBox.add(retryButton);
}
JButton closeButton = new JButton("Close"); JButton closeButton = new JButton("Close");
closeButton.addActionListener(new ActionListener() { closeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -3149,12 +3190,17 @@ public class GUI {
buttonBox.add(closeButton); buttonBox.add(closeButton);
errorPanel.add(messageBox); errorPanel.add(messageBox);
errorPanel.add(Box.createVerticalStrut(20));
errorPanel.add(buttonBox); errorPanel.add(buttonBox);
errorDialog.getContentPane().add(errorPanel); errorDialog.getContentPane().add(errorPanel);
errorDialog.pack(); errorDialog.pack();
errorDialog.setLocationRelativeTo(parentComponent); errorDialog.setLocationRelativeTo(parentComponent);
errorDialog.setVisible(true); errorDialog.setVisible(true);
if (errorDialog.getTitle().equals("-RETRY-"))
return true;
return false;
} }
} }

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: ContikiMoteType.java,v 1.12 2007/05/10 17:01:02 fros4943 Exp $ * $Id: ContikiMoteType.java,v 1.13 2007/05/11 10:55:26 fros4943 Exp $
*/ */
package se.sics.cooja.contikimote; package se.sics.cooja.contikimote;
@ -42,7 +42,6 @@ import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import se.sics.cooja.*; import se.sics.cooja.*;
import se.sics.cooja.MoteType.MoteTypeCreationException;
import se.sics.cooja.dialogs.MessageList; import se.sics.cooja.dialogs.MessageList;
/** /**

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: ContikiMoteTypeDialog.java,v 1.27 2007/05/10 17:02:04 fros4943 Exp $ * $Id: ContikiMoteTypeDialog.java,v 1.28 2007/05/11 10:55:26 fros4943 Exp $
*/ */
package se.sics.cooja.contikimote; package se.sics.cooja.contikimote;
@ -2062,7 +2062,8 @@ public class ContikiMoteTypeDialog extends JDialog {
GUI.showErrorDialog( GUI.showErrorDialog(
myDialog, myDialog,
"Mote type creation error", "Mote type creation error",
ex ex,
false
); );
return; return;
} }