Java Platform 1.2

javax.swing.tree
Class DefaultTreeCellEditor

java.lang.Object
  |
  +--javax.swing.tree.DefaultTreeCellEditor

public class DefaultTreeCellEditor
extends Object
implements ActionListener, TreeCellEditor, TreeSelectionListener

A TreeCellEditor. You need to supply an instance of DefaultTreeCellRenderer so that the icons can be obtained. You can optionaly supply a TreeCellEditor that will be layed out according to the icon in the DefaultTreeCellRenderer. If you do not supply a TreeCellEditor, a TextField will be used. Editing is started on a triple mouse click, or after a click, pause, click and a delay of 1200 miliseconds.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. A future release of Swing will provide support for long term persistence.


Inner Class Summary
 class DefaultTreeCellEditor.DefaultTextField
          TextField used when no editor is supplied.
 class DefaultTreeCellEditor.EditorContainer
          Container responsible for placing the editingComponent.
 
Field Summary
protected  Color borderSelectionColor
          True if the border selection color should be drawn.
protected  boolean canEdit
          Should isCellEditable return true? This is set in configure...
protected  Component editingComponent
          Component used in editing, obtained from the editingContainer.
protected  Container editingContainer
          Editing container, will contain the editorComponent.
protected  Icon editingIcon
          Icon to use when editing.
protected  Font font
          Font to paint with, null indicates font of renderer is to be used.
protected  TreePath lastPath
          last path that was selected.
protected  int lastRow
          Row that was last passed into getTreeCellEditorComponent.
protected  int offset
          Used in editing.
protected  TreeCellEditor realEditor
          Editor handling the editing.
protected  DefaultTreeCellRenderer renderer
          Renderer, used to get border and offsets from.
protected  Timer timer
          Used before starting the editing session.
protected  JTree tree
          JTree instance listening too.
 
Constructor Summary
DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer)
          Constructs a DefaultTreeCellEditor object for a JTree using the specified renderer and a default editor.
DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer, TreeCellEditor editor)
          Constructs a DefaultTreeCellEditor object for a JTree using the specified renderer and the specified editor.
 
Method Summary
 void actionPerformed(ActionEvent e)
          Messaged when the timer fires, this will start the editing session.
 void addCellEditorListener(CellEditorListener l)
          Adds the CellEditorListener.
 void cancelCellEditing()
          Messages cancelCellEditing to the realEditor and removes it from this instance.
protected  boolean canEditImmediately(EventObject event)
          Returns true if event is null, or it is a MouseEvent with a click count > 2.
protected  Container createContainer()
          Creates the container to manage placement of editingComponent.
protected  TreeCellEditor createTreeCellEditor()
          This is invoked if a TreeCellEditor is not supplied in the constructor.
protected  void determineOffset(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)
           
 Color getBorderSelectionColor()
          Returns the color the border is drawn.
 Object getCellEditorValue()
          Returns the value currently being edited.
 Font getFont()
          Gets the font used for editing.
 Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row)
          Configures the editor.
protected  boolean inHitRegion(int x, int y)
          Returns true if x is inside the text region of the renderer, not the icon part.
 boolean isCellEditable(EventObject event)
          If the realEditor returns true to this message, prepareForEditing is messaged and true is returned.
protected  void prepareForEditing()
           
 void removeCellEditorListener(CellEditorListener l)
          Removes the previously added CellEditorListener l.
 void setBorderSelectionColor(Color newColor)
          Sets the color to use for the border.
 void setFont(Font font)
          Sets the font to edit with.
protected  void setTree(JTree newTree)
          Sets the tree currently editing for.
 boolean shouldSelectCell(EventObject event)
          Messages the realEditor for the return value.
protected  boolean shouldStartEditingTimer(EventObject event)
          Returns true if event is a MouseEvent and the click count is 1.
protected  void startEditingTimer()
          Starts the editing timer.
 boolean stopCellEditing()
          If the realEditor will allow editing to stop, the realEditor is removed and true is returned, otherwise false is returned.
 void valueChanged(TreeSelectionEvent e)
          Resets lastPath.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

realEditor

protected TreeCellEditor realEditor
Editor handling the editing.

renderer

protected DefaultTreeCellRenderer renderer
Renderer, used to get border and offsets from.

editingContainer

protected Container editingContainer
Editing container, will contain the editorComponent.

editingComponent

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

canEdit

protected boolean canEdit
Should isCellEditable return true? This is set in configure... based on the path being edited and the selected selected path.

offset

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

tree

protected transient JTree tree
JTree instance listening too.

lastPath

protected transient TreePath lastPath
last path that was selected.

timer

protected transient Timer timer
Used before starting the editing session.

lastRow

protected transient int lastRow
Row that was last passed into getTreeCellEditorComponent.

borderSelectionColor

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

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.
Constructor Detail

DefaultTreeCellEditor

public DefaultTreeCellEditor(JTree tree,
                             DefaultTreeCellRenderer renderer)
Constructs a DefaultTreeCellEditor object for a JTree using the specified renderer and a default editor. (Use this constructor for normal editing.)
Parameters:
tree - a JTree object
renderer - a DefaultTreeCellRenderer object

DefaultTreeCellEditor

public DefaultTreeCellEditor(JTree tree,
                             DefaultTreeCellRenderer renderer,
                             TreeCellEditor editor)
Constructs a DefaultTreeCellEditor object for a JTree using the specified renderer and the specified editor. (Use this constructor for specialized editing.)
Parameters:
tree - a JTree object
renderer - a DefaultTreeCellRenderer object
editor - a TreeCellEditor object
Method Detail

setBorderSelectionColor

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

getBorderSelectionColor

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

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:
getFont()

getFont

public Font getFont()
Gets the font used for editing.
Returns:
the editing Font
See Also:
setFont(java.awt.Font)

getTreeCellEditorComponent

public Component getTreeCellEditorComponent(JTree tree,
                                            Object value,
                                            boolean isSelected,
                                            boolean expanded,
                                            boolean leaf,
                                            int row)
Configures the editor. Passed onto the realEditor.
Specified by:
getTreeCellEditorComponent in interface TreeCellEditor

getCellEditorValue

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

isCellEditable

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

shouldSelectCell

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

stopCellEditing

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

cancelCellEditing

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

addCellEditorListener

public void addCellEditorListener(CellEditorListener l)
Adds the CellEditorListener.

removeCellEditorListener

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

valueChanged

public void valueChanged(TreeSelectionEvent e)
Resets lastPath.
Specified by:
valueChanged in interface TreeSelectionListener

actionPerformed

public void actionPerformed(ActionEvent e)
Messaged when the timer fires, this will start the editing session.
Specified by:
actionPerformed in interface ActionListener

setTree

protected void setTree(JTree newTree)
Sets the tree currently editing for. This is needed to add a selection listener.

shouldStartEditingTimer

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

startEditingTimer

protected void startEditingTimer()
Starts the editing timer.

canEditImmediately

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

inHitRegion

protected boolean inHitRegion(int x,
                              int y)
Returns true if x is inside the text region of the renderer, not the icon part.

determineOffset

protected void determineOffset(JTree tree,
                               Object value,
                               boolean isSelected,
                               boolean expanded,
                               boolean leaf,
                               int row)

prepareForEditing

protected void prepareForEditing()

createContainer

protected Container createContainer()
Creates the container to manage placement of editingComponent.

createTreeCellEditor

protected TreeCellEditor createTreeCellEditor()
This is invoked if a TreeCellEditor is not supplied in the constructor. It returns a TextField editor.

Java Platform 1.2

Submit a bug or feature Version 1.2 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.