basictabbedpaneui.java

来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 2,129 行 · 第 1/5 页

JAVA
2,129
字号
  /**   * 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. */  private transient LayoutManager layoutManager;  /** The rectangle that describes the tab area's position and size. */  private transient Rectangle tabAreaRect;  /** The rectangle that describes the content area's position and size. */  private transient Rectangle contentRect;  /**   * Creates a new BasicTabbedPaneUI object.   */  public BasicTabbedPaneUI()  {    super();  }  /**   * This method creates a ScrollingButton that  points in the appropriate   * direction for an increasing button.   *   * @return The increase ScrollingButton.   */  private 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.   *   * @return The decrease ScrollingButton.   */  private 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.   *   * @param index The index of the first visible tab.   *   * @return The position of the first visible tab.   */  private 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);	tabPane.layout();      }  }  /**   * 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()  {    UIDefaults defaults = UIManager.getLookAndFeelDefaults();    tabPane.setFont(defaults.getFont("TabbedPane.font"));    tabPane.setForeground(defaults.getColor("TabbedPane.foreground"));    tabPane.setBackground(defaults.getColor("TabbedPane.background"));    tabPane.setOpaque(true);    highlight = defaults.getColor("TabbedPane.highlight");    lightHighlight = defaults.getColor("TabbedPane.lightHighlight");    shadow = defaults.getColor("TabbedPane.shadow");    darkShadow = defaults.getColor("TabbedPane.darkShadow");    focus = defaults.getColor("TabbedPane.focus");    textIconGap = defaults.getInt("TabbedPane.textIconGap");    tabRunOverlay = defaults.getInt("TabbedPane.tabRunOverlay");    tabInsets = defaults.getInsets("TabbedPane.tabbedPaneTabInsets");    selectedTabPadInsets = defaults.getInsets("TabbedPane.tabbedPaneTabPadInsets");    tabAreaInsets = defaults.getInsets("TabbedPane.tabbedPaneTabAreaInsets");    contentBorderInsets = defaults.getInsets("TabbedPane.tabbedPaneContentBorderInsets");    calcRect = new Rectangle();    tabRuns = new int[10];    tabAreaRect = new Rectangle();    contentRect = new Rectangle();  }  /**   * This method uninstalls defaults for the Look and Feel.   */  protected void uninstallDefaults()  {    calcRect = null;    tabAreaRect = null;    contentRect = null;    tabRuns = null;    contentBorderInsets = null;    tabAreaInsets = null;    selectedTabPadInsets = null;    tabInsets = null;    focus = null;    darkShadow = null;    shadow = null;    lightHighlight = null;    highlight = null;    tabPane.setBackground(null);    tabPane.setForeground(null);    tabPane.setFont(null);  }  /**   * This method creates and installs the listeners for this UI.   */  protected void installListeners()  {    mouseListener = createMouseListener();    tabChangeListener = createChangeListener();    propertyChangeListener = createPropertyChangeListener();    focusListener = createFocusListener();    tabPane.addMouseListener(mouseListener);    tabPane.addChangeListener(tabChangeListener);    tabPane.addPropertyChangeListener(propertyChangeListener);    tabPane.addFocusListener(focusListener);  }  /**   * This method removes and nulls the listeners for this UI.   */  protected void uninstallListeners()  {    tabPane.removeFocusListener(focusListener);    tabPane.removePropertyChangeListener(propertyChangeListener);    tabPane.removeChangeListener(tabChangeListener);    tabPane.removeMouseListener(mouseListener);    focusListener = null;    propertyChangeListener = null;    tabChangeListener = null;    mouseListener = null;  }  /**   * This method creates a new MouseListener.   *   * @return A new MouseListener.   */  protected MouseListener createMouseListener()  {    return new MouseHandler();  }  /**   * This method creates a new FocusListener.   *   * @return A new FocusListener.   */  protected FocusListener createFocusListener()  {    return new FocusHandler();  }  /**   * This method creates a new ChangeListener.   *   * @return A new ChangeListener.   */  protected ChangeListener createChangeListener()  {    return new TabSelectionHandler();  }  /**   * This method creates a new PropertyChangeListener.   *   * @return A new PropertyChangeListener.   */  protected PropertyChangeListener createPropertyChangeListener()  {    return new PropertyChangeHandler();  }  /**   * This method installs keyboard actions for the JTabbedPane.   */  protected void installKeyboardActions()  {    // FIXME: Implement.  }  /**   * This method uninstalls keyboard actions for the JTabbedPane.   */  protected void uninstallKeyboardActions()  {    // FIXME: Implement.  }  /**   * This method returns the preferred size of the JTabbedPane.   *   * @param c The JComponent to find a size for.   *   * @return The preferred size.   */  public Dimension getPreferredSize(JComponent c)  {    return layoutManager.preferredLayoutSize(tabPane);  }  /**   * This method returns the minimum size of the JTabbedPane.   *   * @param c The JComponent to find a size for.   *   * @return The minimum size.   */  public Dimension getMinimumSize(JComponent c)  {    return layoutManager.minimumLayoutSize(tabPane);  }  /**   * This method returns the maximum size of the JTabbedPane.   *   * @param c The JComponent to find a size for.   *   * @return The maximum size.   */  public Dimension getMaximumSize(JComponent c)  {    return getPreferredSize(c);  }  /**   * This method paints the JTabbedPane.   *   * @param g The Graphics object to paint with.   * @param c The JComponent to paint.   */  public void paint(Graphics g, JComponent c)  {    if (tabPane.getTabCount() == 0)      return;    if (tabPane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT)      paintTabArea(g, tabPane.getTabPlacement(), tabPane.getSelectedIndex());    paintContentBorder(g, tabPane.getTabPlacement(), tabPane.getSelectedIndex());  }  /**   * This method paints the tab area. This includes painting the rectangles

⌨️ 快捷键说明

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