Permalink
Browse files

Slightly improved recent files sizing methods, correcting potential p…

…roblems (including one CheeseBoy came across). ErrorDialog now offers an Exception parameter in place of the String message parameter, to conveniently show the exception stack trace in the textarea. FileChooser makes use of it (probably the only non-plugin class that actually uses the class...).

git-svn-id: https://lateralgm.svn.sourceforge.net/svnroot/lateralgm/LateralGM/trunk@539 8f422083-7f27-0410-bc82-93e204be8cd2
  • Loading branch information...
1 parent caa6a21 commit dc80d84ae2a45dbd4fafd333971021dfd1a40b12 ismavatar committed Oct 10, 2011
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2008 Clam <clamisgood@gmail.com>
+ * Copyright (C) 2011 IsmAvatar <IsmAvatar@gmail.com>
*
* This file is part of LateralGM.
* LateralGM is free software and comes with ABSOLUTELY NO WARRANTY.
@@ -12,6 +13,8 @@
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.io.PrintWriter;
+import java.io.StringWriter;
import javax.swing.JButton;
import javax.swing.JDialog;
@@ -38,6 +41,11 @@ private static JButton makeButton(String key, ActionListener listener)
return but;
}
+ public ErrorDialog(Frame parent, String title, String message, Exception e)
+ {
+ this(parent,title,message,exceptionToString(e));
+ }
+
public ErrorDialog(Frame parent, String title, String message, String debugInfo)
{
super(parent,title,true);
@@ -61,6 +69,13 @@ public ErrorDialog(Frame parent, String title, String message, String debugInfo)
setLocationRelativeTo(parent);
}
+ protected static String exceptionToString(Exception e)
+ {
+ StringWriter sw = new StringWriter();
+ e.printStackTrace(new PrintWriter(sw));
+ return sw.toString();
+ }
+
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == copy)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006 IsmAvatar <IsmAvatar@gmail.com>
+ * Copyright (C) 2006, 2011 IsmAvatar <IsmAvatar@gmail.com>
* Copyright (C) 2007 Quadduc <quadduc@gmail.com>
*
* This file is part of LateralGM.
@@ -14,6 +14,8 @@
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -31,8 +33,8 @@
public class GmMenuBar extends JMenuBar
{
private static final long serialVersionUID = 1L;
- private JMenuItem[] recentFiles = new JMenuItem[0];
- private int recentFilesPos;
+ private List<JMenuItem> recentFiles = new ArrayList<JMenuItem>();
+ private final int recentFilesPos;
private GmMenu fileMenu;
public static final void setTextAndAlt(JMenuItem item, String input)
@@ -53,17 +55,17 @@ public static final void setTextAndAlt(JMenuItem item, String input)
public void updateRecentFiles()
{
- String[] recentList = PrefsStore.getRecentFiles().toArray(new String[0]);
+ List<String> recentList = PrefsStore.getRecentFiles();
for (JMenuItem item : recentFiles)
fileMenu.remove(item);
- recentFiles = new JMenuItem[recentList.length];
- for (int i = 0; i < recentFiles.length; i++)
+ recentFiles.clear();
+ for (String recentStr : recentList)
{
try
{
- URI uri = new URI(recentList[i]);
+ URI uri = new URI(recentStr);
JMenuItem item;
- String number = Integer.toString(i + 1);
+ String number = Integer.toString(recentFiles.size() + 1);
try
{
File file = new File(uri).getAbsoluteFile();
@@ -75,10 +77,10 @@ public void updateRecentFiles()
item = new JMenuItem(String.format("%s %s",number,uri),number.codePointAt(0));
}
- recentFiles[i] = item;
- item.setActionCommand("GmMenuBar.OPEN " + recentList[i]); //$NON-NLS-1$
+ item.setActionCommand("GmMenuBar.OPEN " + recentStr); //$NON-NLS-1$
item.addActionListener(LGM.listener);
- fileMenu.insert(item,recentFilesPos + i);
+ fileMenu.insert(item,recentFilesPos + recentFiles.size());
+ recentFiles.add(item);
}
catch (URISyntaxException e)
{
@@ -489,8 +489,7 @@ public void open(URI uri, FileReader reader)
catch (GmFormatException ex)
{
new ErrorDialog(LGM.frame,Messages.getString("FileChooser.ERROR_LOAD_TITLE"), //$NON-NLS-1$
- Messages.getString("FileChooser.ERROR_LOAD"),Messages.format("FileChooser.DEBUG_INFO", //$NON-NLS-1$ //$NON-NLS-2$
- ex.getClass().getName(),ex.getMessage(),ex.stackAsString())).setVisible(true);
+ Messages.getString("FileChooser.ERROR_LOAD"),ex).setVisible(true); //$NON-NLS-1$
LGM.currentFile = ex.file;
LGM.populateTree();
rebuildTree();
@@ -83,7 +83,7 @@ AboutBox.ABOUT=<h1 style="white-space: nowrap">LateralGM version 1.6.0 (r$rev$)<
&lt;<a href="mailto:quadduc@gmail.com">quadduc@gmail.com</a>&gt;<br>\
Copyright &copy; 2006, 2007 TGMG \
&lt;<a href="mailto:thegamemakerguru@gmail.com">thegamemakerguru@gmail.com</a>&gt;<br>\
- Testing: WittyCheeseBoy<br>\
+ Testing: CheeseBoy<br>\
Copyright &copy; 1998, 1999, 2000, 2003, 2004, 2005, 2006 others</p>\
\
<p>LateralGM comes with ABSOLUTELY NO WARRANTY. This is free software, \
@@ -158,12 +158,6 @@ FileChooser.ERROR_LOAD= <html><style>p {margin-top: 5px; margin-bottom: 5px;}</s
\
<p>Error Report:</p></html>
-FileChooser.DEBUG_INFO=Unhandled Exception:\n\
- {0} - {1}\n\
- \n\
- Stack trace:\n\
- {2}
-
FileChooser.ERROR_BACKUP_TITLE=Error Making Backup
FileChooser.ERROR_BACKUP= Could not move {0} to a backup.\n\
Do you want to overwrite its contents?

0 comments on commit dc80d84

Please sign in to comment.