This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


javax.swing.tree
class DefaultTreeCellEditor

java.lang.Object extended by javax.swing.tree.DefaultTreeCellEditor
All Implemented Interfaces:
ActionListener, TreeSelectionListener, TreeCellEditor

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 optionally 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. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see {@link java.beans.XMLEncoder}.


Nested Class Summary
 class

           TextField used when no editor is supplied.
 class

           Container responsible for placing the editingComponent.
 
Field Summary
protected Color borderSelectionColor
          True if the border selection color should be drawn.
protected boolean canEdit
          As of Java 2 platform v1.4 this field should no longer be used.
protected transient Component editingComponent
          Component used in editing, obtained from the editingContainer.
protected Container editingContainer
          Editing container, will contain the editorComponent.
protected transient Icon editingIcon
          Icon to use when editing.
protected Font font
          Font to paint with, null indicates font of renderer is to be used.
protected transient TreePath lastPath
          Last path that was selected.
protected transient int lastRow
          Row that was last passed into getTreeCellEditorComponent.
protected transient int offset
          Used in editing.
protected TreeCellEditor realEditor
          Editor handling the editing.
protected DefaultTreeCellRenderer renderer
          Renderer, used to get border and offsets from.
protected transient Timer timer
          Used before starting the editing session.
protected transient JTree tree
          JTree instance listening too.
 
Constructor Summary

          Constructs a DefaultTreeCellEditor object for a JTree using the specified renderer and a default editor.

          Constructs a DefaultTreeCellEditor object for a JTree using the specified renderer and the specified editor.
 
Method Summary
 void

          Messaged when the timer fires, this will start the editing session.
 void

          Adds the CellEditorListener.
 void

          Messages cancelCellEditing to the realEditor and removes it from this instance.
protected boolean

          Returns true if event is null, or it is a MouseEvent with a click count > 2 and inHitRegion returns true.
protected Container

          Creates the container to manage placement of editingComponent.
protected TreeCellEditor

          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

          Returns the color the border is drawn.
 CellEditorListener[]

          Returns an array of all the CellEditorListeners added to this DefaultTreeCellEditor with addCellEditorListener().
 Object

          Returns the value currently being edited.
 Font

          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 the passed in location is a valid mouse location to start editing from.
 boolean

          If the realEditor returns true to this message, prepareForEditing is messaged and true is returned.
protected void

          Invoked just before editing is to start.
 void

          Removes the previously added CellEditorListener.
 void

          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

          Messages the realEditor for the return value.
protected boolean

          Returns true if event is a MouseEvent and the click count is 1.
protected void

          Starts the editing timer.
 boolean

          If the realEditor will allow editing to stop, the realEditor is removed and true is returned, otherwise false is returned.
 void

          Resets lastPath.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

borderSelectionColor

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

canEdit

protected boolean canEdit
As of Java 2 platform v1.4 this field should no longer be used. If you wish to provide similar behavior you should directly override isCellEditable.

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.

lastPath

protected transient TreePath lastPath
Last path that was selected.

lastRow

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

offset

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

realEditor

protected TreeCellEditor realEditor
Editor handling the editing.

renderer

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

timer

protected transient Timer timer
Used before starting the editing session.

tree

protected transient JTree tree
JTree instance listening too.
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

actionPerformed

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

Parameters:
e

addCellEditorListener

public void addCellEditorListener(CellEditorListener l)
Adds the CellEditorListener.

Parameters:
l - the listener to be added

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.

Parameters:
event - the event being studied

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.

Returns:
a new TextField editor

determineOffset

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

getBorderSelectionColor

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

Returns:
the border selection color

getCellEditorListeners

public CellEditorListener[] getCellEditorListeners()
Returns an array of all the CellEditorListeners added to this DefaultTreeCellEditor with addCellEditorListener().

Returns:
all of the CellEditorListeners added or an empty array if no listeners have been added

getCellEditorValue

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

Returns:
the value currently being edited

getFont

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

Returns:
the editing Font

getTreeCellEditorComponent

public Component getTreeCellEditorComponent(JTree tree,
                                            Object value,
                                            boolean isSelected,
                                            boolean expanded,
                                            boolean leaf,
                                            int row)
Configures the editor. Passed onto the realEditor.

Parameters:
tree
value
isSelected
expanded
leaf
row

inHitRegion

protected boolean inHitRegion(int x,
                              int y)
Returns 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.

Parameters:
x - the x-coordinate of the point
y - the y-coordinate of the point
Returns:
true if the passed in location is a valid mouse location

isCellEditable

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

Parameters:
event

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.

Parameters:
l - the listener to be removed

setBorderSelectionColor

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

Parameters:
newColor - the new border color

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

setTree

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

Parameters:
newTree - the new tree to be edited

shouldSelectCell

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

Parameters:
event

shouldStartEditingTimer

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

Parameters:
event - the event being studied

startEditingTimer

protected void startEditingTimer()
Starts the editing timer.


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(TreeSelectionEvent e)
Resets lastPath.

Parameters:
e


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.