Search this API

y.view
Class PopupMode

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

public abstract class PopupMode
extends ViewMode

A view mode that is responsible for showing context sensitive popup menus when a right click occurs on a view element. The popup menus will be displayed at the view coordinate where the right click occurred.

Subclasses should overwrite the methods that provide JPopupMenu objects for different kinds of contexts. By default these methods return empty popup menus.

 
Your browser does not support SVG content.

Field Summary
static int POPUP_TYPE_BEND
          Popup type specifier that will result in opening a popup menu returned by getBendPopup(Bend)
static int POPUP_TYPE_EDGE
          Popup type specifier that will result in opening a popup menu returned by getEdgePopup(Edge)
static int POPUP_TYPE_EDGE_LABEL
          Popup type specifier that will result in opening a popup menu returned by getEdgeLabelPopup(EdgeLabel)
static int POPUP_TYPE_NODE
          Popup type specifier that indicates will result in opening a popup menu returned by getNodePopup(Node)
static int POPUP_TYPE_NODE_LABEL
          Popup type specifier that will result in opening a popup menu returned by getNodeLabelPopup(NodeLabel)
static int POPUP_TYPE_NODE_PORT
          Popup type specifier that will result in opening a popup menu returned by getNodePortPopup(NodePort)
static int POPUP_TYPE_PAPER
          Popup type specifier that will result in opening a popup menu returned by getPaperPopup(double, double)
static int POPUP_TYPE_SELECTION
          Popup type specifier that will result in opening a popup menu returned by getSelectionPopup(double, double)
static int POPUP_TYPE_UNKNOWN
          Popup type specifier that will result in not opening a popup menu.
 
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
PopupMode()
          Initializes a new PopupMode
PopupMode(ViewContainer vc)
          Initializes a new PopupMode for a given ViewContainer
 
Method Summary
protected  void adjustSelectionState(HitInfo hitInfo, double x, double y, int popupType)
          Adjusts the selection state of elements depending on the popup type and hit info.
 javax.swing.JPopupMenu getBendPopup(Bend b)
          Provides a JPopupMenu that is displayed for the given bend.
 javax.swing.JPopupMenu getEdgeLabelPopup(EdgeLabel label)
          Provides a JPopupMenu that is displayed for the given edge label.
 javax.swing.JPopupMenu getEdgePopup(Edge e)
          Provides a JPopupMenu that is displayed for the given edge.
 javax.swing.JPopupMenu getNodeLabelPopup(NodeLabel label)
          Provides a JPopupMenu that is displayed for the given node label.
 javax.swing.JPopupMenu getNodePopup(Node v)
          Provides a JPopupMenu that is displayed for the given node.
 javax.swing.JPopupMenu getNodePortPopup(NodePort port)
          Provides a JPopupMenu that is displayed for the given node port.
 javax.swing.JPopupMenu getPaperPopup(double x, double y)
          Provides a JPopupMenu that is displayed if a hit on the view background occurred and no graph elements are selected.
protected  javax.swing.JPopupMenu getPopup(HitInfo hitInfo, double x, double y, int popupType)
          Returns the popup menu to be opened by this view mode.
protected  int getPopupType(HitInfo info, double x, double y)
          Returns the popup type for a given HitInfo and hit coordinates.
 javax.swing.JPopupMenu getSelectionPopup(double x, double y)
          Provides a JPopupMenu that is displayed if a hit on the view background occurred and some graph elements are selected.
 boolean getSelectSubject()
          Returns whether or not to automatically select the subject (node, edge, bend,...) for which the popup menu gets activated.
protected  boolean isSelectionEmpty(Graph2D graph)
          Returns true if there are no selected nodes, node labels, node ports, edges, edge labels, and/or bends in the specified graph and false otherwise.
 boolean isSingleNodeSelectionModeEnabled()
          Returns whether or not single node selection mode is enabled.
 void mousePressed(java.awt.event.MouseEvent e)
          Internal use only
 void mouseReleased(java.awt.event.MouseEvent e)
          Triggers the display of a context sensitive menu on a right mouse button press.
 void reactivateParent()
          Internal use only.
protected  void setSelected(Graph2D graph, Bend bend, boolean flag)
          Sets the specified selection state for the specified bend.
protected  void setSelected(Graph2D graph, Edge edge, boolean flag)
          Sets the specified selection state for the specified edge.
protected  void setSelected(Graph2D graph, Node node, boolean flag)
          Sets the specified selection state for the specified node.
protected  void setSelected(Graph2D graph, NodePort port, boolean flag)
          Sets the specified selection state for the specified node port.
protected  void setSelected(Graph2D graph, YLabel label, boolean flag)
          Sets the specified selection state for the specified label.
 void setSelectSubject(boolean select)
          Sets whether or not to automatically select the subject (node, edge, bend,...) for which the popup menu gets activated.
 void setSingleNodeSelectionModeEnabled(boolean singleNodeSelectionModeEnabled)
          Whether or not single node selection mode is enabled.
