117 * a graphic icon and text), subclass {@link TreeCellRenderer} and use
118 * {@link #setCellRenderer} to tell the tree to use it. To edit such nodes,
119 * subclass {@link TreeCellEditor} and use {@link #setCellEditor}.
120 * </p>
121 * <p>
122 * Like all <code>JComponent</code> classes, you can use {@link InputMap} and
123 * {@link ActionMap}
124 * to associate an {@link Action} object with a {@link KeyStroke}
125 * and execute the action under specified conditions.
126 * </p>
127 * <strong>Warning:</strong> Swing is not thread safe. For more
128 * information see <a
129 * href="package-summary.html#threading">Swing's Threading
130 * Policy</a>.
131 * <p>
132 * <strong>Warning:</strong>
133 * Serialized objects of this class will not be compatible with
134 * future Swing releases. The current serialization support is
135 * appropriate for short term storage or RMI between applications running
136 * the same version of Swing. As of 1.4, support for long term storage
137 * of all JavaBeans™
138 * has been added to the <code>java.beans</code> package.
139 * Please see {@link java.beans.XMLEncoder}.
140 *</p>
141 *
142 * @author Rob Davis
143 * @author Ray Ryan
144 * @author Scott Violet
145 * @since 1.2
146 */
147 @JavaBean(defaultProperty = "UI", description = "A component that displays a set of hierarchical data as an outline.")
148 @SwingContainer(false)
149 @SuppressWarnings("serial")
150 public class JTree extends JComponent implements Scrollable, Accessible
151 {
152 /**
153 * @see #getUIClassID
154 * @see #readObject
155 */
156 private static final String uiClassID = "TreeUI";
157
3295
3296 TreePath parentPath = new TreePath(parent);
3297 for(int counter = 0; counter < count; counter++) {
3298 parent = model.getChild(parent, indexs[counter]);
3299 if(parent == null)
3300 return null;
3301 parentPath = parentPath.pathByAddingChild(parent);
3302 }
3303 return parentPath;
3304 }
3305
3306 /**
3307 * <code>EmptySelectionModel</code> is a <code>TreeSelectionModel</code>
3308 * that does not allow anything to be selected.
3309 * <p>
3310 * <strong>Warning:</strong>
3311 * Serialized objects of this class will not be compatible with
3312 * future Swing releases. The current serialization support is
3313 * appropriate for short term storage or RMI between applications running
3314 * the same version of Swing. As of 1.4, support for long term storage
3315 * of all JavaBeans™
3316 * has been added to the <code>java.beans</code> package.
3317 * Please see {@link java.beans.XMLEncoder}.
3318 */
3319 @SuppressWarnings("serial")
3320 protected static class EmptySelectionModel extends
3321 DefaultTreeSelectionModel
3322 {
3323 /**
3324 * The single instance of {@code EmptySelectionModel}.
3325 */
3326 protected static final EmptySelectionModel sharedInstance =
3327 new EmptySelectionModel();
3328
3329 /**
3330 * Returns the single instance of {@code EmptySelectionModel}.
3331 *
3332 * @return single instance of {@code EmptySelectionModel}
3333 */
3334 public static EmptySelectionModel sharedInstance() {
3335 return sharedInstance;
3417 *
3418 * @param listener the listener to remove; this is ignored
3419 * @since 1.7
3420 */
3421 public void removePropertyChangeListener(
3422 PropertyChangeListener listener) {
3423 }
3424 }
3425
3426
3427 /**
3428 * Handles creating a new <code>TreeSelectionEvent</code> with the
3429 * <code>JTree</code> as the
3430 * source and passing it off to all the listeners.
3431 * <p>
3432 * <strong>Warning:</strong>
3433 * Serialized objects of this class will not be compatible with
3434 * future Swing releases. The current serialization support is
3435 * appropriate for short term storage or RMI between applications running
3436 * the same version of Swing. As of 1.4, support for long term storage
3437 * of all JavaBeans™
3438 * has been added to the <code>java.beans</code> package.
3439 * Please see {@link java.beans.XMLEncoder}.
3440 */
3441 @SuppressWarnings("serial")
3442 protected class TreeSelectionRedirector implements Serializable,
3443 TreeSelectionListener
3444 {
3445 /**
3446 * Invoked by the <code>TreeSelectionModel</code> when the
3447 * selection changes.
3448 *
3449 * @param e the <code>TreeSelectionEvent</code> generated by the
3450 * <code>TreeSelectionModel</code>
3451 */
3452 public void valueChanged(TreeSelectionEvent e) {
3453 TreeSelectionEvent newE;
3454
3455 newE = (TreeSelectionEvent)e.cloneWithSource(JTree.this);
3456 fireValueChanged(newE);
3457 }
3937
3938 if(model == null || model.isLeaf(parent.getLastPathComponent()))
3939 expandedState.remove(parent);
3940
3941 removeDescendantSelectedPaths(e);
3942 }
3943 }
3944
3945
3946 /**
3947 * <code>DynamicUtilTreeNode</code> can wrap
3948 * vectors/hashtables/arrays/strings and
3949 * create the appropriate children tree nodes as necessary. It is
3950 * dynamic in that it will only create the children as necessary.
3951 * <p>
3952 * <strong>Warning:</strong>
3953 * Serialized objects of this class will not be compatible with
3954 * future Swing releases. The current serialization support is
3955 * appropriate for short term storage or RMI between applications running
3956 * the same version of Swing. As of 1.4, support for long term storage
3957 * of all JavaBeans™
3958 * has been added to the <code>java.beans</code> package.
3959 * Please see {@link java.beans.XMLEncoder}.
3960 */
3961 @SuppressWarnings("serial")
3962 public static class DynamicUtilTreeNode extends DefaultMutableTreeNode {
3963 /**
3964 * Does the this <code>JTree</code> have children?
3965 * This property is currently not implemented.
3966 */
3967 protected boolean hasChildren;
3968 /** Value to create children with. */
3969 protected Object childValue;
3970 /** Have the children been loaded yet? */
3971 protected boolean loadedChildren;
3972
3973 /**
3974 * Adds to parent all the children in <code>children</code>.
3975 * If <code>children</code> is an array or vector all of its
3976 * elements are added is children, otherwise if <code>children</code>
3977 * is a hashtable all the key/value pairs are added in the order
4173 * AccessibleContext of this JTree
4174 */
4175 @BeanProperty(bound = false)
4176 public AccessibleContext getAccessibleContext() {
4177 if (accessibleContext == null) {
4178 accessibleContext = new AccessibleJTree();
4179 }
4180 return accessibleContext;
4181 }
4182
4183 /**
4184 * This class implements accessibility support for the
4185 * <code>JTree</code> class. It provides an implementation of the
4186 * Java Accessibility API appropriate to tree user-interface elements.
4187 * <p>
4188 * <strong>Warning:</strong>
4189 * Serialized objects of this class will not be compatible with
4190 * future Swing releases. The current serialization support is
4191 * appropriate for short term storage or RMI between applications running
4192 * the same version of Swing. As of 1.4, support for long term storage
4193 * of all JavaBeans™
4194 * has been added to the <code>java.beans</code> package.
4195 * Please see {@link java.beans.XMLEncoder}.
4196 */
4197 @SuppressWarnings("serial")
4198 protected class AccessibleJTree extends AccessibleJComponent
4199 implements AccessibleSelection, TreeSelectionListener,
4200 TreeModelListener, TreeExpansionListener {
4201
4202 TreePath leadSelectionPath;
4203 Accessible leadSelectionAccessible;
4204
4205 /**
4206 * Constructs {@code AccessibleJTree}
4207 */
4208 public AccessibleJTree() {
4209 // Add a tree model listener for JTree
4210 TreeModel model = JTree.this.getModel();
4211 if (model != null) {
4212 model.addTreeModelListener(this);
4213 }
|
117 * a graphic icon and text), subclass {@link TreeCellRenderer} and use
118 * {@link #setCellRenderer} to tell the tree to use it. To edit such nodes,
119 * subclass {@link TreeCellEditor} and use {@link #setCellEditor}.
120 * </p>
121 * <p>
122 * Like all <code>JComponent</code> classes, you can use {@link InputMap} and
123 * {@link ActionMap}
124 * to associate an {@link Action} object with a {@link KeyStroke}
125 * and execute the action under specified conditions.
126 * </p>
127 * <strong>Warning:</strong> Swing is not thread safe. For more
128 * information see <a
129 * href="package-summary.html#threading">Swing's Threading
130 * Policy</a>.
131 * <p>
132 * <strong>Warning:</strong>
133 * Serialized objects of this class will not be compatible with
134 * future Swing releases. The current serialization support is
135 * appropriate for short term storage or RMI between applications running
136 * the same version of Swing. As of 1.4, support for long term storage
137 * of all JavaBeans
138 * has been added to the <code>java.beans</code> package.
139 * Please see {@link java.beans.XMLEncoder}.
140 *</p>
141 *
142 * @author Rob Davis
143 * @author Ray Ryan
144 * @author Scott Violet
145 * @since 1.2
146 */
147 @JavaBean(defaultProperty = "UI", description = "A component that displays a set of hierarchical data as an outline.")
148 @SwingContainer(false)
149 @SuppressWarnings("serial")
150 public class JTree extends JComponent implements Scrollable, Accessible
151 {
152 /**
153 * @see #getUIClassID
154 * @see #readObject
155 */
156 private static final String uiClassID = "TreeUI";
157
3295
3296 TreePath parentPath = new TreePath(parent);
3297 for(int counter = 0; counter < count; counter++) {
3298 parent = model.getChild(parent, indexs[counter]);
3299 if(parent == null)
3300 return null;
3301 parentPath = parentPath.pathByAddingChild(parent);
3302 }
3303 return parentPath;
3304 }
3305
3306 /**
3307 * <code>EmptySelectionModel</code> is a <code>TreeSelectionModel</code>
3308 * that does not allow anything to be selected.
3309 * <p>
3310 * <strong>Warning:</strong>
3311 * Serialized objects of this class will not be compatible with
3312 * future Swing releases. The current serialization support is
3313 * appropriate for short term storage or RMI between applications running
3314 * the same version of Swing. As of 1.4, support for long term storage
3315 * of all JavaBeans
3316 * has been added to the <code>java.beans</code> package.
3317 * Please see {@link java.beans.XMLEncoder}.
3318 */
3319 @SuppressWarnings("serial")
3320 protected static class EmptySelectionModel extends
3321 DefaultTreeSelectionModel
3322 {
3323 /**
3324 * The single instance of {@code EmptySelectionModel}.
3325 */
3326 protected static final EmptySelectionModel sharedInstance =
3327 new EmptySelectionModel();
3328
3329 /**
3330 * Returns the single instance of {@code EmptySelectionModel}.
3331 *
3332 * @return single instance of {@code EmptySelectionModel}
3333 */
3334 public static EmptySelectionModel sharedInstance() {
3335 return sharedInstance;
3417 *
3418 * @param listener the listener to remove; this is ignored
3419 * @since 1.7
3420 */
3421 public void removePropertyChangeListener(
3422 PropertyChangeListener listener) {
3423 }
3424 }
3425
3426
3427 /**
3428 * Handles creating a new <code>TreeSelectionEvent</code> with the
3429 * <code>JTree</code> as the
3430 * source and passing it off to all the listeners.
3431 * <p>
3432 * <strong>Warning:</strong>
3433 * Serialized objects of this class will not be compatible with
3434 * future Swing releases. The current serialization support is
3435 * appropriate for short term storage or RMI between applications running
3436 * the same version of Swing. As of 1.4, support for long term storage
3437 * of all JavaBeans
3438 * has been added to the <code>java.beans</code> package.
3439 * Please see {@link java.beans.XMLEncoder}.
3440 */
3441 @SuppressWarnings("serial")
3442 protected class TreeSelectionRedirector implements Serializable,
3443 TreeSelectionListener
3444 {
3445 /**
3446 * Invoked by the <code>TreeSelectionModel</code> when the
3447 * selection changes.
3448 *
3449 * @param e the <code>TreeSelectionEvent</code> generated by the
3450 * <code>TreeSelectionModel</code>
3451 */
3452 public void valueChanged(TreeSelectionEvent e) {
3453 TreeSelectionEvent newE;
3454
3455 newE = (TreeSelectionEvent)e.cloneWithSource(JTree.this);
3456 fireValueChanged(newE);
3457 }
3937
3938 if(model == null || model.isLeaf(parent.getLastPathComponent()))
3939 expandedState.remove(parent);
3940
3941 removeDescendantSelectedPaths(e);
3942 }
3943 }
3944
3945
3946 /**
3947 * <code>DynamicUtilTreeNode</code> can wrap
3948 * vectors/hashtables/arrays/strings and
3949 * create the appropriate children tree nodes as necessary. It is
3950 * dynamic in that it will only create the children as necessary.
3951 * <p>
3952 * <strong>Warning:</strong>
3953 * Serialized objects of this class will not be compatible with
3954 * future Swing releases. The current serialization support is
3955 * appropriate for short term storage or RMI between applications running
3956 * the same version of Swing. As of 1.4, support for long term storage
3957 * of all JavaBeans
3958 * has been added to the <code>java.beans</code> package.
3959 * Please see {@link java.beans.XMLEncoder}.
3960 */
3961 @SuppressWarnings("serial")
3962 public static class DynamicUtilTreeNode extends DefaultMutableTreeNode {
3963 /**
3964 * Does the this <code>JTree</code> have children?
3965 * This property is currently not implemented.
3966 */
3967 protected boolean hasChildren;
3968 /** Value to create children with. */
3969 protected Object childValue;
3970 /** Have the children been loaded yet? */
3971 protected boolean loadedChildren;
3972
3973 /**
3974 * Adds to parent all the children in <code>children</code>.
3975 * If <code>children</code> is an array or vector all of its
3976 * elements are added is children, otherwise if <code>children</code>
3977 * is a hashtable all the key/value pairs are added in the order
4173 * AccessibleContext of this JTree
4174 */
4175 @BeanProperty(bound = false)
4176 public AccessibleContext getAccessibleContext() {
4177 if (accessibleContext == null) {
4178 accessibleContext = new AccessibleJTree();
4179 }
4180 return accessibleContext;
4181 }
4182
4183 /**
4184 * This class implements accessibility support for the
4185 * <code>JTree</code> class. It provides an implementation of the
4186 * Java Accessibility API appropriate to tree user-interface elements.
4187 * <p>
4188 * <strong>Warning:</strong>
4189 * Serialized objects of this class will not be compatible with
4190 * future Swing releases. The current serialization support is
4191 * appropriate for short term storage or RMI between applications running
4192 * the same version of Swing. As of 1.4, support for long term storage
4193 * of all JavaBeans
4194 * has been added to the <code>java.beans</code> package.
4195 * Please see {@link java.beans.XMLEncoder}.
4196 */
4197 @SuppressWarnings("serial")
4198 protected class AccessibleJTree extends AccessibleJComponent
4199 implements AccessibleSelection, TreeSelectionListener,
4200 TreeModelListener, TreeExpansionListener {
4201
4202 TreePath leadSelectionPath;
4203 Accessible leadSelectionAccessible;
4204
4205 /**
4206 * Constructs {@code AccessibleJTree}
4207 */
4208 public AccessibleJTree() {
4209 // Add a tree model listener for JTree
4210 TreeModel model = JTree.this.getModel();
4211 if (model != null) {
4212 model.addTreeModelListener(this);
4213 }
|