Search this API

y.view
Class SelectionBoxMode

java.lang.Object
  extended by y.view.ViewMode
      extended by y.view.AbstractSelectionBoxMode
          extended by y.view.SelectionBoxMode
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener, javax.swing.event.MouseInputListener

public class SelectionBoxMode
extends AbstractSelectionBoxMode

This ViewMode is responsible for letting the user open up a selection box. Graph elements inside that box will automatically be selected.

By default, this mode never selects nodes and edges at the same time. What actually gets selected depends on whether or not the shift key is pressed down when opening the selection box and on the set of currently selected graph elements.

If the shift key is pressed down when opening the selection box the new selection will consist of the previously selected elements plus the ones that lie inside of the selection box.

By default, the shift key driven union mechanism selects more edges if the graph elements already selected were edges. Otherwise more nodes and bends will be selected.

Use method setExtendedTypeSelectionEnabled(boolean) to enable this mode to select graph elements such as node and edge labels and/or node ports besides nodes, edges, and bends.

 

Field Summary
static int TYPE_BEND
          Type bit mask representing bends.
static int TYPE_EDGE
          Type bit mask representing edges.
static int TYPE_EDGE_LABEL
          Type bit mask representing edge labels.
static int TYPE_NODE
          Type bit mask representing nodes.
static int TYPE_NODE_LABEL
          Type bit mask representing node labels.
static int TYPE_NODE_PORT
          Type bit mask representing node ports.
 
Fields inherited from class y.view.ViewMode
ACTIVE_PROPERTY, ACTIVE_VIEW_PROPERTY, CHILD_MODE_PROPERTY, EDITING_PROPERTY, GRAB_FOCUS_ENABLED_PROPERTY, lastClickEvent, lastDragEvent, lastMoveEvent, lastPressEvent, lastReleaseEvent, MODIFIER_MASK_PROPERTY, NAME_PROPERTY, originalX, originalY, PARENT_MODE_PROPERTY, view
 
Constructor Summary
SelectionBoxMode()
          Instantiates a new SelectionBoxMode.
SelectionBoxMode(ViewContainer view)
          Instantiates a new SelectionBoxMode for a given ViewContainer
 
Method Summary
protected  int adjustTypes(int typeMask)
          Determines which types of graph elements have to be selected.
protected  boolean belongsToSelection(Bend b, java.awt.geom.Rectangle2D box)
          Callback method that decides whether or not the given bend should be selected, by the given selection box bounds.
protected  boolean belongsToSelection(Edge e, java.awt.geom.Rectangle2D box)
          Callback method that decides whether or not the given edge should be selected, by the given selection box bounds.
protected  boolean belongsToSelection(NodePort p, java.awt.geom.Rectangle2D box)
          Callback method that decides whether or not the given node port should be selected, by the given selection box bounds.
protected  boolean belongsToSelection(Node v, java.awt.geom.Rectangle2D box)
          Callback method that decides whether or not the given node should be selected, by the given selection box bounds.
protected  boolean belongsToSelection(YLabel l, java.awt.geom.Rectangle2D box)
          Callback method that decides whether or not the given label should be selected, by the given selection box bounds.
protected  int getSelectedEdgeTypes(Graph2D graph, Edge edge)
          Determines whether the specified edge and/or any graph elements related to the specified edge (that is edge labels and/or bends) are selected.
protected  int getSelectedNodeTypes(Graph2D graph, Node node)
          Determines whether the specified node and/or any graph elements related to the specified node (that is node labels and/or node ports) are selected.
protected  int getSelectedTypes(Graph2D graph)
          Determines the types of graph elements that are selected in the specified graph.
 boolean isExtendedTypeSelectionEnabled()
          Determines whether or not this mode supports selecting graph elements other than nodes, edges, and bends such as node and edge labels and/or node ports.
 boolean isMixedSelectionEnabled()
          Determines whether or not this mode supports selecting different types of graph elements at once when extendedTypeSelectionEnabled is set to true.
protected  boolean isSelected(Graph2D graph, Bend bend)
          Returns true if the specified bend is currently selected; false otherwise.
protected  boolean isSelected(Graph2D graph, Edge edge)
          Returns true if the specified edge is currently selected; false otherwise.
protected  boolean isSelected(Graph2D graph, Node node)
          Returns true if the specified node is currently selected; false otherwise.
protected  boolean isSelected(Graph2D graph, NodePort port)
          Returns true if the specified port is currently selected; false otherwise.
protected  boolean isSelected(Graph2D graph, YLabel label)
          Returns true if the specified label is currently selected; false otherwise.
protected  void selectEdgeTypes(Graph2D graph, Edge edge, int typeMask, java.awt.Rectangle sb, boolean shiftMode)
          Selects the specified edge and/or related graph elements (that is edge labels and bends) depending on whether or not the elements intersect or lie in the specified rectangle.
protected  void selectionBoxAction(java.awt.Rectangle sb, boolean shiftMode)
          Selects graph objects within selection box bounds.
protected  void selectNodeTypes(Graph2D graph, Node node, int typeMask, java.awt.Rectangle sb, boolean shiftMode)
          Selects the specified node and/or related graph elements (that is node labels and node ports) depending on whether or not the elements lie in the specified rectangle.
protected  void selectTypes(Graph2D graph, int typeMask, java.awt.Rectangle sb, boolean shiftMode)
          Selects the specified types of graph elements that lie in the specified rectangle.
 void setExtendedTypeSelectionEnabled(boolean enabled)
          Specifies whether or not this mode supports selecting graph elements other than nodes, edges, and bends such as node and edge labels and/or node ports.
 void setMixedSelectionEnabled(boolean enabled)
          Specifies whether or not this mode supports selecting different types of graph elements at once when extendedTypeSelectionEnabled is set to true.
protected  void setSelected(Graph2D graph, Bend b, boolean state)
          Sets the specified selection state for the specified bend.
protected  void setSelected(Graph2D graph, Edge e, boolean state)
          Sets the specified selection state for the specified edge.
protected  void setSelected(Graph2D graph, Node n, boolean state)
          Sets the specified selection state for the specified node.
protected  void setSelected(Graph2D graph, NodePort p, boolean state)
          Sets the specified selection state for the specified node port.
protected  void setSelected(Graph2D graph, YLabel l, boolean state)
          Sets the specified selection state for the specified label.
protected  void unselectAll(Graph2D graph)
          Sets the selection state of all nodes, node labels, node ports, edges, edge labels, and bends to false.
 
Methods inherited from class y.view.AbstractSelectionBoxMode
cancelEditing, mouseDraggedLeft, mousePressedLeft, mouseReleasedLeft, mouseReleasedRight, mouseShiftPressedLeft, mouseShiftReleasedLeft, selectionBoxAction, updateDoubleSelectionBox
 
Methods inherited from class y.view.ViewMode
activate, addPropertyChangeListener, addPropertyChangeListener, deactivateChild, firePropertyChange, firePropertyChange, firePropertyChange, getChild, getGraph2D, getGridX, getGridY, getHitInfo, getHitInfo, getLastClickEvent, getLastDragEvent, getLastHitInfo, getLastMoveEvent, getLastPressEvent, getLastReleaseEvent, getModifierMask, getName, getParent, init, isActive, isEditing, isGrabFocusEnabled, isGridMode, isModifierPressed, mouseClicked, mouseClicked, mouseDragged, mouseDraggedMiddle, mouseDraggedRight, mouseEntered, mouseExited, mouseMoved, mouseMoved, mousePressed, mousePressedMiddle, mousePressedRight, mouseReleased, mouseReleased, mouseReleasedMiddle, mouseShiftPressedMiddle, mouseShiftPressedRight, mouseShiftReleasedMiddle, mouseShiftReleasedRight, reactivateParent, removePropertyChangeListener, removePropertyChangeListener, setActiveView, setChild, setChild, setEditing, setGrabFocusEnabled, setGridMode, setLastHitInfo, setModifierMask, setName, setParent, translateX, translateY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_NODE

public static final int TYPE_NODE
Type bit mask representing nodes.

See Also:
Constant Field Values

TYPE_EDGE

public static final int TYPE_EDGE
Type bit mask representing edges.

See Also:
Constant Field Values

TYPE_BEND

public static final int TYPE_BEND
Type bit mask representing bends.

See Also:
Constant Field Values

TYPE_NODE_LABEL

public static final int TYPE_NODE_LABEL
Type bit mask representing node labels.

See Also:
Constant Field Values

TYPE_EDGE_LABEL

public static final int TYPE_EDGE_LABEL
Type bit mask representing edge labels.

See Also:
Constant Field Values

TYPE_NODE_PORT

public static final int TYPE_NODE_PORT
Type bit mask representing node ports.

See Also:
Constant Field Values
Constructor Detail

SelectionBoxMode

public SelectionBoxMode(ViewContainer view)
Instantiates a new SelectionBoxMode for a given ViewContainer


SelectionBoxMode

public SelectionBoxMode()
Instantiates a new SelectionBoxMode.

Method Detail

isExtendedTypeSelectionEnabled

public boolean isExtendedTypeSelectionEnabled()
Determines whether or not this mode supports selecting graph elements other than nodes, edges, and bends such as node and edge labels and/or node ports.

By default, this property is set to false.

Returns:
true if this mode supports selecting node and edge labels and/or node ports as well as nodes, edges, and bends; false if this mode supports selecting nodes, edges, and bends only.
See Also:
setExtendedTypeSelectionEnabled(boolean), isMixedSelectionEnabled(), setMixedSelectionEnabled(boolean)

setExtendedTypeSelectionEnabled

public void setExtendedTypeSelectionEnabled(boolean enabled)
Specifies whether or not this mode supports selecting graph elements other than nodes, edges, and bends such as node and edge labels and/or node ports.

By default, this property is set to false.

Parameters:
enabled - if true this mode supports selecting node and edge labels and/or node ports as well as nodes, edges, and bends; otherwise this mode supports selecting nodes, edges, and bends only.
See Also:
isExtendedTypeSelectionEnabled(), isMixedSelectionEnabled(), setMixedSelectionEnabled(boolean)

isMixedSelectionEnabled

public boolean isMixedSelectionEnabled()
Determines whether or not this mode supports selecting different types of graph elements at once when extendedTypeSelectionEnabled is set to true.

By default, this property is set to false.

Note: Nodes and bends will be selected at the same time independent of the value of this property.

Returns:
true if this mode supports selecting different types of graph elements at once; false otherwise.
See Also:
setMixedSelectionEnabled(boolean), isExtendedTypeSelectionEnabled(), setExtendedTypeSelectionEnabled(boolean)

setMixedSelectionEnabled

public void setMixedSelectionEnabled(boolean enabled)
Specifies whether or not this mode supports selecting different types of graph elements at once when extendedTypeSelectionEnabled is set to true.

By default, this property is set to false.

Note: Nodes and bends will be selected at the same time independent of the value of this property.

Parameters:
enabled - if true if this mode supports selecting different types of graph elements at once; otherwise only one type of graph elements can be selected.
See Also:
isMixedSelectionEnabled(), isExtendedTypeSelectionEnabled(), setExtendedTypeSelectionEnabled(boolean)

selectionBoxAction

protected void selectionBoxAction(java.awt.Rectangle sb,
                                  boolean shiftMode)
Selects graph objects within selection box bounds. if in shift mode a union of already selected and newly selected objects is created. Usually this operation operates on nodes and bends. But if already some edges are selected and we are in shift mode then more edges got selected.

Specified by:
selectionBoxAction in class AbstractSelectionBoxMode
Parameters:
sb - The position and size of the selection box.
shiftMode - true if shift was pressed when box was closed, false otherwise.

belongsToSelection

protected boolean belongsToSelection(Node v,
                                     java.awt.geom.Rectangle2D box)
Callback method that decides whether or not the given node should be selected, by the given selection box bounds.


belongsToSelection

protected boolean belongsToSelection(Edge e,
                                     java.awt.geom.Rectangle2D box)
Callback method that decides whether or not the given edge should be selected, by the given selection box bounds.


belongsToSelection

protected boolean belongsToSelection(Bend b,
                                     java.awt.geom.Rectangle2D box)
Callback method that decides whether or not the given bend should be selected, by the given selection box bounds.


belongsToSelection

protected boolean belongsToSelection(YLabel l,
                                     java.awt.geom.Rectangle2D box)
Callback method that decides whether or not the given label should be selected, by the given selection box bounds.


belongsToSelection

protected boolean belongsToSelection(NodePort p,
                                     java.awt.geom.Rectangle2D box)
Callback method that decides whether or not the given node port should be selected, by the given selection box bounds.


adjustTypes

protected int adjustTypes(int typeMask)
Determines which types of graph elements have to be selected. Called from selectionBoxAction(java.awt.Rectangle, boolean).

Parameters:
typeMask - bit mask specifying the types of graph elements that are already selected.
Returns:
bit mask specifying the types of graph elements that have to be selected.
See Also:
getSelectedTypes(Graph2D), selectTypes(Graph2D, int, java.awt.Rectangle, boolean), TYPE_BEND, TYPE_EDGE, TYPE_EDGE_LABEL, TYPE_NODE, TYPE_NODE_LABEL, TYPE_NODE_PORT

getSelectedTypes

protected int getSelectedTypes(Graph2D graph)
Determines the types of graph elements that are selected in the specified graph. Called from selectionBoxAction(java.awt.Rectangle, boolean). The default implementation queries getSelectedEdgeTypes(Graph2D, y.base.Edge) for each edge and getSelectedNodeTypes(Graph2D, y.base.Node) for each node in the graph to determine the types of selected elements in the graph.

Parameters:
graph - the graph whose elements have to be checked.
Returns:
a bit mask specifying the types of graph elements whose current selection state is true.
See Also:
adjustTypes(int), selectTypes(Graph2D, int, java.awt.Rectangle, boolean), TYPE_BEND, TYPE_EDGE, TYPE_EDGE_LABEL, TYPE_NODE, TYPE_NODE_LABEL, TYPE_NODE_PORT

getSelectedEdgeTypes

protected int getSelectedEdgeTypes(Graph2D graph,
                                   Edge edge)
Determines whether the specified edge and/or any graph elements related to the specified edge (that is edge labels and/or bends) are selected.

Parameters:
graph - the graph to which the specified edge belongs.
edge - the edge to check.
Returns:
a bit mask specifying the types of graph elements whose current selection state is true.
See Also:
getSelectedTypes(Graph2D), getSelectedNodeTypes(Graph2D, y.base.Node)

getSelectedNodeTypes

protected int getSelectedNodeTypes(Graph2D graph,
                                   Node node)
Determines whether the specified node and/or any graph elements related to the specified node (that is node labels and/or node ports) are selected.

Parameters:
graph - the graph to which the specified node belongs.
node - the node to check.
Returns:
a bit mask specifying the types of graph elements whose current selection state is true.
See Also:
getSelectedTypes(Graph2D), getSelectedEdgeTypes(Graph2D, y.base.Edge)

selectTypes

protected void selectTypes(Graph2D graph,
                           int typeMask,
                           java.awt.Rectangle sb,
                           boolean shiftMode)
Selects the specified types of graph elements that lie in the specified rectangle. Called from selectionBoxAction(java.awt.Rectangle, boolean). The default implementation delegates selecting elements to selectEdgeTypes(Graph2D, y.base.Edge, int, java.awt.Rectangle, boolean) and selectNodeTypes(Graph2D, y.base.Node, int, java.awt.Rectangle, boolean) for each edge and each node in the graph.

Parameters:
graph - the graph whose elements are selected.
typeMask - a bit mask specifying which types of elements to select.
sb - the rectangle that contains elements that have to be selected.
shiftMode - if true elements that are selected but lie outside the specified rectangle will remain selected; if false the selection state of said elements is set to false.
See Also:
adjustTypes(int), getSelectedTypes(Graph2D), TYPE_BEND, TYPE_EDGE, TYPE_EDGE_LABEL, TYPE_NODE, TYPE_NODE_LABEL, TYPE_NODE_PORT

selectEdgeTypes

protected void selectEdgeTypes(Graph2D graph,
                               Edge edge,
                               int typeMask,
                               java.awt.Rectangle sb,
                               boolean shiftMode)
Selects the specified edge and/or related graph elements (that is edge labels and bends) depending on whether or not the elements intersect or lie in the specified rectangle.

Parameters:
graph - the graph to which the specified edge belongs.
edge - the edge to select.
typeMask - a bit mask specifying which types of elements to select.
sb - the rectangle that contains elements that have to be selected.
shiftMode - if true elements that are selected but lie outside the specified rectangle will remain selected; if false the selection state of said elements is set to false.
See Also:
selectTypes(Graph2D, int, java.awt.Rectangle, boolean), selectNodeTypes(Graph2D, y.base.Node, int, java.awt.Rectangle, boolean)

