/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A <code>TreeCellEditor</code>. You need to supply an
* instance of <code>DefaultTreeCellRenderer</code>
* so that the icons can be obtained. You can optionally supply
* a <code>TreeCellEditor</code> that will be layed out according
* to the icon in the <code>DefaultTreeCellRenderer</code>.
* If you do not supply a <code>TreeCellEditor</code>,
* a <code>TextField</code> will be used. Editing is started
* on a triple mouse click, or after a click, pause, click and
* a delay of 1200 miliseconds.
*<p>
* <strong>Warning:</strong>
* 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 JavaBeans<sup><font size="-2">TM</font></sup>
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*
* @see javax.swing.JTree
*
* @author Scott Violet
*/
/** Editor handling the editing. */
/** Renderer, used to get border and offsets from. */
/** Editing container, will contain the <code>editorComponent</code>. */
/**
* Component used in editing, obtained from the
* <code>editingContainer</code>.
*/
/**
* 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
* <code>isCellEditable</code>.
*/
protected boolean canEdit;
/**
* Used in editing. Indicates x position to place
* <code>editingComponent</code>.
*/
protected transient int offset;
/** <code>JTree</code> instance listening too. */
/** Last path that was selected. */
/** Used before starting the editing session. */
/**
* Row that was last passed into
* <code>getTreeCellEditorComponent</code>.
*/
protected transient int lastRow;
/** True if the border selection color should be drawn. */
/** Icon to use when editing. */
/**
* Font to paint with, <code>null</code> indicates
* font of renderer is to be used.
*/
/**
* Constructs a <code>DefaultTreeCellEditor</code>
* object for a JTree using the specified renderer and
* a default editor. (Use this constructor for normal editing.)
*
* @param tree a <code>JTree</code> object
* @param renderer a <code>DefaultTreeCellRenderer</code> object
*/
}
/**
* Constructs a <code>DefaultTreeCellEditor</code>
* object for a <code>JTree</code> using the
* specified renderer and the specified editor. (Use this constructor
* for specialized editing.)
*
* @param tree a <code>JTree</code> object
* @param renderer a <code>DefaultTreeCellRenderer</code> object
* @param editor a <code>TreeCellEditor</code> object
*/
realEditor = editor;
if(realEditor == null)
("Tree.editorBorderSelectionColor"));
}
/**
* Sets the color to use for the border.
* @param newColor the new border color
*/
}
/**
* Returns the color the border is drawn.
* @return the border selection color
*/
return borderSelectionColor;
}
/**
* Sets the font to edit with. <code>null</code> 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 <code>null</code>
* for an editor was passed in a default editor will be
* created that will pick up this font.
*
* @param font the editing <code>Font</code>
* @see #getFont
*/
}
/**
* Gets the font used for editing.
*
* @return the editing <code>Font</code>
* @see #setFont
*/
return font;
}
//
// TreeCellEditor
//
/**
* Configures the editor. Passed onto the <code>realEditor</code>.
*/
boolean isSelected,
boolean expanded,
if (editingComponent != null) {
}
// this is kept for backwards compatability but isn't really needed
// with the current BasicTreeUI implementation.
}
return editingContainer;
}
/**
* Returns the value currently being edited.
* @return the value currently being edited
*/
return realEditor.getCellEditorValue();
}
/**
* If the <code>realEditor</code> returns true to this
* message, <code>prepareForEditing</code>
* is messaged and true is returned.
*/
boolean retValue = false;
boolean editable = false;
if (event instanceof MouseEvent) {
}
}
}
}
return false;
if(canEditImmediately(event))
retValue = true;
}
if(retValue)
return retValue;
}
/**
* Messages the <code>realEditor</code> for the return value.
*/
}
/**
* If the <code>realEditor</code> will allow editing to stop,
* the <code>realEditor</code> is removed and true is returned,
* otherwise false is returned.
*/
public boolean stopCellEditing() {
if(realEditor.stopCellEditing()) {
return true;
}
return false;
}
/**
* Messages <code>cancelCellEditing</code> to the
* <code>realEditor</code> and removes it from this instance.
*/
public void cancelCellEditing() {
}
/**
* Adds the <code>CellEditorListener</code>.
* @param l the listener to be added
*/
}
/**
* Removes the previously added <code>CellEditorListener</code>.
* @param l the listener to be removed
*/
}
/**
* Returns an array of all the <code>CellEditorListener</code>s added
* to this DefaultTreeCellEditor with addCellEditorListener().
*
* @return all of the <code>CellEditorListener</code>s added or an empty
* array if no listeners have been added
* @since 1.4
*/
}
//
// TreeSelectionListener
//
/**
* Resets <code>lastPath</code>.
*/
else
}
}
}
//
// ActionListener (for Timer).
//
/**
* Messaged when the timer fires, this will start the editing
* session.
*/
}
}
//
// Local methods
//
/**
* Sets the tree currently editing for. This is needed to add
* a selection listener.
* @param newTree the new tree to be edited
*/
tree.removeTreeSelectionListener(this);
tree.addTreeSelectionListener(this);
}
}
}
/**
* Returns true if <code>event</code> is a <code>MouseEvent</code>
* and the click count is 1.
* @param event the event being studied
*/
if((event instanceof MouseEvent) &&
}
return false;
}
/**
* Starts the editing timer.
*/
protected void startEditingTimer() {
timer.setRepeats(false);
}
}
/**
* Returns true if <code>event</code> is <code>null</code>,
* or it is a <code>MouseEvent</code> with a click count > 2
* and <code>inHitRegion</code> returns true.
* @param event the event being studied
*/
if((event instanceof MouseEvent) &&
}
}
/**
* Returns true if the passed in location is a valid mouse location
* to start editing from. This is implemented to return false if
* <code>x</code> 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.
* @param x the x-coordinate of the point
* @param y the y-coordinate of the point
* @return true if the passed in location is a valid mouse location
*/
protected boolean inHitRegion(int x, int y) {
if ( treeOrientation.isLeftToRight() ) {
return false;
}
x <= (bounds.x + 5) ) &&
return false;
}
}
return true;
}
boolean isSelected, boolean expanded,
if(leaf)
else if(expanded)
else
if(editingIcon != null)
else
}
else {
editingIcon = null;
offset = 0;
}
}
/**
* Invoked just before editing is to start. Will add the
* <code>editingComponent</code> to the
* <code>editingContainer</code>.
*/
protected void prepareForEditing() {
if (editingComponent != null) {
}
}
/**
* Creates the container to manage placement of
* <code>editingComponent</code>.
*/
return new EditorContainer();
}
/**
* This is invoked if a <code>TreeCellEditor</code>
* is not supplied in the constructor.
* It returns a <code>TextField</code> editor.
* @return a new <code>TextField</code> editor
*/
(new DefaultTextField(aBorder)) {
return retValue;
}
};
// One click to edit.
return editor;
}
/**
* Cleans up any state after editing has completed. Removes the
* <code>editingComponent</code> the <code>editingContainer</code>.
*/
private void cleanupAfterEditing() {
if (editingComponent != null) {
}
}
// Serialization support.
s.defaultWriteObject();
// Save the realEditor, if its Serializable.
}
s.writeObject(values);
}
throws IOException, ClassNotFoundException {
s.defaultReadObject();
int indexCounter = 0;
equals("realEditor")) {
indexCounter++;
}
}
/**
* <code>TextField</code> used when no editor is supplied.
* This textfield locks into the border it is constructed with.
* It also prefers its parents font over its font. And if the
* renderer is not <code>null</code> and no font
* has been specified the preferred height is that of the renderer.
*/
/** Border to use. */
/**
* Constructs a
* <code>DefaultTreeCellEditor.DefaultTextField</code> object.
*
* @param border a <code>Border</code> object
* @since 1.4
*/
}
/**
* Sets the border of this component.<p>
* This is a bound property.
*
* @param border the border to be rendered for this component
* @see Border
* @see CompoundBorder
* @beaninfo
* bound: true
* preferred: true
* attribute: visualUpdate true
* description: The component's border.
*/
}
/**
* Overrides <code>JComponent.getBorder</code> to
* returns the current border.
*/
return border;
}
// implements java.awt.MenuContainer
// Prefer the parent containers font if our font is a
// FontUIResource
if(font instanceof FontUIResource) {
}
return font;
}
/**
* Overrides <code>JTextField.getPreferredSize</code> to
* return the preferred size based on current font, if set,
* or else use renderer's font.
* @return a <code>Dimension</code> object containing
* the preferred size
*/
// If not font has been set, prefer the renderers height.
}
return size;
}
}
/**
* Container responsible for placing the <code>editingComponent</code>.
*/
/**
* Constructs an <code>EditorContainer</code> object.
*/
public EditorContainer() {
}
// This should not be used. It will be removed when new API is
// allowed.
public void EditorContainer() {
}
/**
* Overrides <code>Container.paint</code> to paint the node's
* icon and use the selection color for the background.
*/
// Then the icon.
if(editingIcon != null) {
if (getComponentOrientation().isLeftToRight()) {
} else {
yLoc);
}
}
// Border selection color
if(background != null) {
g.setColor(background);
}
super.paint(g);
}
/**
* Lays out this <code>Container</code>. If editing,
* the editor will be placed at
* <code>offset</code> in the x direction and 0 for y.
*/
public void doLayout() {
if(editingComponent != null) {
if (getComponentOrientation().isLeftToRight()) {
} else {
}
}
}
/**
* Calculate the y location for the icon.
*/
// To make sure the icon position matches that of the
// renderer, use the same algorithm as JLabel
// (SwingUtilities.layoutCompoundLabel).
}
/**
* Returns the preferred size for the <code>Container</code>.
* This will be at least preferred size of the editor plus
* <code>offset</code>.
* @return a <code>Dimension</code> containing the preferred
* size for the <code>Container</code>; if
* <code>editingComponent</code> is <code>null</code> the
* <code>Dimension</code> returned is 0, 0
*/
if(editingComponent != null) {
if(editingIcon != null)
// Make sure width is at least 100.
return pSize;
}
}
}
}