Search this API

y.view
Class Graph2DViewActions

java.lang.Object
  extended by y.view.Graph2DViewActions

public class Graph2DViewActions
extends java.lang.Object

This class provides actions for Graph2DView.

The easiest way to add the provided actions to an instance of Graph2DView is demonstrated below:

   new Graph2DViewActions(view).install();
 
However, the behavior may be tweaked a lot using the following technique:
   Graph2DViewActions actions = new Graph2DViewActions(view);
   ActionMap amap = actions.createActionMap();
   InputMap imap = actions.createDefaultInputMap(amap);
   view.getCanvasComponent().setActionMap(amap);
   view.getCanvasComponent().setInputMap(JComponent.WHEN_FOCUSED, imap);
 

See Also:
Graph2DViewActions(Graph2DView), install()
 
Your browser does not support SVG content.

Nested Class Summary
static class Graph2DViewActions.AbstractGroupingAction
          Abstract base class for grouping related actions.
static class Graph2DViewActions.AddPredecessorsAction
          Action that adds a predecessor node to selected nodes.
static class Graph2DViewActions.AddSuccessorsAction
          Action that adds a successor node to selected nodes.
static class Graph2DViewActions.CloseGroupsAction
          Action that closes multiple group nodes.
static class Graph2DViewActions.DeleteSelectionAction
          Action that deletes selected elements of predefined types.
static class Graph2DViewActions.DuplicateAction
          Action that allows to duplicate nodes or edges.
static class Graph2DViewActions.EditLabelAction
          Action that opens the label editor for interactive text editing.
static class Graph2DViewActions.FoldSelectionAction
          Action that moves multiple nodes in a new folder node.
static class Graph2DViewActions.GroupSelectionAction
          Action that puts multiple nodes in a new group node.
static class Graph2DViewActions.OpenFoldersAction
          Action that closes multiple group nodes.
static class Graph2DViewActions.SelectAllAction
          Action that selects elements of predefined types.
static class Graph2DViewActions.UnfoldSelectionAction
          Action that removes the selected nodes from their folder.
static class Graph2DViewActions.UngroupSelectionAction
          Action that ungroups the selected nodes from their group.
 
Field Summary
static java.lang.Object ADD_PREDECESSORS
          ActionMap key for action returned by getAddPredecessorsAction().
static java.lang.Object ADD_SUCCESSORS
          ActionMap key for action returned by getAddSuccessorsAction().
static java.lang.Object ALIGN_HORIZONTALLY
          ActionMap key for action returned by getAlignHorizontallyAction()
static java.lang.Object ALIGN_VERTICALLY
          ActionMap key for action returned by getAlignVerticallyAction().
static java.lang.Object BOTTOM_ALIGN
          ActionMap key for action returned by getBottomAlignAction().
static java.lang.Object CLOSE_GROUPS
          ActionMap key for action returned by getCloseGroupsAction().
static java.lang.Object DELETE_SELECTION
          ActionMap key for action returned by getDeleteSelectionAction().
static java.lang.Object DISTRIBUTE_HORIZONTALLY
          ActionMap key for action returned by getDistributeHorizontallyAction().
static java.lang.Object DISTRIBUTE_VERTICALLY
          ActionMap key for action returned by getDistributeVerticallyAction().
static java.lang.Object DUPLICATE_GRAPH
          ActionMap key for action returned by getDuplicateGraphAction().
static java.lang.Object EDIT_LABEL
          ActionMap key for action returned by getEditLabelAction().
static java.lang.Object EDIT_NODE
          ActionMap key for action returned by getEditNodeAction().
static java.lang.Object FOCUS_BOTTOM_NODE
          ActionMap key for action returned by getFocusBottomNodeAction().
static java.lang.Object FOCUS_LEFT_NODE
          ActionMap key for action returned by getFocusLeftNodeAction().
static java.lang.Object FOCUS_RIGHT_NODE
          ActionMap key for action returned by getFocusRightNodeAction().
static java.lang.Object FOCUS_TOP_NODE
          ActionMap key for action returned by getFocusTopNodeAction().
