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

📄 synthtabbedpaneui.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                //forward the event (this will set the selected index, or none at all                delegate.mousePressed(e);            }            public void mouseReleased(MouseEvent e) {                if (selectedTabIsPressed) {                    selectedTabIsPressed = false;                    //TODO need to just repaint the tab area!                    tabPane.repaint();                }                //forward the event                delegate.mouseReleased(e);                //hack: The super method *should* be setting the mouse-over property correctly                //here, but it doesn't. That is, when the mouse is released, whatever tab is below the                //released mouse should be in rollover state. But, if you select a tab and don't                //move the mouse, this doesn't happen. Hence, forwarding the event.                delegate2.mouseMoved(e);            }        };    }    @Override    protected int getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected) {        if (nudgeSelectedLabel) {            return super.getTabLabelShiftX(tabPlacement, tabIndex, isSelected);        } else {            return 0;        }    }    @Override    protected int getTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected) {        if (nudgeSelectedLabel) {            return super.getTabLabelShiftY(tabPlacement, tabIndex, isSelected);        } else {            return 0;        }    }    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();    }    protected int getBaseline(int tab) {        if (tabPane.getTabComponentAt(tab) != null ||                getTextViewForTab(tab) != null) {            return super.getBaseline(tab);        }        String title = tabPane.getTitleAt(tab);        Font font = tabContext.getStyle().getFont(tabContext);        FontMetrics metrics = getFontMetrics(font);        Icon icon = getIconForTab(tab);        textRect.setBounds(0, 0, 0, 0);        iconRect.setBounds(0, 0, 0, 0);        calcRect.setBounds(0, 0, Short.MAX_VALUE, maxTabHeight);        tabContext.getStyle().getGraphicsUtils(tabContext).layoutText(                tabContext, metrics, title, icon, SwingUtilities.CENTER,                SwingUtilities.CENTER, SwingUtilities.LEADING,                SwingUtilities.TRAILING, calcRect,                iconRect, textRect, textIconGap);        return textRect.y + metrics.getAscent() + getBaselineOffset();    }    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;        int width = tabPane.getWidth() - insets.left - insets.right;        int height = tabPane.getHeight() - insets.top - insets.bottom;        paintTabArea(tabAreaContext, g, tabPlacement, selectedIndex,                     new Rectangle(x, y, width, height));    }    protected void paintTabArea(SynthContext ss, Graphics g,                                int tabPlacement, int selectedIndex,                                Rectangle tabAreaBounds) {        Rectangle clipRect = g.getClipBounds();          //if the tab area's states should match that of the selected tab, then        //first update the selected tab's states, then set the state        //for the tab area to match        //otherwise, restore the tab area's state to ENABLED (which is the        //only supported state otherwise).        if (tabAreaStatesMatchSelectedTab && selectedIndex >= 0) {            updateTabContext(selectedIndex, true, selectedTabIsPressed,                              (getRolloverTab() == selectedIndex),                              (getFocusIndex() == selectedIndex));            ss.setComponentState(tabContext.getComponentState());        } else {            ss.setComponentState(SynthConstants.ENABLED);        }        // Paint the tab area.        SynthLookAndFeel.updateSubregion(ss, g, tabAreaBounds);        ss.getPainter().paintTabbedPaneTabAreaBackground(ss, g,             tabAreaBounds.x, tabAreaBounds.y, tabAreaBounds.width,             tabAreaBounds.height, tabPlacement);        ss.getPainter().paintTabbedPaneTabAreaBorder(ss, g, tabAreaBounds.x,             tabAreaBounds.y, tabAreaBounds.width, tabAreaBounds.height,             tabPlacement);        int tabCount = tabPane.getTabCount();        iconRect.setBounds(0, 0, 0, 0);        textRect.setBounds(0, 0, 0, 0);        // Paint tabRuns of tabs from back to front        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; j <= end; j++) {                if (rects[j].intersects(clipRect) && selectedIndex != j) {                    paintTab(tabContext, g, tabPlacement, rects, j, iconRect,                             textRect);                }            }        }        if (selectedIndex >= 0) {            if (rects[selectedIndex].intersects(clipRect)) {                paintTab(tabContext, g, tabPlacement, rects, selectedIndex,                         iconRect, textRect);            }        }    }        protected void setRolloverTab(int index) {        int oldRolloverTab = getRolloverTab();        super.setRolloverTab(index);        Rectangle r = null;                if (oldRolloverTab != index && tabAreaStatesMatchSelectedTab) {            //TODO need to just repaint the tab area!            tabPane.repaint();        } else {            if ((oldRolloverTab >= 0) && (oldRolloverTab < tabPane.getTabCount())) {                r = getTabBounds(tabPane, oldRolloverTab);                if (r != null) {                    tabPane.repaint(r);                }            }            if (index >= 0) {                r = getTabBounds(tabPane, index);                if (r != null) {                    tabPane.repaint(r);                }            }        }    }    protected void paintTab(SynthContext ss, Graphics g,                            int tabPlacement, Rectangle[] rects, int tabIndex,                             Rectangle iconRect, Rectangle textRect) {        Rectangle tabRect = rects[tabIndex];        int selectedIndex = tabPane.getSelectedIndex();        boolean isSelected = selectedIndex == tabIndex;        updateTabContext(tabIndex, isSelected, isSelected && selectedTabIsPressed,                          (getRolloverTab() == tabIndex),                           (getFocusIndex() == tabIndex));        SynthLookAndFeel.updateSubregion(ss, g, tabRect);        int x = tabRect.x;        int y = tabRect.y;        int height = tabRect.height;        int width = tabRect.width;        int placement = tabPane.getTabPlacement();        if (extendTabsToBase && runCount > 1) {            //paint this tab such that its edge closest to the base is equal to            //edge of the selected tab closest to the base. In terms of the TOP            //tab placement, this will cause the bottom of each tab to be            //painted even with the bottom of the selected tab. This is because            //in each tab placement (TOP, LEFT, BOTTOM, RIGHT) the selected tab            //is closest to the base.            if (selectedIndex >= 0) {                Rectangle r = rects[selectedIndex];                switch (placement) {                    case TOP:                        int bottomY = r.y + r.height;                        height = bottomY - tabRect.y;                        break;                    case LEFT:                        int rightX = r.x + r.width;                        width = rightX - tabRect.x;                        break;                    case BOTTOM:                        int topY = r.y;                        height = (tabRect.y + tabRect.height) - topY;                        y = topY;                        break;                    case RIGHT:                        int leftX = r.x;                        width = (tabRect.x + tabRect.width) - leftX;                        x = leftX;                        break;                }            }        }        tabContext.getPainter().paintTabbedPaneTabBackground(tabContext, g,                x, y, width, height, tabIndex, placement);

⌨️ 快捷键说明

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