Search this API

y.view
Class Graph2DViewActions.EditLabelAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by y.view.Graph2DViewActions.EditLabelAction
All Implemented Interfaces:
java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action
Enclosing class:
Graph2DViewActions

public static class Graph2DViewActions.EditLabelAction
extends javax.swing.AbstractAction

Action that opens the label editor for interactive text editing.

See Also:
Serialized Form
 

Field Summary
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
Graph2DViewActions.EditLabelAction()
          Initializes a new EditLabelAction instance that has no default view, that means if the view cannot be determined from the event that triggers a delete action, no editor is opened.
Graph2DViewActions.EditLabelAction(Graph2DView view)
          Initializes a new EditLabelAction instance.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Invokes editLabel for the view returned by getView.
protected  NodeLabel createColumnLabel(TableGroupNodeRealizer realizer, TableGroupNodeRealizer.Column c)
          Creates a new NodeLabel instance, adds the created instance to the specified realizer, and associates the instance to the specified column.
protected  EdgeLabel createEdgeLabel(EdgeRealizer realizer)
          Creates a new EdgeLabel instance and adds the created instance to the specified realizer.
protected  NodeLabel createNodeLabel(NodeRealizer realizer)
          Creates a new NodeLabel instance and adds the created instance to the specified realizer.
protected  NodeLabel createRowLabel(TableGroupNodeRealizer realizer, TableGroupNodeRealizer.Row r)
          Creates a new NodeLabel instance, adds the created instance to the specified realizer, and associates the instance to the specified row.
 void editLabel(Graph2DView view)
          Opens the interactive label editor for the specified view.
protected  YLabel findLabel(Graph2DView view)
          Determines the label to edit.
protected  java.beans.PropertyChangeListener getPropertyChangeListener()
          Returns a PropertyChangeListener that is notified of text changes when interactive label text editing is done.
protected  Graph2DView getView(java.awt.event.ActionEvent e)
          Determines the view in which to edit labels.
protected  boolean isSingleLineModeEnabled()
          Determines the interactive editor's line editing mode.
protected  void openLabelEditor(Graph2DView view, YLabel label, java.beans.PropertyChangeListener listener, boolean useSingleLineMode)
          Opens the specified view's editor for interactive label text editing.
protected  void setText(YLabel label, java.lang.String text)
          Sets the text of the specified label.
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Graph2DViewActions.EditLabelAction

public Graph2DViewActions.EditLabelAction()
Initializes a new EditLabelAction instance that has no default view, that means if the view cannot be determined from the event that triggers a delete action, no editor is opened. Invoking this constructor is equivalent to:
new EditLabelAction(null)


Graph2DViewActions.EditLabelAction

public Graph2DViewActions.EditLabelAction(Graph2DView view)
Initializes a new EditLabelAction instance.

Parameters:
view - the default view that is used if the actual view cannot be determined from the information provided by an ActionEvent.
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Invokes editLabel for the view returned by getView.

Parameters:
e - the ActionEvent that triggers label text editing.
See Also:
getView(java.awt.event.ActionEvent), editLabel(y.view.Graph2DView)

editLabel

public void editLabel(Graph2DView view)
Opens the interactive label editor for the specified view. Calls the following methods:

