summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/javax/swing/tree
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/javax/swing/tree')
-rw-r--r--libjava/classpath/javax/swing/tree/AbstractLayoutCache.java14
-rw-r--r--libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java520
-rw-r--r--libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java1216
-rw-r--r--libjava/classpath/javax/swing/tree/DefaultTreeModel.java924
-rw-r--r--libjava/classpath/javax/swing/tree/DefaultTreeSelectionModel.java2
-rw-r--r--libjava/classpath/javax/swing/tree/FixedHeightLayoutCache.java2
6 files changed, 1557 insertions, 1121 deletions
diff --git a/libjava/classpath/javax/swing/tree/AbstractLayoutCache.java b/libjava/classpath/javax/swing/tree/AbstractLayoutCache.java
index 9f8e9da5984..adece101deb 100644
--- a/libjava/classpath/javax/swing/tree/AbstractLayoutCache.java
+++ b/libjava/classpath/javax/swing/tree/AbstractLayoutCache.java
@@ -134,11 +134,11 @@ public abstract class AbstractLayoutCache
/**
* getNodeDimensions
*
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- * @param value3 TODO
- * @param value4 TODO
+ * @param value TODO
+ * @param row TODO
+ * @param depth TODO
+ * @param expanded TODO
+ * @param bounds TODO
*
* @return Rectangle
*/
@@ -154,7 +154,7 @@ public abstract class AbstractLayoutCache
/**
* Sets the model that provides the tree data.
*
- * @param the model
+ * @param model the model
*/
public void setModel(TreeModel model)
{
@@ -318,7 +318,7 @@ public abstract class AbstractLayoutCache
*
* @return int
*/
- public abstract int getVisibleChildCount(TreePath value0);
+ public abstract int getVisibleChildCount(TreePath path);
/**
* setExpandedState
diff --git a/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java b/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java
index e509d2c18e0..7a44e738338 100644
--- a/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java
+++ b/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java
@@ -1,5 +1,5 @@
/* DefaultTreeCellEditor.java --
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -43,17 +43,30 @@ import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
+import java.awt.FontMetrics;
import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.Rectangle;
+import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.EventObject;
+import javax.swing.CellRendererPane;
+import javax.swing.DefaultCellEditor;
import javax.swing.Icon;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
import javax.swing.JTextField;
import javax.swing.JTree;
+import javax.swing.SwingUtilities;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.event.CellEditorListener;
import javax.swing.event.EventListenerList;
@@ -90,29 +103,62 @@ public class DefaultTreeCellEditor
}
/**
- * getPreferredSize
- * @return Dimension
+ * Returns the preferred size for the Container.
+ *
+ * @return Dimension of EditorContainer
*/
public Dimension getPreferredSize()
{
- return null; // TODO
+ Dimension containerSize = super.getPreferredSize();
+ containerSize.width += DefaultTreeCellEditor.this.offset;
+ return containerSize;
}
/**
- * paint
- * @param value0 TODO
+ * Overrides Container.paint to paint the node's icon and use the selection
+ * color for the background.
+ *
+ * @param g -
+ * the specified Graphics window
*/
- public void paint(Graphics value0)
+ public void paint(Graphics g)
{
- // TODO
+ Rectangle tr = tree.getPathBounds(lastPath);
+ if (tr != null)
+ {
+ Insets i = ((DefaultTextField) editingComponent).getBorder()
+ .getBorderInsets(this);
+ int textIconGap = 3;
+ tr.x -= i.left;
+
+ // paints icon
+ if (editingIcon != null)
+ {
+ editingIcon.paintIcon(this, g, tr.x - editingIcon.
+ getIconWidth()/2, tr.y + i.top + i.bottom);
+ tr.x += editingIcon.getIconWidth()/2 + textIconGap;
+ }
+
+ tr.width += offset;
+
+ // paint background
+ g.translate(tr.x, tr.y);
+ editingComponent.setSize(new Dimension(tr.width, tr.height));
+ editingComponent.paint(g);
+ g.translate(-tr.x, -tr.y);
+ }
+ super.paint(g);
}
/**
- * doLayout
+ * Lays out this Container. If editing, the editor will be placed at offset
+ * in the x direction and 0 for y.
*/
public void doLayout()
{
- // TODO
+ if (DefaultTreeCellEditor.this.tree.isEditing())
+ setLocation(offset, 0);
+ super.doLayout();
}
}
@@ -137,12 +183,22 @@ public class DefaultTreeCellEditor
}
/**
- * getFont
- * @return Font
+ * Gets the font of this component.
+ * @return this component's font; if a font has not been set for
+ * this component, the font of its parent is returned (if the parent
+ * is not null, otherwise null is returned).
*/
public Font getFont()
{
- return null; // TODO
+ Font font = super.getFont();
+ if (font == null)
+ {
+ Component parent = getParent();
+ if (parent != null)
+ return parent.getFont();
+ return null;
+ }
+ return font;
}
/**
@@ -156,108 +212,184 @@ public class DefaultTreeCellEditor
}
/**
- * getPreferredSize
- * @return Dimension
+ * Overrides JTextField.getPreferredSize to return the preferred size
+ * based on current font, if set, or else use renderer's font.
+ *
+ * @return the Dimension of this textfield.
*/
public Dimension getPreferredSize()
{
- return null; // TODO
+ String s = getText();
+
+ Font f = getFont();
+
+ if (f != null)
+ {
+ FontMetrics fm = getToolkit().getFontMetrics(f);
+
+ return new Dimension(SwingUtilities.computeStringWidth(fm, s),
+ fm.getHeight());
+ }
+ return renderer.getPreferredSize();
}
}
private EventListenerList listenerList = new EventListenerList();
-
+
/**
- * realEditor
+ * Editor handling the editing.
*/
protected TreeCellEditor realEditor;
/**
- * renderer
+ * Renderer, used to get border and offsets from.
*/
protected DefaultTreeCellRenderer renderer;
/**
- * editingContainer
+ * Editing container, will contain the editorComponent.
*/
protected Container editingContainer;
/**
- * editingComponent
+ * Component used in editing, obtained from the editingContainer.
*/
protected transient Component editingComponent;
/**
- * 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.
*/
protected boolean canEdit;
/**
- * offset
+ * Used in editing. Indicates x position to place editingComponent.
*/
protected transient int offset;
/**
- * tree
+ * JTree instance listening too.
*/
protected transient JTree tree;
/**
- * lastPath
+ * Last path that was selected.
*/
protected transient TreePath lastPath;
/**
- * timer
+ * Used before starting the editing session.
*/
- protected transient javax.swing.Timer timer; // TODO
+ protected transient javax.swing.Timer timer;
/**
- * lastRow
+ * Row that was last passed into getTreeCellEditorComponent.
*/
protected transient int lastRow;
/**
- * borderSelectionColor
+ * True if the border selection color should be drawn.
*/
protected Color borderSelectionColor;
/**
- * editingIcon
+ * Icon to use when editing.
*/
protected transient Icon editingIcon;
/**
- * font
+ * Font to paint with, null indicates font of renderer is to be used.
*/
protected Font font;
-
+
/**
- * Constructor DefaultTreeCellEditor
- * @param value0 TODO
- * @param value1 TODO
+ * Helper field used to save the last path seen while the timer was
+ * running.
*/
- public DefaultTreeCellEditor(JTree value0, DefaultTreeCellRenderer value1)
+ private TreePath tPath;
+
+ /**
+ * Constructs a DefaultTreeCellEditor object for a JTree using the
+ * specified renderer and a default editor. (Use this constructor
+ * for normal editing.)
+ *
+ * @param tree - a JTree object
+ * @param renderer - a DefaultTreeCellRenderer object
+ */
+ public DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer)
{
- // TODO
+ this(tree, renderer, null);
}
/**
- * Constructor DefaultTreeCellEditor
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
+ * Constructs a DefaultTreeCellEditor object for a JTree using the specified
+ * renderer and the specified editor. (Use this constructor
+ * for specialized editing.)
+ *
+ * @param tree - a JTree object
+ * @param renderer - a DefaultTreeCellRenderer object
+ * @param editor - a TreeCellEditor object
*/
- public DefaultTreeCellEditor(JTree value0, DefaultTreeCellRenderer value1,
- TreeCellEditor value2)
+ public DefaultTreeCellEditor(JTree tree, DefaultTreeCellRenderer renderer,
+ TreeCellEditor editor)
{
- // TODO
+ setTree(tree);
+ this.renderer = renderer;
+
+ if (editor == null)
+ editor = createTreeCellEditor();
+ realEditor = editor;
+
+ lastPath = tree.getLeadSelectionPath();
+ tree.addTreeSelectionListener(this);
+ editingContainer = createContainer();
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+ setFont(defaults.getFont("Tree.font"));
+ setBorderSelectionColor(defaults.getColor("Tree.selectionBorderColor"));
+ editingIcon = renderer.getIcon();
+ timer = new javax.swing.Timer(1200, this);
}
/**
+ * Configures the editing component whenever it is null.
+ *
+ * @param tree- the tree to configure to component for.
+ * @param renderer- the renderer used to set up the nodes
+ * @param editor- the editor used
+ */
+ private void configureEditingComponent(JTree tree,
+ DefaultTreeCellRenderer renderer,
+ TreeCellEditor editor)
+ {
+ if (tree != null && lastPath != null)
+ {
+ Object val = lastPath.getLastPathComponent();
+ boolean isLeaf = tree.getModel().isLeaf(val);
+ boolean expanded = tree.isExpanded(lastPath);
+ determineOffset(tree, val, true, expanded, isLeaf, lastRow);
+
+ // set up icon
+ if (isLeaf)
+ renderer.setIcon(renderer.getLeafIcon());
+ else if (expanded)
+ renderer.setIcon(renderer.getOpenIcon());
+ else
+ renderer.setIcon(renderer.getClosedIcon());
+ editingIcon = renderer.getIcon();
+
+ editingComponent = getTreeCellEditorComponent(tree, val, true,
+ expanded, isLeaf, lastRow);
+ }
+ }
+
+ /**
* writeObject
- * @param value0 TODO
- * @exception IOException TODO
+ *
+ * @param value0
+ * TODO
+ * @exception IOException
+ * TODO
*/
private void writeObject(ObjectOutputStream value0) throws IOException
{
@@ -277,102 +409,152 @@ public class DefaultTreeCellEditor
}
/**
- * setBorderSelectionColor
- * @param value0 TODO
+ * Sets the color to use for the border.
+ * @param newColor - the new border color
*/
- public void setBorderSelectionColor(Color value0)
+ public void setBorderSelectionColor(Color newColor)
{
- // TODO
+ this.borderSelectionColor = newColor;
}
/**
- * getBorderSelectionColor
+ * Returns the color the border is drawn.
* @return Color
*/
public Color getBorderSelectionColor()
{
- return null; // TODO
+ return borderSelectionColor;
}
/**
- * setFont
- * @param value0 TODO
+ * 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.
+ *
+ * @param font - the editing Font
*/
- public void setFont(Font value0)
+ public void setFont(Font font)
{
- // TODO
+ if (font != null)
+ this.font = font;
+ else
+ this.font = renderer.getFont();
}
/**
- * getFont
- * @return Font
+ * Gets the font used for editing.
+ *
+ * @return the editing font
*/
public Font getFont()
{
- return null; // TODO
+ return font;
}
/**
- * getTreeCellEditorComponent
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- * @param value3 TODO
- * @param value4 TODO
- * @param value5 TODO
- * @return Component
- */
- public Component getTreeCellEditorComponent(JTree value0, Object value1,
- boolean value2, boolean value3,
- boolean value4, int value5)
+ * Configures the editor. Passed onto the realEditor.
+ * Sets an initial value for the editor. This will cause
+ * the editor to stopEditing and lose any partially edited value
+ * if the editor is editing when this method is called.
+ * Returns the component that should be added to the client's Component
+ * hierarchy. Once installed in the client's hierarchy this component will
+ * then be able to draw and receive user input.
+ *
+ * @param tree - the JTree that is asking the editor to edit; this parameter can be null
+ * @param value - the value of the cell to be edited
+ * @param isSelected - true is the cell is to be rendered with selection highlighting
+ * @param expanded - true if the node is expanded
+ * @param leaf - true if the node is a leaf node
+ * @param row - the row index of the node being edited
+ *
+ * @return the component for editing
+ */
+ public Component getTreeCellEditorComponent(JTree tree, Object value,
+ boolean isSelected, boolean expanded,
+ boolean leaf, int row)
{
- return null; // TODO
+ if (realEditor == null)
+ createTreeCellEditor();
+
+ return realEditor.getTreeCellEditorComponent(tree, value, isSelected,
+ expanded, leaf, row);
}
/**
- * getCellEditorValue
- * @return Object
+ * Returns the value currently being edited.
+ *
+ * @return the value currently being edited
*/
public Object getCellEditorValue()
{
- return null; // TODO
+ return editingComponent;
}
-
- /**
- * isCellEditable
- * @param value0 TODO
- * @return boolean
- */
- public boolean isCellEditable(EventObject value0)
- {
- return false; // TODO
+
+ /**
+ * If the realEditor returns true to this message, prepareForEditing
+ * is messaged and true is returned.
+ *
+ * @param event - the event the editor should use to consider whether to begin editing or not
+ * @return true if editing can be started
+ */
+ public boolean isCellEditable(EventObject event)
+ {
+ if (editingComponent == null)
+ configureEditingComponent(tree, renderer, realEditor);
+
+ if (editingComponent != null && realEditor.isCellEditable(event))
+ {
+ prepareForEditing();
+ return true;
+ }
+
+ // Cell may not be currently editable, but may need to start timer.
+ if (shouldStartEditingTimer(event))
+ startEditingTimer();
+ return false;
}
/**
- * shouldSelectCell
- * @param value0 TODO
- * @return boolean
+ * Messages the realEditor for the return value.
+ *
+ * @param event -
+ * the event the editor should use to start editing
+ * @return true if the editor would like the editing cell to be selected;
+ * otherwise returns false
*/
- public boolean shouldSelectCell(EventObject value0)
+ public boolean shouldSelectCell(EventObject event)
{
- return false; // TODO
+ return true;
}
/**
- * stopCellEditing
- * @return boolean
+ * If the realEditor will allow editing to stop, the realEditor
+ * is removed and true is returned, otherwise false is returned.
+ * @return true if editing was stopped; false otherwise
*/
public boolean stopCellEditing()
{
- return false; // TODO
+ if (editingComponent != null && realEditor.stopCellEditing())
+ {
+ timer.stop();
+ return true;
+ }
+ return false;
}
/**
- * cancelCellEditing
+ * Messages cancelCellEditing to the realEditor and removes it
+ * from this instance.
*/
public void cancelCellEditing()
{
- // TODO
+ if (editingComponent != null)
+ {
+ timer.stop();
+ realEditor.cancelCellEditing();
+ }
}
/**
@@ -382,7 +564,7 @@ public class DefaultTreeCellEditor
*/
public void addCellEditorListener(CellEditorListener listener)
{
- listenerList.add(CellEditorListener.class, listener);
+ realEditor.addCellEditorListener(listener);
}
/**
@@ -392,7 +574,7 @@ public class DefaultTreeCellEditor
*/
public void removeCellEditorListener(CellEditorListener listener)
{
- listenerList.remove(CellEditorListener.class, listener);
+ realEditor.removeCellEditorListener(listener);
}
/**
@@ -408,109 +590,157 @@ public class DefaultTreeCellEditor
}
/**
- * valueChanged
- * @param value0 TODO
+ * Resets lastPath.
+ *
+ * @param e - the event that characterizes the change.
*/
- public void valueChanged(TreeSelectionEvent value0)
+ public void valueChanged(TreeSelectionEvent e)
{
- // TODO
+ tPath = lastPath;
+ lastPath = e.getNewLeadSelectionPath();
+ lastRow = tree.getRowForPath(lastPath);
+ configureEditingComponent(tree, renderer, realEditor);
}
-
+
/**
- * actionPerformed
- * @param value0 TODO
+ * Messaged when the timer fires, this will start the editing session.
+ *
+ * @param @param e - the event that characterizes the action.
*/
- public void actionPerformed(ActionEvent value0)
+ public void actionPerformed(ActionEvent e)
{
- // TODO
+ if (lastPath != null && tPath != null && tPath.equals(lastPath))
+ {
+ tree.startEditingAtPath(lastPath);
+ timer.stop();
+ }
}
/**
- * setTree
- * @param value0 TODO
+ * Sets the tree currently editing for. This is needed to add a selection
+ * listener.
+ *
+ * @param newTree -
+ * the new tree to be edited
*/
- protected void setTree(JTree value0)
+ protected void setTree(JTree newTree)
{
- // TODO
+ tree = newTree;
}
/**
- * shouldStartEditingTimer
- * @param value0 TODO
- * @return boolean
+ * Returns true if event is a MouseEvent and the click count is 1.
+ *
+ * @param event - the event being studied
+ * @return true if editing should start
*/
- protected boolean shouldStartEditingTimer(EventObject value0)
+ protected boolean shouldStartEditingTimer(EventObject event)
{
- return false; // TODO
+ if ((event instanceof MouseEvent) &&
+ ((MouseEvent) event).getClickCount() == 1)
+ return true;
+ return false;
}
/**
- * startEditingTimer
+ * Starts the editing timer.
*/
protected void startEditingTimer()
{
- // TODO
+ if (timer == null)
+ timer = new javax.swing.Timer(1200, this);
+ if (!timer.isRunning())
+ timer.start();
}
/**
- * canEditImmediately
- * @param value0 TODO
- * @return boolean
+ * Returns true if event is null, or it is a MouseEvent with
+ * a click count > 2 and inHitRegion returns true.
+ *
+ * @param event - the event being studied
+ * @return true if event is null, or it is a MouseEvent with
+ * a click count > 2 and inHitRegion returns true
*/
- protected boolean canEditImmediately(EventObject value0)
+ protected boolean canEditImmediately(EventObject event)
{
- return false; // TODO
+ if (event == null || !(event instanceof MouseEvent) || (((MouseEvent) event).
+ getClickCount() > 2 && inHitRegion(((MouseEvent) event).getX(),
+ ((MouseEvent) event).getY())))
+ return true;
+ return false;
}
/**
- * inHitRegion
- * @param value0 TODO
- * @param value1 TODO
- * @return boolean
+ * 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
+ * less than or equal to 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 value0, int value1)
+ protected boolean inHitRegion(int x, int y)
{
- return false; // TODO
+ Rectangle bounds = tree.getPathBounds(lastPath);
+
+ return bounds.contains(x, y);
}
/**
* determineOffset
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- * @param value3 TODO
- * @param value4 TODO
- * @param value5 TODO
- */
- protected void determineOffset(JTree value0, Object value1, boolean value2,
- boolean value3, boolean value4, int value5)
+ * @param tree -
+ * @param value -
+ * @param isSelected -
+ * @param expanded -
+ * @param leaf -
+ * @param row -
+ */
+ protected void determineOffset(JTree tree, Object value, boolean isSelected,
+ boolean expanded, boolean leaf, int row)
{
- // TODO
+ renderer.getTreeCellRendererComponent(tree, value, isSelected, expanded,
+ leaf, row, true);
+ Icon c = renderer.getIcon();
+ if (c != null)
+ offset = renderer.getIconTextGap() + c.getIconWidth();
+ else
+ offset = 0;
}
/**
- * prepareForEditing
+ * Invoked just before editing is to start. Will add the
+ * editingComponent to the editingContainer.
*/
protected void prepareForEditing()
{
- // TODO
+ editingContainer.add(editingComponent);
}
/**
- * createContainer
- * @return Container
+ * Creates the container to manage placement of editingComponent.
+ *
+ * @return the container to manage the placement of the editingComponent.
*/
protected Container createContainer()
{
- return null; // TODO
+ return new DefaultTreeCellEditor.EditorContainer();
}
/**
- * createTreeCellEditor
- * @return TreeCellEditor
+ * This is invoked if a TreeCellEditor is not supplied in the constructor.
+ * It returns a TextField editor.
+ *
+ * @return a new TextField editor
*/
protected TreeCellEditor createTreeCellEditor()
{
- return null; // TODO
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+ realEditor = new DefaultCellEditor(new DefaultTreeCellEditor.DefaultTextField(
+ defaults.getBorder("Tree.selectionBorder")));
+ return realEditor;
}
}
diff --git a/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java b/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java
index db69c605554..4a353b30176 100644
--- a/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java
+++ b/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java
@@ -1,39 +1,40 @@
/* DefaultTreeCellRenderer.java
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004 Free Software Foundation, Inc.
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath 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 for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
+ This file is part of GNU Classpath.
+
+ GNU Classpath is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU Classpath 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 for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU Classpath; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ Linking this library statically or dynamically with other modules is
+ making a combined work based on this library. Thus, the terms and
+ conditions of the GNU General Public License cover the whole
+ combination.
+
+ As a special exception, the copyright holders of this library give you
+ permission to link this library with independent modules to produce an
+ executable, regardless of the license terms of these independent
+ modules, and to copy and distribute the resulting executable under
+ terms of your choice, provided that you also meet, for each linked
+ independent module, the terms and conditions of the license of that
+ module. An independent module is a module which is not derived from
+ or based on this library. If you modify this library, you may extend
+ this exception to your version of the library, but you are not
+ obligated to do so. If you do not wish to do so, delete this
+ exception statement from your version. */
+
package javax.swing.tree;
@@ -41,14 +42,18 @@ import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
+import java.awt.FontMetrics;
import java.awt.Graphics;
+import java.awt.Insets;
import java.awt.Rectangle;
+import javax.swing.border.Border;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
+import javax.swing.SwingUtilities;
import javax.swing.plaf.UIResource;
/**
@@ -57,535 +62,626 @@ import javax.swing.plaf.UIResource;
* @author Andrew Selkirk
*/
public class DefaultTreeCellRenderer
- extends JLabel
- implements TreeCellRenderer
+ extends JLabel
+ implements TreeCellRenderer
{
- // -------------------------------------------------------------
- // Variables --------------------------------------------------
- // -------------------------------------------------------------
-
- /**
- * selected
- */
- protected boolean selected;
-
- /**
- * hasFocus
- */
- protected boolean hasFocus;
-
- /**
- * drawsFocusBorderAroundIcon
- */
- private boolean drawsFocusBorderAroundIcon;
-
- /**
- * closedIcon
- */
- protected transient Icon closedIcon;
-
- /**
- * leafIcon
- */
- protected transient Icon leafIcon;
-
- /**
- * openIcon
- */
- protected transient Icon openIcon;
-
- /**
- * textSelectionColor
- */
- protected Color textSelectionColor;
-
- /**
- * textNonSelectionColor
- */
- protected Color textNonSelectionColor;
-
- /**
- * backgroundSelectionColor
- */
- protected Color backgroundSelectionColor;
-
- /**
- * backgroundNonSelectionColor
- */
- protected Color backgroundNonSelectionColor;
-
- /**
- * borderSelectionColor
- */
- protected Color borderSelectionColor;
-
-
- // -------------------------------------------------------------
- // Initialization ---------------------------------------------
- // -------------------------------------------------------------
-
- /**
- * Constructor DefaultTreeCellRenderer
- */
- public DefaultTreeCellRenderer()
- {
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
-
- setLeafIcon(getDefaultLeafIcon());
- setOpenIcon(getDefaultOpenIcon());
- setClosedIcon(getDefaultClosedIcon());
-
- setTextNonSelectionColor(defaults.getColor("Tree.textForeground"));
- setTextSelectionColor(defaults.getColor("Tree.selectionForeground"));
- setBackgroundNonSelectionColor(defaults
- .getColor("Tree.nonSelectionBackground"));
- setBackgroundSelectionColor(defaults
- .getColor("Tree.selectionBackground"));
- setBorderSelectionColor(defaults
- .getColor("Tree.selectionBorderColor"));
- }
-
- // -------------------------------------------------------------
- // Methods ----------------------------------------------------
- // -------------------------------------------------------------
-
- /**
- * getDefaultOpenIcon
- *
- * @returns Icon
- */
- public Icon getDefaultOpenIcon()
- {
- return UIManager.getLookAndFeelDefaults().getIcon("Tree.openIcon");
- }
-
- /**
- * getDefaultClosedIcon
- *
- * @returns Icon
- */
- public Icon getDefaultClosedIcon()
- {
- return UIManager.getLookAndFeelDefaults().getIcon("Tree.closedIcon");
- }
-
- /**
- * getDefaultLeafIcon
- *
- * @returns Icon
- */
- public Icon getDefaultLeafIcon()
- {
- return UIManager.getLookAndFeelDefaults().getIcon("Tree.leafIcon");
- }
-
- /**
- * setOpenIcon
- *
- * @param value0 TODO
- */
- public void setOpenIcon(Icon i)
- {
- openIcon = i;
- }
-
- /**
- * getOpenIcon
- *
- * @returns Icon
- */
- public Icon getOpenIcon()
- {
- return openIcon;
- }
-
- /**
- * setClosedIcon
- *
- * @param value0 TODO
- */
- public void setClosedIcon(Icon i)
- {
- closedIcon = i;
- }
-
- /**
- * getClosedIcon
- *
- * @returns Icon
- */
- public Icon getClosedIcon()
- {
- return closedIcon;
- }
-
- /**
- * setLeafIcon
- *
- * @param value0 TODO
- */
- public void setLeafIcon(Icon i)
- {
- leafIcon = i;
- }
-
- /**
- * getLeafIcon
- *
- * @returns Icon
- */
- public Icon getLeafIcon()
- {
- return leafIcon;
- }
-
- /**
- * setTextSelectionColor
- *
- * @param value0 TODO
- */
- public void setTextSelectionColor(Color c)
- {
- textSelectionColor = c;
- }
-
- /**
- * getTextSelectionColor
- *
- * @returns Color
- */
- public Color getTextSelectionColor()
- {
- return textSelectionColor;
- }
-
- /**
- * setTextNonSelectionColor
- *
- * @param value0 TODO
- */
- public void setTextNonSelectionColor(Color c)
- {
- textNonSelectionColor = c;
- }
-
- /**
- * getTextNonSelectionColor
- *
- * @returns Color
- */
- public Color getTextNonSelectionColor()
- {
- return textNonSelectionColor;
- }
-
- /**
- * setBackgroundSelectionColor
- *
- * @param value0 TODO
- */
- public void setBackgroundSelectionColor(Color c)
- {
- backgroundSelectionColor = c;
- }
-
- /**
- * getBackgroundSelectionColor
- *
- * @returns Color
- */
- public Color getBackgroundSelectionColor()
- {
- return backgroundSelectionColor;
- }
-
- /**
- * setBackgroundNonSelectionColor
- *
- * @param value0 TODO
- */
- public void setBackgroundNonSelectionColor(Color c)
- {
- backgroundNonSelectionColor = c;
- }
-
- /**
- * getBackgroundNonSelectionColor
- *
- * @returns Color
- */
- public Color getBackgroundNonSelectionColor()
- {
- return backgroundNonSelectionColor;
- }
-
- /**
- * setBorderSelectionColor
- *
- * @param value0 TODO
- */
- public void setBorderSelectionColor(Color c)
- {
- borderSelectionColor = c;
- }
-
- /**
- * getBorderSelectionColor
- *
- * @returns Color
- */
- public Color getBorderSelectionColor()
- {
- return borderSelectionColor;
- }
-
- /**
- * setFont
- *
- * @param value0 TODO
- */
- public void setFont(Font f)
- {
- if (f != null && f instanceof UIResource)
- f = null;
- super.setFont(f);
- }
-
- /**
- * setBackground
- *
- * @param value0 TODO
- */
- public void setBackground(Color c)
- {
- if (c != null && c instanceof UIResource)
- c = null;
- super.setBackground(c);
- }
-
- /**
- * getTreeCellRendererComponent
- *
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- * @param value3 TODO
- * @param value4 TODO
- * @param value5 TODO
- * @param value6 TODO
- * @returns Component
- */
- public Component getTreeCellRendererComponent(JTree tree, Object val,
- boolean selected, boolean expanded, boolean leaf, int row,
- boolean hasFocus)
- {
- if (val instanceof Icon)
- setIcon((Icon) val);
- else
+ // -------------------------------------------------------------
+ // Variables --------------------------------------------------
+ // -------------------------------------------------------------
+
+ /**
+ * selected
+ */
+ protected boolean selected;
+
+ /**
+ * hasFocus
+ */
+ protected boolean hasFocus;
+
+ /**
+ * drawsFocusBorderAroundIcon
+ */
+ private boolean drawsFocusBorderAroundIcon;
+
+ /**
+ * closedIcon
+ */
+ protected transient Icon closedIcon;
+
+ /**
+ * leafIcon
+ */
+ protected transient Icon leafIcon;
+
+ /**
+ * openIcon
+ */
+ protected transient Icon openIcon;
+
+ /**
+ * textSelectionColor
+ */
+ protected Color textSelectionColor;
+
+ /**
+ * textNonSelectionColor
+ */
+ protected Color textNonSelectionColor;
+
+ /**
+ * backgroundSelectionColor
+ */
+ protected Color backgroundSelectionColor;
+
+ /**
+ * backgroundNonSelectionColor
+ */
+ protected Color backgroundNonSelectionColor;
+
+ /**
+ * borderSelectionColor
+ */
+ protected Color borderSelectionColor;
+
+ // -------------------------------------------------------------
+ // Initialization ---------------------------------------------
+ // -------------------------------------------------------------
+
+ /**
+ * Constructor DefaultTreeCellRenderer
+ */
+ public DefaultTreeCellRenderer()
+ {
+ UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+
+ setLeafIcon(getDefaultLeafIcon());
+ setOpenIcon(getDefaultOpenIcon());
+ setClosedIcon(getDefaultClosedIcon());
+
+ setTextNonSelectionColor(defaults.getColor("Tree.textForeground"));
+ setTextSelectionColor(defaults.getColor("Tree.selectionForeground"));
+ setBackgroundNonSelectionColor(defaults.getColor("Tree.nonSelectionBackground"));
+ setBackgroundSelectionColor(defaults.getColor("Tree.selectionBackground"));
+ setBorderSelectionColor(defaults.getColor("Tree.selectionBorderColor"));
+ }
+
+ // -------------------------------------------------------------
+ // Methods ----------------------------------------------------
+ // -------------------------------------------------------------
+
+ /**
+ * getDefaultOpenIcon
+ *
+ * @returns Icon
+ */
+ public Icon getDefaultOpenIcon()
+ {
+ return UIManager.getLookAndFeelDefaults().getIcon("Tree.openIcon");
+ }
+
+ /**
+ * getDefaultClosedIcon
+ *
+ * @returns Icon
+ */
+ public Icon getDefaultClosedIcon()
+ {
+ return UIManager.getLookAndFeelDefaults().getIcon("Tree.closedIcon");
+ }
+
+ /**
+ * getDefaultLeafIcon
+ *
+ * @returns Icon
+ */
+ public Icon getDefaultLeafIcon()
+ {
+ return UIManager.getLookAndFeelDefaults().getIcon("Tree.leafIcon");
+ }
+
+ /**
+ * setOpenIcon
+ *
+ * @param i
+ * the icon.
+ */
+ public void setOpenIcon(Icon i)
+ {
+ openIcon = i;
+ }
+
+ /**
+ * getOpenIcon
+ *
+ * @returns Icon
+ */
+ public Icon getOpenIcon()
+ {
+ return openIcon;
+ }
+
+ /**
+ * setClosedIcon
+ *
+ * @param i
+ * the icon.
+ */
+ public void setClosedIcon(Icon i)
+ {
+ closedIcon = i;
+ }
+
+ /**
+ * getClosedIcon
+ *
+ * @returns Icon
+ */
+ public Icon getClosedIcon()
+ {
+ return closedIcon;
+ }
+
+ /**
+ * setLeafIcon
+ *
+ * @param i
+ * the icon.
+ */
+ public void setLeafIcon(Icon i)
+ {
+ leafIcon = i;
+ }
+
+ /**
+ * getLeafIcon
+ *
+ * @returns Icon
+ */
+ public Icon getLeafIcon()
+ {
+ return leafIcon;
+ }
+
+ /**
+ * setTextSelectionColor
+ *
+ * @param c
+ * the color.
+ */
+ public void setTextSelectionColor(Color c)
+ {
+ textSelectionColor = c;
+ }
+
+ /**
+ * getTextSelectionColor
+ *
+ * @returns Color
+ */
+ public Color getTextSelectionColor()
+ {
+ return textSelectionColor;
+ }
+
+ /**
+ * setTextNonSelectionColor
+ *
+ * @param c
+ * the color.
+ */
+ public void setTextNonSelectionColor(Color c)
+ {
+ textNonSelectionColor = c;
+ }
+
+ /**
+ * getTextNonSelectionColor
+ *
+ * @returns Color
+ */
+ public Color getTextNonSelectionColor()
+ {
+ return textNonSelectionColor;
+ }
+
+ /**
+ * setBackgroundSelectionColor
+ *
+ * @param c
+ * the color.
+ */
+ public void setBackgroundSelectionColor(Color c)
+ {
+ backgroundSelectionColor = c;
+ }
+
+ /**
+ * getBackgroundSelectionColor
+ *
+ * @returns Color
+ */
+ public Color getBackgroundSelectionColor()
+ {
+ return backgroundSelectionColor;
+ }
+
+ /**
+ * setBackgroundNonSelectionColor
+ *
+ * @param c
+ * the color.
+ */
+ public void setBackgroundNonSelectionColor(Color c)
+ {
+ backgroundNonSelectionColor = c;
+ }
+
+ /**
+ * getBackgroundNonSelectionColor
+ *
+ * @returns Color
+ */
+ public Color getBackgroundNonSelectionColor()
+ {
+ return backgroundNonSelectionColor;
+ }
+
+ /**
+ * setBorderSelectionColor
+ *
+ * @param c
+ * the color.
+ */
+ public void setBorderSelectionColor(Color c)
+ {
+ borderSelectionColor = c;
+ }
+
+ /**
+ * getBorderSelectionColor
+ *
+ * @returns Color
+ */
+ public Color getBorderSelectionColor()
+ {
+ return borderSelectionColor;
+ }
+
+ /**
+ * setFont
+ *
+ * @param f
+ * the font.
+ */
+ public void setFont(Font f)
+ {
+ if (f != null && f instanceof UIResource)
+ f = null;
+ super.setFont(f);
+ }
+
+ /**
+ * setBackground
+ *
+ * @param c
+ * the color.
+ */
+ public void setBackground(Color c)
+ {
+ if (c != null && c instanceof UIResource)
+ c = null;
+ super.setBackground(c);
+ }
+
+ /**
+ * getTreeCellRendererComponent
+ *
+ * @param tree
+ * TODO
+ * @param val
+ * TODO
+ * @param selected
+ * TODO
+ * @param expanded
+ * TODO
+ * @param leaf
+ * TODO
+ * @param row
+ * TODO
+ * @param hasFocus
+ * TODO
+ * @returns Component
+ */
+ public Component getTreeCellRendererComponent(JTree tree, Object val,
+ boolean selected,
+ boolean expanded, boolean leaf,
+ int row, boolean hasFocus)
+ {
+ if (leaf)
+ setIcon(getLeafIcon());
+ else if (expanded)
+ setIcon(getOpenIcon());
+ else
+ setIcon(getClosedIcon());
+
+ setText(val.toString());
+ this.selected = selected;
+ this.hasFocus = hasFocus;
+ setHorizontalAlignment(LEFT);
+ setOpaque(false);
+ setVerticalAlignment(TOP);
+ setEnabled(true);
+ super.setFont(UIManager.getLookAndFeelDefaults().getFont("Tree.font"));
+
+ if (selected)
+ {
+ super.setBackground(getBackgroundSelectionColor());
+ setForeground(getTextSelectionColor());
+
+ if (tree.getLeadSelectionPath() == null ||
+ (tree.getLeadSelectionPath().getLastPathComponent()).equals(val))
+ setBorderSelectionColor(UIManager.getLookAndFeelDefaults().
+ getColor("Tree.selectionBorderColor"));
+ else
+ setBorderSelectionColor(null);
+ }
+ else
{
- setText(val.toString());
- setIcon(null);
- this.selected = selected;
- this.hasFocus = hasFocus;
- setHorizontalAlignment(LEFT);
- setOpaque(true);
- setVerticalAlignment(TOP);
- setEnabled(true);
- super.setFont(UIManager.getLookAndFeelDefaults().getFont("Tree.font"));
+ super.setBackground(getBackgroundNonSelectionColor());
+ setForeground(getTextNonSelectionColor());
+ setBorderSelectionColor(null);
}
- if (selected)
- {
- super.setBackground(getBackgroundSelectionColor());
- setForeground(getTextSelectionColor());
- }
- else
- {
- super.setBackground(getBackgroundNonSelectionColor());
- setForeground(getTextNonSelectionColor());
- }
-
- return this;
- }
-
- /**
- * getFont
- *
- * @return the current Font
- */
- public Font getFont()
- {
- return super.getFont();
- }
-
- /**
- * paint
- *
- * @param value0 TODO
- */
- public void paint(Graphics g)
- {
- super.paint(g);
- }
-
- /**
- * getPreferredSize
- *
- * @returns Dimension
- */
- public Dimension getPreferredSize()
- {
- return null; // TODO
- } // getPreferredSize()
-
- /**
- * validate
- */
- public void validate()
- {
- // Overridden for performance reasons.
- } // validate()
-
- /**
- * revalidate
- */
- public void revalidate()
- {
- // Overridden for performance reasons.
- } // revalidate()
-
- /**
- * repaint
- *
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- * @param value3 TODO
- * @param value4 TODO
- */
- public void repaint(long value0, int value1, int value2, int value3,
- int value4)
- {
- // Overridden for performance reasons.
- } // repaint()
-
- /**
- * repaint
- *
- * @param value0 TODO
- */
- public void repaint(Rectangle value0)
- {
- // Overridden for performance reasons.
- } // repaint()
-
- /**
- * firePropertyChange
- *
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- */
- protected void firePropertyChange(String value0, Object value1,
- Object value2)
- {
- // Overridden for performance reasons.
- } // firePropertyChange()
-
- /**
- * firePropertyChange
- *
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- */
- public void firePropertyChange(String value0, byte value1, byte value2)
- {
- // Overridden for performance reasons.
- } // firePropertyChange()
-
- /**
- * firePropertyChange
- *
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- */
- public void firePropertyChange(String value0, char value1, char value2)
- {
- // Overridden for performance reasons.
- } // firePropertyChange()
-
- /**
- * firePropertyChange
- *
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- */
- public void firePropertyChange(String value0, short value1, short value2)
- {
- // Overridden for performance reasons.
- } // firePropertyChange()
-
- /**
- * firePropertyChange
- *
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- */
- public void firePropertyChange(String value0, int value1, int value2)
- {
- // Overridden for performance reasons.
- } // firePropertyChange()
-
- /**
- * firePropertyChange
- *
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- */
- public void firePropertyChange(String value0, long value1, long value2)
- {
- // Overridden for performance reasons.
- } // firePropertyChange()
-
- /**
- * firePropertyChange
- *
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- */
- public void firePropertyChange(String value0, float value1, float value2)
- {
- // Overridden for performance reasons.
- } // firePropertyChange()
-
- /**
- * firePropertyChange
- *
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- */
- public void firePropertyChange(String value0, double value1, double value2)
- {
- // Overridden for performance reasons.
- } // firePropertyChange()
-
- /**
- * firePropertyChange
- *
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- */
- public void firePropertyChange(String value0, boolean v1, boolean v2)
- {
- // Overridden for performance reasons.
- } // firePropertyChange()
+ return this;
+ }
+
+ /**
+ * getFont
+ *
+ * @return the current Font
+ */
+ public Font getFont()
+ {
+ return super.getFont();
+ }
+
+ /**
+ * Paints the value. The background is filled based on selected.
+ *
+ * @param g
+ * the graphics device.
+ */
+ public void paint(Graphics g)
+ {
+ // paint background
+ Rectangle vr = new Rectangle();
+ Rectangle ir = new Rectangle();
+ Rectangle tr = new Rectangle();
+
+ Insets insets = new Insets(0, 0, 0, 0);
+ Border border = UIManager.getLookAndFeelDefaults().getBorder(
+ "Tree.selectionBorder");
+ if (border != null)
+ insets = border.getBorderInsets(this);
+
+ FontMetrics fm = getToolkit().getFontMetrics(getFont());
+ SwingUtilities.layoutCompoundLabel(((JLabel) this), fm, getText(),
+ getIcon(), getVerticalAlignment(),
+ getHorizontalAlignment(),
+ getVerticalTextPosition(),
+ getHorizontalTextPosition(), vr, ir, tr,
+ getIconTextGap());
+
+ g.setColor(super.getBackground());
+ g.fillRect(tr.x, tr.y, tr.width, tr.height - insets.top - insets.bottom);
+
+ // paint border
+ Color b = getBorderSelectionColor();
+ if (b != null)
+ {
+ g.setColor(b);
+ g.drawRect(tr.x, tr.y, tr.width, tr.height - insets.top - insets.bottom);
+ }
+ super.paint(g);
+ }
+
+ /**
+ * returns the preferred size of the cell.
+ *
+ * @returns Dimension
+ */
+ public Dimension getPreferredSize()
+ {
+ Rectangle vr = new Rectangle();
+ Rectangle ir = new Rectangle();
+ Rectangle tr = new Rectangle();
+
+ FontMetrics fm = getToolkit().getFontMetrics(getFont());
+ SwingUtilities.layoutCompoundLabel(((JLabel) this), fm, getText(),
+ getIcon(), getVerticalAlignment(),
+ getHorizontalAlignment(),
+ getVerticalTextPosition(),
+ getHorizontalTextPosition(), vr, ir, tr,
+ getIconTextGap());
+ Rectangle cr = ir.union(tr);
+ return new Dimension(cr.width, cr.height);
+ } // getPreferredSize()
+
+ /**
+ * validate
+ */
+ public void validate()
+ {
+ // Overridden for performance reasons.
+ } // validate()
+
+ /**
+ * revalidate
+ */
+ public void revalidate()
+ {
+ // Overridden for performance reasons.
+ } // revalidate()
+
+ /**
+ * repaint
+ *
+ * @param value0
+ * TODO
+ * @param value1
+ * TODO
+ * @param value2
+ * TODO
+ * @param value3
+ * TODO
+ * @param value4
+ * TODO
+ */
+ public void repaint(long value0, int value1, int value2, int value3,
+ int value4)
+ {
+ // Overridden for performance reasons.
+ } // repaint()
+
+ /**
+ * repaint
+ *
+ * @param value0
+ * TODO
+ */
+ public void repaint(Rectangle value0)
+ {
+ // Overridden for performance reasons.
+ } // repaint()
+
+ /**
+ * firePropertyChange
+ *
+ * @param value0
+ * TODO
+ * @param value1
+ * TODO
+ * @param value2
+ * TODO
+ */
+ protected void firePropertyChange(String value0, Object value1, Object value2)
+ {
+ // Overridden for performance reasons.
+ } // firePropertyChange()
+
+ /**
+ * firePropertyChange
+ *
+ * @param value0
+ * TODO
+ * @param value1
+ * TODO
+ * @param value2
+ * TODO
+ */
+ public void firePropertyChange(String value0, byte value1, byte value2)
+ {
+ // Overridden for performance reasons.
+ } // firePropertyChange()
+
+ /**
+ * firePropertyChange
+ *
+ * @param value0
+ * TODO
+ * @param value1
+ * TODO
+ * @param value2
+ * TODO
+ */
+ public void firePropertyChange(String value0, char value1, char value2)
+ {
+ // Overridden for performance reasons.
+ } // firePropertyChange()
+
+ /**
+ * firePropertyChange
+ *
+ * @param value0
+ * TODO
+ * @param value1
+ * TODO
+ * @param value2
+ * TODO
+ */
+ public void firePropertyChange(String value0, short value1, short value2)
+ {
+ // Overridden for performance reasons.
+ } // firePropertyChange()
+
+ /**
+ * firePropertyChange
+ *
+ * @param value0
+ * TODO
+ * @param value1
+ * TODO
+ * @param value2
+ * TODO
+ */
+ public void firePropertyChange(String value0, int value1, int value2)
+ {
+ // Overridden for performance reasons.
+ } // firePropertyChange()
+
+ /**
+ * firePropertyChange
+ *
+ * @param value0
+ * TODO
+ * @param value1
+ * TODO
+ * @param value2
+ * TODO
+ */
+ public void firePropertyChange(String value0, long value1, long value2)
+ {
+ // Overridden for performance reasons.
+ } // firePropertyChange()
+
+ /**
+ * firePropertyChange
+ *
+ * @param value0
+ * TODO
+ * @param value1
+ * TODO
+ * @param value2
+ * TODO
+ */
+ public void firePropertyChange(String value0, float value1, float value2)
+ {
+ // Overridden for performance reasons.
+ } // firePropertyChange()
+
+ /**
+ * firePropertyChange
+ *
+ * @param value0 TODO
+ * @param value1 TODO
+ * @param value2 TODO
+ */
+ public void firePropertyChange(String value0, double value1, double value2)
+ {
+ // Overridden for performance reasons.
+ } // firePropertyChange()
+
+ /**
+ * firePropertyChange
+ *
+ * @param name the property name.
+ * @param v1 the old value.
+ * @param v2 the new value.
+ */
+ public void firePropertyChange(String name, boolean v1, boolean v2)
+ {
+ // Overridden for performance reasons.
+ } // firePropertyChange()
} // DefaultTreeCellRenderer
diff --git a/libjava/classpath/javax/swing/tree/DefaultTreeModel.java b/libjava/classpath/javax/swing/tree/DefaultTreeModel.java
index 3278ffadc77..5b5e0391478 100644
--- a/libjava/classpath/javax/swing/tree/DefaultTreeModel.java
+++ b/libjava/classpath/javax/swing/tree/DefaultTreeModel.java
@@ -1,6 +1,6 @@
-/* DefaultTreeModel.java --
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
-
+/* DefaultTreeModel.java --
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
@@ -10,16 +10,16 @@ any later version.
GNU Classpath 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
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
+along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
+making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
@@ -29,13 +29,12 @@ executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
+obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package javax.swing.tree;
import java.io.IOException;
@@ -51,405 +50,516 @@ import javax.swing.tree.DefaultMutableTreeNode;
/**
* DefaultTreeModel
+ *
* @author Andrew Selkirk
*/
public class DefaultTreeModel
- implements Serializable, TreeModel
+ implements Serializable, TreeModel
{
- static final long serialVersionUID = -2621068368932566998L;
-
- /**
- * root
- */
- protected TreeNode root = null;
-
- /**
- * listenerList
- */
- protected EventListenerList listenerList = new EventListenerList();
-
- /**
- * asksAllowsChildren
- */
- protected boolean asksAllowsChildren;
-
- /**
- * Constructor DefaultTreeModel
- * @param value0 TODO
- */
- public DefaultTreeModel(TreeNode root)
- {
- if (root == null)
- root = new DefaultMutableTreeNode();
- setRoot(root);
- }
-
- /**
- * Constructor DefaultTreeModel
- * @param value0 TODO
- * @param value1 TODO
- */
- public DefaultTreeModel(TreeNode root, boolean asksAllowsChildren)
- {
- setRoot(root);
- this.asksAllowsChildren = asksAllowsChildren;
- }
-
- /**
- * writeObject
- * @param value0 TODO
- * @exception IOException TODO
- */
- private void writeObject(ObjectOutputStream value0) throws IOException
- {
- // TODO
- }
-
- /**
- * readObject
- * @param value0 TODO
- * @exception IOException TODO
- * @exception ClassNotFoundException TODO
- */
- private void readObject(ObjectInputStream value0) throws IOException,
- ClassNotFoundException
- {
- // TODO
- }
-
- /**
- * asksAllowsChildren
- * @return boolean
- */
- public boolean asksAllowsChildren()
- {
- return asksAllowsChildren;
- }
-
- /**
- * setAsksAllowsChildren
- * @param value0 TODO
- */
- public void setAsksAllowsChildren(boolean value)
- {
- asksAllowsChildren = value; // TODO
- }
-
- /**
- * setRoot
- * @param value0 TODO
- */
- public void setRoot(TreeNode root)
- {
- // Sanity Check
- if (root == null)
- {
- throw new IllegalArgumentException("null root");
- }
- // Set new root
- this.root = root;
-
- // TODO
- }
-
- /**
- * getRoot
- * @return Object
- */
- public Object getRoot()
- {
- return root;
- }
-
- /**
- * getIndexOfChild
- * @param value0 TODO
- * @param value1 TODO
- * @return int
- */
- public int getIndexOfChild(Object parent, Object child)
- {
- return 0; // TODO
- }
-
- /**
- * getChild
- * @param value0 TODO
- * @param value1 TODO
- * @return Object
- */
- public Object getChild(Object node, int idx)
- {
- if (node instanceof TreeNode)
- return ((TreeNode) node).getChildAt(idx);
- else
- return null;
- }
-
- /**
- * getChildCount
- * @param value0 TODO
- * @return int
- */
- public int getChildCount(Object node)
- {
- if (node instanceof TreeNode)
- return ((TreeNode) node).getChildCount();
- else
- return 0;
- }
-
- /**
- * isLeaf
- * @param value0 TODO
- * @return boolean
- */
- public boolean isLeaf(Object node)
- {
- if (node instanceof TreeNode)
- return ((TreeNode) node).isLeaf();
- else
- return true;
- }
-
- /**
- * reload
- */
- public void reload()
- {
- // TODO
- }
-
- /**
- * reload
- * @param value0 TODO
- */
- public void reload(TreeNode value0)
- {
- // TODO
- }
-
- /**
- * valueForPathChanged
- * @param value0 TODO
- * @param value1 TODO
- */
- public void valueForPathChanged(TreePath value0, Object value1)
- {
- // TODO
- }
-
- /**
- * insertNodeInto
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- */
- public void insertNodeInto(MutableTreeNode value0, MutableTreeNode value1,
- int value2)
- {
- // TODO
- }
-
- /**
- * removeNodeFromParent
- * @param value0 TODO
- */
- public void removeNodeFromParent(MutableTreeNode value0)
- {
- // TODO
- }
-
- /**
- * nodeChanged
- * @param value0 TODO
- */
- public void nodeChanged(TreeNode value0)
- {
- // TODO
- }
-
- /**
- * nodesWereInserted
- * @param value0 TODO
- * @param value1 TODO
- */
- public void nodesWereInserted(TreeNode value0, int[] value1)
- {
- // TODO
- }
-
- /**
- * nodesWereRemoved
- * @param value0 TODO
- * @param value1 TODO
- * @param value2 TODO
- */
- public void nodesWereRemoved(TreeNode value0, int[] value1, Object[] value2)
- {
- // TODO
- }
-
- /**
- * nodesChanged
- * @param value0 TODO
- * @param value1 TODO
- */
- public void nodesChanged(TreeNode value0, int[] value1)
- {
- // TODO
- }
-
- /**
- * nodeStructureChanged
- * @param value0 TODO
- */
- public void nodeStructureChanged(TreeNode value0)
- {
- // TODO
- }
-
- /**
- * getPathToRoot
- * @param value0 TODO
- * @return TreeNode[]
- */
- public TreeNode[] getPathToRoot(TreeNode value0)
- {
- return null; // TODO
- }
-
- /**
- * getPathToRoot
- * @param value0 TODO
- * @param value1 TODO
- * @return TreeNode[]
- */
- protected TreeNode[] getPathToRoot(TreeNode value0, int value1)
- {
- return null; // TODO
- }
-
- /**
- * Registers a listere to the model.
- *
- * @param listener the listener to add
- */
- public void addTreeModelListener(TreeModelListener listener)
- {
- listenerList.add(TreeModelListener.class, listener);
- }
-
- /**
- * Removes a listener from the model.
- *
- * @param listener the listener to remove
- */
- public void removeTreeModelListener(TreeModelListener listener)
- {
- listenerList.remove(TreeModelListener.class, listener);
- }
-
- /**
- * Returns all registered <code>TreeModelListener</code> listeners.
- *
- * @return an array of listeners.
- *
- * @since 1.4
- */
- public TreeModelListener[] getTreeModelListeners()
- {
- return (TreeModelListener[]) listenerList
- .getListeners(TreeModelListener.class);
- }
-
- /**
- * fireTreeNodesChanged
- *
- * @param source the node being changed
- * @param path the path to the root node
- * @param childIndices the indices of the changed elements
- * @param children the changed elements
- */
- protected void fireTreeNodesChanged(Object source, Object[] path,
- int[] childIndices, Object[] children)
- {
- TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
- children);
- TreeModelListener[] listeners = getTreeModelListeners();
-
- for (int i = listeners.length - 1; i >= 0; --i)
- listeners[i].treeNodesChanged(event);
- }
-
- /**
- * fireTreeNodesInserted
- *
- * @param source the node where new nodes got inserted
- * @param path the path to the root node
- * @param childIndices the indices of the new elements
- * @param children the new elements
- */
- protected void fireTreeNodesInserted(Object source, Object[] path,
- int[] childIndices, Object[] children)
- {
- TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
- children);
- TreeModelListener[] listeners = getTreeModelListeners();
-
- for (int i = listeners.length - 1; i >= 0; --i)
- listeners[i].treeNodesInserted(event);
- }
-
- /**
- * fireTreeNodesRemoved
- *
- * @param source the node where nodes got removed-
- * @param path the path to the root node
- * @param childIndices the indices of the removed elements
- * @param children the removed elements
- */
- protected void fireTreeNodesRemoved(Object source, Object[] path,
- int[] childIndices, Object[] children)
- {
- TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
- children);
- TreeModelListener[] listeners = getTreeModelListeners();
-
- for (int i = listeners.length - 1; i >= 0; --i)
- listeners[i].treeNodesRemoved(event);
- }
-
- /**
- * fireTreeStructureChanged
- *
- * @param source the node where the model has changed
- * @param path the path to the root node
- * @param childIndices the indices of the affected elements
- * @param children the affected elements
- */
- protected void fireTreeStructureChanged(Object source, Object[] path,
- int[] childIndices, Object[] children)
- {
- TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
- children);
- TreeModelListener[] listeners = getTreeModelListeners();
-
- for (int i = listeners.length - 1; i >= 0; --i)
- listeners[i].treeStructureChanged(event);
- }
-
- /**
- * Returns the registered listeners of a given type.
- *
- * @param listenerType the listener type to return
- *
- * @return an array of listeners
- *
- * @since 1.3
- */
- public EventListener[] getListeners(Class listenerType)
- {
- return listenerList.getListeners(listenerType);
- }
+ static final long serialVersionUID = -2621068368932566998L;
+
+ /**
+ * root
+ */
+ protected TreeNode root = null;
+
+ /**
+ * listenerList
+ */
+ protected EventListenerList listenerList = new EventListenerList();
+
+ /**
+ * asksAllowsChildren
+ */
+ protected boolean asksAllowsChildren;
+
+ /**
+ * Constructor DefaultTreeModel
+ *
+ * @param root the tree root.
+ */
+ public DefaultTreeModel(TreeNode root)
+ {
+ if (root == null)
+ root = new DefaultMutableTreeNode();
+ setRoot(root);
+ }
+
+ /**
+ * Constructor DefaultTreeModel
+ *
+ * @param root the tree root.
+ * @param asksAllowsChildren TODO
+ */
+ public DefaultTreeModel(TreeNode root, boolean asksAllowsChildren)
+ {
+ setRoot(root);
+ this.asksAllowsChildren = asksAllowsChildren;
+ }
+
+ /**
+ * writeObject
+ *
+ * @param obj the object.
+ * @exception IOException TODO
+ */
+ private void writeObject(ObjectOutputStream obj) throws IOException
+ {
+ // TODO
+ }
+
+ /**
+ * readObject
+ *
+ * @param value0 TODO
+ * @exception IOException TODO
+ * @exception ClassNotFoundException TODO
+ */
+ private void readObject(ObjectInputStream value0) throws IOException,
+ ClassNotFoundException
+ {
+ // TODO
+ }
+
+ /**
+ * asksAllowsChildren
+ *
+ * @return boolean
+ */
+ public boolean asksAllowsChildren()
+ {
+ return asksAllowsChildren;
+ }
+
+ /**
+ * setAsksAllowsChildren
+ *
+ * @param value TODO
+ */
+ public void setAsksAllowsChildren(boolean value)
+ {
+ asksAllowsChildren = value;
+ }
+
+ /**
+ * setRoot
+ *
+ * @param root the root node.
+ */
+ public void setRoot(TreeNode root)
+ {
+ // Sanity Check
+ if (root == null)
+ {
+ throw new IllegalArgumentException("null root");
+ }
+ // Set new root
+ this.root = root;
+ }
+
+ /**
+ * getRoot
+ *
+ * @return Object
+ */
+ public Object getRoot()
+ {
+ return root;
+ }
+
+ /**
+ * getIndexOfChild
+ *
+ * @param parent TODO
+ * @param child TODO
+ * @return int
+ */
+ public int getIndexOfChild(Object parent, Object child)
+ {
+ for (int i = 0; i < getChildCount(parent); i++)
+ {
+ if (getChild(parent, i).equals(child))
+ return i;
+ }
+ return -1;
+ }
+
+ /**
+ * getChild
+ *
+ * @param node TODO
+ * @param idx TODO
+ * @return Object
+ */
+ public Object getChild(Object node, int idx)
+ {
+ if (node instanceof TreeNode)
+ return ((TreeNode) node).getChildAt(idx);
+ else
+ return null;
+ }
+
+ /**
+ * getChildCount
+ *
+ * @param node TODO
+ * @return int
+ */
+ public int getChildCount(Object node)
+ {
+ if (node instanceof TreeNode)
+ return ((TreeNode) node).getChildCount();
+ else
+ return 0;
+ }
+
+ /**
+ * isLeaf
+ *
+ * @param node TODO
+ * @return boolean
+ */
+ public boolean isLeaf(Object node)
+ {
+ if (node instanceof TreeNode)
+ return ((TreeNode) node).isLeaf();
+ else
+ return true;
+ }
+
+ /**
+ * Invoke this method if you've modified the TreeNodes upon
+ * which this model depends. The model will notify all of its
+ * listeners that the model has changed.
+ */
+ public void reload()
+ {
+ // TODO
+ }
+
+ /**
+ * Invoke this method if you've modified the TreeNodes upon
+ * which this model depends. The model will notify all of its
+ * listeners that the model has changed.
+ *
+ * @param node - TODO
+ */
+ public void reload(TreeNode node)
+ {
+ // TODO
+ }
+
+ /**
+ * Messaged when the user has altered the value for the item
+ * identified by path to newValue. If newValue signifies a truly new
+ * value the model should post a treeNodesChanged event.
+ * This sets the user object of the TreeNode identified by
+ * path and posts a node changed. If you use custom user objects
+ * in the TreeModel you're going to need to subclass this and set
+ * the user object of the changed node to something meaningful.
+ *
+ * @param path - path to the node that the user has altered
+ * @param newValue - the new value from the TreeCellEditor
+ */
+ public void valueForPathChanged(TreePath path, Object newValue)
+ {
+ Object node = path.getLastPathComponent();
+ if (node instanceof MutableTreeNode)
+ {
+ ((MutableTreeNode) node).setUserObject(newValue);
+ int[] ci = null;
+ Object[] c = null;
+ Object[] parentPath = path.getPath();
+ if (path.getPathCount() > 1)
+ {
+ Object parent = ((TreeNode) node).getParent();
+ ci = new int[1];
+ ci[0] = getIndexOfChild(parent, node);
+ node = newValue;
+ path = path.getParentPath().pathByAddingChild(node);
+ c = new Object[1];
+ c[0] = node;
+ parentPath = path.getParentPath().getPath();
+ }
+
+ fireTreeNodesChanged(this, parentPath, ci, c);
+ }
+ }
+
+ /**
+ * Invoked this to insert newChild at location index in parents children.
+ * This will then message nodesWereInserted to create the appropriate event.
+ * This is the preferred way to add children as it will create the
+ * appropriate event.
+ *
+ * @param newChild is the node to add to the parent's children
+ * @param parent is the parent of the newChild
+ * @param index is the index of the newChild
+ */
+ public void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent,
+ int index)
+ {
+ parent.insert(newChild, index);
+ int[] childIndices = new int[1];
+ childIndices[0] = index;
+ nodesWereInserted(parent, childIndices);
+ }
+
+ /**
+ * Message this to remove node from its parent. This will message
+ * nodesWereRemoved to create the appropriate event. This is the preferred
+ * way to remove a node as it handles the event creation for you.
+ *
+ * @param node to be removed
+ */
+ public void removeNodeFromParent(MutableTreeNode node)
+ {
+ TreeNode parent = node.getParent();
+ Object[] children = new Object[1];
+ children[0] = node;
+ int[] childIndices = new int[1];
+ childIndices[0] = getIndexOfChild(parent, node);
+ node.removeFromParent();
+ nodesWereRemoved(parent, childIndices, children);
+ }
+
+ /**
+ * Invoke this method after you've changed how node is to be represented
+ * in the tree.
+ *
+ * @param node that was changed
+ */
+ public void nodeChanged(TreeNode node)
+ {
+ TreeNode parent = node.getParent();
+ int[] childIndices = new int[1];
+ childIndices[0] = getIndexOfChild(parent, node);
+ Object[] children = new Object[1];
+ children[0] = node;
+ fireTreeNodesChanged(this, getPathToRoot(node), childIndices, children);
+ }
+
+ /**
+ * Invoke this method after you've inserted some TreeNodes
+ * into node. childIndices should be the index of the new elements and must
+ * be sorted in ascending order.
+ *
+ * @param parent that had a child added to
+ * @param childIndices of the children added
+ */
+ public void nodesWereInserted(TreeNode parent, int[] childIndices)
+ {
+ Object[] children = new Object[childIndices.length];
+ for (int i = 0; i < children.length; i++)
+ children[i] = getChild(parent, childIndices[i]);
+ fireTreeNodesInserted(this, getPathToRoot(parent), childIndices, children);
+ }
+
+ /**
+ * Invoke this method after you've removed some TreeNodes from node.
+ * childIndices should be the index of the removed elements and
+ * must be sorted in ascending order. And removedChildren should be the
+ * array of the children objects that were removed.
+ *
+ * @param parent that had a child added to
+ * @param childIndices of the children added
+ * @param removedChildren are all the children removed from parent.
+ */
+ public void nodesWereRemoved(TreeNode parent, int[] childIndices,
+ Object[] removedChildren)
+ {
+ fireTreeNodesRemoved(this, getPathToRoot(parent), childIndices,
+ removedChildren);
+ }
+
+ /**
+ * Invoke this method after you've changed how the children identified by
+ * childIndices are to be represented in the tree.
+ *
+ * @param node that is the parent of the children that changed in a tree.
+ * @param childIndices are the child nodes that changed.
+ */
+ public void nodesChanged(TreeNode node, int[] childIndices)
+ {
+ Object[] children = new Object[childIndices.length];
+ for (int i = 0; i < children.length; i++)
+ children[i] = getChild(node, childIndices[i]);
+ fireTreeNodesChanged(this, getPathToRoot(node), childIndices, children);
+ }
+
+ /**
+ * Invoke this method if you've totally changed the children of node and
+ * its childrens children. This will post a treeStructureChanged event.
+ *
+ * @param node that had its children and grandchildren changed.
+ */
+ public void nodeStructureChanged(TreeNode node)
+ {
+ // TODO
+ }
+
+ /**
+ * Builds the parents of node up to and including the root node, where
+ * the original node is the last element in the returned array. The
+ * length of the returned array gives the node's depth in the tree.
+ *
+ * @param node - the TreeNode to get the path for
+ * @return TreeNode[] - the path from node to the root
+ */
+ public TreeNode[] getPathToRoot(TreeNode node)
+ {
+ return getPathToRoot(node, 0);
+ }
+
+ /**
+ * Builds the parents of node up to and including the root node, where
+ * the original node is the last element in the returned array. The
+ * length of the returned array gives the node's depth in the tree.
+ *
+ * @param node - the TreeNode to get the path for
+ * @param depth - an int giving the number of steps already taken
+ * towards the root (on recursive calls), used to size the returned array
+ * @return an array of TreeNodes giving the path from the root to the
+ * specified node
+ */
+ protected TreeNode[] getPathToRoot(TreeNode node, int depth)
+ {
+ if (node == null)
+ {
+ if (depth == 0)
+ return null;
+
+ return new TreeNode[depth];
+ }
+
+ TreeNode[] path = getPathToRoot(node.getParent(), depth + 1);
+ path[path.length - depth - 1] = node;
+ return path;
+ }
+
+ /**
+ * Registers a listere to the model.
+ *
+ * @param listener the listener to add
+ */
+ public void addTreeModelListener(TreeModelListener listener)
+ {
+ listenerList.add(TreeModelListener.class, listener);
+ }
+
+ /**
+ * Removes a listener from the model.
+ *
+ * @param listener the listener to remove
+ */
+ public void removeTreeModelListener(TreeModelListener listener)
+ {
+ listenerList.remove(TreeModelListener.class, listener);
+ }
+
+ /**
+ * Returns all registered <code>TreeModelListener</code> listeners.
+ *
+ * @return an array of listeners.
+ *
+ * @since 1.4
+ */
+ public TreeModelListener[] getTreeModelListeners()
+ {
+ return (TreeModelListener[]) listenerList
+ .getListeners(TreeModelListener.class);
+ }
+
+ /**
+ * Notifies all listeners that have registered interest for notification
+ * on this event type. The event instance is lazily created using the parameters
+ * passed into the fire method.
+ *
+ * @param source the node being changed
+ * @param path the path to the root node
+ * @param childIndices the indices of the changed elements
+ * @param children the changed elements
+ */
+ protected void fireTreeNodesChanged(Object source, Object[] path,
+ int[] childIndices, Object[] children)
+ {
+ TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
+ children);
+
+ TreeModelListener[] listeners = getTreeModelListeners();
+
+ for (int i = listeners.length - 1; i >= 0; --i)
+ listeners[i].treeNodesChanged(event);
+ }
+
+ /**
+ * fireTreeNodesInserted
+ *
+ * @param source the node where new nodes got inserted
+ * @param path the path to the root node
+ * @param childIndices the indices of the new elements
+ * @param children the new elements
+ */
+ protected void fireTreeNodesInserted(Object source, Object[] path,
+ int[] childIndices, Object[] children)
+ {
+ TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
+ children);
+ TreeModelListener[] listeners = getTreeModelListeners();
+
+ for (int i = listeners.length - 1; i >= 0; --i)
+ listeners[i].treeNodesInserted(event);
+ }
+
+ /**
+ * fireTreeNodesRemoved
+ *
+ * @param source the node where nodes got removed-
+ * @param path the path to the root node
+ * @param childIndices the indices of the removed elements
+ * @param children the removed elements
+ */
+ protected void fireTreeNodesRemoved(Object source, Object[] path,
+ int[] childIndices, Object[] children)
+ {
+ TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
+ children);
+ TreeModelListener[] listeners = getTreeModelListeners();
+
+ for (int i = listeners.length - 1; i >= 0; --i)
+ listeners[i].treeNodesRemoved(event);
+ }
+
+ /**
+ * fireTreeStructureChanged
+ *
+ * @param source the node where the model has changed
+ * @param path the path to the root node
+ * @param childIndices the indices of the affected elements
+ * @param children the affected elements
+ */
+ protected void fireTreeStructureChanged(Object source, Object[] path,
+ int[] childIndices, Object[] children)
+ {
+ TreeModelEvent event = new TreeModelEvent(source, path, childIndices,
+ children);
+ TreeModelListener[] listeners = getTreeModelListeners();
+
+ for (int i = listeners.length - 1; i >= 0; --i)
+ listeners[i].treeStructureChanged(event);
+ }
+
+ /**
+ * Returns the registered listeners of a given type.
+ *
+ * @param listenerType the listener type to return
+ *
+ * @return an array of listeners
+ *
+ * @since 1.3
+ */
+ public EventListener[] getListeners(Class listenerType)
+ {
+ return listenerList.getListeners(listenerType);
+ }
}
diff --git a/libjava/classpath/javax/swing/tree/DefaultTreeSelectionModel.java b/libjava/classpath/javax/swing/tree/DefaultTreeSelectionModel.java
index de27dad04f9..75b76a9e8c6 100644
--- a/libjava/classpath/javax/swing/tree/DefaultTreeSelectionModel.java
+++ b/libjava/classpath/javax/swing/tree/DefaultTreeSelectionModel.java
@@ -116,7 +116,7 @@ public class DefaultTreeSelectionModel
*/
public DefaultTreeSelectionModel()
{
- setSelectionMode(DISCONTIGUOUS_TREE_SELECTION);
+ setSelectionMode(SINGLE_TREE_SELECTION);
listenerList = new EventListenerList();
}
diff --git a/libjava/classpath/javax/swing/tree/FixedHeightLayoutCache.java b/libjava/classpath/javax/swing/tree/FixedHeightLayoutCache.java
index 67a21f0205a..535417ec389 100644
--- a/libjava/classpath/javax/swing/tree/FixedHeightLayoutCache.java
+++ b/libjava/classpath/javax/swing/tree/FixedHeightLayoutCache.java
@@ -125,7 +125,7 @@ public class FixedHeightLayoutCache
/**
* getPathForRow
*
- * @param value0 TODO
+ * @param row TODO
* @returns TreePath
*/
public TreePath getPathForRow(int row)
OpenPOWER on IntegriCloud