static java.lang.Object FOLD_SELECTION
          ActionMap key for action returned by getFoldSelectionAction().
static java.lang.Object GROUP_SELECTION
          ActionMap key for action returned by getGroupSelectionAction().
static java.lang.Object LEFT_ALIGN
          ActionMap key for action returned by getLeftAlignAction().
static java.lang.Object OPEN_FOLDERS
          ActionMap key for action returned by getOpenFoldersAction().
static java.lang.Object RIGHT_ALIGN
          ActionMap key for action returned by getRightAlignAction().
static java.lang.Object SELECT_ALL
          ActionMap key for action returned by getSelectAllAction().
static java.lang.Object SELECT_BOTTOM_EDGE
          ActionMap key for action returned by getSelectBottomEdgeAction().
static java.lang.Object SELECT_LEFT_EDGE
          ActionMap key for action returned by getSelectLeftEdgeAction().
static java.lang.Object SELECT_RIGHT_EDGE
          ActionMap key for action returned by getSelectRightEdgeAction().
static java.lang.Object SELECT_TOP_EDGE
          ActionMap key for action returned by getSelectTopEdgeAction().
static java.lang.Object TOP_ALIGN
          ActionMap key for action returned by getTopAlignAction().
static java.lang.Object UNFOLD_SELECTION
          ActionMap key for action returned by getUnfoldSelectionAction().
static java.lang.Object UNGROUP_SELECTION
          ActionMap key for action returned by getUngroupSelectionAction().
 
Constructor Summary
Graph2DViewActions()
          Creates a new instance that is not bound to any Graph2DView.
Graph2DViewActions(Graph2DView view)
          Creates a new instance of Graph2DViewActions for the given view.
 
Method Summary
 javax.swing.ActionMap createActionMap()
          Returns a new ActionMap that contains the actions provided by this class.
 javax.swing.InputMap createDefaultInputMap()
          Returns a default key binding for the actions provided by this class.
 javax.swing.InputMap createDefaultInputMap(javax.swing.ActionMap amap)
          Returns a default key binding for the actions provided by this class that are also bound by the given ActionMap.
protected  void deleteSelection(Graph2DView view)
          Deprecated. Use Graph2DViewActions.DeleteSelectionAction.delete(Graph2DView) instead.
protected  void editNode(Graph2DView view)
          Called by the EDIT_NODE action.
 javax.swing.Action getAddPredecessorsAction()
          Returns an action that create children for selected nodes
 javax.swing.Action getAddSuccessorsAction()
          Returns an action that create children for selected nodes
 javax.swing.Action getAlignHorizontallyAction()
          Returns an action that aligns the currently selected nodes by their center x-coordinate.
 javax.swing.Action getAlignVerticallyAction()
          Returns an action that aligns the currently selected nodes by their center y-coordinate.
 javax.swing.Action getBottomAlignAction()
          Returns an action that aligns the currently selected nodes by their maximum y-coordinate.
 javax.swing.Action getCloseGroupsAction()
          Returns an action that closes one or more group nodes.
 javax.swing.Action getDeleteSelectionAction()
          Returns an action that deletes the currently selected elements from the graph.
 javax.swing.Action getDistributeHorizontallyAction()
          Returns an action that places the currently selected nodes such that they do not overlap horizontally.
 javax.swing.Action getDistributeVerticallyAction()
          Returns an action that places the currently selected nodes such that they do not overlap vertically.
 javax.swing.Action getDuplicateGraphAction()
          Returns an action that duplicates selected graph.
 javax.swing.Action getEditLabelAction()
          Returns an action that triggers the inline label editor.
 javax.swing.Action getEditNodeAction()
          Returns an action that starts editing a selected node if the current ViewMode is either a suitable EditMode or CellEditorMode instance.
 javax.swing.Action getFocusBottomNodeAction()
          Returns an action that selects a node that is below the currently selected node.
 javax.swing.Action getFocusLeftNodeAction()
          Returns an action that selects a node that is to the left of the currently selected node.
 javax.swing.Action getFocusRightNodeAction()
          Returns an action that selects a node that is to the right of the currently selected node.
 javax.swing.Action getFocusTopNodeAction()
          Returns an action that selects a node that is above the currently selected node.
 javax.swing.Action getFoldSelectionAction()
          Returns an action that folds the current selection.
 javax.swing.Action getGroupSelectionAction()
          Returns an action that groups the current selection.
 javax.swing.Action getLeftAlignAction()
          Returns an action that aligns the currently selected nodes by their x-coordinate.
 javax.swing.Action getOpenFoldersAction()
          Returns an action that opens one or more folder nodes.
 javax.swing.Action getRightAlignAction()
          Returns an action that aligns the currently selected nodes by their maximum x-coordinate.
 javax.swing.Action getSelectAllAction()
          Returns an action that selects the all nodes and bends or alternatively all edges if at least one edge is currently selected.
 javax.swing.Action getSelectBottomEdgeAction()
          Returns an action that selects the bottommost edge connected to the currently selected node.
 javax.swing.Action getSelectLeftEdgeAction()
          Returns an action that selects the leftmost edge connected to the currently selected node.
 javax.swing.Action getSelectRightEdgeAction()
          Returns an action that selects the rightmost edge connected to the currently selected node.
 javax.swing.Action getSelectTopEdgeAction()
          Returns an action that selects the topmost edge connected to the currently selected node.
 javax.swing.Action getTopAlignAction()
          Returns an action that aligns the currently selected nodes by their y-coordinate.
 javax.swing.Action getUnfoldSelectionAction()
          Returns an action that unfolds the current selection.
 javax.swing.Action getUngroupSelectionAction()
          Returns an action that ungroups the current selection.
protected  Graph2DView getView(java.awt.event.ActionEvent e)
          Tries to obtain the associated view with the event.
 void install()
          Install the actions provided by this instance into the view provided to the constructor
 void install(Graph2DView view)
          Installs this instance into the given view using JComponent.WHEN_FOCUSED as the condition.
 void install(Graph2DView view, int condition)
          Installs the action into the given view using the specified condition.
 void install(int condition)
          Installs the actions provided by this instance into the view provided to the constructor using the specified input condition.
protected  void selectAll(Graph2DView view)
          Deprecated. Use Graph2DViewActions.SelectAllAction.select(Graph2DView) instead.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FOCUS_RIGHT_NODE

public static final java.lang.Object FOCUS_RIGHT_NODE
ActionMap key for action returned by getFocusRightNodeAction().


EDIT_NODE

public static final java.lang.Object EDIT_NODE
ActionMap key for action returned by getEditNodeAction().


FOCUS_LEFT_NODE

public static final java.lang.Object FOCUS_LEFT_NODE
ActionMap key for action returned by getFocusLeftNodeAction().


FOCUS_TOP_NODE

public static final java.lang.Object FOCUS_TOP_NODE
ActionMap key for action returned by getFocusTopNodeAction().


FOCUS_BOTTOM_NODE

public static final java.lang.Object FOCUS_BOTTOM_NODE
ActionMap key for action returned by getFocusBottomNodeAction().


SELECT_ALL

public static final java.lang.Object SELECT_ALL
ActionMap key for action returned by getSelectAllAction().


TOP_ALIGN

public static final java.lang.Object TOP_ALIGN
ActionMap key for action returned by getTopAlignAction().


ALIGN_VERTICALLY

public static final java.lang.Object ALIGN_VERTICALLY
ActionMap key for action returned by getAlignVerticallyAction().


BOTTOM_ALIGN

public static final java.lang.Object BOTTOM_ALIGN
ActionMap key for action returned by getBottomAlignAction().


DISTRIBUTE_VERTICALLY

public static final java.lang.Object DISTRIBUTE_VERTICALLY
ActionMap key for action returned by getDistributeVerticallyAction().


LEFT_ALIGN

public static final java.lang.Object LEFT_ALIGN
ActionMap key for action returned by getLeftAlignAction().


ALIGN_HORIZONTALLY

public static final java.lang.Object ALIGN_HORIZONTALLY
ActionMap key for action returned by getAlignHorizontallyAction()


RIGHT_ALIGN

public static final java.lang.Object RIGHT_ALIGN
ActionMap key for action returned by getRightAlignAction().


DISTRIBUTE_HORIZONTALLY

public static final java.lang.Object DISTRIBUTE_HORIZONTALLY
ActionMap key for action returned by getDistributeHorizontallyAction().


SELECT_LEFT_EDGE

public static final java.lang.Object SELECT_LEFT_EDGE
ActionMap key for action returned by getSelectLeftEdgeAction().


SELECT_RIGHT_EDGE

public static final java.lang.Object SELECT_RIGHT_EDGE
ActionMap key for action returned by getSelectRightEdgeAction().


SELECT_TOP_EDGE

public static final java.lang.Object SELECT_TOP_EDGE
ActionMap key for action returned by getSelectTopEdgeAction().


SELECT_BOTTOM_EDGE

public static final java.lang.Object SELECT_BOTTOM_EDGE
ActionMap key for action returned by getSelectBottomEdgeAction().


DELETE_SELECTION

public static final java.lang.Object DELETE_SELECTION
ActionMap key for action returned by getDeleteSelectionAction().


GROUP_SELECTION

public static final java.lang.Object GROUP_SELECTION
ActionMap key for action returned by getGroupSelectionAction().


FOLD_SELECTION

public static final java.lang.Object FOLD_SELECTION
ActionMap key for action returned by getFoldSelectionAction().


UNGROUP_SELECTION

public static final java.lang.Object UNGROUP_SELECTION
ActionMap key for action returned by getUngroupSelectionAction().


UNFOLD_SELECTION

public static final java.lang.Object UNFOLD_SELECTION
ActionMap key for action returned by getUnfoldSelectionAction().


OPEN_FOLDERS

public static final java.lang.Object OPEN_FOLDERS
ActionMap key for action returned by getOpenFoldersAction().


CLOSE_GROUPS

public static final java.lang.Object CLOSE_GROUPS
ActionMap key for action returned by getCloseGroupsAction().


EDIT_LABEL

public static final java.lang.Object EDIT_LABEL
ActionMap key for action returned by getEditLabelAction().


DUPLICATE_GRAPH

public static final java.lang.Object DUPLICATE_GRAPH
ActionMap key for action returned by getDuplicateGraphAction().


ADD_SUCCESSORS

public static final java.lang.Object ADD_SUCCESSORS
ActionMap key for action returned by getAddSuccessorsAction().


ADD_PREDECESSORS

public static final java.lang.Object ADD_PREDECESSORS
ActionMap key for action returned by getAddPredecessorsAction().

Constructor Detail

Graph2DViewActions

public Graph2DViewActions()
Creates a new instance that is not bound to any Graph2DView. For internal use only. To ensure that all actions are properly working for a specific Graph2DView, clients should use constructor Graph2DViewActions(Graph2DView).


Graph2DViewActions

public Graph2DViewActions(Graph2DView view)
Creates a new instance of Graph2DViewActions for the given view. To install the actions for that view use method install() or install(int).

Parameters:
view - the view acted upon.
Method Detail

install

public void install(int condition)
Installs the actions provided by this instance into the view provided to the constructor using the specified input condition.

Parameters:
condition - the condition as used in JComponent.setInputMap(int,javax.swing.InputMap)
See Also:
Graph2DViewActions(Graph2DView)

install

public void install()
Install the actions provided by this instance into the view provided to the constructor

Throws:
java.lang.IllegalStateException - if no view had been provided to the constructor.

install

public void install(Graph2DView view)
Installs this instance into the given view using JComponent.WHEN_FOCUSED as the condition.

Parameters:
view - the to install the actions for
See Also:
install(Graph2DView,int)

install

public void install(Graph2DView view,
                    int condition)
Installs the action into the given view using the specified condition.

