?? synthtabbedpaneui.java
字號:
/* * @(#)SynthTabbedPaneUI.java 1.32 04/04/02 * * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package javax.swing.plaf.synth;import javax.swing.*;import javax.swing.event.*;import javax.swing.plaf.*;import javax.swing.plaf.basic.*;import javax.swing.text.View;import java.awt.*;import java.awt.event.*;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeEvent;import java.util.Vector;import java.util.Hashtable;import sun.swing.plaf.synth.SynthUI;import com.sun.java.swing.SwingUtilities2;/** * A Synth L&F implementation of TabbedPaneUI. * * @version 1.32, 04/02/04 * @author Scott Violet *//** * Looks up 'selectedTabPadInsets' from the Style, which will be additional * insets for the selected tab. */class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyChangeListener { private SynthContext tabAreaContext; private SynthContext tabContext; private SynthContext tabContentContext; private SynthStyle style; private SynthStyle tabStyle; private SynthStyle tabAreaStyle; private SynthStyle tabContentStyle; private Rectangle tabAreaBounds = new Rectangle(); public static ComponentUI createUI(JComponent c) { return new SynthTabbedPaneUI(); } private boolean scrollableTabLayoutEnabled() { return (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT); } protected void installDefaults() { updateStyle(tabPane); } private void updateStyle(JTabbedPane c) { SynthContext context = getContext(c, ENABLED); SynthStyle oldStyle = style; style = SynthLookAndFeel.updateStyle(context, this); // Add properties other than JComponent colors, Borders and // opacity settings here: if (style != oldStyle) { tabRunOverlay = style.getInt(context, "TabbedPane.tabRunOverlay", 0); textIconGap = style.getInt(context, "TabbedPane.textIconGap", 0); selectedTabPadInsets = (Insets)style.get(context, "TabbedPane.selectedTabPadInsets"); if (selectedTabPadInsets == null) { selectedTabPadInsets = new Insets(0, 0, 0, 0); } if (oldStyle != null) { uninstallKeyboardActions(); installKeyboardActions(); } } context.dispose(); if (tabContext != null) { tabContext.dispose(); } tabContext = getContext(c, Region.TABBED_PANE_TAB, ENABLED); this.tabStyle = SynthLookAndFeel.updateStyle(tabContext, this); tabInsets = tabStyle.getInsets(tabContext, null); if (tabAreaContext != null) { tabAreaContext.dispose(); } tabAreaContext = getContext(c, Region.TABBED_PANE_TAB_AREA, ENABLED); this.tabAreaStyle = SynthLookAndFeel.updateStyle(tabAreaContext, this); tabAreaInsets = tabAreaStyle.getInsets(tabAreaContext, null); if (tabContentContext != null) { tabContentContext.dispose(); } tabContentContext = getContext(c, Region.TABBED_PANE_CONTENT, ENABLED); this.tabContentStyle = SynthLookAndFeel.updateStyle(tabContentContext, this); contentBorderInsets = tabContentStyle.getInsets(tabContentContext, null); } protected void installListeners() { super.installListeners(); tabPane.addPropertyChangeListener(this); } protected void uninstallListeners() { super.uninstallListeners(); tabPane.removePropertyChangeListener(this); } protected void uninstallDefaults() { SynthContext context = getContext(tabPane, ENABLED); style.uninstallDefaults(context); context.dispose(); style = null; tabStyle.uninstallDefaults(tabContext); tabContext.dispose(); tabContext = null; tabStyle = null; tabAreaStyle.uninstallDefaults(tabAreaContext); tabAreaContext.dispose(); tabAreaContext = null; tabAreaStyle = null; tabContentStyle.uninstallDefaults(tabContentContext); tabContentContext.dispose(); tabContentContext = null; tabContentStyle = null; } public SynthContext getContext(JComponent c) { return getContext(c, getComponentState(c)); } public SynthContext getContext(JComponent c, int state) { return SynthContext.getContext(SynthContext.class, c, SynthLookAndFeel.getRegion(c),style, state); } public SynthContext getContext(JComponent c, Region subregion) { return getContext(c, subregion, getComponentState(c)); } private SynthContext getContext(JComponent c, Region subregion, int state){ SynthStyle style = null; Class klass = SynthContext.class; if (subregion == Region.TABBED_PANE_TAB) { style = tabStyle; } else if (subregion == Region.TABBED_PANE_TAB_AREA) { style = tabAreaStyle; } else if (subregion == Region.TABBED_PANE_CONTENT) { style = tabContentStyle; } return SynthContext.getContext(klass, c, subregion, style, state); } private Region getRegion(JComponent c) { return SynthLookAndFeel.getRegion(c); } private int getComponentState(JComponent c) { return SynthLookAndFeel.getComponentState(c); } protected JButton createScrollButton(int direction) { return new SynthScrollableTabButton(direction); } public void propertyChange(PropertyChangeEvent e) { if (SynthLookAndFeel.shouldUpdateStyle(e)) { updateStyle(tabPane); } } public void update(Graphics g, JComponent c) { SynthContext context = getContext(c); SynthLookAndFeel.update(context, g); context.getPainter().paintTabbedPaneBackground(context, g, 0, 0, c.getWidth(), c.getHeight()); paint(context, g); context.dispose(); } public void paintBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { context.getPainter().paintTabbedPaneBorder(context, g, x, y, w, h); } public void paint(Graphics g, JComponent c) { SynthContext context = getContext(c); paint(context, g); context.dispose(); } protected void paint(SynthContext context, Graphics g) { int selectedIndex = tabPane.getSelectedIndex(); int tabPlacement = tabPane.getTabPlacement(); ensureCurrentLayout(); // Paint tab area // If scrollable tabs are enabled, the tab area will be // painted by the scrollable tab panel instead. // if (!scrollableTabLayoutEnabled()) { // WRAP_TAB_LAYOUT Insets insets = tabPane.getInsets(); int x = insets.left; int y = insets.top; int width = tabPane.getWidth() - insets.left - insets.right; int height = tabPane.getHeight() - insets.top - insets.bottom; int size; switch(tabPlacement) { case LEFT: width = calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth); break; case RIGHT: size = calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth); x = x + width - size; width = size; break; case BOTTOM: size = calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight); y = y + height - size; height = size; break; case TOP: default: height = calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight); } tabAreaBounds.setBounds(x, y, width, height); if (g.getClipBounds().intersects(tabAreaBounds)) { paintTabArea(tabAreaContext, g, tabPlacement, selectedIndex, tabAreaBounds); } } // Paint content border paintContentBorder(tabContentContext, g, tabPlacement, selectedIndex); } protected void paintTabArea(Graphics g, int tabPlacement, int selectedIndex) { // This can be invoked from ScrollabeTabPanel Insets insets = tabPane.getInsets(); int x = insets.left; int y = insets.top;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -