trackeditor: implement circuit view delete all objects for graphic objects and add undo
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@9085 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 40e2f670f5caa629479a5e8b0d79111f1e71e83a Former-commit-id: d8e120a9ac29c58b837cbbf9714530bdb7ca2d0f
This commit is contained in:
parent
f70065eba7
commit
a70c191a70
3 changed files with 82 additions and 7 deletions
|
@ -57,12 +57,14 @@ import utils.circuit.Reliefs;
|
||||||
import utils.circuit.Segment;
|
import utils.circuit.Segment;
|
||||||
import utils.circuit.Straight;
|
import utils.circuit.Straight;
|
||||||
import utils.circuit.XmlObjPits;
|
import utils.circuit.XmlObjPits;
|
||||||
|
import utils.undo.DeletedObject;
|
||||||
import utils.undo.MovedObject;
|
import utils.undo.MovedObject;
|
||||||
import utils.undo.ObjectMapObject;
|
import utils.undo.ObjectMapObject;
|
||||||
import utils.undo.Undo;
|
import utils.undo.Undo;
|
||||||
import utils.undo.UndoAddGraphicObject;
|
import utils.undo.UndoAddGraphicObject;
|
||||||
import utils.undo.UndoAddObject;
|
import utils.undo.UndoAddObject;
|
||||||
import utils.undo.UndoAddSegment;
|
import utils.undo.UndoAddSegment;
|
||||||
|
import utils.undo.UndoDeleteAllGraphicObjects;
|
||||||
import utils.undo.UndoDeleteAllObjects;
|
import utils.undo.UndoDeleteAllObjects;
|
||||||
import utils.undo.UndoDeleteGraphicObject;
|
import utils.undo.UndoDeleteGraphicObject;
|
||||||
import utils.undo.UndoDeleteObject;
|
import utils.undo.UndoDeleteObject;
|
||||||
|
@ -2387,6 +2389,8 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<ObjectMap> objectMaps = editorFrame.getObjectMaps();
|
Vector<ObjectMap> objectMaps = editorFrame.getObjectMaps();
|
||||||
|
@ -2449,6 +2453,8 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<ObjectMap> objectMaps = editorFrame.getObjectMaps();
|
Vector<ObjectMap> objectMaps = editorFrame.getObjectMaps();
|
||||||
|
@ -2545,6 +2551,8 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<ObjectMap> objectMaps = editorFrame.getObjectMaps();
|
Vector<ObjectMap> objectMaps = editorFrame.getObjectMaps();
|
||||||
|
@ -2583,14 +2591,28 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
|
||||||
|
|
||||||
if (isGraphicObject)
|
if (isGraphicObject)
|
||||||
{
|
{
|
||||||
for (GraphicObject graphicObject : editorFrame.getGraphicObjects())
|
Vector<DeletedObject> deletedObjects = new Vector<DeletedObject>();
|
||||||
|
|
||||||
|
for (int i = 0; i < editorFrame.getGraphicObjects().size(); i++)
|
||||||
{
|
{
|
||||||
if (graphicObject.getShape() == shape)
|
if (editorFrame.getGraphicObjects().get(i).getShape().getRGB() == shape.getRGB())
|
||||||
{
|
{
|
||||||
JOptionPane.showMessageDialog(null, "Not implemented yet!", "Delete All Objects", JOptionPane.INFORMATION_MESSAGE);
|
deletedObjects.add(0, new DeletedObject(editorFrame.getGraphicObjects().get(i), i));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Undo.add(new UndoDeleteAllGraphicObjects(editorFrame.getGraphicObjects(), deletedObjects));
|
||||||
|
|
||||||
|
for (int i = 0; i < deletedObjects.size(); i++)
|
||||||
|
{
|
||||||
|
editorFrame.getGraphicObjects().remove(deletedObjects.get(i).object);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedShape = null;
|
||||||
|
editorFrame.documentIsModified = true;
|
||||||
|
invalidate();
|
||||||
|
repaint();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rgb = shape.getRGB();
|
int rgb = shape.getRGB();
|
||||||
|
@ -2893,7 +2915,7 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
|
||||||
JMenuItem itemEdit = new JMenuItem("Edit");
|
JMenuItem itemEdit = new JMenuItem("Edit");
|
||||||
JMenuItem itemEditAll = isGraphicObject ? null : new JMenuItem("Edit All");
|
JMenuItem itemEditAll = isGraphicObject ? null : new JMenuItem("Edit All");
|
||||||
JMenuItem itemDelete = new JMenuItem("Delete");
|
JMenuItem itemDelete = new JMenuItem("Delete");
|
||||||
JMenuItem itemDeleteAll = isGraphicObject ? null : new JMenuItem("Delete All");
|
JMenuItem itemDeleteAll = new JMenuItem("Delete All");
|
||||||
JMenuItem itemDeleteAdjacent = isGraphicObject ? null : new JMenuItem("Delete Adjacent");
|
JMenuItem itemDeleteAdjacent = isGraphicObject ? null : new JMenuItem("Delete Adjacent");
|
||||||
JMenuItem itemDeleteAllAdjacent = isGraphicObject ? null : new JMenuItem("Delete All Adjacent");
|
JMenuItem itemDeleteAllAdjacent = isGraphicObject ? null : new JMenuItem("Delete All Adjacent");
|
||||||
JMenuItem itemMoveToObjects = isGraphicObject ? null : new JMenuItem("Move To Objects");
|
JMenuItem itemMoveToObjects = isGraphicObject ? null : new JMenuItem("Move To Objects");
|
||||||
|
@ -2902,13 +2924,13 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
|
||||||
itemCopy.setAction(copyAction);
|
itemCopy.setAction(copyAction);
|
||||||
itemEdit.setAction(editAction);
|
itemEdit.setAction(editAction);
|
||||||
itemDelete.setAction(deleteAction);
|
itemDelete.setAction(deleteAction);
|
||||||
|
itemDeleteAll.setAction(deleteAllAction);
|
||||||
if (isGraphicObject)
|
if (isGraphicObject)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
itemEditAll.setAction(editAllAction);
|
itemEditAll.setAction(editAllAction);
|
||||||
itemDeleteAll.setAction(deleteAllAction);
|
|
||||||
itemDeleteAdjacent.setAction(deleteAdjacentAction);
|
itemDeleteAdjacent.setAction(deleteAdjacentAction);
|
||||||
itemDeleteAllAdjacent.setAction(deleteAllAdjacentAction);
|
itemDeleteAllAdjacent.setAction(deleteAllAdjacentAction);
|
||||||
itemMoveToObjects.setAction(moveToObjectsAction);
|
itemMoveToObjects.setAction(moveToObjectsAction);
|
||||||
|
@ -2924,9 +2946,9 @@ public class CircuitView extends JComponent implements KeyListener, MouseListene
|
||||||
}
|
}
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
menu.add(itemDelete);
|
menu.add(itemDelete);
|
||||||
|
menu.add(itemDeleteAll);
|
||||||
if (!isGraphicObject)
|
if (!isGraphicObject)
|
||||||
{
|
{
|
||||||
menu.add(itemDeleteAll);
|
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
menu.add(itemDeleteAdjacent);
|
menu.add(itemDeleteAdjacent);
|
||||||
menu.add(itemDeleteAllAdjacent);
|
menu.add(itemDeleteAllAdjacent);
|
||||||
|
|
15
src/tools/trackeditor/utils/undo/DeletedObject.java
Normal file
15
src/tools/trackeditor/utils/undo/DeletedObject.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package utils.undo;
|
||||||
|
|
||||||
|
import utils.circuit.GraphicObject;
|
||||||
|
|
||||||
|
public class DeletedObject
|
||||||
|
{
|
||||||
|
public GraphicObject object;
|
||||||
|
public int objectIndex;
|
||||||
|
|
||||||
|
public DeletedObject(GraphicObject object, int objectIndex)
|
||||||
|
{
|
||||||
|
this.object = object;
|
||||||
|
this.objectIndex = objectIndex;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package utils.undo;
|
||||||
|
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import utils.circuit.GraphicObject;
|
||||||
|
|
||||||
|
public class UndoDeleteAllGraphicObjects implements UndoInterface
|
||||||
|
{
|
||||||
|
Vector<GraphicObject> graphicObjects;
|
||||||
|
Vector<DeletedObject> undo;
|
||||||
|
Vector<DeletedObject> redo;
|
||||||
|
|
||||||
|
public UndoDeleteAllGraphicObjects(Vector<GraphicObject> graphicObjects, Vector<DeletedObject> deletedObjects)
|
||||||
|
{
|
||||||
|
this.graphicObjects = graphicObjects;
|
||||||
|
this.undo = deletedObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void undo()
|
||||||
|
{
|
||||||
|
for (int i = undo.size() - 1; i >= 0 ; i--)
|
||||||
|
{
|
||||||
|
graphicObjects.add(undo.get(i).objectIndex, undo.get(i).object);
|
||||||
|
}
|
||||||
|
redo = undo;
|
||||||
|
undo = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void redo()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < redo.size(); i++)
|
||||||
|
{
|
||||||
|
graphicObjects.remove(redo.get(i).object);
|
||||||
|
}
|
||||||
|
undo = redo;
|
||||||
|
redo = null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue