📄 basictabbedpaneui.java
字号:
* * @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; /** * 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; /** * Creates a new BasicTabbedPaneUI object. */ public BasicTabbedPaneUI() { super(); } /** * 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); 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() { LookAndFeel.installColorsAndFont(tabPane, "TabbedPane.background", "TabbedPane.foreground", "TabbedPane.font"); tabPane.setOpaque(false); highlight = UIManager.getColor("TabbedPane.highlight"); lightHighlight = UIManager.getColor("TabbedPane.lightHighlight"); shadow = UIManager.getColor("TabbedPane.shadow"); darkShadow = UIManager.getColor("TabbedPane.darkShadow"); focus = UIManager.getColor("TabbedPane.focus"); textIconGap = UIManager.getInt("TabbedPane.textIconGap"); tabRunOverlay = UIManager.getInt("TabbedPane.tabRunOverlay"); tabInsets = UIManager.getInsets("TabbedPane.tabbedPaneTabInsets"); selectedTabPadInsets = UIManager.getInsets("TabbedPane.tabbedPaneTabPadInsets"); tabAreaInsets = UIManager.getInsets("TabbedPane.tabbedPaneTabAreaInsets"); contentBorderInsets = UIManager.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); } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -