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

📄 synthtabbedpaneui.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        tabContext.getPainter().paintTabbedPaneTabBorder(tabContext, g,                x, y, width, height, tabIndex, placement);                if (tabPane.getTabComponentAt(tabIndex) == null) {            String title = tabPane.getTitleAt(tabIndex);            Font font = ss.getStyle().getFont(ss);            FontMetrics metrics = SwingUtilities2.getFontMetrics(tabPane, g, font);            Icon icon = getIconForTab(tabIndex);            layoutLabel(ss, tabPlacement, metrics, tabIndex, title, icon,                    tabRect, iconRect, textRect, isSelected);            paintText(ss, g, tabPlacement, font, metrics,                    tabIndex, title, textRect, isSelected);            paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);        }    }    protected void layoutLabel(SynthContext ss, int tabPlacement,                                FontMetrics metrics, int tabIndex,                               String title, Icon icon,                               Rectangle tabRect, Rectangle iconRect,                                Rectangle textRect, boolean isSelected ) {	View v = getTextViewForTab(tabIndex);	if (v != null) {	    tabPane.putClientProperty("html", v);	}        textRect.x = textRect.y = iconRect.x = iconRect.y = 0;        ss.getStyle().getGraphicsUtils(ss).layoutText(ss, metrics, title,                         icon, SwingUtilities.CENTER, SwingUtilities.CENTER,                         SwingUtilities.LEADING, SwingUtilities.TRAILING,                         tabRect, iconRect, textRect, textIconGap);	tabPane.putClientProperty("html", null);        int xNudge = getTabLabelShiftX(tabPlacement, tabIndex, isSelected);        int yNudge = getTabLabelShiftY(tabPlacement, tabIndex, isSelected);        iconRect.x += xNudge;        iconRect.y += yNudge;        textRect.x += xNudge;        textRect.y += yNudge;    }    protected void paintText(SynthContext ss,                             Graphics g, int tabPlacement,                             Font font, FontMetrics metrics, int tabIndex,                             String title, Rectangle textRect,                              boolean isSelected) {        g.setFont(font);	View v = getTextViewForTab(tabIndex);	if (v != null) {	    // html	    v.paint(g, textRect);	} else {	    // plain text            int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);            g.setColor(ss.getStyle().getColor(ss, ColorType.TEXT_FOREGROUND));            ss.getStyle().getGraphicsUtils(ss).paintText(ss, g, title,                                  textRect, mnemIndex);	}    }     protected void paintContentBorder(SynthContext ss, Graphics g,                                      int tabPlacement, int selectedIndex) {        int width = tabPane.getWidth();        int height = tabPane.getHeight();        Insets insets = tabPane.getInsets();        int x = insets.left;        int y = insets.top;        int w = width - insets.right - insets.left;        int h = height - insets.top - insets.bottom;        switch(tabPlacement) {          case LEFT:              x += calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);              w -= (x - insets.left);              break;          case RIGHT:              w -= calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);              break;                      case BOTTOM:               h -= calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);              break;          case TOP:          default:              y += calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);              h -= (y - insets.top);        }        SynthLookAndFeel.updateSubregion(ss, g, new Rectangle(x, y, w, h));        ss.getPainter().paintTabbedPaneContentBackground(ss, g, x, y,                                                           w, h);        ss.getPainter().paintTabbedPaneContentBorder(ss, g, x, y, w, h);    }             private void ensureCurrentLayout() {        if (!tabPane.isValid()) {            tabPane.validate();        } 	/* If tabPane doesn't have a peer yet, the validate() call will	 * silently fail.  We handle that by forcing a layout if tabPane	 * is still invalid.  See bug 4237677.	 */        if (!tabPane.isValid()) {            TabbedPaneLayout layout = (TabbedPaneLayout)tabPane.getLayout();            layout.calculateLayoutInfo();        }    }        protected int calculateMaxTabHeight(int tabPlacement) {        FontMetrics metrics = getFontMetrics(tabContext.getStyle().getFont(                                             tabContext));        int tabCount = tabPane.getTabCount();        int result = 0;         int fontHeight = metrics.getHeight();        for(int i = 0; i < tabCount; i++) {            result = Math.max(calculateTabHeight(tabPlacement, i, fontHeight), result);        }        return result;     }    protected int calculateTabWidth(int tabPlacement, int tabIndex,                                    FontMetrics metrics) {        Icon icon = getIconForTab(tabIndex);        Insets tabInsets = getTabInsets(tabPlacement, tabIndex);        int width = tabInsets.left + tabInsets.right + 3;        Component tabComponent = tabPane.getTabComponentAt(tabIndex);        if (tabComponent != null) {            width += tabComponent.getPreferredSize().width;        } else {            if (icon != null) {                width += icon.getIconWidth() + textIconGap;            }            View v = getTextViewForTab(tabIndex);            if (v != null) {                // html                width += (int) v.getPreferredSpan(View.X_AXIS);            } else {                // plain text                String title = tabPane.getTitleAt(tabIndex);                width += tabContext.getStyle().getGraphicsUtils(tabContext).                        computeStringWidth(tabContext, metrics.getFont(),                                metrics, title);            }        }        return width;    }    protected int calculateMaxTabWidth(int tabPlacement) {        FontMetrics metrics = getFontMetrics(tabContext.getStyle().getFont(                                     tabContext));        int tabCount = tabPane.getTabCount();        int result = 0;         for(int i = 0; i < tabCount; i++) {            result = Math.max(calculateTabWidth(tabPlacement, i, metrics),                              result);        }        return result;     }    protected Insets getTabInsets(int tabPlacement, int tabIndex) {        updateTabContext(tabIndex, false, false, false,                          (getFocusIndex() == tabIndex));        return tabInsets;    }    protected FontMetrics getFontMetrics() {        return getFontMetrics(tabContext.getStyle().getFont(tabContext));    }    protected FontMetrics getFontMetrics(Font font) {        return tabPane.getFontMetrics(font);    }    private void updateTabContext(int index, boolean selected,                                  boolean isMouseDown, boolean isMouseOver, boolean hasFocus) {        int state = 0;        if (!tabPane.isEnabled() || !tabPane.isEnabledAt(index)) {	    state |= SynthConstants.DISABLED;            if (selected) {                state |= SynthConstants.SELECTED;            }        }        else if (selected) {            state |= (SynthConstants.ENABLED | SynthConstants.SELECTED);            if (isMouseOver && UIManager.getBoolean("TabbedPane.isTabRollover")) {                state |= SynthConstants.MOUSE_OVER;            }        }        else if (isMouseOver) {            state |= (SynthConstants.ENABLED | SynthConstants.MOUSE_OVER);        }        else {            state = SynthLookAndFeel.getComponentState(tabPane);	    state &= ~SynthConstants.FOCUSED; // don't use tabbedpane focus state        }	if (hasFocus && tabPane.hasFocus()) {	    state |= SynthConstants.FOCUSED; // individual tab has focus	}        if (isMouseDown) {            state |= SynthConstants.PRESSED;        }	tabContext.setComponentState(state);    }        /**     * @inheritDoc     *      * Overridden to create a TabbedPaneLayout subclass which takes into     * account tabOverlap.     */    @Override protected LayoutManager createLayoutManager() {        if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) {            return super.createLayoutManager();        } else { /* WRAP_TAB_LAYOUT */            return new TabbedPaneLayout() {                @Override                public void calculateLayoutInfo() {                    super.calculateLayoutInfo();                    //shift all the tabs, if necessary                    if (tabOverlap != 0) {                        int tabCount = tabPane.getTabCount();                         //left-to-right/right-to-left only affects layout                        //when placement is TOP or BOTTOM                        boolean ltr = tabPane.getComponentOrientation().isLeftToRight();                        for (int i = runCount - 1; i >= 0; i--) {                            int start = tabRuns[i];                            int next = tabRuns[(i == runCount - 1)? 0 : i + 1];                            int end = (next != 0? next - 1: tabCount - 1);                            for (int j = start+1; j <= end; j++) {                                // xshift and yshift represent the amount &                                // direction to shift the tab in their                                // respective axis.                                int xshift = 0;                                int yshift = 0;                                // configure xshift and y shift based on tab                                // position and ltr/rtl                                switch (tabPane.getTabPlacement()) {                                    case JTabbedPane.TOP:                                    case JTabbedPane.BOTTOM:                                        xshift = ltr ? tabOverlap : -tabOverlap;                                        break;                                    case JTabbedPane.LEFT:                                    case JTabbedPane.RIGHT:                                        yshift = tabOverlap;                                        break;                                    default: //do nothing                                }                                rects[j].x += xshift;                                rects[j].y += yshift;                                rects[j].width += Math.abs(xshift);                                rects[j].height += Math.abs(yshift);                            }                        }                    }                }            };        }    }        private class SynthScrollableTabButton extends SynthArrowButton implements            UIResource {        public SynthScrollableTabButton(int direction) {            super(direction);        }    }}

⌨️ 快捷键说明

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