protected  void showPopup(javax.swing.JPopupMenu pm, double x, double y)
          Opens the given popup menu at the world coordinates (x,y).
protected  void startAction(double x, double y)
          Starts the popup mode action.
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.ViewMode
activate, addPropertyChangeListener, addPropertyChangeListener, cancelEditing, 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, mouseDraggedLeft, mouseDraggedMiddle, mouseDraggedRight, mouseEntered, mouseExited, mouseMoved, mouseMoved, mousePressedLeft, mousePressedMiddle, mousePressedRight, mouseReleased, mouseReleasedLeft, mouseReleasedMiddle, mouseReleasedRight, mouseShiftPressedLeft, mouseShiftPressedMiddle, mouseShiftPressedRight, mouseShiftReleasedLeft, mouseShiftReleasedMiddle, mouseShiftReleasedRight, 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

POPUP_TYPE_NODE

public static final int POPUP_TYPE_NODE
Popup type specifier that indicates will result in opening a popup menu returned by getNodePopup(Node)

See Also:
Constant Field Values

POPUP_TYPE_BEND

public static final int POPUP_TYPE_BEND
Popup type specifier that will result in opening a popup menu returned by getBendPopup(Bend)

See Also:
Constant Field Values

POPUP_TYPE_EDGE_LABEL

public static final int POPUP_TYPE_EDGE_LABEL
Popup type specifier that will result in opening a popup menu returned by getEdgeLabelPopup(EdgeLabel)

See Also:
Constant Field Values

POPUP_TYPE_EDGE

public static final int POPUP_TYPE_EDGE
Popup type specifier that will result in opening a popup menu returned by getEdgePopup(Edge)

See Also:
Constant Field Values

POPUP_TYPE_NODE_LABEL

public static final int POPUP_TYPE_NODE_LABEL
Popup type specifier that will result in opening a popup menu returned by getNodeLabelPopup(NodeLabel)

See Also:
Constant Field Values

POPUP_TYPE_PAPER

public static final int POPUP_TYPE_PAPER
Popup type specifier that will result in opening a popup menu returned by getPaperPopup(double, double)

See Also:
Constant Field Values

POPUP_TYPE_SELECTION

public static final int POPUP_TYPE_SELECTION
Popup type specifier that will result in opening a popup menu returned by getSelectionPopup(double, double)

See Also:
Constant Field Values

POPUP_TYPE_UNKNOWN

public static final int POPUP_TYPE_UNKNOWN
Popup type specifier that will result in not opening a popup menu.

See Also:
Constant Field Values

POPUP_TYPE_NODE_PORT

public static final int POPUP_TYPE_NODE_PORT
Popup type specifier that will result in opening a popup menu returned by getNodePortPopup(NodePort)

See Also:
Constant Field Values
Constructor Detail

PopupMode

public PopupMode()
Initializes a new PopupMode


PopupMode

public PopupMode(ViewContainer vc)
Initializes a new PopupMode for a given ViewContainer

Method Detail

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Internal use only

Specified by:
mousePressed in interface java.awt.event.MouseListener
Overrides:
mousePressed in class ViewMode

reactivateParent

public void reactivateParent()
Internal use only.

Overrides:
reactivateParent in class ViewMode

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Triggers the display of a context sensitive menu on a right mouse button press. Depending on the kind of hit element an appropriate JPopupMenu will be displayed.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Overrides:
mouseReleased in class ViewMode

getPopupType

protected int getPopupType(HitInfo info,
                           double x,
                           double y)
Returns the popup type for a given HitInfo and hit coordinates.

Returns:
one of POPUP_TYPE_BEND, POPUP_TYPE_EDGE, POPUP_TYPE_EDGE_LABEL, POPUP_TYPE_NODE, POPUP_TYPE_NODE_LABEL, POPUP_TYPE_PAPER, POPUP_TYPE_SELECTION, POPUP_TYPE_NODE_PORT, or POPUP_TYPE_UNKNOWN.

adjustSelectionState

protected void adjustSelectionState(HitInfo hitInfo,
                                    double x,
                                    double y,
                                    int popupType)
Adjusts the selection state of elements depending on the popup type and hit info.


isSelectionEmpty

protected boolean isSelectionEmpty(Graph2D graph)
Returns true if there are no selected nodes, node labels, node ports, edges, edge labels, and/or bends in the specified graph and false otherwise.

Parameters:
graph - the graph whose elements' selection states are checked.
Returns:
true if there are no selected nodes, node labels, node ports, edges, edge labels, and/or bends in the specified graph and false otherwise.

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,
                           NodePort port,
                           boolean flag)
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.
port - the node port whose selection state has to be changed.
flag - the new selection state for the specified node port.

setSelected

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

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

setSelected

protected void setSelected(Graph2D graph,
                           YLabel label,
                           boolean flag)
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.
label - the label whose selection state has to be changed.
flag - the new selection state for the specified label.

setSelected

protected void setSelected(Graph2D graph,
                           Edge edge,
                           boolean flag)
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.
edge - the edge whose selection state has to be changed.
flag - the new selection state for the specified edge.

setSelected

protected void setSelected(Graph2D graph,
                           Bend bend,
                           boolean flag)
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.
bend - the bend whose selection state has to be changed.
flag - the new selection state for the specified bend.

startAction

protected void startAction(double x,
                           double y)
Starts the popup mode action. This method is called once a popup gesture has been recognized.

Parameters:
x - x-coordinate measured in world coordinates where the mouse gesture has occurred.
y - y-coordinate measured in world coordinates where the mouse gesture has occurred.

getPopup

protected javax.swing.JPopupMenu getPopup(HitInfo hitInfo,
                                          double x,
                                          double y,
                                          int popupType)
Returns the popup menu to be opened by this view mode. This method delegates to one of the specialized popup creation methods for nodes, bends, edge labels, node labels. paper or selection depending on the given popupType specifier.


showPopup

protected void showPopup(javax.swing.JPopupMenu pm,
                         double x,
                         double y)
Opens the given popup menu at the world coordinates (x,y).


getNodePopup

public javax.swing.JPopupMenu getNodePopup(Node v)
Provides a JPopupMenu that is displayed for the given node. This method will be called if no graph elements are selected and a right click on a node occurred. If the JPopupMenu contains no elements or is null no popup menu will be displayed.


getBendPopup

public javax.swing.JPopupMenu getBendPopup(Bend b)
Provides a JPopupMenu that is displayed for the given bend. This method will be called if no graph elements are selected and a right click on a bend occurred. If the JPopupMenu contains no elements or is null no popup menu will be displayed.


getEdgePopup

public javax.swing.JPopupMenu getEdgePopup(Edge e)
Provides a JPopupMenu that is displayed for the given edge. This method will be called if no graph elements are selected and a right click on an edge occurred. If the JPopupMenu contains no elements or is null no popup menu will be displayed.


getPaperPopup

public javax.swing.JPopupMenu getPaperPopup(double x,
                                            double y)
Provides a JPopupMenu that is displayed if a hit on the view background occurred and no graph elements are selected.

The hit on the background occurred at the given world coordinate.

If the JPopupMenu contains no elements or is null no popup menu will be displayed.


getSelectionPopup

public javax.swing.JPopupMenu getSelectionPopup(double x,
                                                double y)
Provides a JPopupMenu that is displayed if a hit on the view background occurred and some graph elements are selected.

The hit on the background occurred at the given world coordinate.

If the JPopupMenu contains no elements or is null no popup menu will be displayed.


getEdgeLabelPopup

public javax.swing.JPopupMenu getEdgeLabelPopup(EdgeLabel label)
Provides a JPopupMenu that is displayed for the given edge label. If the JPopupMenu contains no elements or is null no popup menu will be displayed.


getNodePortPopup

public javax.swing.JPopupMenu getNodePortPopup(NodePort port)
Provides a JPopupMenu that is displayed for the given node port. If the JPopupMenu contains no elements or is null no popup menu will be displayed.

Parameters:
port - the node port
Returns:
the popup menu for the node port.

getNodeLabelPopup

public javax.swing.JPopupMenu getNodeLabelPopup(NodeLabel label)
Provides a JPopupMenu that is displayed for the given node label. If the JPopupMenu contains no elements or is null no popup menu will be displayed.

Parameters:
label - the label
Returns:
the popup menu for the label

setSelectSubject

public void setSelectSubject(boolean select)
Sets whether or not to automatically select the subject (node, edge, bend,...) for which the popup menu gets activated. By default the subject gets automatically selected.


getSelectSubject

public boolean getSelectSubject()
Returns whether or not to automatically select the subject (node, edge, bend,...) for which the popup menu gets activated. By default the subject gets automatically selected.


setSingleNodeSelectionModeEnabled

public void setSingleNodeSelectionModeEnabled(boolean singleNodeSelectionModeEnabled)
Whether or not single node selection mode is enabled. If enabled, single node selections are treated differently than multi-selections. Single selection mode will deselect the selected node, select the node being clicked and sets popup type to POPUP_TYPE_NODE. If not enabled a click on an unselected node will not change the selection. The popup type is set to POPUP_TYPE_SELECTION.

By default, this feature is enabled.


isSingleNodeSelectionModeEnabled

public boolean isSingleNodeSelectionModeEnabled()
Returns whether or not single node selection mode is enabled.

See Also:
setSingleNodeSelectionModeEnabled(boolean)

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