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

📄 metaltabbedpaneui.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * @(#)MetalTabbedPaneUI.java	1.40 06/02/14 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package javax.swing.plaf.metal;import javax.swing.*;import javax.swing.event.*;import java.awt.*;import java.awt.event.*;import javax.swing.plaf.*;import java.io.Serializable; import javax.swing.plaf.basic.BasicTabbedPaneUI;/** * The Metal subclass of BasicTabbedPaneUI. * <p> * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing.  As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Please see {@link java.beans.XMLEncoder}. * * @version 1.19 08/28/98 * @author Tom Santos */public class MetalTabbedPaneUI extends BasicTabbedPaneUI {    protected int minTabWidth = 40;    // Background color for unselected tabs that don't have an explicitly    // set color.    private Color unselectedBackground;    protected Color tabAreaBackground;    protected Color selectColor;    protected Color selectHighlight;    private boolean tabsOpaque = true;    // Whether or not we're using ocean. This is cached as it is used    // extensively during painting.    private boolean ocean;    // Selected border color for ocean.    private Color oceanSelectedBorderColor;    public static ComponentUI createUI( JComponent x ) {        return new MetalTabbedPaneUI();    }      protected LayoutManager createLayoutManager() {	if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) {            return super.createLayoutManager(); 	}        return new TabbedPaneLayout();    }      protected void installDefaults() {        super.installDefaults();        tabAreaBackground = UIManager.getColor("TabbedPane.tabAreaBackground");        selectColor = UIManager.getColor("TabbedPane.selected");        selectHighlight = UIManager.getColor("TabbedPane.selectHighlight");        tabsOpaque = UIManager.getBoolean("TabbedPane.tabsOpaque");        unselectedBackground = UIManager.getColor(                                         "TabbedPane.unselectedBackground");        ocean = MetalLookAndFeel.usingOcean();        if (ocean) {            oceanSelectedBorderColor = UIManager.getColor(                         "TabbedPane.borderHightlightColor");        }    }    protected void paintTabBorder( Graphics g, int tabPlacement,                                   int tabIndex, int x, int y, int w, int h,                                    boolean isSelected) {        int bottom = y + (h-1);        int right = x + (w-1);        switch ( tabPlacement ) {        case LEFT:            paintLeftTabBorder(tabIndex, g, x, y, w, h, bottom, right, isSelected);            break;        case BOTTOM:            paintBottomTabBorder(tabIndex, g, x, y, w, h, bottom, right, isSelected);            break;        case RIGHT:            paintRightTabBorder(tabIndex, g, x, y, w, h, bottom, right, isSelected);            break;        case TOP:        default:            paintTopTabBorder(tabIndex, g, x, y, w, h, bottom, right, isSelected);        }    }    protected void paintTopTabBorder( int tabIndex, Graphics g,                                       int x, int y, int w, int h,                                      int btm, int rght,                                      boolean isSelected ) {        int currentRun = getRunForTab( tabPane.getTabCount(), tabIndex );        int lastIndex = lastTabInRun( tabPane.getTabCount(), currentRun );        int firstIndex = tabRuns[ currentRun ];	boolean leftToRight = MetalUtils.isLeftToRight(tabPane);        int selectedIndex = tabPane.getSelectedIndex();        int bottom = h - 1;        int right = w - 1;        //        // Paint Gap        //        if (shouldFillGap( currentRun, tabIndex, x, y ) ) {            g.translate( x, y );	    if ( leftToRight ) {	        g.setColor( getColorForGap( currentRun, x, y + 1 ) );		g.fillRect( 1, 0, 5, 3 );		g.fillRect( 1, 3, 2, 2 );	    } else {	        g.setColor( getColorForGap( currentRun, x + w - 1, y + 1 ) );		g.fillRect( right - 5, 0, 5, 3 );		g.fillRect( right - 2, 3, 2, 2 );	    }            g.translate( -x, -y );        }        g.translate( x, y );        //        // Paint Border        //        if (ocean && isSelected) {            g.setColor(oceanSelectedBorderColor);        }        else {            g.setColor( darkShadow );        }	if ( leftToRight ) {	    // Paint slant	    g.drawLine( 1, 5, 6, 0 );	    // Paint top	    g.drawLine( 6, 0, right, 0 );	    // Paint right	    if ( tabIndex==lastIndex ) {	        // last tab in run	        g.drawLine( right, 1, right, bottom );	    }            if (ocean && tabIndex - 1 == selectedIndex &&                                currentRun == getRunForTab(                                tabPane.getTabCount(), selectedIndex)) {                g.setColor(oceanSelectedBorderColor);            }	    // Paint left	    if ( tabIndex != tabRuns[ runCount - 1 ] ) {	        // not the first tab in the last run                if (ocean && isSelected) {                    g.drawLine(0, 6, 0, bottom);                    g.setColor(darkShadow);                    g.drawLine(0, 0, 0, 5);                }                else {                    g.drawLine( 0, 0, 0, bottom );                }	    } else {	        // the first tab in the last run	        g.drawLine( 0, 6, 0, bottom );	    }	} else {	    // Paint slant	    g.drawLine( right - 1, 5, right - 6, 0 );	    // Paint top	    g.drawLine( right - 6, 0, 0, 0 );	    // Paint left	    if ( tabIndex==lastIndex ) {	        // last tab in run	        g.drawLine( 0, 1, 0, bottom );	    }            // Paint right            if (ocean && tabIndex - 1 == selectedIndex &&                                currentRun == getRunForTab(                                tabPane.getTabCount(), selectedIndex)) {                g.setColor(oceanSelectedBorderColor);                g.drawLine(right, 0, right, bottom);            }            else if (ocean && isSelected) {                g.drawLine(right, 6, right, bottom);                if (tabIndex != 0) {                    g.setColor(darkShadow);                    g.drawLine(right, 0, right, 5);                }            }            else {                if ( tabIndex != tabRuns[ runCount - 1 ] ) {                    // not the first tab in the last run                    g.drawLine( right, 0, right, bottom );                } else {                    // the first tab in the last run                    g.drawLine( right, 6, right, bottom );                }            }	}        //        // Paint Highlight        //        g.setColor( isSelected ? selectHighlight : highlight );	if ( leftToRight ) {	    // Paint slant	    g.drawLine( 1, 6, 6, 1 );	    // Paint top            g.drawLine( 6, 1, (tabIndex == lastIndex) ? right - 1 : right, 1 );	    // Paint left	    g.drawLine( 1, 6, 1, bottom );	    // paint highlight in the gap on tab behind this one	    // on the left end (where they all line up)	    if ( tabIndex==firstIndex && tabIndex!=tabRuns[runCount - 1] ) {	        //  first tab in run but not first tab in last run	        if (tabPane.getSelectedIndex()==tabRuns[currentRun+1]) {		    // tab in front of selected tab		    g.setColor( selectHighlight );		}		else {		    // tab in front of normal tab		    g.setColor( highlight );		}		g.drawLine( 1, 0, 1, 4 );	    }	} else {	    // Paint slant	    g.drawLine( right - 1, 6, right - 6, 1 );	    // Paint top	    g.drawLine( right - 6, 1, 1, 1 );	    // Paint left	    if ( tabIndex==lastIndex ) {	        // last tab in run	        g.drawLine( 1, 1, 1, bottom );	    } else {	        g.drawLine( 0, 1, 0, bottom );	    }	}        g.translate( -x, -y );    }    protected boolean shouldFillGap( int currentRun, int tabIndex, int x, int y ) {        boolean result = false;        if (!tabsOpaque) {            return false;        }                if ( currentRun == runCount - 2 ) {  // If it's the second to last row.            Rectangle lastTabBounds = getTabBounds( tabPane, tabPane.getTabCount() - 1 );	    Rectangle tabBounds = getTabBounds( tabPane, tabIndex );            if (MetalUtils.isLeftToRight(tabPane)) {	        int lastTabRight = lastTabBounds.x + lastTabBounds.width - 1;		// is the right edge of the last tab to the right		// of the left edge of the current tab?		if ( lastTabRight > tabBounds.x + 2 ) {		    return true;		}	    } else {	        int lastTabLeft = lastTabBounds.x;		int currentTabRight = tabBounds.x + tabBounds.width - 1;		// is the left edge of the last tab to the left		// of the right edge of the current tab?		if ( lastTabLeft < currentTabRight - 2 ) {		    return true;		}            }        } else {	    // fill in gap for all other rows except last row            result = currentRun != runCount - 1;        }        return result;    }    protected Color getColorForGap( int currentRun, int x, int y ) {        final int shadowWidth = 4;        int selectedIndex = tabPane.getSelectedIndex();        int startIndex = tabRuns[ currentRun + 1 ];        int endIndex = lastTabInRun( tabPane.getTabCount(), currentRun + 1 );        int tabOverGap = -1;        // Check each tab in the row that is 'on top' of this row        for ( int i = startIndex; i <= endIndex; ++i ) {            Rectangle tabBounds = getTabBounds( tabPane, i );            int tabLeft = tabBounds.x;            int tabRight = (tabBounds.x + tabBounds.width) - 1;            // Check to see if this tab is over the gap	    if ( MetalUtils.isLeftToRight(tabPane) ) {                if ( tabLeft <= x && tabRight - shadowWidth > x ) {                    return selectedIndex == i ? selectColor : getUnselectedBackgroundAt( i );                }            }            else {	        if ( tabLeft + shadowWidth < x && tabRight >= x ) {                    return selectedIndex == i ? selectColor : getUnselectedBackgroundAt( i );                }            }        }        return tabPane.getBackground();    }    protected void paintLeftTabBorder( int tabIndex, Graphics g,                                        int x, int y, int w, int h,                                       int btm, int rght,                                       boolean isSelected ) {        int tabCount = tabPane.getTabCount();        int currentRun = getRunForTab( tabCount, tabIndex );        int lastIndex = lastTabInRun( tabCount, currentRun );        int firstIndex = tabRuns[ currentRun ];        g.translate( x, y );        int bottom = h - 1;        int right = w - 1;        //        // Paint part of the tab above        //        if ( tabIndex != firstIndex && tabsOpaque ) {            g.setColor( tabPane.getSelectedIndex() == tabIndex - 1 ?                        selectColor :                        getUnselectedBackgroundAt( tabIndex - 1 ) );            g.fillRect( 2, 0, 4, 3 );            g.drawLine( 2, 3, 2, 3 );        }        //        // Paint Highlight        //        if (ocean) {            g.setColor(isSelected ? selectHighlight :                       MetalLookAndFeel.getWhite());        }        else {            g.setColor( isSelected ? selectHighlight : highlight );        }        // Paint slant        g.drawLine( 1, 6, 6, 1 );        // Paint left        g.drawLine( 1, 6, 1, bottom );        // Paint top        g.drawLine( 6, 1, right, 1 );        if ( tabIndex != firstIndex ) {            if (tabPane.getSelectedIndex() == tabIndex - 1) {                g.setColor(selectHighlight);            } else {                g.setColor(ocean ? MetalLookAndFeel.getWhite() : highlight);            }            g.drawLine( 1, 0, 1, 4 );        }        //        // Paint Border        //        if (ocean) {            if (isSelected) {                g.setColor(oceanSelectedBorderColor);            }            else {                g.setColor( darkShadow );            }        }        else {

⌨️ 快捷键说明

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