basictabbedpaneui.java

来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 2,001 行 · 第 1/5 页

JAVA
2,001
字号
       * rectangles for the JTabbedPane in the panel.       *       * @param g The Graphics object to paint with.       * @param c The JComponent to paint.       */      public void paint(Graphics g, JComponent c)      {        paintTabArea(g, tabPane.getTabPlacement(), tabPane.getSelectedIndex());      }    }    /**     * This method overrides the updateUI method. It makes the default UI for     * this ScrollingPanel to be  a ScrollingPanelUI.     */    public void updateUI()    {      setUI((PanelUI) new ScrollingPanelUI());    }  }  /**   * This is a helper class that paints the panel that paints tabs. This   * custom JViewport is used so that the tabs painted in the panel will be   * clipped. This class implements UIResource so tabs are not added when   * this objects of this class are added to the  JTabbedPane.   */  private class ScrollingViewport extends JViewport implements UIResource  {    // TODO: Maybe remove this inner class.  }  /**   * This is a helper class that implements UIResource so it is not added as a   * tab when an object of this class is added to the JTabbedPane.   */  private class ScrollingButton extends BasicArrowButton implements UIResource  {    /**     * Creates a ScrollingButton given the direction.     *     * @param dir The direction to point in.     */    public ScrollingButton(int dir)    {      super(dir);    }  }  /** The button that increments the current scroll location.   * This is package-private to avoid an accessor method.  */  transient ScrollingButton incrButton;  /** The button that decrements the current scroll location.   * This is package-private to avoid an accessor method.  */  transient ScrollingButton decrButton;  /** The viewport used to display the tabs.   * This is package-private to avoid an accessor method.  */  transient ScrollingViewport viewport;  /** The panel inside the viewport that paints the tabs.   * This is package-private to avoid an accessor method.  */  transient ScrollingPanel panel;  /** The starting visible tab in the run in SCROLL_TAB_MODE.   * This is package-private to avoid an accessor method.  */  transient int currentScrollLocation;  /** A reusable rectangle. */  protected Rectangle calcRect;  /** An array of Rectangles keeping track of the tabs' area and position. */  protected Rectangle[] rects;  /** The insets around the content area. */  protected Insets contentBorderInsets;  /** The extra insets around the selected tab. */  protected Insets selectedTabPadInsets;  /** The insets around the tab area. */  protected Insets tabAreaInsets;  /** The insets around each and every tab. */  protected Insets tabInsets;  /**   * The outer bottom and right edge color for both the tab and content   * border.   */  protected Color darkShadow;  /** The color of the focus outline on the selected tab. */  protected Color focus;  /** FIXME: find a use for this. */  protected Color highlight;  /** The top and left edge color for both the tab and content border. */  protected Color lightHighlight;  /** The inner bottom and right edge color for the tab and content border. */  protected Color shadow;  /** The maximum tab height. */  protected int maxTabHeight;  /** The maximum tab width. */  protected int maxTabWidth;  /** The number of runs in the JTabbedPane. */  protected int runCount;  /** The index of the run that the selected index is in. */  protected int selectedRun;  /** The amount of space each run overlaps the previous by. */  protected int tabRunOverlay;  /** The gap between text and label */  protected int textIconGap;  // Keeps track of tab runs.  // The organization of this array is as follows (lots of experimentation to  // figure this out)  // index 0 = furthest away from the component area (aka outer run)  // index 1 = closest to component area (aka selected run)  // index > 1 = listed in order leading from selected run to outer run.  // each int in the array is the tab index + 1 (counting starts at 1)  // for the last tab in the run. (same as the rects array)  /** This array keeps track of which tabs are in which run. See above. */  protected int[] tabRuns;  /**   * Indicates if the layout of the tab runs is ok or not. This is package   * private to avoid a synthetic accessor method.   */  boolean tabRunsDirty;  /**   * This is the keystroke for moving down.   *   * @deprecated 1.3   */  protected KeyStroke downKey;  /**   * This is the keystroke for moving left.   *   * @deprecated 1.3   */  protected KeyStroke leftKey;  /**   * This is the keystroke for moving right.   *   * @deprecated 1.3   */  protected KeyStroke rightKey;  /**   * This is the keystroke for moving up.   *   * @deprecated 1.3   */  protected KeyStroke upKey;  /** The listener that listens for focus events. */  protected FocusListener focusListener;  /** The listener that listens for mouse events. */  protected MouseListener mouseListener;  /** The listener that listens for property change events. */  protected PropertyChangeListener propertyChangeListener;  /** The listener that listens for change events. */  protected ChangeListener tabChangeListener;  /** The tab pane that this UI paints. */  protected JTabbedPane tabPane;  /** The current layout manager for the tabPane.   * This is package-private to avoid an accessor method.  */  transient LayoutManager layoutManager;  /** The rectangle that describes the tab area's position and size.   * This is package-private to avoid an accessor method.  */  transient Rectangle tabAreaRect;  /** The rectangle that describes the content area's position and   * size.  This is package-private to avoid an accessor method.  */  transient Rectangle contentRect;  /**   * The index over which the mouse is currently moving.   */  private int rolloverTab;  /**   * Determines if tabs are painted opaque or not. This can be adjusted using   * the UIManager property 'TabbedPane.tabsOpaque'.   */  private boolean tabsOpaque;  /**   * Creates a new BasicTabbedPaneUI object.   */  public BasicTabbedPaneUI()  {    super();    rects = new Rectangle[0];    tabRuns = new int[10];  }  /**   * This method creates a ScrollingButton that  points in the appropriate   * direction for an increasing button.   * This is package-private to avoid an accessor method.   *   * @return The increase ScrollingButton.   */  ScrollingButton createIncreaseButton()  {    if (incrButton == null)      incrButton = new ScrollingButton(SwingConstants.NORTH);    if (tabPane.getTabPlacement() == SwingConstants.TOP        || tabPane.getTabPlacement() == SwingConstants.BOTTOM)      incrButton.setDirection(SwingConstants.EAST);    else      incrButton.setDirection(SwingConstants.SOUTH);    return incrButton;  }  /**   * This method creates a ScrollingButton that points in the appropriate   * direction for a decreasing button.   * This is package-private to avoid an accessor method.   *   * @return The decrease ScrollingButton.   */  ScrollingButton createDecreaseButton()  {    if (decrButton == null)      decrButton = new ScrollingButton(SwingConstants.SOUTH);    if (tabPane.getTabPlacement() == SwingConstants.TOP        || tabPane.getTabPlacement() == SwingConstants.BOTTOM)      decrButton.setDirection(SwingConstants.WEST);    else      decrButton.setDirection(SwingConstants.NORTH);    return decrButton;  }  /**   * This method finds the point to set the view  position at given the index   * of a tab. The tab will be the first visible tab in the run.   * This is package-private to avoid an accessor method.   *   * @param index The index of the first visible tab.   *   * @return The position of the first visible tab.   */  Point findPointForIndex(int index)  {    int tabPlacement = tabPane.getTabPlacement();    int selectedIndex = tabPane.getSelectedIndex();    Insets insets = getSelectedTabPadInsets(tabPlacement);    int w = 0;    int h = 0;    if (tabPlacement == TOP || tabPlacement == BOTTOM)      {        if (index > 0)          {            w += rects[index - 1].x + rects[index - 1].width;            if (index > selectedIndex)              w -= insets.left + insets.right;          }      }    else      {        if (index > 0)          {            h += rects[index - 1].y + rects[index - 1].height;            if (index > selectedIndex)              h -= insets.top + insets.bottom;          }      }    Point p = new Point(w, h);    return p;  }  /**   * This method creates a new BasicTabbedPaneUI.   *   * @param c The JComponent to create a UI for.   *   * @return A new BasicTabbedPaneUI.   */  public static ComponentUI createUI(JComponent c)  {    return new BasicTabbedPaneUI();  }  /**   * This method installs the UI for the given JComponent.   *   * @param c The JComponent to install the UI for.   */  public void installUI(JComponent c)  {    super.installUI(c);    if (c instanceof JTabbedPane)      {        tabPane = (JTabbedPane) c;                installComponents();        installDefaults();        installListeners();        installKeyboardActions();                layoutManager = createLayoutManager();        tabPane.setLayout(layoutManager);      }  }  /**   * This method uninstalls the UI for the  given JComponent.   *   * @param c The JComponent to uninstall the UI for.   */  public void uninstallUI(JComponent c)  {    layoutManager = null;    uninstallKeyboardActions();    uninstallListeners();    uninstallDefaults();    uninstallComponents();    tabPane = null;  }  /**   * This method creates the appropriate layout manager for the JTabbedPane's   * current tab layout policy. If the tab layout policy is   * SCROLL_TAB_LAYOUT, then all the associated components that need to be   * created will be done so now.   *   * @return A layout manager given the tab layout policy.   */  protected LayoutManager createLayoutManager()  {    if (tabPane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT)      return new TabbedPaneLayout();    else      {        incrButton = createIncreaseButton();        decrButton = createDecreaseButton();        viewport = new ScrollingViewport();        viewport.setLayout(null);        panel = new ScrollingPanel();        viewport.setView(panel);        tabPane.add(incrButton);        tabPane.add(decrButton);        tabPane.add(viewport);        currentScrollLocation = 0;        decrButton.setEnabled(false);        panel.addMouseListener(mouseListener);        incrButton.addMouseListener(mouseListener);        decrButton.addMouseListener(mouseListener);        viewport.setBackground(Color.LIGHT_GRAY);        return new TabbedPaneScrollLayout();      }  }  /**   * This method installs components for this JTabbedPane.   */  protected void installComponents()  {    // Nothing to be done.  }  /**   * This method uninstalls components for this JTabbedPane.   */  protected void uninstallComponents()  {    // Nothing to be done.  }  /**   * This method installs defaults for the Look and Feel.   */  protected void installDefaults()

⌨️ 快捷键说明

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