Package org.jgraph.graph
Class DefaultGraphCellEditor
- java.lang.Object
-
- org.jgraph.graph.DefaultGraphCellEditor
-
- All Implemented Interfaces:
java.awt.event.ActionListener,java.io.Serializable,java.util.EventListener,javax.swing.CellEditor,GraphSelectionListener,GraphCellEditor
public class DefaultGraphCellEditor extends java.lang.Object implements java.awt.event.ActionListener, GraphCellEditor, GraphSelectionListener, java.io.Serializable
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classDefaultGraphCellEditor.DefaultTextFieldTextField used when no editor is supplied.classDefaultGraphCellEditor.EditorContainerContainer responsible for placing the editingComponent.
-
Field Summary
Fields Modifier and Type Field Description protected java.awt.ColorborderSelectionColorTrue if the border selection color should be drawn.protected booleancanEditInternal Note, maybe isCellEditable return true.protected java.awt.ComponenteditingComponentComponent used in editing, obtained from the editingContainer.protected java.awt.ContainereditingContainerEditing container, will contain the editorComponent.protected javax.swing.IconeditingIconIcon to use when editing.protected java.awt.FontfontFont to paint with, null indicates font of renderer is to be used.protected JGraphgraphJTree instance listening too.protected java.lang.ObjectlastCelllast path that was selected.protected intoffsetXUsed in editing.protected intoffsetYprotected GraphCellEditorrealEditorEditor handling the editing.
-
Constructor Summary
Constructors Constructor Description DefaultGraphCellEditor()Constructs a DefaultTreeCellEditor object for a JGraph using the specified renderer and a default editor.DefaultGraphCellEditor(GraphCellEditor editor)Constructs a DefaultTreeCellEditor object for a JTree using the specified renderer and the specified editor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactionPerformed(java.awt.event.ActionEvent e)Messaged when the timer fires, this will start the editing session.voidaddCellEditorListener(javax.swing.event.CellEditorListener l)Adds the CellEditorListener.voidcancelCellEditing()Messages cancelCellEditing to the realEditor and removes it from this instance.protected booleancanEditImmediately(java.util.EventObject event)Returns true ifeventis null, or it is a MouseEvent with a click count > 2 and inHitRegion returns true.protected java.awt.ContainercreateContainer()Creates the container to manage placement of editingComponent.protected GraphCellEditorcreateGraphCellEditor()This is invoked if a TreeCellEditor is not supplied in the constructor.protected voiddetermineOffset(JGraph graph, java.lang.Object value, boolean isSelected)java.awt.ColorgetBorderSelectionColor()Returns the color the border is drawn.java.lang.ObjectgetCellEditorValue()Returns the value currently being edited.java.awt.FontgetFont()Gets the font used for editing.java.awt.ComponentgetGraphCellEditorComponent(JGraph graph, java.lang.Object cell, boolean isSelected)Configures the editor.protected booleaninHitRegion(double x, double y)Should return true if the passed in location is a valid mouse location to start editing from.booleanisCellEditable(java.util.EventObject event)If the realEditor returns true to this message, prepareForEditing is messaged and true is returned.protected voidprepareForEditing()Invoked just before editing is to start.voidremoveCellEditorListener(javax.swing.event.CellEditorListener l)Removes the previously added CellEditorListener l.voidsetBorderSelectionColor(java.awt.Color newColor)Sets the color to use for the border.voidsetFont(java.awt.Font font)Sets the font to edit with.protected voidsetGraph(JGraph newGraph)Sets the tree currently editing for.booleanshouldSelectCell(java.util.EventObject event)Messages the realEditor for the return value.protected booleanshouldStartEditingTimer(java.util.EventObject event)Returns true ifeventis a MouseEvent and the click count is 1.booleanstopCellEditing()If the realEditor will allow editing to stop, the realEditor is removed and true is returned, otherwise false is returned.voidvalueChanged(GraphSelectionEvent e)Resets lastPath.
-
-
-
Field Detail
-
realEditor
protected GraphCellEditor realEditor
Editor handling the editing.
-
editingContainer
protected java.awt.Container editingContainer
Editing container, will contain the editorComponent.
-
editingComponent
protected transient java.awt.Component editingComponent
Component used in editing, obtained from the editingContainer.
-
canEdit
protected boolean canEdit
Internal Note, maybe isCellEditable return true. This is set in configure based on the path being edited and the selected selected path.
-
offsetX
protected transient int offsetX
Used in editing. Indicates position to place editingComponent.
-
offsetY
protected transient int offsetY
-
graph
protected transient JGraph graph
JTree instance listening too.
-
lastCell
protected transient java.lang.Object lastCell
last path that was selected.
-
borderSelectionColor
protected java.awt.Color borderSelectionColor
True if the border selection color should be drawn.
-
editingIcon
protected transient javax.swing.Icon editingIcon
Icon to use when editing.
-
font
protected java.awt.Font font
Font to paint with, null indicates font of renderer is to be used.
-
-
Constructor Detail
-
DefaultGraphCellEditor
public DefaultGraphCellEditor()
Constructs a DefaultTreeCellEditor object for a JGraph using the specified renderer and a default editor. (Use this constructor for normal editing.)
-
DefaultGraphCellEditor
public DefaultGraphCellEditor(GraphCellEditor editor)
Constructs a DefaultTreeCellEditor object for a JTree using the specified renderer and the specified editor. (Use this constructor for specialized editing.)- Parameters:
editor- a TreeCellEditor object
-
-
Method Detail
-
setBorderSelectionColor
public void setBorderSelectionColor(java.awt.Color newColor)
Sets the color to use for the border.
-
getBorderSelectionColor
public java.awt.Color getBorderSelectionColor()
Returns the color the border is drawn.
-
setFont
public void setFont(java.awt.Font font)
Sets the font to edit with.nullindicates the renderers font should be used. This will NOT override any font you have set in the editor the receiver was instantied with. If null for an editor was passed in a default editor will be created that will pick up this font.- Parameters:
font- the editing Font- See Also:
getFont()
-
getFont
public java.awt.Font getFont()
Gets the font used for editing.- Returns:
- the editing Font
- See Also:
setFont(java.awt.Font)
-
getGraphCellEditorComponent
public java.awt.Component getGraphCellEditorComponent(JGraph graph, java.lang.Object cell, boolean isSelected)
Configures the editor. Passed onto the realEditor.- Specified by:
getGraphCellEditorComponentin interfaceGraphCellEditor- Parameters:
graph- the JGraph that is asking the editor to edit This parameter can be null.cell- the value of the cell to be edited.isSelected- true if the cell is to be rendered with selection highlighting- Returns:
- the component for editing
-
getCellEditorValue
public java.lang.Object getCellEditorValue()
Returns the value currently being edited.- Specified by:
getCellEditorValuein interfacejavax.swing.CellEditor
-
isCellEditable
public boolean isCellEditable(java.util.EventObject event)
If the realEditor returns true to this message, prepareForEditing is messaged and true is returned.- Specified by:
isCellEditablein interfacejavax.swing.CellEditor
-
shouldSelectCell
public boolean shouldSelectCell(java.util.EventObject event)
Messages the realEditor for the return value.- Specified by:
shouldSelectCellin interfacejavax.swing.CellEditor
-
stopCellEditing
public boolean stopCellEditing()
If the realEditor will allow editing to stop, the realEditor is removed and true is returned, otherwise false is returned.- Specified by:
stopCellEditingin interfacejavax.swing.CellEditor
-
cancelCellEditing
public void cancelCellEditing()
Messages cancelCellEditing to the realEditor and removes it from this instance.- Specified by:
cancelCellEditingin interfacejavax.swing.CellEditor
-
addCellEditorListener
public void addCellEditorListener(javax.swing.event.CellEditorListener l)
Adds the CellEditorListener.- Specified by:
addCellEditorListenerin interfacejavax.swing.CellEditor
-
removeCellEditorListener
public void removeCellEditorListener(javax.swing.event.CellEditorListener l)
Removes the previously added CellEditorListener l.- Specified by:
removeCellEditorListenerin interfacejavax.swing.CellEditor
-
valueChanged
public void valueChanged(GraphSelectionEvent e)
Resets lastPath.- Specified by:
valueChangedin interfaceGraphSelectionListener- Parameters:
e- the event that characterizes the change.
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
Messaged when the timer fires, this will start the editing session.- Specified by:
actionPerformedin interfacejava.awt.event.ActionListener
-
setGraph
protected void setGraph(JGraph newGraph)
Sets the tree currently editing for. This is needed to add a selection listener.
-
shouldStartEditingTimer
protected boolean shouldStartEditingTimer(java.util.EventObject event)
Returns true ifeventis a MouseEvent and the click count is 1.
-
canEditImmediately
protected boolean canEditImmediately(java.util.EventObject event)
Returns true ifeventis null, or it is a MouseEvent with a click count > 2 and inHitRegion returns true.
-
inHitRegion
protected boolean inHitRegion(double x, double y)Should return true if the passed in location is a valid mouse location to start editing from. This is implemented to return false ifxis <= the width of the icon and icon gap displayed by the renderer. In other words this returns true if the user clicks over the text part displayed by the renderer, and false otherwise.
-
determineOffset
protected void determineOffset(JGraph graph, java.lang.Object value, boolean isSelected)
-
prepareForEditing
protected void prepareForEditing()
Invoked just before editing is to start. Will add theeditingComponentto theeditingContainer.
-
createContainer
protected java.awt.Container createContainer()
Creates the container to manage placement of editingComponent.
-
createGraphCellEditor
protected GraphCellEditor createGraphCellEditor()
This is invoked if a TreeCellEditor is not supplied in the constructor. It returns a TextField editor.
-
-