y.view
Class Graph2DClipboard

java.lang.Object
  extended by y.view.Graph2DClipboard
Direct Known Subclasses:
Graph2DHierarchyClipboard

public class Graph2DClipboard
extends Object

Provides clipboard functionality for diagrams of type Graph2D. The clipboard can be used to create a copy of the selected parts of a Graph2D instance. Also it can be used to paste a formerly copied subgraph into a graph again. Swing Actions are provided that encapsulate Cut, Copy and Paste functionality.

The clipboard uses a GraphFactory to create copies of graph elements. By default an instance of Graph2DCopyFactory is used as factory.

See Also:
setGraphFactory(GraphFactory)
 

Field Summary
protected  PropertyChangeSupport propertyChangeSupport
          Utility field used by bound properties.
 
Constructor Summary
Graph2DClipboard(ViewContainer vc)
          Creates a new clipboard for the graphs managed by the given view container.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener l)
          Adds a PropertyChangeListener to this clipboard.
protected  NodeList copyGraph(Graph sourceGraph, Graph targetGraph, NodeCursor sourceNodes)
          Copies parts of one graph to another graph.
 void copyToClipBoard(Graph graph, NodeCursor nc)
          Copies parts the given graph to the clipboard.
protected  Graph getClipboardGraph()
          Returns the internal graph that is used to store the contents of the clipboard.
 Action getCopyAction()
          Returns a swing action that provides the Copy operation on graphs.
 Action getCutAction()
          Returns a swing action that provides the Cut operation on graphs.
protected  Graph2D getGraph2D()
          Returns the graph that is displayed in the current view.
 GraphFactory getGraphFactory()
          Returns the graph factory used by this class.
 Action getPasteAction()
          Returns a swing action that provides the Paste operation on graphs.
 ViewContainer getViewContainer()
          Returns the viewContainer associated with this clipboard.
 boolean isEmpty()
          Returns whether or not the clipboard is currently empty.
 boolean isSelectionEmpty()
          Returns whether or not there are selected nodes in the active graph.
 boolean isSelectionStateObserverEnabled()
          Whether or not the selection state of the current graph will be observed.
 NodeList pasteFromClipBoard(Graph targetGraph)
          Pastes the elements of the clipboard graph to the given graph.
 NodeList pasteFromClipBoard(Graph targetGraph, double x, double y)
          Pastes the elements of the clipboard graph to the given graph.
 void removePropertyChangeListener(PropertyChangeListener l)
          Removes a PropertyChangeListener from this clipboard.
 void setGraphFactory(GraphFactory graphFactory)
          Sets the graph factory used to create copies of graph elements.
 void setSelectionStateObserverEnabled(boolean enabled)
          Whether or not to enable the observation of the selection state of the current graph.
 void updateSelectionState()
          Forces update of the selection state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

propertyChangeSupport

protected PropertyChangeSupport propertyChangeSupport
Utility field used by bound properties.

Constructor Detail

Graph2DClipboard

public Graph2DClipboard(ViewContainer vc)
Creates a new clipboard for the graphs managed by the given view container.

Method Detail

setGraphFactory

public void setGraphFactory(GraphFactory graphFactory)
Sets the graph factory used to create copies of graph elements.


getGraphFactory

public GraphFactory getGraphFactory()
Returns the graph factory used by this class.


getClipboardGraph

protected Graph getClipboardGraph()
Returns the internal graph that is used to store the contents of the clipboard.


isEmpty

public boolean isEmpty()
Returns whether or not the clipboard is currently empty. A PropertyChangeEvent will be fired whenever this state changes.


isSelectionEmpty

public boolean isSelectionEmpty()
Returns whether or not there are selected nodes in the active graph. A PropertyChangeEvent will be fired whenever this state changes.


copyToClipBoard

public void copyToClipBoard(Graph graph,
                            NodeCursor nc)
Copies parts the given graph to the clipboard. The copied subgraph is induced by the nodes accessible via the given NodeCursor.


getGraph2D

protected Graph2D getGraph2D()
Returns the graph that is displayed in the current view. The actions provided by this class act upon this graph.


copyGraph

protected NodeList copyGraph(Graph sourceGraph,
                             Graph targetGraph,
                             NodeCursor sourceNodes)
Copies parts of one graph to another graph.


pasteFromClipBoard

public NodeList pasteFromClipBoard(Graph targetGraph,
                                   double x,
                                   double y)
Pastes the elements of the clipboard graph to the given graph. The clipboard graph will be pasted in a way that the upper left corner of its bounding box matches the given location.

Parameters:
targetGraph - the graph pasted to.
x - the x-coordinate of the paste location
y - the y-coordinate of the paste location

pasteFromClipBoard

public NodeList pasteFromClipBoard(Graph targetGraph)
Pastes the elements of the clipboard graph to the given graph.

Parameters:
targetGraph - the graph pasted to.

getCutAction

public Action getCutAction()
Returns a swing action that provides the Cut operation on graphs.


getCopyAction

public Action getCopyAction()
Returns a swing action that provides the Copy operation on graphs.


getPasteAction

public Action getPasteAction()
Returns a swing action that provides the Paste operation on graphs. The property value PASTE_LOCATION can be used to provide an instance of YPoint that specifies the preferred paste location.


addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
Adds a PropertyChangeListener to this clipboard. Listeners will be informed when the property "empty" changes.


removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Removes a PropertyChangeListener from this clipboard.


getViewContainer

public ViewContainer getViewContainer()
Returns the viewContainer associated with this clipboard.


updateSelectionState

public void updateSelectionState()
Forces update of the selection state. Depending on the selection state the Cut and Copy actions will be enabled or not.


isSelectionStateObserverEnabled

public boolean isSelectionStateObserverEnabled()
Whether or not the selection state of the current graph will be observed.


setSelectionStateObserverEnabled

public void setSelectionStateObserverEnabled(boolean enabled)
Whether or not to enable the observation of the selection state of the current graph. Observing the selection state will allow to keep the enabled state of the Cut and Copy actions in sync with the selection state. Disabling the observation will effectively deregister all listeners from the current graph.


© Copyright 2000-2008,
yWorks GmbH.
All rights reserved.