selectNodeTypes

protected void selectNodeTypes(Graph2D graph,
                               Node node,
                               int typeMask,
                               java.awt.Rectangle sb,
                               boolean shiftMode)
Selects the specified node and/or related graph elements (that is node labels and node ports) depending on whether or not the elements lie in the specified rectangle.

Parameters:
graph - the graph to which the specified node belongs.
node - the node to select.
typeMask - a bit mask specifying which types of elements to select.
sb - the rectangle that contains elements that have to be selected.
shiftMode - if true elements that are selected but lie outside the specified rectangle will remain selected; if false the selection state of said elements is set to false.
See Also:
selectTypes(Graph2D, int, java.awt.Rectangle, boolean), selectEdgeTypes(Graph2D, y.base.Edge, int, java.awt.Rectangle, boolean)

unselectAll

protected void unselectAll(Graph2D graph)
Sets the selection state of all nodes, node labels, node ports, edges, edge labels, and bends to false.

Parameters:
graph - the graph whose elements' selection states have to be changed.

setSelected

protected void setSelected(Graph2D graph,
                           Node n,
                           boolean state)
Sets the specified selection state for the specified node. Subclasses may override this method to add notifications for node selection state changes.

The default implementation sets the selection state of the specified node as well as the states of all bends in self loop edges incident to the specified node.

Parameters:
graph - the graph the specified node resides in.
n - the node whose selection state has to be changed.
state - the new selection state for the specified node.

setSelected

protected void setSelected(Graph2D graph,
                           Bend b,
                           boolean state)
Sets the specified selection state for the specified bend. Subclasses may override this method to add notifications for bend selection state changes.

Parameters:
graph - the graph the specified bend's associated edge resides in.
b - the bend whose selection state has to be changed.
state - the new selection state for the specified bend.

setSelected

protected void setSelected(Graph2D graph,
                           Edge e,
                           boolean state)
Sets the specified selection state for the specified edge. Subclasses may override this method to add notifications for edge selection state changes.

Parameters:
graph - the graph the specified edge resides in.
e - the edge whose selection state has to be changed.
state - the new selection state for the specified edge.

setSelected

protected void setSelected(Graph2D graph,
                           YLabel l,
                           boolean state)
Sets the specified selection state for the specified label. Subclasses may override this method to add notifications for label selection state changes.

Parameters:
graph - the graph the specified label's associated node or edge resides in.
l - the label whose selection state has to be changed.
state - the new selection state for the specified label.

setSelected

protected void setSelected(Graph2D graph,
                           NodePort p,
                           boolean state)
Sets the specified selection state for the specified node port. Subclasses may override this method to add notifications for node port selection state changes.

Parameters:
graph - the graph the specified port's associated node resides in.
p - the node port whose selection state has to be changed.
state - the new selection state for the specified node port.

isSelected

protected boolean isSelected(Graph2D graph,
                             Bend bend)
Returns true if the specified bend is currently selected; false otherwise.

Parameters:
graph - the graph that holds the specified bend's associated edge.
bend - the bend whose selection state is checked.
Returns:
true if the specified bend is currently selected; false otherwise.

isSelected

protected boolean isSelected(Graph2D graph,
                             YLabel label)
Returns true if the specified label is currently selected; false otherwise.

Parameters:
graph - the graph that holds the specified label's associated edge or node.
label - the label whose selection state is checked.
Returns:
true if the specified label is currently selected; false otherwise.

isSelected

protected boolean isSelected(Graph2D graph,
                             Edge edge)
Returns true if the specified edge is currently selected; false otherwise.

Parameters:
graph - the graph that holds the specified edge.
edge - the edge whose selection state is checked.
Returns:
true if the specified edge is currently selected; false otherwise.

isSelected

protected boolean isSelected(Graph2D graph,
                             Node node)
Returns true if the specified node is currently selected; false otherwise.

Parameters:
graph - the graph that holds the specified node.
node - the node whose selection state is checked.
Returns:
true if the specified node is currently selected; false otherwise.

isSelected

protected boolean isSelected(Graph2D graph,
                             NodePort port)
Returns true if the specified port is currently selected; false otherwise.

Parameters:
graph - the graph that holds the specified port's associated node.
port - the node port whose selection state is checked.
Returns:
true if the specified port is currently selected; false otherwise.

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