⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jtree.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* JTree.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 modifyit under the terms of the GNU General Public License as published bythe 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, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package javax.swing;import java.awt.Color;import java.awt.Cursor;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Point;import java.awt.Rectangle;import java.awt.event.FocusListener;import java.beans.PropertyChangeListener;import java.io.Serializable;import java.util.Enumeration;import java.util.Hashtable;import java.util.Iterator;import java.util.Locale;import java.util.Vector;import javax.accessibility.Accessible;import javax.accessibility.AccessibleAction;import javax.accessibility.AccessibleComponent;import javax.accessibility.AccessibleContext;import javax.accessibility.AccessibleRole;import javax.accessibility.AccessibleSelection;import javax.accessibility.AccessibleState;import javax.accessibility.AccessibleStateSet;import javax.accessibility.AccessibleText;import javax.accessibility.AccessibleValue;import javax.swing.event.TreeExpansionEvent;import javax.swing.event.TreeExpansionListener;import javax.swing.event.TreeModelEvent;import javax.swing.event.TreeModelListener;import javax.swing.event.TreeSelectionEvent;import javax.swing.event.TreeSelectionListener;import javax.swing.event.TreeWillExpandListener;import javax.swing.plaf.TreeUI;import javax.swing.text.Position;import javax.swing.tree.DefaultMutableTreeNode;import javax.swing.tree.DefaultTreeModel;import javax.swing.tree.DefaultTreeSelectionModel;import javax.swing.tree.ExpandVetoException;import javax.swing.tree.TreeCellEditor;import javax.swing.tree.TreeCellRenderer;import javax.swing.tree.TreeModel;import javax.swing.tree.TreeNode;import javax.swing.tree.TreePath;import javax.swing.tree.TreeSelectionModel;public class JTree extends JComponent implements Scrollable, Accessible{  /**   * This class implements accessibility support for the JTree class. It    * provides an implementation of the Java Accessibility API appropriate    * to tree user-interface elements.   */  protected class AccessibleJTree extends JComponent.AccessibleJComponent      implements AccessibleSelection, TreeSelectionListener, TreeModelListener,      TreeExpansionListener  {        /**     * This class implements accessibility support for the JTree child. It provides      * an implementation of the Java Accessibility API appropriate to tree nodes.     */    protected class AccessibleJTreeNode extends AccessibleContext        implements Accessible, AccessibleComponent, AccessibleSelection,        AccessibleAction    {            private JTree tree;      private TreePath tp;      private Accessible acc;      private AccessibleStateSet states;      private Vector selectionList;      private Vector actionList;      private TreeModel mod;      private Cursor cursor;            /**       * Constructs an AccessibleJTreeNode       *        * @param t - the current tree       * @param p - the current path to be dealt with       * @param ap - the accessible object to use       */      public AccessibleJTreeNode(JTree t, TreePath p, Accessible ap)      {        states = new AccessibleStateSet();        selectionList = new Vector();        actionList = new Vector();        mod = tree.getModel();        cursor = JTree.this.getCursor();                        tree = t;        tp = p;        acc = ap;                // Add all the children of this path that may already be        // selected to the selection list.        TreePath[] selected = tree.getSelectionPaths();        for (int i = 0; i < selected.length; i++)          {            TreePath sel = selected[i];            if ((sel.getParentPath()).equals(tp))              selectionList.add(sel);          }                // Add all the actions available for a node to         // the action list.        actionList.add("EXPAND");        actionList.add("COLLAPSE");        actionList.add("EDIT");        actionList.add("SELECT");        actionList.add("DESELECT");      }                  /**       * Adds the specified selected item in the object to the object's       * selection.       *        * @param i - the i-th child of this node.       */      public void addAccessibleSelection(int i)      {        if (mod != null)          {            Object child = mod.getChild(tp.getLastPathComponent(), i);            if (child != null)              {                if (!states.contains(AccessibleState.MULTISELECTABLE))                  clearAccessibleSelection();                selectionList.add(child);                                  tree.addSelectionPath(tp.pathByAddingChild(child));              }          }      }            /**       * Adds the specified focus listener to receive focus events        * from this component.       *        * @param l - the new focus listener       */      public void addFocusListener(FocusListener l)      {        tree.addFocusListener(l);      }            /**       * Add a PropertyChangeListener to the listener list.       *        * @param l - the new property change listener       */      public void addPropertyChangeListener(PropertyChangeListener l)      {        // Nothing to do here.      }            /**       * Clears the selection in the object, so that nothing in the        * object is selected.       */      public void clearAccessibleSelection()      {        selectionList.clear();      }            /**       * Checks whether the specified point is within this object's        * bounds, where the point's x and y coordinates are defined to be        * relative to the coordinate system of the object.        *        * @param p - the point to check       * @return true if p is in the bounds       */      public boolean contains(Point p)      {        return getBounds().contains(p);      }            /**       * Perform the specified Action on the tree node.       *        * @param i - the i-th action to perform       * @return true if the the action was performed; else false.       */      public boolean doAccessibleAction(int i)      {        if (i >= actionList.size() || i < 0)          return false;                if (actionList.get(i).equals("EXPAND"))          tree.expandPath(tp);        else if (actionList.get(i).equals("COLLAPSE"))          tree.collapsePath(tp);        else if (actionList.get(i).equals("SELECT"))          tree.addSelectionPath(tp);        else if (actionList.get(i).equals("DESELECT"))          tree.removeSelectionPath(tp);        else if (actionList.get(i).equals("EDIT"))          tree.startEditingAtPath(tp);        else          return false;        return true;      }            /**       * Get the AccessibleAction associated with this object.       *        * @return the action       */      public AccessibleAction getAccessibleAction()      {        return this;      }            /**       * Returns the number of accessible actions available in this tree node.       *        * @return the number of actions       */      public int getAccessibleActionCount()      {        return actionList.size();      }            /**       * Return a description of the specified action of the tree node.       *        * @param i - the i-th action's description       * @return a description of the action       */      public String getAccessibleActionDescription(int i)      {        if (i < 0 || i >= actionList.size())          return (actionList.get(i)).toString();        return super.getAccessibleDescription();      }            /**       * Returns the Accessible child, if one exists, contained at the        * local coordinate Point.       *        * @param p - the point of the accessible       * @return the accessible at point p if it exists       */      public Accessible getAccessibleAt(Point p)      {        TreePath acc = tree.getClosestPathForLocation(p.x, p.y);        if (acc != null)          return new AccessibleJTreeNode(tree, acc, this);        return null;      }            /**       * Return the specified Accessible child of the object.       *        * @param i - the i-th child of the current path       * @return the child if it exists       */      public Accessible getAccessibleChild(int i)      {        if (mod != null)          {            Object child = mod.getChild(tp.getLastPathComponent(), i);            if (child != null)              return new AccessibleJTreeNode(tree, tp.pathByAddingChild(child),                                             acc);          }        return null;      }            /**       * Returns the number of accessible children in the object.       *        * @return the number of children the current node has       */      public int getAccessibleChildrenCount()      {        TreeModel mod = getModel();        if (mod != null)          return mod.getChildCount(tp.getLastPathComponent());        return 0;      }            /**       * Get the AccessibleComponent associated with this object.       *        * @return the accessible component if it is supported.       */      public AccessibleComponent getAccessibleComponent()      {        return this;      }            /**       * Get the AccessibleContext associated with this tree node.       *        * @return an instance of this class       */      public AccessibleContext getAccessibleContext()      {        return this;      }            /**       * Get the accessible description of this object.       *        * @return the accessible description       */      public String getAccessibleDescription()      {        return super.getAccessibleDescription();      }            /**       * Get the index of this object in its accessible parent.       *        * @return the index of this in the parent.       */      public int getAccessibleIndexInParent()      {        AccessibleContext parent = getAccessibleParent().getAccessibleContext();        if (parent != null)          for (int i = 0; i < parent.getAccessibleChildrenCount(); i++)            {              if ((parent.getAccessibleChild(i)).equals(this))                return i;            }        return -1;      }            /**       * Get the accessible name of this object.       *        * @return the accessible name       */      public String getAccessibleName()      {        return super.getAccessibleName();      }            /**       * Get the Accessible parent of this object.       *        * @return the accessible parent if it exists.       */      public Accessible getAccessibleParent()      {        return super.getAccessibleParent();      }            /**       * Get the role of this object.       *        * @return the accessible role       */      public AccessibleRole getAccessibleRole()      {        return AccessibleJTree.this.getAccessibleRole();      }            /**       * Get the AccessibleSelection associated with this object if one exists.       *        * @return the accessible selection for this.       */      public AccessibleSelection getAccessibleSelection()      {        return this;      }            /**       * Returns an Accessible representing the specified selected item        * in the object.       *        * @return the accessible representing a certain selected item.       */      public Accessible getAccessibleSelection(int i)      {        if (i > 0 && i < getAccessibleSelectionCount())            return new AccessibleJTreeNode(tree,                   tp.pathByAddingChild(selectionList.get(i)), acc);        return null;      }            /**       * Returns the number of items currently selected.       *        * @return the number of items selected.       */      public int getAccessibleSelectionCount()      {        return selectionList.size();      }            /**       * Get the state set of this object.       *        * @return the state set for this object       */      public AccessibleStateSet getAccessibleStateSet()      {        if (isVisible())          states.add(AccessibleState.VISIBLE);        if (tree.isCollapsed(tp))          states.add(AccessibleState.COLLAPSED);        if (tree.isEditable())          states.add(AccessibleState.EDITABLE);        if (mod != null &&             !mod.isLeaf(tp.getLastPathComponent()))          states.add(AccessibleState.EXPANDABLE);        if (tree.isExpanded(tp))          states.add(AccessibleState.EXPANDED);        if (isFocusable())          states.add(AccessibleState.FOCUSABLE);        if (hasFocus())          states.add(AccessibleState.FOCUSED);        if (tree.getSelectionModel().getSelectionMode() !=           TreeSelectionModel.SINGLE_TREE_SELECTION)          states.add(AccessibleState.MULTISELECTABLE);        if (tree.isOpaque())          states.add(AccessibleState.OPAQUE);        if (tree.isPathSelected(tp))          states.add(AccessibleState.SELECTED);        if (isShowing())          states.add(AccessibleState.SHOWING);        states.add(AccessibleState.SELECTABLE);        return states;      }            /**       * Get the AccessibleText associated with this object if one exists.       *        * @return the accessible text       */      public AccessibleText getAccessibleText()      {        return super.getAccessibleText();      }            /**       * Get the AccessibleValue associated with this object if one exists.       *        * @return the accessible value if it exists       */      public AccessibleValue getAccessibleValue()      {        return super.getAccessibleValue();      }            /**       * Get the background color of this object.       *        * @return the color of the background.       */      public Color getBackground()      {        return tree.getBackground();      }            /**       * Gets the bounds of this object in the form of a Rectangle object.       *        * @return the bounds of the current node.       */      public Rectangle getBounds()      {        return tree.getPathBounds(tp);      }            /**       * Gets the Cursor of this object.       *        * @return the cursor for the current node       */      public Cursor getCursor()      {        return cursor;      }            /**       * Gets the Font of this object.       *        * @return the font for the current node       */      public Font getFont()      {        return tree.getFont();      }            /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -