org.jgraph.graph

Class DefaultGraphCellEditor

public class DefaultGraphCellEditor extends Object implements ActionListener, GraphCellEditor, GraphSelectionListener, Serializable

Nested Class Summary
classDefaultGraphCellEditor.DefaultTextField
TextField used when no editor is supplied.
classDefaultGraphCellEditor.EditorContainer
Container responsible for placing the editingComponent.
Field Summary
protected ColorborderSelectionColor
True if the border selection color should be drawn.
protected booleancanEdit
Internal Note, maybe isCellEditable return true.
protected ComponenteditingComponent
Component used in editing, obtained from the editingContainer.
protected ContainereditingContainer
Editing container, will contain the editorComponent.
protected IconeditingIcon
Icon to use when editing.
protected Fontfont
Font to paint with, null indicates font of renderer is to be used.
protected JGraphgraph
JTree instance listening too.
protected ObjectlastCell
last path that was selected.
protected intoffsetX
Used in editing.
protected intoffsetY
protected GraphCellEditorrealEditor
Editor handling the editing.
Constructor Summary
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
voidactionPerformed(ActionEvent e)
Messaged when the timer fires, this will start the editing session.
voidaddCellEditorListener(CellEditorListener l)
Adds the CellEditorListener.
voidcancelCellEditing()
Messages cancelCellEditing to the realEditor and removes it from this instance.
protected booleancanEditImmediately(EventObject event)
Returns true if event is null, or it is a MouseEvent with a click count > 2 and inHitRegion returns true.
protected 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, Object value, boolean isSelected)
ColorgetBorderSelectionColor()
Returns the color the border is drawn.
ObjectgetCellEditorValue()
Returns the value currently being edited.
FontgetFont()
Gets the font used for editing.
ComponentgetGraphCellEditorComponent(JGraph graph, 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(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(CellEditorListener l)
Removes the previously added CellEditorListener l.
voidsetBorderSelectionColor(Color newColor)
Sets the color to use for the border.
voidsetFont(Font font)
Sets the font to edit with.
protected voidsetGraph(JGraph newGraph)
Sets the tree currently editing for.
booleanshouldSelectCell(EventObject event)
Messages the realEditor for the return value.
protected booleanshouldStartEditingTimer(EventObject event)
Returns true if event is 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

borderSelectionColor

protected Color borderSelectionColor
True if the border selection color should be drawn.

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.

editingComponent

protected transient Component editingComponent
Component used in editing, obtained from the editingContainer.

editingContainer

protected Container editingContainer
Editing container, will contain the editorComponent.

editingIcon

protected transient Icon editingIcon
Icon to use when editing.

font

protected Font font
Font to paint with, null indicates font of renderer is to be used.

graph

protected transient JGraph graph
JTree instance listening too.

lastCell

protected transient Object lastCell
last path that was selected.

offsetX

protected transient int offsetX
Used in editing. Indicates position to place editingComponent.

offsetY

protected transient int offsetY

realEditor

protected GraphCellEditor realEditor
Editor handling the editing.

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

actionPerformed

public void actionPerformed(ActionEvent e)
Messaged when the timer fires, this will start the editing session.

addCellEditorListener

public void addCellEditorListener(CellEditorListener l)
Adds the CellEditorListener.

cancelCellEditing

public void cancelCellEditing()
Messages cancelCellEditing to the realEditor and removes it from this instance.

canEditImmediately

protected boolean canEditImmediately(EventObject event)
Returns true if event is null, or it is a MouseEvent with a click count > 2 and inHitRegion returns true.

createContainer

protected 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.

determineOffset

protected void determineOffset(JGraph graph, Object value, boolean isSelected)

getBorderSelectionColor

public Color getBorderSelectionColor()
Returns the color the border is drawn.

getCellEditorValue

public Object getCellEditorValue()
Returns the value currently being edited.

getFont

public Font getFont()
Gets the font used for editing.

Returns: the editing Font

See Also: DefaultGraphCellEditor

getGraphCellEditorComponent

public Component getGraphCellEditorComponent(JGraph graph, Object cell, boolean isSelected)
Configures the editor. Passed onto the realEditor.

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 if x is <= 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.

isCellEditable

public boolean isCellEditable(EventObject event)
If the realEditor returns true to this message, prepareForEditing is messaged and true is returned.

prepareForEditing

protected void prepareForEditing()
Invoked just before editing is to start. Will add the editingComponent to the editingContainer.

removeCellEditorListener

public void removeCellEditorListener(CellEditorListener l)
Removes the previously added CellEditorListener l.

setBorderSelectionColor

public void setBorderSelectionColor(Color newColor)
Sets the color to use for the border.

setFont

public void setFont(Font font)
Sets the font to edit with. null indicates 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: DefaultGraphCellEditor

setGraph

protected void setGraph(JGraph newGraph)
Sets the tree currently editing for. This is needed to add a selection listener.

shouldSelectCell

public boolean shouldSelectCell(EventObject event)
Messages the realEditor for the return value.

shouldStartEditingTimer

protected boolean shouldStartEditingTimer(EventObject event)
Returns true if event is a MouseEvent and the click count is 1.

stopCellEditing

public boolean stopCellEditing()
If the realEditor will allow editing to stop, the realEditor is removed and true is returned, otherwise false is returned.

valueChanged

public void valueChanged(GraphSelectionEvent e)
Resets lastPath.
Copyright (C) 2001-2009 JGraph Ltd. All rights reserved.