Note: The label editor is only opened for labels that are visible in the specified view (i.e. the label's bounds intersect the visible region of the view).

Parameters:
view - the view in which to delete graph elements.
Throws:
java.lang.NullPointerException - if the specified view is null.
See Also:
findLabel(Graph2DView), openLabelEditor(Graph2DView, YLabel, java.beans.PropertyChangeListener, boolean)

getPropertyChangeListener

protected java.beans.PropertyChangeListener getPropertyChangeListener()
Returns a PropertyChangeListener that is notified of text changes when interactive label text editing is done.

By default, null is returned. To specify a listener use

putValue("PROPERTY_CHANGE_LISTENER", listener);

Returns:
a PropertyChangeListener that is notified of text changes when interactive label text editing is done or null if no notification is desired.

isSingleLineModeEnabled

protected boolean isSingleLineModeEnabled()
Determines the interactive editor's line editing mode. In single line mode pressing the "Enter" key will terminate editing and "Ctrl-Enter" or "Shift-Enter" will add a new line; in multiple lines mode pressing "Enter" will add a new line and "Ctrl-Enter" or "Shift-Enter" will terminate editing.

By default, single line mode is assumed. To activate multiple lines mode, use

putValue("SINGLE_LINE_MODE", Boolean.FALSE);

Returns:
true for single line mode and false for multiple lines mode.

openLabelEditor

protected void openLabelEditor(Graph2DView view,
                               YLabel label,
                               java.beans.PropertyChangeListener listener,
                               boolean useSingleLineMode)
Opens the specified view's editor for interactive label text editing.

Parameters:
view - the view in which a label is edited.
label - the label whose text is edited.
listener - a listener that has to be notified of label text changes. May be null if no notification is desired.
useSingleLineMode - if true label editing should be done in single line mode; otherwise multiple lines mode should be used.
See Also:
getPropertyChangeListener(), isSingleLineModeEnabled(), Graph2DView.openLabelEditorCentered(YLabel, double, double, java.beans.PropertyChangeListener, boolean, boolean)

getView

protected Graph2DView getView(java.awt.event.ActionEvent e)
Determines the view in which to edit labels.

Parameters:
e - the ActionEvent that triggers label text editing.
Returns:
the view in which to edit labels.
See Also:
actionPerformed(java.awt.event.ActionEvent), Graph2DViewActions.EditLabelAction(y.view.Graph2DView)

findLabel

protected YLabel findLabel(Graph2DView view)
Determines the label to edit. The default implementation first tries to find a selected label. If there are no selected labels, the specified view's graph is searched for a selected node, edge, table row, or table column (in that order). If a selected element of one of the mentioned types exists, the first selected element's default label (in the case of a node or edge) or its associated label (in the case of a row or column) is returned. If the first selected element has no associated labels, such a label is created using the appropriate factory method (createNodeLabel, createEdgeLabel, createRowLabel, or createColumnLabel). If there is no selected element, null is returned.

Parameters:
view - the view whose graph is searched for a label to edit.
Returns:
the YLabel instance to edit or null if no label should be edited.

createEdgeLabel

protected EdgeLabel createEdgeLabel(EdgeRealizer realizer)
Creates a new EdgeLabel instance and adds the created instance to the specified realizer.

The default implementation simply returns realizer.getLabel().

Parameters:
realizer - the owner realizer of the new label.
Returns:
a new EdgeLabel instance.

createNodeLabel

protected NodeLabel createNodeLabel(NodeRealizer realizer)
Creates a new NodeLabel instance and adds the created instance to the specified realizer.

The default implementation simply returns realizer.getLabel().

Parameters:
realizer - the owner realizer of the new label.
Returns:
a new NodeLabel instance.

createColumnLabel

protected NodeLabel createColumnLabel(TableGroupNodeRealizer realizer,
                                      TableGroupNodeRealizer.Column c)
Creates a new NodeLabel instance, adds the created instance to the specified realizer, and associates the instance to the specified column.

Parameters:
realizer - the owner realizer of the new label.
c - the column to which the label is associated.
Returns:
a new NodeLabel instance.

createRowLabel

protected NodeLabel createRowLabel(TableGroupNodeRealizer realizer,
                                   TableGroupNodeRealizer.Row r)
Creates a new NodeLabel instance, adds the created instance to the specified realizer, and associates the instance to the specified row.

Parameters:
realizer - the owner realizer of the new label.
r - the row to which the label is associated.
Returns:
a new NodeLabel instance.

setText

protected void setText(YLabel label,
                       java.lang.String text)
Sets the text of the specified label. Called when interactive editing is done to set the edited label's text.

Parameters:
label - the label whose text content is set.
text - the new text content.

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