|
Search this API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object y.view.Graph2DUndoManager
public class Graph2DUndoManager
This class provides undoability and redoability support for Graph2D changes.
It must be registered
as a GraphListener
and Graph2D.BackupRealizersHandler
to make this class aware of Graph2D changes. The backup mechanism of realizers depends
on a correct implementation of their createCopy method.
HierarchyListener
and must therefore be registered
with HierarchyManager
if one is being used.
Note that using the non-empty constructor will automatically register the listeners for you on the provided
instance (both on the Graph2D and on its HierarchyManager if one is associated with it).
GraphEvents of type GraphEvent.PRE_EVENT
and GraphEvent.POST_EVENT
serve as hints for the undo manager to decide which commands to group into a single
command that can be undone or redone. To group a sequence of graph changes in one
undoable command use the following code:
Graph2D graph = ... graph.firePreEvent(); //block of graph changes follows graph.firePostEvent;changes to the realizers of the nodes and edges are handled by backing up realizers that are about to change. Use the Graph2D methods
Graph2D.backupRealizers(NodeCursor)
and Graph2D.backupRealizers(EdgeCursor)
in your code whenever you want to be able to revert to the former state of the realizers
at a later time.
Nested Class Summary | |
---|---|
static interface |
Graph2DUndoManager.UndoListener
Implementations of this interface can register with the UndoManager to receive notification whenever a new command is added to the queue of undoable events. |
Constructor Summary | |
---|---|
Graph2DUndoManager()
Creates a new Instance of UndoManager. |
|
Graph2DUndoManager(Graph2D graph)
Creates a new instance of this class, that conveniently registers the necessary listeners on the provided graph instance. |
Method Summary | |
---|---|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener l)
Adds a PropertyChangeListener to the listener list. |
void |
addUndoListener(Graph2DUndoManager.UndoListener listener)
Registers the given UndoListener with the UndoManager. |
void |
backupRealizers(Graph2D graph,
EdgeCursor ec)
Graph2D.BackupRealizersHandler implementation. |
void |
backupRealizers(Graph2D graph,
NodeCursor nc)
Graph2D.BackupRealizersHandler implementation. |
boolean |
canRedo()
Returns whether or not there is a command that can be redone. |
boolean |
canUndo()
Returns whether or not there is a command that can be undone. |
protected void |
commandAdded(Command com)
Calling this method will inform all registered UndoListeners that the given command has been added to the command queue. |
void |
dispose()
Disposes this Graph2DUndoManager instance. |
Graph |
getActiveGraph()
Getter for property activeGraph. |
java.lang.Object |
getActiveToken()
Obtains a token which determines the currently active position in the stream. |
int |
getMaximumUndoDepth()
Returns the maximum number of commands stored on the undo stream. |
javax.swing.Action |
getRedoAction()
Returns a swing action that can be used to trigger a redo operation. |
javax.swing.Action |
getUndoAction()
Returns a swing action that can be used to trigger an undo operation. |
ViewContainer |
getViewContainer()
Returns the view container this undo manager is associated with. |
void |
hierarchyChange(HierarchyEvent ev)
HierarchyListener implementation. |
boolean |
isActive()
Getter for property active. |
boolean |
isActiveToken(java.lang.Object token)
Determines, whether the stream is currently at the same position, the time the token was obtained using getActiveToken() |
boolean |
isSelectionStateAdjusting()
Determines whether this instance adjust the selection state
of the realizers to match that of the currently active realizers upon realizer exchange. |
void |
onGraphEvent(GraphEvent e)
Graph2DListener implementation.Structural changes of the graph will be
converted to undoable commands and stored in a command stream for later execution. |
void |
push(Command com)
This method can be used to push undoable commands on the stream. |
void |
redo()
Causes the next command in line to be redone. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener l)
Removes a PropertyChangeListener from the listener list. |
void |
removeUndoListener(Graph2DUndoManager.UndoListener listener)
Removed the given UndoListener from the UndoManager. |
void |
resetQueue()
Clears the current undo queue, i.e. canUndo() and canRedo() will return false if invoked directly after this call. |
protected void |
sanatize()
Performs the suitable number of close bracket operations, to ensure undo() and redo() will work as expected. |
void |
setActiveGraph(Graph activeGraph)
Setter for property activeGraph. |
boolean |
setExchangeRealizersOnBackup()
Returns the exchangeRealizerOnBackup policy used. |
void |
setExchangeRealizersOnBackup(boolean exchange)
Controls whether or not an exchange of the realizers associated with a node or edge is desired when backing them up. |
void |
setMaximumUndoDepth(int depth)
Sets the maximum number of commands stored on the undo stream. |
void |
setSelectionStateAdjusting(boolean selectionStateAdjusting)
Sets whether this instance should adjust the selection state
of the realizers to match that of the currently active realizers upon realizer exchange. |
void |
setViewContainer(ViewContainer view)
Sets the view container this undo manager is associated with. |
void |
undo()
Causes the next command in line to be undone. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Graph2DUndoManager(Graph2D graph)
graph listener
and
backup realizers handler
if the graph has already been passed to this
instance via this constructor. Also if at the time of the invocation, there is a hierarchy manager
associated with the provided graph instance, it will be registered with it correctly, so
that again this instance should not be add this instance
to the HierarchyManager
's event listener list.
graph
- The graph that should be managed for undoability. This will register this instance as the a listener
and backup handler on the graph instance, as well as will try to listen for hierarchy event on the associated hierarchy manager.public Graph2DUndoManager()
Graph2D
instances, it needs to be registered as a listener
with the corresponding graph events.
Method Detail |
---|
public void dispose()
Graph2DUndoManager
instance.
To free resources, this method should be called after a
Graph2DUndoManager
instance is not needed anymore.
If this Graph2DUndoManager
was automatically registered as
a GraphListener
, HierarchyListener
, and
BackupRealizersHandler
by using the
Graph2DUndoManager(Graph2D)
constructor, invoking this method will
also deregister this manager from the corresponding graph and hierarchy
manager.
Note: It is not safe to invoke any methods on a disposed
Graph2DUndoManager
instance. Doing so may result in
NullPointerException
being thrown.
public boolean isSelectionStateAdjusting()
selection state
of the realizers to match that of the currently active realizers upon realizer exchange.
true
.public void setSelectionStateAdjusting(boolean selectionStateAdjusting)
selection state
of the realizers to match that of the currently active realizers upon realizer exchange.
public void setExchangeRealizersOnBackup(boolean exchange)
false
.
public boolean setExchangeRealizersOnBackup()
public boolean canUndo()
public boolean canRedo()
public void push(Command com)
public void setMaximumUndoDepth(int depth)
public void resetQueue()
public int getMaximumUndoDepth()
public void undo()
public void redo()
protected void sanatize()
public java.lang.Object getActiveToken()
isActiveToken(Object)
can be used to determine, whether the
current stream position equals the position at the time to token was
obtained
public boolean isActiveToken(java.lang.Object token)
getActiveToken()
token
- the token
public boolean isActive()
public void onGraphEvent(GraphEvent e)
Graph2DListener
implementation.Structural changes of the graph will be
converted to undoable commands and stored in a command stream for later execution.
onGraphEvent
in interface GraphListener
public javax.swing.Action getUndoAction()
setViewContainer(ViewContainer)
public javax.swing.Action getRedoAction()
setViewContainer(ViewContainer)
public void hierarchyChange(HierarchyEvent ev)
HierarchyListener
implementation. This class keeps track of hierarchy changes.
hierarchyChange
in interface HierarchyListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
public Graph getActiveGraph()
public void setActiveGraph(Graph activeGraph)
public void addUndoListener(Graph2DUndoManager.UndoListener listener)
public void removeUndoListener(Graph2DUndoManager.UndoListener listener)
protected void commandAdded(Command com)
public void setViewContainer(ViewContainer view)
public ViewContainer getViewContainer()
public void backupRealizers(Graph2D graph, NodeCursor nc)
Graph2D.BackupRealizersHandler
implementation. This method
creates copies of the given realizer and stores them in undoable commands
for later reactivation.
backupRealizers
in interface Graph2D.BackupRealizersHandler
public void backupRealizers(Graph2D graph, EdgeCursor ec)
Graph2D.BackupRealizersHandler
implementation. This method
creates copies of the given realizer and stores them in undoable commands
for later reactivation.
backupRealizers
in interface Graph2D.BackupRealizersHandler
|
© Copyright 2000-2022, yWorks GmbH. All rights reserved. |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |