Permalink
Browse files

Fix load error messages.

When you have an error from loading a project the stack trace will
properly be displayed now. I also fixed the error dialog from showing
multiple times, it's supposed to append text. Additionally fixed a GMX
reading exception.
  • Loading branch information...
RobertBColton committed Oct 11, 2014
1 parent aa4ec0a commit 907c58d3093e90fcd1776a0452e361e5c396f70e
@@ -44,13 +44,14 @@
protected JButton submit;
protected JButton cancel;
protected JScrollPane scroll;
protected JOptionPane optionpane;
public static ErrorDialog getInstance()
{
return myInstance;
}
public String generateAgnosticInformation()
public static String generateAgnosticInformation()
{
String ret = "Operating System: " + System.getProperty("os.name");
ret += "\nVersion: " + System.getProperty("os.version");
@@ -80,17 +81,37 @@ public String generateAgnosticInformation()
ret += "\n\nStack trace:";
return ret;
}
public void setMessage(String message)
{
optionpane.setMessage(new Object[] { message,scroll });
}
public void setDefaults() {
setMessage(Messages.getString("ErrorDialog.UNCAUGHT_MESSAGE"));
setTitle(Messages.getString("ErrorDialog.UNCAUGHT_TITLE"));
}
public void setDebugInfo(String text)
{
debugInfo.setText("\n" + text);
debugInfo.setCaretPosition(0);
}
public void setDebugInfo(Throwable e)
{
debugInfo.setText("\n" + throwableToString(e));
debugInfo.setCaretPosition(0);
}
public void appendDebugInfo(String text)
{
debugInfo.append("\n" + text);
debugInfo.setCaretPosition(0);
}
public void appendDebugInfo(Throwable e)
{
debugInfo.append("\n" + throwableToString(e));
debugInfo.setCaretPosition(0);
}
private static JButton makeButton(String key, ActionListener listener)
@@ -121,7 +142,9 @@ public ErrorDialog(Frame parent, String title, String message, String debugText,
setResizable(false);
submiturl = url;
this.debugInfo = new JTextArea(debugText);
this.debugInfo = new JTextArea();
debugInfo.setText(ErrorDialog.generateAgnosticInformation());
this.appendDebugInfo(debugText);
scroll = new JScrollPane(this.debugInfo);
Dimension dim = new Dimension(scroll.getWidth(),DEBUG_HEIGHT);
@@ -135,28 +158,27 @@ public ErrorDialog(Frame parent, String title, String message, String debugText,
submit.setPreferredSize(dim);
copy.setPreferredSize(dim);
cancel.setPreferredSize(dim);
JOptionPane wtfwjd = new JOptionPane(new Object[] { message,scroll },JOptionPane.ERROR_MESSAGE,
optionpane = new JOptionPane(new Object[] { message,scroll },JOptionPane.ERROR_MESSAGE,
JOptionPane.DEFAULT_OPTION,null,new JButton[] { copy,submit,cancel });
add(wtfwjd);
add(optionpane);
pack();
setLocationRelativeTo(parent);
this.addWindowListener(new java.awt.event.WindowAdapter()
{
@Override
public void windowClosing(java.awt.event.WindowEvent windowEvent)
{
debugInfo.setText("");
setDefaults();
}
});
}
@Override
public void setVisible(boolean visible)
{
public void setVisible(boolean visible) {
super.setVisible(visible);
debugInfo.setText(generateAgnosticInformation());
}
setDefaults();
}
protected static String throwableToString(Throwable e)
{
StringWriter sw = new StringWriter();
@@ -1481,15 +1481,19 @@ public boolean invoke()
obj.put(
PGmObject.PHYSICS_DAMPING_ANGULAR,
Double.parseDouble(objdoc.getElementsByTagName("PhysicsObjectAngularDamping").item(0).getTextContent()));
obj.put(
PGmObject.PHYSICS_FRICTION,
Double.parseDouble(objdoc.getElementsByTagName("PhysicsObjectFriction").item(0).getTextContent()));
obj.put(
PGmObject.PHYSICS_AWAKE,
Integer.parseInt(objdoc.getElementsByTagName("PhysicsObjectAwake").item(0).getTextContent()) < 0);
obj.put(
PGmObject.PHYSICS_KINEMATIC,
Integer.parseInt(objdoc.getElementsByTagName("PhysicsObjectKinematic").item(0).getTextContent()) < 0);
//TODO: I guess some versions of the format didn't have these?
Node fNode = objdoc.getElementsByTagName("PhysicsObjectFriction").item(0);
if (fNode != null) {
obj.put(
PGmObject.PHYSICS_FRICTION,
Double.parseDouble(fNode.getTextContent()));
obj.put(
PGmObject.PHYSICS_AWAKE,
Integer.parseInt(objdoc.getElementsByTagName("PhysicsObjectAwake").item(0).getTextContent()) < 0);
obj.put(
PGmObject.PHYSICS_KINEMATIC,
Integer.parseInt(objdoc.getElementsByTagName("PhysicsObjectKinematic").item(0).getTextContent()) < 0);
}
NodeList pointNodes = objdoc.getElementsByTagName("point");
for (int p = 0; p < pointNodes.getLength(); p++)
@@ -570,17 +570,19 @@ public void run()
LGM.currentFile = ex.file;
LGM.populateTree();
rebuildTree();
new ErrorDialog(LGM.frame,Messages.getString("FileChooser.ERROR_LOAD_TITLE"), //$NON-NLS-1$
Messages.getString("FileChooser.ERROR_LOAD"),ex).setVisible(true); //$NON-NLS-1$
LGM.showDefaultExceptionHandler(ex);
ErrorDialog.getInstance().setMessage(Messages.getString("FileChooser.ERROR_LOAD"));
ErrorDialog.getInstance().setTitle(Messages.getString("FileChooser.ERROR_LOAD_TITLE"));
}
catch (Exception e)
{
//TODO: This catches exceptions in EGM reading without freezing the program with the progress bar
// or destroying the tree.
LGM.populateTree();
rebuildTree();
new ErrorDialog(LGM.frame,Messages.getString("FileChooser.ERROR_LOAD_TITLE"), //$NON-NLS-1$
Messages.getString("FileChooser.ERROR_LOAD"),e).setVisible(true); //$NON-NLS-1$
LGM.showDefaultExceptionHandler(e);
ErrorDialog.getInstance().setMessage(Messages.getString("FileChooser.ERROR_LOAD"));
ErrorDialog.getInstance().setTitle(Messages.getString("FileChooser.ERROR_LOAD_TITLE"));
}
setTitleURI(uri);
PrefsStore.addRecentFile(uri.toString());
@@ -762,6 +762,16 @@ public static void populateTree()
for (Class<? extends Resource<?,?>> k : Resource.kinds)
{
boolean hasNode = true;
// Check to see if the appropriate node already exists.
Enumeration<?> children = root.depthFirstEnumeration();
while (children.hasMoreElements()) {
ResNode it = (ResNode) children.nextElement();
if (it.kind == k) {
hasNode = false;
break;
}
}
if (!hasNode) continue;
try
{
//NOTE: Use reflection on the class to see if it has a variable telling us whether to create
@@ -2409,6 +2419,7 @@ public static void showDefaultExceptionHandler(Throwable e)
if (!ErrorDialog.getInstance().isVisible())
{
ErrorDialog.getInstance().setVisible(true);
ErrorDialog.getInstance().setDebugInfo(ErrorDialog.generateAgnosticInformation());
}
ErrorDialog.getInstance().appendDebugInfo(e); //$NON-NLS-1$
}
@@ -1,4 +1,4 @@
### Package components ###
Messages.getString("ErrorDialog.UNCAUGHT_TITLE")### Package components ###
ColorSelect.CHOOSE_TITLE=Choose a Color
@@ -113,7 +113,7 @@ QuickFind.HIGHLIGHT = Highlight All
AboutBox.TITLE=About LateralGM
AboutBox.ABOUT=<h1 style="white-space: nowrap">Copyright &copy; 2006-2014</h1>\
<p style="white-space: nowrap">Version: 1.8.6.722<br><br>\
<p style="white-space: nowrap">Version: 1.8.6.724<br><br>\
IsmAvatar \
&lt;<a href="mailto:IsmAvatar@gmail.com">IsmAvatar@gmail.com</a>&gt;<br>\
Clam \
@@ -199,8 +199,8 @@ FileChooser.ERROR_LOAD_TITLE=Error Loading File
FileChooser.ERROR_LOAD= <html><style>p {margin-top: 5px; margin-bottom: 5px;}</style>\
<p>Your file appears to be corrupted. You can still use what LGM has managed to read, but<br>\
the tree has been rebuilt, so all grouping and order has been lost.<br>\
If you think this was caused by a bug in LGM, please submit this error report, and we will<br>\
do our best to fix the problem.</p>\
If you think this was caused by a bug in LGM, please submit this error report, and we<br>\
will do our best to fix the problem.</p>\
\
<p>Error Report:</p></html>

0 comments on commit 907c58d

Please sign in to comment.