Don't die if the last scene doesn't exist or if it's malformed
git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@591 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
@@ -31,6 +31,7 @@ import java.awt.event.MouseWheelListener;
|
|||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
import javax.swing.JInternalFrame;
|
import javax.swing.JInternalFrame;
|
||||||
@@ -42,6 +43,8 @@ import javax.swing.JScrollBar;
|
|||||||
import javax.swing.KeyStroke;
|
import javax.swing.KeyStroke;
|
||||||
import javax.swing.filechooser.FileFilter;
|
import javax.swing.filechooser.FileFilter;
|
||||||
|
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import com.samskivert.swing.GroupLayout;
|
import com.samskivert.swing.GroupLayout;
|
||||||
import com.samskivert.swing.HGroupLayout;
|
import com.samskivert.swing.HGroupLayout;
|
||||||
import com.samskivert.swing.util.MenuUtil;
|
import com.samskivert.swing.util.MenuUtil;
|
||||||
@@ -163,10 +166,17 @@ public class EditorFrame extends ManagedJFrame
|
|||||||
|
|
||||||
// finally set a default scene
|
// finally set a default scene
|
||||||
String lastFile = EditorConfig.config.getValue("editor.last_file", "");
|
String lastFile = EditorConfig.config.getValue("editor.last_file", "");
|
||||||
if (lastFile.equals("")) {
|
boolean loaded = false;
|
||||||
|
if (!lastFile.equals("")) {
|
||||||
|
try {
|
||||||
|
loaded = loadScene(lastFile);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.warning("Unable to load last scene, creating new one [file=" + lastFile + "]");
|
||||||
|
Log.logStackTrace(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!loaded) {
|
||||||
newScene();
|
newScene();
|
||||||
} else {
|
|
||||||
openScene(lastFile);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,7 +322,8 @@ public class EditorFrame extends ManagedJFrame
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the scene from the specified path.
|
* Loads the scene from the specified path into the editor and displays an error dialog if it
|
||||||
|
* fails.
|
||||||
*/
|
*/
|
||||||
public void openScene (String path)
|
public void openScene (String path)
|
||||||
{
|
{
|
||||||
@@ -320,13 +331,8 @@ public class EditorFrame extends ManagedJFrame
|
|||||||
|
|
||||||
// attempt loading and installation of the scene
|
// attempt loading and installation of the scene
|
||||||
try {
|
try {
|
||||||
StageSceneModel model = (StageSceneModel)_parser.parseScene(path);
|
if (!loadScene(path)) {
|
||||||
if (model == null) {
|
|
||||||
errmsg = "No scene data found";
|
errmsg = "No scene data found";
|
||||||
} else {
|
|
||||||
setScene(new StageScene(model, null));
|
|
||||||
// keep track of the path for later saving
|
|
||||||
setFilePath(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -341,6 +347,22 @@ public class EditorFrame extends ManagedJFrame
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the scene from the specified path into the editor and returns true if it succeeds.
|
||||||
|
*/
|
||||||
|
protected boolean loadScene (String path)
|
||||||
|
throws IOException, SAXException
|
||||||
|
{
|
||||||
|
StageSceneModel model = (StageSceneModel)_parser.parseScene(path);
|
||||||
|
if (model == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
setScene(new StageScene(model, null));
|
||||||
|
// keep track of the path for later saving
|
||||||
|
setFilePath(path);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the scenes to the file they were last associated with.
|
* Save the scenes to the file they were last associated with.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user