- Expose the results of addObject and deleteObject on EditorScenePanel

- Allow subclasses of EditorFrame to specify the EditorScenePanel and StageSceneWriter used



git-svn-id: svn+ssh://src.earth.threerings.net/vilya/trunk@570 c613c5cb-e716-0410-b11b-feb51c14d237
This commit is contained in:
Charlie Groves
2008-03-12 06:09:41 +00:00
parent d96a1390c5
commit 53655b2856
3 changed files with 75 additions and 40 deletions
@@ -28,6 +28,7 @@ import java.awt.EventQueue;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
@@ -66,6 +67,7 @@ import com.threerings.miso.tile.MisoTileManager;
import com.threerings.stage.data.StageSceneModel;
import com.threerings.stage.tools.editor.util.EditorContext;
import com.threerings.stage.tools.xml.StageSceneWriter;
/**
* A scene editor application that provides facilities for viewing,
@@ -245,13 +247,14 @@ public class EditorApp implements Runnable
_frame.setSize(1024, 768);
SwingUtil.centerWindow(_frame);
_frame.setVisible(true);
SwingUtil.refresh((JComponent)_frame.getContentPane());
}
_framemgr.start();
}
protected EditorFrame createEditorFrame ()
{
return new EditorFrame();
return new EditorFrame(new StageSceneWriter());
}
/**
@@ -34,7 +34,6 @@ import java.awt.event.WindowEvent;
import java.io.File;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
@@ -65,8 +64,9 @@ import com.threerings.stage.tools.xml.StageSceneWriter;
public class EditorFrame extends ManagedJFrame
{
public EditorFrame ()
public EditorFrame (StageSceneWriter writer)
{
_writer = writer;
// treat a closing window as a request to quit
addWindowListener(new WindowAdapter () {
public void windowClosing (WindowEvent e) {
@@ -87,16 +87,15 @@ public class EditorFrame extends ManagedJFrame
// create the file chooser used for saving and loading scenes
if (target == null) {
target = EditorConfig.config.getValue(
"editor.last_dir", System.getProperty("user.dir"));
target = EditorConfig.config.getValue("editor.last_dir",
System.getProperty("user.dir"));
}
_chooser = (target == null) ?
new JFileChooser() : new JFileChooser(target);
_chooser = (target == null) ? new JFileChooser() : new JFileChooser(target);
_chooser.setFileFilter(new FileFilter () {
public boolean accept (File f) {
@Override public boolean accept (File f) {
return (f.isDirectory() || f.getName().endsWith(".xml"));
}
public String getDescription () {
@Override public String getDescription () {
return "XML Files";
}
});
@@ -117,14 +116,12 @@ public class EditorFrame extends ManagedJFrame
_main = new JPanel(new BorderLayout());
// set up the scene view panel with a default scene
_svpanel = new EditorScenePanel(_ctx, this, _model);
_svpanel = createScenePanel();
_main.add(_svpanel, BorderLayout.CENTER);
// create a toolbar for action selection and other options
JPanel upper = new JPanel(
new HGroupLayout(GroupLayout.NONE, GroupLayout.LEFT));
upper.add(new EditorToolBarPanel(_ctx.getTileManager(), _model),
GroupLayout.FIXED);
JPanel upper = new JPanel(new HGroupLayout(GroupLayout.NONE, GroupLayout.LEFT));
upper.add(new EditorToolBarPanel(_ctx.getTileManager(), _model), GroupLayout.FIXED);
_sceneInfoPanel = new SceneInfoPanel(_ctx, _model, _svpanel);
upper.add(_sceneInfoPanel, GroupLayout.FIXED);
_main.add(upper, BorderLayout.NORTH);
@@ -170,7 +167,20 @@ public class EditorFrame extends ManagedJFrame
});
// finally set a default scene
newScene();
String lastFile = EditorConfig.config.getValue("editor.last_file", "");
if (lastFile.equals("")) {
newScene();
} else {
openScene(lastFile);
}
}
/**
* Creates the EditorScenePanel to use in this frame.
*/
protected EditorScenePanel createScenePanel ()
{
return new EditorScenePanel(_ctx, this, _model);
}
/**
@@ -508,8 +518,8 @@ public class EditorFrame extends ManagedJFrame
switch (_chooser.getDialogType()) {
case JFileChooser.OPEN_DIALOG:
openScene(filescene.getPath());
EditorConfig.config.setValue(
"editor.last_dir", filescene.getParent());
EditorConfig.config.setValue("editor.last_dir", filescene.getParent());
EditorConfig.config.setValue("editor.last_file", filescene.getAbsolutePath());
break;
case JFileChooser.SAVE_DIALOG:
@@ -518,8 +528,7 @@ public class EditorFrame extends ManagedJFrame
break;
default:
Log.warning("Wha? Weird dialog type " +
_chooser.getDialogType() + ".");
Log.warning("Wha? Weird dialog type " + _chooser.getDialogType() + ".");
break;
}
}
@@ -574,7 +583,7 @@ public class EditorFrame extends ManagedJFrame
protected StageSceneParser _parser = new StageSceneParser();
/** We use this to save scenes. */
protected StageSceneWriter _writer = new StageSceneWriter();
protected StageSceneWriter _writer;
/** The test tileset loader. */
protected TestTileLoader _testLoader;
@@ -51,7 +51,6 @@ import com.samskivert.swing.Controller;
import com.samskivert.swing.TGraphics2D;
import com.samskivert.swing.util.SwingUtil;
import com.samskivert.util.RandomUtil;
import com.samskivert.util.StringUtil;
import com.threerings.util.DirectionCodes;
import com.threerings.media.tile.ObjectTile;
@@ -72,7 +71,6 @@ import com.threerings.stage.client.StageScenePanel;
import com.threerings.stage.data.StageLocation;
import com.threerings.stage.data.StageMisoSceneModel;
import com.threerings.stage.data.StageScene;
import com.threerings.stage.tools.editor.util.EditorContext;
import com.threerings.stage.tools.editor.util.EditorDialogUtil;
import com.threerings.stage.tools.editor.util.ExtrasPainter;
@@ -609,47 +607,72 @@ public class EditorScenePanel extends StageScenePanel
}
/**
* Sets an object tile at the specified position in the scene (in tile
* coordinates).
* Sets an object tile at the specified position in the scene (in tile coordinates).
*
* @return - the created object or null if an identical object was already in that spot.
*/
public void addObject (ObjectTile tile, int fqTileId, int x, int y)
public ObjectInfo addObject (ObjectTile tile, int fqTileId, int x, int y)
{
Point p = new Point(x, y);
adjustObjectCoordsAccordingToGrip(p, tile);
return addObject(new ObjectInfo(fqTileId, x, y));
}
ObjectInfo oinfo = new ObjectInfo(fqTileId, x, y);
/**
* Adds the given object to the scene.
*
* @return the added object or null if an identical object was already in that spot.
*/
public ObjectInfo addObject (ObjectInfo oinfo)
{
// first attempt to add it to the appropriate scene block; this
// will fail if there's already a copy of the same object at this
// coordinate
if (getBlock(x, y).addObject(oinfo)) {
if (getBlock(oinfo.x, oinfo.y).addObject(oinfo)) {
// create an object info and add it to the scene model
_model.addObject(oinfo);
// recompute our visible object set
recomputeVisible();
return oinfo;
}
return null;
}
/**
* Deletes the object tile at the specified tile coordinates.
*
* @return true - if a matching object was found and deleted.
*/
public void deleteObject (SceneObject scobj)
public boolean deleteObject (SceneObject scobj)
{
if (deleteObject(scobj.info)) {
// make sure we clear the hover if that's what we're deleting
if (_hobject == scobj) {
_hobject = null;
}
return true;
}
Log.warning("Requested to remove unknown object " + scobj + ".");
return false;
}
/**
* Delete the given object from the scene.
*
* @return true - if a matching object was found and deleted.
*/
public boolean deleteObject (ObjectInfo info)
{
// remove it from the scene model
if (_model.removeObject(scobj.info)) {
if (_model.removeObject(info)) {
// clear the object out of its block
getBlock(scobj.info.x, scobj.info.y).deleteObject(scobj.info);
} else {
Log.warning("Requested to remove unknown object " + scobj + ".");
}
getBlock(info.x, info.y).deleteObject(info);
// recompute our visible object set
recomputeVisible();
// make sure we clear the hover if that's what we're deleting
if (_hobject == scobj) {
_hobject = null;
// recompute our visible object set
recomputeVisible();
return true;
}
return false;
}
/**