jdk/src/share/classes/javax/swing/JTree.java

Print this page

        

@@ -20,28 +20,31 @@
  *
  * 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.
  */
-
 package javax.swing;
 
 import java.awt.*;
 import java.awt.event.*;
-import java.beans.*;
+import java.beans.JavaBean;
+import java.beans.BeanProperty;
+import java.beans.ConstructorProperties;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.io.*;
 import java.util.*;
 import javax.swing.event.*;
 import javax.swing.plaf.*;
 import javax.swing.tree.*;
 import javax.swing.text.Position;
 import javax.accessibility.*;
+
 import sun.swing.SwingUtilities2;
 import sun.swing.SwingUtilities2.Section;
 import static sun.swing.SwingUtilities2.Section.*;
 
-
 /**
  * <a name="jtree_description"></a>
  * A control that displays a set of hierarchical data as an outline.
  * You can find task-oriented documentation and examples of using trees in
  * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/tree.html">How to Use Trees</a>,

@@ -132,19 +135,18 @@
  * the same version of Swing.  As of 1.4, support for long term storage
  * of all JavaBeans&trade;
  * has been added to the <code>java.beans</code> package.
  * Please see {@link java.beans.XMLEncoder}.
  *</p>
- * @beaninfo
- *   attribute: isContainer false
- * description: A component that displays a set of hierarchical data as an outline.
  *
  * @author Rob Davis
  * @author Ray Ryan
  * @author Scott Violet
  * @since 1.2
  */