Parameters:
view - the view to install the actions for. This view needs to be the same instance as given in the constructor {Graph2DViewActions(Graph2DView).
condition - the condition as used in JComponent.setInputMap(int,javax.swing.InputMap)
See Also:
install(Graph2DView)

getView

protected Graph2DView getView(java.awt.event.ActionEvent e)
Tries to obtain the associated view with the event.

Parameters:
e - The event for which to obtain the view. This is done by getting the parent of the source component.
Returns:
The Graph2DView associated with the event or the view for which this class has been instantiated if unsuccessful.

getEditNodeAction

public javax.swing.Action getEditNodeAction()
Returns an action that starts editing a selected node if the current ViewMode is either a suitable EditMode or CellEditorMode instance.


getFocusLeftNodeAction

public javax.swing.Action getFocusLeftNodeAction()
Returns an action that selects a node that is to the left of the currently selected node. The viewport of the view will moved in a way that the newly selected node gets displayed in the center of the view.


getFocusRightNodeAction

public javax.swing.Action getFocusRightNodeAction()
Returns an action that selects a node that is to the right of the currently selected node. The viewport of the view will moved in a way that the newly selected node gets displayed in the center of the view.


getFocusTopNodeAction

public javax.swing.Action getFocusTopNodeAction()
Returns an action that selects a node that is above the currently selected node. The viewport of the view will moved in a way that the newly selected node gets displayed in the center of the view.


getFocusBottomNodeAction

public javax.swing.Action getFocusBottomNodeAction()
Returns an action that selects a node that is below the currently selected node. The viewport of the view will moved in a way that the newly selected node gets displayed in the center of the view.


getSelectLeftEdgeAction

public javax.swing.Action getSelectLeftEdgeAction()
Returns an action that selects the leftmost edge connected to the currently selected node. Once an edge has been selected this way, the next time the action will select the counterclockwise next edge around the previously selected node. If initially no elements are selected the action will select an edge that is closest to the center of the view.


getSelectRightEdgeAction

public javax.swing.Action getSelectRightEdgeAction()
Returns an action that selects the rightmost edge connected to the currently selected node. Once an edge has been selected this way, the next time the action will select the clockwise next edge around the previously selected node. If initially no elements are selected the action will select an edge that is closest to the center of the view.


getSelectAllAction

public javax.swing.Action getSelectAllAction()
Returns an action that selects the all nodes and bends or alternatively all edges if at least one edge is currently selected.


selectAll

protected final void selectAll(Graph2DView view)
Deprecated. Use Graph2DViewActions.SelectAllAction.select(Graph2DView) instead.

Sets the selected state of either all edges or all nodes and bends to true depending on the current selection states of edges, nodes, and bends.

Parameters:
view - the view to act upon

getSelectTopEdgeAction

public javax.swing.Action getSelectTopEdgeAction()
Returns an action that selects the topmost edge connected to the currently selected node. Once an edge has been selected this way, the next time the action will select the clockwise next edge around the previously selected node. If initially no elements are selected the action will select an edge that is closest to the center of the view.


getSelectBottomEdgeAction

public javax.swing.Action getSelectBottomEdgeAction()
Returns an action that selects the bottommost edge connected to the currently selected node. Once an edge has been selected this way, the next time the action will select the counterclockwise next edge around the previously selected node. If initially no elements are selected the action will select an edge that is closest to the center of the view.


getDeleteSelectionAction

public javax.swing.Action getDeleteSelectionAction()
Returns an action that deletes the currently selected elements from the graph.


getTopAlignAction

public javax.swing.Action getTopAlignAction()
Returns an action that aligns the currently selected nodes by their y-coordinate.

Returns:
an action that aligns the currently selected nodes by their y-coordinate.
See Also:
LayoutTool.alignNodeLayouts(y.layout.LayoutGraph, y.base.NodeList, y.base.Node, boolean, byte)

getLeftAlignAction

public javax.swing.Action getLeftAlignAction()
Returns an action that aligns the currently selected nodes by their x-coordinate.

Returns:
an action that aligns the currently selected nodes by their x-coordinate.
See Also:
LayoutTool.alignNodeLayouts(y.layout.LayoutGraph, y.base.NodeList, y.base.Node, boolean, byte)

getRightAlignAction

public javax.swing.Action getRightAlignAction()
Returns an action that aligns the currently selected nodes by their maximum x-coordinate.

Returns:
an action that aligns the currently selected nodes by their maximum x-coordinate.
See Also:
LayoutTool.alignNodeLayouts(y.layout.LayoutGraph, y.base.NodeList, y.base.Node, boolean, byte)

getBottomAlignAction

public javax.swing.Action getBottomAlignAction()
Returns an action that aligns the currently selected nodes by their maximum y-coordinate.

Returns:
an action that aligns the currently selected nodes by their maximum y-coordinate.
See Also:
LayoutTool.alignNodeLayouts(y.layout.LayoutGraph, y.base.NodeList, y.base.Node, boolean, byte)

getAlignVerticallyAction

public javax.swing.Action getAlignVerticallyAction()
Returns an action that aligns the currently selected nodes by their center y-coordinate.

Returns:
an action that aligns the currently selected nodes by their center y-coordinate.
See Also:
LayoutTool.alignNodeLayouts(y.layout.LayoutGraph, y.base.NodeList, y.base.Node, boolean, byte)

getAlignHorizontallyAction

public javax.swing.Action getAlignHorizontallyAction()
Returns an action that aligns the currently selected nodes by their center x-coordinate.

Returns:
an action that aligns the currently selected nodes by their center x-coordinate.
See Also:
LayoutTool.alignNodeLayouts(y.layout.LayoutGraph, y.base.NodeList, y.base.Node, boolean, byte)

getDistributeHorizontallyAction

public javax.swing.Action getDistributeHorizontallyAction()
Returns an action that places the currently selected nodes such that they do not overlap horizontally.

Returns:
an action that places the currently selected nodes such that they do not overlap horizontally.
See Also:
LayoutTool.alignNodeLayouts(y.layout.LayoutGraph, y.base.NodeList, y.base.Node, boolean, byte)

getDistributeVerticallyAction

public javax.swing.Action getDistributeVerticallyAction()
Returns an action that places the currently selected nodes such that they do not overlap vertically.

Returns:
an action that places the currently selected nodes such that they do not overlap vertically.
See Also:
LayoutTool.alignNodeLayouts(y.layout.LayoutGraph, y.base.NodeList, y.base.Node, boolean, byte)

getCloseGroupsAction

public javax.swing.Action getCloseGroupsAction()
Returns an action that closes one or more group nodes.


getOpenFoldersAction

public javax.swing.Action getOpenFoldersAction()
Returns an action that opens one or more folder nodes.


getGroupSelectionAction

public javax.swing.Action getGroupSelectionAction()
Returns an action that groups the current selection.


getFoldSelectionAction

public javax.swing.Action getFoldSelectionAction()
Returns an action that folds the current selection.


getUngroupSelectionAction

public javax.swing.Action getUngroupSelectionAction()
Returns an action that ungroups the current selection.


getUnfoldSelectionAction

public javax.swing.Action getUnfoldSelectionAction()
Returns an action that unfolds the current selection.


deleteSelection

protected final void deleteSelection(Graph2DView view)
Deprecated. Use Graph2DViewActions.DeleteSelectionAction.delete(Graph2DView) instead.

Removes the currently selected bends, labels, edges, and nodes from the specified view's graph.

Parameters:
view - the view to act upon

getDuplicateGraphAction

public javax.swing.Action getDuplicateGraphAction()
Returns an action that duplicates selected graph.


getAddSuccessorsAction

public javax.swing.Action getAddSuccessorsAction()
Returns an action that create children for selected nodes


getAddPredecessorsAction

public javax.swing.Action getAddPredecessorsAction()
Returns an action that create children for selected nodes


getEditLabelAction

public javax.swing.Action getEditLabelAction()
Returns an action that triggers the inline label editor.


createActionMap

public javax.swing.ActionMap createActionMap()
Returns a new ActionMap that contains the actions provided by this class.


createDefaultInputMap

public javax.swing.InputMap createDefaultInputMap()
Returns a default key binding for the actions provided by this class.


createDefaultInputMap

public javax.swing.InputMap createDefaultInputMap(javax.swing.ActionMap amap)
Returns a default key binding for the actions provided by this class that are also bound by the given ActionMap.


editNode

protected void editNode(Graph2DView view)
Called by the EDIT_NODE action.


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