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

📄 basictreeui.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* BasicTreeUI.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 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.plaf.basic;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.Point;import java.awt.Rectangle;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ComponentAdapter;import java.awt.event.ComponentEvent;import java.awt.event.ComponentListener;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.awt.event.KeyAdapter;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.event.MouseMotionListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.util.Enumeration;import java.util.Hashtable;import javax.swing.AbstractAction;import javax.swing.Action;import javax.swing.ActionMap;import javax.swing.CellRendererPane;import javax.swing.Icon;import javax.swing.InputMap;import javax.swing.JComponent;import javax.swing.JScrollBar;import javax.swing.JScrollPane;import javax.swing.JTextField;import javax.swing.JTree;import javax.swing.KeyStroke;import javax.swing.LookAndFeel;import javax.swing.SwingUtilities;import javax.swing.Timer;import javax.swing.UIManager;import javax.swing.event.CellEditorListener;import javax.swing.event.ChangeEvent;import javax.swing.event.MouseInputListener;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.plaf.ActionMapUIResource;import javax.swing.plaf.ComponentUI;import javax.swing.plaf.InputMapUIResource;import javax.swing.plaf.TreeUI;import javax.swing.text.Caret;import javax.swing.tree.AbstractLayoutCache;import javax.swing.tree.DefaultTreeCellEditor;import javax.swing.tree.DefaultTreeCellRenderer;import javax.swing.tree.FixedHeightLayoutCache;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;/** * A delegate providing the user interface for <code>JTree</code> according to * the Basic look and feel. *  * @see javax.swing.JTree * * @author Lillian Angel (langel@redhat.com) * @author Sascha Brawer (brawer@dandelis.ch) */public class BasicTreeUI extends TreeUI{  /** Collapse Icon for the tree. */  protected transient Icon collapsedIcon;  /** Expanded Icon for the tree. */  protected transient Icon expandedIcon;  /** Distance between left margin and where vertical dashes will be drawn. */  protected int leftChildIndent;  /**   * Distance between leftChildIndent and where cell contents will be drawn.   */  protected int rightChildIndent;  /**   * Total fistance that will be indented. The sum of leftChildIndent and   * rightChildIndent .   */  protected int totalChildIndent;  /** Index of the row that was last selected. */  protected int lastSelectedRow;  /** Component that we're going to be drawing onto. */  protected JTree tree;  /** Renderer that is being used to do the actual cell drawing. */  protected transient TreeCellRenderer currentCellRenderer;  /**   * Set to true if the renderer that is currently in the tree was created by   * this instance.   */  protected boolean createdRenderer;  /** Editor for the tree. */  protected transient TreeCellEditor cellEditor;  /**   * Set to true if editor that is currently in the tree was created by this   * instance.   */  protected boolean createdCellEditor;  /**   * Set to false when editing and shouldSelectCall() returns true meaning the   * node should be selected before editing, used in completeEditing.   */  protected boolean stopEditingInCompleteEditing;  /** Used to paint the TreeCellRenderer. */  protected CellRendererPane rendererPane;  /** Size needed to completely display all the nodes. */  protected Dimension preferredSize;    /** Minimum size needed to completely display all the nodes. */  protected Dimension preferredMinSize;  /** Is the preferredSize valid? */  protected boolean validCachedPreferredSize;  /** Object responsible for handling sizing and expanded issues. */  protected AbstractLayoutCache treeState;  /** Used for minimizing the drawing of vertical lines. */  protected Hashtable drawingCache;  /**   * True if doing optimizations for a largeModel. Subclasses that don't support   * this may wish to override createLayoutCache to not return a   * FixedHeightLayoutCache instance.   */  protected boolean largeModel;  /** Responsible for telling the TreeState the size needed for a node. */  protected AbstractLayoutCache.NodeDimensions nodeDimensions;  /** Used to determine what to display. */  protected TreeModel treeModel;  /** Model maintaining the selection. */  protected TreeSelectionModel treeSelectionModel;  /**   * How much the depth should be offset to properly calculate x locations. This   * is based on whether or not the root is visible, and if the root handles are   * visible.   */  protected int depthOffset;  /**   * When editing, this will be the Component that is doing the actual editing.   */  protected Component editingComponent;  /** Path that is being edited. */  protected TreePath editingPath;  /**   * Row that is being edited. Should only be referenced if editingComponent is   * null.   */  protected int editingRow;  /** Set to true if the editor has a different size than the renderer. */  protected boolean editorHasDifferentSize;    /** The action listener for the editor's Timer. */  Timer editorTimer = new EditorUpdateTimer();  /** The new value of the node after editing. */  Object newVal;  /** The action bound to KeyStrokes. */  TreeAction action;    /** Boolean to keep track of editing. */  boolean isEditing;    /** The current path of the visible nodes in the tree. */  TreePath currentVisiblePath;    /** The gap between the icon and text. */  int gap = 4;    /** Default row height, if none was set. */  int rowHeight = 20;  /** Listeners */  private PropertyChangeListener propertyChangeListener;  private FocusListener focusListener;  private TreeSelectionListener treeSelectionListener;  private MouseListener mouseListener;  private KeyListener keyListener;  private PropertyChangeListener selectionModelPropertyChangeListener;  private ComponentListener componentListener;  CellEditorListener cellEditorListener;  private TreeExpansionListener treeExpansionListener;  private TreeModelListener treeModelListener;  /**   * Creates a new BasicTreeUI object.   */  public BasicTreeUI()  {    validCachedPreferredSize = false;    drawingCache = new Hashtable();    nodeDimensions = createNodeDimensions();    configureLayoutCache();    propertyChangeListener = createPropertyChangeListener();    focusListener = createFocusListener();    treeSelectionListener = createTreeSelectionListener();    mouseListener = createMouseListener();    keyListener = createKeyListener();    selectionModelPropertyChangeListener = createSelectionModelPropertyChangeListener();    componentListener = createComponentListener();    cellEditorListener = createCellEditorListener();    treeExpansionListener = createTreeExpansionListener();    treeModelListener = createTreeModelListener();    editingRow = -1;    lastSelectedRow = -1;  }  /**   * Returns an instance of the UI delegate for the specified component.   *    * @param c   *          the <code>JComponent</code> for which we need a UI delegate for.   * @return the <code>ComponentUI</code> for c.   */  public static ComponentUI createUI(JComponent c)  {    return new BasicTreeUI();  }  /**   * Returns the Hash color.   *    * @return the <code>Color</code> of the Hash.   */  protected Color getHashColor()  {    return UIManager.getColor("Tree.hash");  }  /**   * Sets the Hash color.   *    * @param color   *          the <code>Color</code> to set the Hash to.   */  protected void setHashColor(Color color)  {    // FIXME: Putting something in the UIDefaults map is certainly wrong.    UIManager.put("Tree.hash", color);  }  /**   * Sets the left child's indent value.   *    * @param newAmount   *          is the new indent value for the left child.   */  public void setLeftChildIndent(int newAmount)  {    leftChildIndent = newAmount;  }  /**   * Returns the indent value for the left child.   *    * @return the indent value for the left child.   */  public int getLeftChildIndent()  {    return leftChildIndent;  }  /**   * Sets the right child's indent value.   *    * @param newAmount   *          is the new indent value for the right child.   */  public void setRightChildIndent(int newAmount)  {    rightChildIndent = newAmount;  }  /**   * Returns the indent value for the right child.   *    * @return the indent value for the right child.   */  public int getRightChildIndent()  {    return rightChildIndent;  }  /**   * Sets the expanded icon.   *    * @param newG   *          is the new expanded icon.   */  public void setExpandedIcon(Icon newG)  {    expandedIcon = newG;  }  /**   * Returns the current expanded icon.   *    * @return the current expanded icon.   */  public Icon getExpandedIcon()  {    return expandedIcon;  }  /**   * Sets the collapsed icon.   *    * @param newG   *          is the new collapsed icon.   */  public void setCollapsedIcon(Icon newG)  {    collapsedIcon = newG;  }  /**   * Returns the current collapsed icon.   *    * @return the current collapsed icon.   */  public Icon getCollapsedIcon()  {    return collapsedIcon;  }  /**   * Updates the componentListener, if necessary.   *    * @param largeModel   *          sets this.largeModel to it.   */  protected void setLargeModel(boolean largeModel)  {    if (largeModel != this.largeModel)      {        tree.removeComponentListener(componentListener);        this.largeModel = largeModel;        tree.addComponentListener(componentListener);      }  }  /**   * Returns true if largeModel is set   *    * @return true if largeModel is set, otherwise false.   */  protected boolean isLargeModel()  {    return largeModel;  }  /**   * Sets the row height.   *    * @param rowHeight   *          is the height to set this.rowHeight to.   */  protected void setRowHeight(int rowHeight)  {    if (rowHeight == 0)      rowHeight = this.rowHeight;    treeState.setRowHeight(rowHeight);  }  /**   * Returns the current row height.   *    * @return current row height.   */  protected int getRowHeight()  {    return treeState.getRowHeight();  }  /**   * Sets the TreeCellRenderer to <code>tcr</code>. This invokes   * <code>updateRenderer</code>.   *    * @param tcr   *          is the new TreeCellRenderer.   */  protected void setCellRenderer(TreeCellRenderer tcr)  {    currentCellRenderer = tcr;

⌨️ 快捷键说明

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