+@JavaBean(defaultProperty = "UI", description = "A component that displays a set of hierarchical data as an outline.")
+@SwingContainer(false)
 @SuppressWarnings("serial")
 public class JTree extends JComponent implements Scrollable, Accessible
 {
     /**
      * @see #getUIClassID

@@ -685,16 +687,13 @@
      * <p>
      * This is a bound property.
      *
      * @param ui  the <code>TreeUI</code> L&amp;F object
      * @see UIDefaults#getUI
-     * @beaninfo
-     *        bound: true
-     *       hidden: true
-     *    attribute: visualUpdate true
-     *  description: The UI object that implements the Component's LookAndFeel.
      */
+    @BeanProperty(hidden = true, visualUpdate = true, description
+            = "The UI object that implements the Component's LookAndFeel.")
     public void setUI(TreeUI ui) {
         if (this.ui != ui) {
             settingUI = true;
             uiTreeExpansionListener = null;
             try {

@@ -726,10 +725,11 @@
      *
      * @return the string "TreeUI"
      * @see JComponent#getUIClassID
      * @see UIDefaults#getUI
      */
+    @BeanProperty(bound = false)
     public String getUIClassID() {
         return uiClassID;
     }
 
 

@@ -748,15 +748,13 @@
      * draw each cell.
      * <p>
      * This is a bound property.
      *
      * @param x  the <code>TreeCellRenderer</code> that is to render each cell
-     * @beaninfo
-     *        bound: true
-     *  description: The TreeCellRenderer that will be used to draw
-     *               each cell.
      */
+    @BeanProperty(description
+            = "The TreeCellRenderer that will be used to draw each cell.")
     public void setCellRenderer(TreeCellRenderer x) {
         TreeCellRenderer oldValue = cellRenderer;
 
         cellRenderer = x;
         firePropertyChange(CELL_RENDERER_PROPERTY, oldValue, cellRenderer);

@@ -769,14 +767,13 @@
       * setting.
      * <p>
      * This is a bound property.
       *
       * @param flag  a boolean value, true if the tree is editable
-      * @beaninfo
-      *        bound: true
-      *  description: Whether the tree is editable.
       */
+    @BeanProperty(description
+            = "Whether the tree is editable.")
     public void setEditable(boolean flag) {
         boolean                 oldValue = this.editable;
 
         this.editable = flag;
         firePropertyChange(EDITABLE_PROPERTY, oldValue, flag);

@@ -804,15 +801,13 @@
      * method is invoked on all listeners.
      * <p>
      * This is a bound property.
      *
      * @param cellEditor the <code>TreeCellEditor</code> to use
-     * @beaninfo
-     *        bound: true
-     *  description: The cell editor. A null value implies the tree
-     *               cannot be edited.
      */
+    @BeanProperty(description
+            = "The cell editor. A null value implies the tree cannot be edited.")
     public void setCellEditor(TreeCellEditor cellEditor) {
         TreeCellEditor        oldEditor = this.cellEditor;
 
         this.cellEditor = cellEditor;
         firePropertyChange(CELL_EDITOR_PROPERTY, oldEditor, cellEditor);

@@ -842,14 +837,13 @@
      * Sets the <code>TreeModel</code> that will provide the data.
      * <p>
      * This is a bound property.
      *
      * @param newModel the <code>TreeModel</code> that is to provide the data
-     * @beaninfo
-     *        bound: true
-     *  description: The TreeModel that will provide the data.
      */
+    @BeanProperty(description
+            = "The TreeModel that will provide the data.")
     public void setModel(TreeModel newModel) {
         clearSelection();
 
         TreeModel oldModel = treeModel;
 

@@ -899,15 +893,13 @@
      * <p>
      * This is a bound property.
      *
      * @param rootVisible true if the root node of the tree is to be displayed
      * @see #rootVisible
-     * @beaninfo
-     *        bound: true
-     *  description: Whether or not the root node
-     *               from the TreeModel is visible.
      */
+    @BeanProperty(description
+            = "Whether or not the root node from the TreeModel is visible.")
     public void setRootVisible(boolean rootVisible) {
         boolean                oldValue = this.rootVisible;
 
         this.rootVisible = rootVisible;
         firePropertyChange(ROOT_VISIBLE_PROPERTY, oldValue, this.rootVisible);

@@ -928,15 +920,13 @@
      *
      * @param newValue <code>true</code> if root handles should be displayed;
      *                 otherwise, <code>false</code>
      * @see #showsRootHandles
      * @see #getShowsRootHandles
-     * @beaninfo
-     *        bound: true
-     *  description: Whether the node handles are to be
-     *               displayed.
      */
+    @BeanProperty(description
+            = "Whether the node handles are to be displayed.")
     public void setShowsRootHandles(boolean newValue) {
         boolean                oldValue = showsRootHandles;
         TreeModel              model = getModel();
 
         showsRootHandles = newValue;

@@ -966,14 +956,13 @@
      * queried for each row's height.
      * <p>
      * This is a bound property.
      *
      * @param rowHeight the height of each cell, in pixels
-     * @beaninfo
-     *        bound: true
-     *  description: The height of each cell.
      */
+    @BeanProperty(description
+            = "The height of each cell.")
     public void setRowHeight(int rowHeight)
     {
         int                oldValue = this.rowHeight;
 
         this.rowHeight = rowHeight;

@@ -997,10 +986,11 @@
     /**
      * Returns true if the height of each display row is a fixed size.
      *
      * @return true if the height of each row is a fixed size
      */
+    @BeanProperty(bound = false)
     public boolean isFixedRowHeight()
     {
         return (rowHeight > 0);
     }
 

@@ -1011,15 +1001,13 @@
      * <p>
      * This is a bound property.
      *
      * @param newValue true to suggest a large model to the UI
      * @see #largeModel
-     * @beaninfo
-     *        bound: true
-     *  description: Whether the UI should use a
-     *               large model.
      */
+    @BeanProperty(description
+            = "Whether the UI should use a large model.")
     public void setLargeModel(boolean newValue) {
         boolean                oldValue = largeModel;
 
         largeModel = newValue;
         firePropertyChange(LARGE_MODEL_PROPERTY, oldValue, newValue);

@@ -1044,16 +1032,14 @@
      * Fires a property change for the INVOKES_STOP_CELL_EDITING_PROPERTY.
      *
      * @param newValue true means that <code>stopCellEditing</code> is invoked
      *        when editing is interrupted, and data is saved; false means that
      *        <code>cancelCellEditing</code> is invoked, and changes are lost
-     * @beaninfo
-     *        bound: true
-     *  description: Determines what happens when editing is interrupted,
-     *               selecting another node in the tree, a change in the
-     *               tree's data, or some other means.
      */
+    @BeanProperty(description
+            = "Determines what happens when editing is interrupted, selecting another node in the tree, "
+            + "a change in the tree's data, or some other means.")
     public void setInvokesStopCellEditing(boolean newValue) {
         boolean                  oldValue = invokesStopCellEditing;
 
         invokesStopCellEditing = newValue;
         firePropertyChange(INVOKES_STOP_CELL_EDITING_PROPERTY, oldValue,

@@ -1086,15 +1072,13 @@
      * This is a bound property.
      *
      * @param newValue <code>false</code> to disable scrolling on expansion;
      *                 <code>true</code> to enable it
      * @see #getScrollsOnExpand
-     *
-     * @beaninfo
-     *        bound: true
-     *  description: Indicates if a node descendant should be scrolled when expanded.
      */
+    @BeanProperty(description
+            = "Indicates if a node descendant should be scrolled when expanded.")
     public void setScrollsOnExpand(boolean newValue) {
         boolean           oldValue = scrollsOnExpand;
 
         scrollsOnExpand = newValue;
         scrollsOnExpandSet = true;

@@ -1117,14 +1101,13 @@
      * <p>
      * This is a bound property.
      *
      * @param clickCount the number of mouse clicks to get a node expanded or closed
      * @since 1.3
-     * @beaninfo
-     *        bound: true
-     *  description: Number of clicks before a node will expand/collapse.
      */
+    @BeanProperty(description
+            = "Number of clicks before a node will expand/collapse.")
     public void setToggleClickCount(int clickCount) {
         int         oldCount = toggleClickCount;
 
         toggleClickCount = clickCount;
         firePropertyChange(TOGGLE_CLICK_COUNT_PROPERTY, oldCount,

@@ -1156,15 +1139,13 @@
      * This is a bound property.
      *
      * @param newValue the new value for <code>expandsSelectedPaths</code>
      *
      * @since 1.3
-     * @beaninfo
-     *        bound: true
-     *  description: Indicates whether changes to the selection should make
-     *               the parent of the path visible.
      */
+    @BeanProperty(description
+            = "Indicates whether changes to the selection should make the parent of the path visible.")
     public void setExpandsSelectedPaths(boolean newValue) {
         boolean         oldValue = expandsSelectedPaths;
 
         expandsSelectedPaths = newValue;
         firePropertyChange(EXPANDS_SELECTED_PATHS_PROPERTY, oldValue,

@@ -1208,15 +1189,13 @@
      * @see java.awt.GraphicsEnvironment#isHeadless
      * @see #getDragEnabled
      * @see #setTransferHandler
      * @see TransferHandler
      * @since 1.4
-     *
-     * @beaninfo
-     *  description: determines whether automatic drag handling is enabled
-     *        bound: false
      */
+    @BeanProperty(bound = false, description
+            = "determines whether automatic drag handling is enabled")
     public void setDragEnabled(boolean b) {
         checkDragEnabled(b);
         dragEnabled = b;
     }
 

@@ -1494,10 +1473,11 @@
      * @return the drop location
      * @see #setDropMode
      * @see TransferHandler#canImport(TransferHandler.TransferSupport)
      * @since 1.6
      */
+    @BeanProperty(bound = false)
     public final DropLocation getDropLocation() {
         return dropLocation;
     }
 
     private void startDropTimer() {

@@ -1624,10 +1604,11 @@
      * {@code isRootVisible()} is {@code true}. This returns {@code 0} if
      * the UI has not been set.
      *
      * @return the number of viewable nodes
      */
+    @BeanProperty(bound = false)
     public int getRowCount() {
         TreeUI            tree = getUI();
 
         if(tree != null)
             return tree.getRowCount(this);

@@ -1666,14 +1647,13 @@
      * <p>
      * This is a bound property.
      *
      * @param newPath  the new lead path
      * @since 1.3
-     * @beaninfo
-     *        bound: true
-     *  description: Lead selection path
      */
+    @BeanProperty(description
+            = "Lead selection path")
     public void setLeadSelectionPath(TreePath newPath) {
         TreePath          oldValue = leadPath;
 
         leadPath = newPath;
         firePropertyChange(LEAD_SELECTION_PATH_PROPERTY, oldValue, newPath);

@@ -1694,14 +1674,13 @@
      * <p>
      * This is a bound property.
      *
      * @param newPath  the new anchor path
      * @since 1.3
-     * @beaninfo
-     *        bound: true
-     *  description: Anchor selection path
      */
+    @BeanProperty(description
+            = "Anchor selection path")
     public void setAnchorSelectionPath(TreePath newPath) {
         TreePath          oldValue = anchorPath;
 
         anchorPath = newPath;
         firePropertyChange(ANCHOR_SELECTION_PATH_PROPERTY, oldValue, newPath);

@@ -1817,10 +1796,11 @@
      *
      * @return the last path component of the selected path, or
      *         <code>null</code> if nothing is selected
      * @see TreePath#getLastPathComponent
      */
+    @BeanProperty(bound = false)
     public Object getLastSelectedPathComponent() {
         TreePath     selPath = getSelectionModel().getSelectionPath();
 
         if(selPath != null)
             return selPath.getLastPathComponent();

@@ -1883,30 +1863,33 @@
     /**
      * Returns the number of nodes selected.
      *
      * @return the number of nodes selected
      */
+    @BeanProperty(bound = false)
     public int getSelectionCount() {
         return selectionModel.getSelectionCount();
     }
 
     /**
      * Returns the smallest selected row. If the selection is empty, or
      * none of the selected paths are viewable, {@code -1} is returned.
      *
      * @return the smallest selected row
      */
+    @BeanProperty(bound = false)
     public int getMinSelectionRow() {
         return getSelectionModel().getMinSelectionRow();
     }
 
     /**
      * Returns the largest selected row. If the selection is empty, or
      * none of the selected paths are viewable, {@code -1} is returned.
      *
      * @return the largest selected row
      */
+    @BeanProperty(bound = false)
     public int getMaxSelectionRow() {
         return getSelectionModel().getMaxSelectionRow();
     }
 
     /**

@@ -1914,10 +1897,11 @@
      *
      * @return an integer giving the row index of the lead path,
      *          where 0 is the first row in the display; or -1
      *          if <code>leadPath</code> is <code>null</code>
      */
+    @BeanProperty(bound = false)
     public int getLeadSelectionRow() {
         TreePath leadPath = getLeadSelectionPath();
 
         if (leadPath != null) {
             return getRowForPath(leadPath);

@@ -2187,10 +2171,11 @@
      * @param row  an integer specifying a row
      * @return the <code>TreePath</code> to the specified node,
      *          <code>null</code> if <code>row &lt; 0</code>
      *          or <code>row &gt;= getRowCount()</code>
      */
+    @BeanProperty(bound = false)
     public TreePath getPathForRow(int row) {
         TreeUI                  tree = getUI();
 
         if(tree != null)
             return tree.getPathForRow(this, row);

@@ -2357,10 +2342,11 @@
      * edited can be obtained using <code>getSelectionPath</code>.
      *
      * @return true if the user is currently editing a node
      * @see #getSelectionPath
      */
+    @BeanProperty(bound = false)
     public boolean isEditing() {
         TreeUI                  tree = getUI();
 
         if(tree != null)
             return tree.isEditing(this);

@@ -2419,10 +2405,11 @@
     /**
      * Returns the path to the element that is currently being edited.
      *
      * @return  the <code>TreePath</code> for the node being edited
      */
+    @BeanProperty(bound = false)
     public TreePath getEditingPath() {
         TreeUI                  tree = getUI();
 
         if(tree != null)
             return tree.getEditingPath(this);

@@ -2446,14 +2433,13 @@
      * This is a bound property.
      *
      * @param selectionModel the <code>TreeSelectionModel</code> to use,
      *          or <code>null</code> to disable selections
      * @see TreeSelectionModel
-     * @beaninfo
-     *        bound: true
-     *  description: The tree's selection model.
      */
+    @BeanProperty(description
+            = "The tree's selection model.")
     public void setSelectionModel(TreeSelectionModel selectionModel) {
         if(selectionModel == null)
             selectionModel = EmptySelectionModel.sharedInstance();
 
         TreeSelectionModel         oldValue = this.selectionModel;

@@ -2689,10 +2675,11 @@
     /**
      * Returns true if the selection is currently empty.
      *
      * @return true if the selection is currently empty
      */
+    @BeanProperty(bound = false)
     public boolean isSelectionEmpty() {
         return getSelectionModel().isSelectionEmpty();
     }
 
     /**

@@ -2727,10 +2714,11 @@
      *
      * @return all of the <code>TreeExpansionListener</code>s added or an empty
      *         array if no listeners have been added
      * @since 1.4
      */
+    @BeanProperty(bound = false)
     public TreeExpansionListener[] getTreeExpansionListeners() {
         return listenerList.getListeners(TreeExpansionListener.class);
     }
 
     /**

@@ -2759,10 +2747,11 @@
      *
      * @return all of the <code>TreeWillExpandListener</code>s added or an empty
      *         array if no listeners have been added
      * @since 1.4
      */
+    @BeanProperty(bound = false)
     public TreeWillExpandListener[] getTreeWillExpandListeners() {
         return listenerList.getListeners(TreeWillExpandListener.class);
     }
 
     /**

@@ -2918,10 +2907,11 @@
      *
      * @return all of the <code>TreeSelectionListener</code>s added or an empty
      *         array if no listeners have been added
      * @since 1.4
      */
+    @BeanProperty(bound = false)
     public TreeSelectionListener[] getTreeSelectionListeners() {
         return listenerList.getListeners(TreeSelectionListener.class);
     }
 
     /**

@@ -2969,14 +2959,13 @@
      * and will adjust the preferred size and size of that scrollpane.
      * <p>
      * This is a bound property.
      *
      * @param newCount the number of rows to display
-     * @beaninfo
-     *        bound: true
-     *  description: The number of rows that are to be displayed.
      */
+    @BeanProperty(description
+            = "The number of rows that are to be displayed.")
     public void setVisibleRowCount(int newCount) {
         int                 oldCount = visibleRowCount;
 
         visibleRowCount = newCount;
         firePropertyChange(VISIBLE_ROW_COUNT_PROPERTY, oldCount,

@@ -3446,10 +3435,11 @@
      * determined from <code>getVisibleRowCount</code> and the width
      * is the current preferred width.
      *
      * @return a <code>Dimension</code> object containing the preferred size
      */
+    @BeanProperty(bound = false)
     public Dimension getPreferredScrollableViewportSize() {
         int                 width = getPreferredSize().width;
         int                 visRows = getVisibleRowCount();
         int                 height = -1;
 

@@ -3552,10 +3542,11 @@
      * ensure that the tree is never smaller than its viewport.
      *
      * @return whether the tree should track the width of the viewport
      * @see Scrollable#getScrollableTracksViewportWidth
      */
+    @BeanProperty(bound = false)
     public boolean getScrollableTracksViewportWidth() {
         Container parent = SwingUtilities.getUnwrappedParent(this);
         if (parent instanceof JViewport) {
             return parent.getWidth() > getPreferredSize().width;
         }

@@ -3569,10 +3560,11 @@
      * ensure that the tree is never smaller than its viewport.
      *
      * @return whether the tree should track the height of the viewport
      * @see Scrollable#getScrollableTracksViewportHeight
      */
+    @BeanProperty(bound = false)
     public boolean getScrollableTracksViewportHeight() {
         Container parent = SwingUtilities.getUnwrappedParent(this);
         if (parent instanceof JViewport) {
             return parent.getHeight() > getPreferredSize().height;
         }

@@ -4144,10 +4136,11 @@
      * A new AccessibleJTree instance is created if necessary.
      *
      * @return an AccessibleJTree that serves as the
      *         AccessibleContext of this JTree
      */
+    @BeanProperty(bound = false)
     public AccessibleContext getAccessibleContext() {
         if (accessibleContext == null) {
             accessibleContext = new AccessibleJTree();
         }
         return accessibleContext;