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

📄 closetabbedpaneui.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                if (isSelected) {            g.setColor(activeColor);        } else {            g.setColor(unselectedBackground);        }                switch(tabPlacement) {                        case LEFT:                g.fillRect(x+1, y+1, w-2, h-3);                break;            case RIGHT:                g.fillRect(x, y+1, w-2, h-3);                break;            case BOTTOM:                g.fillRect(x+1, y, w-3, h-1);                g.fillRect(x+w-3, y, 3, h-2);                break;            case TOP:            default:                g.fillRect(x+1, y+1, w-3, h-1);                g.fillRect(x+w-3, y+1, 2, h-2);                        }            }        protected void paintContentBorder(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);        }        // Fill region behind content area        if (unselectedBackground == null) {            g.setColor(tabPane.getBackground());        } else {            g.setColor(unselectedBackground);        }                g.fillRect(x,y,w,h);                paintContentBorderTopEdge(g, tabPlacement, selectedIndex, x, y, w, h);        paintContentBorderLeftEdge(g, tabPlacement, selectedIndex, x, y, w, h);        paintContentBorderBottomEdge(g, tabPlacement, selectedIndex, x, y, w, h);        paintContentBorderRightEdge(g, tabPlacement, selectedIndex, x, y, w, h);            }    protected void paintContentBorderTopEdge(Graphics g,            int tabPlacement,            int selectedIndex,            int x, int y, int w, int h) {                // paint the far edges        g.setColor(darkShadow);        g.drawLine(x, y, x+w-2, y);        if (selectedIndex == -1) {            return;        }                if (tabPlacement == TOP) {            Rectangle rect = rects[selectedIndex];            g.setColor(activeColor);            g.drawLine(rect.x+1, y, rect.x + rect.width - 2, y);        }    }        protected void paintContentBorderBottomEdge(Graphics g,            int tabPlacement,            int selectedIndex,            int x, int y, int w, int h) {                // TODO: CHANGED                // paint the far edges        g.setColor(darkShadow);        g.drawLine(x, y+h-1, x+w, y+h-1);                if (selectedIndex == -1) {            return;        }                if (tabPlacement == BOTTOM) {            Rectangle rect = rects[selectedIndex];            g.setColor(activeColor);            g.drawLine(rect.x+1, y+h-1,                        rect.x + rect.width - 2, y+h-1);        }    }        protected void paintContentBorderLeftEdge(Graphics g, int tabPlacement,            int selectedIndex,            int x, int y, int w, int h) {                g.setColor(controlShadow);        g.drawLine(x, y, x, y+h-2);    }        protected void paintContentBorderRightEdge(Graphics g, int tabPlacement,            int selectedIndex,            int x, int y, int w, int h) {                g.setColor(controlShadow);        g.drawLine(x+w-1, y, x+w-1, y+h-1);            }        private boolean isLeftToRight( Component c ) {        return c.getComponentOrientation().isLeftToRight();    }        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();        }    }            // TabbedPaneUI methods        /**     * Returns the bounds of the specified tab index.  The bounds are     * with respect to the JTabbedPane's coordinate space.     */    public Rectangle getTabBounds(JTabbedPane pane, int i) {        ensureCurrentLayout();        Rectangle tabRect = new Rectangle();        return getTabBounds(i, tabRect);    }        public int getTabRunCount(JTabbedPane pane) {        ensureCurrentLayout();        return runCount;    }        /**     * Returns the tab index which intersects the specified point     * in the JTabbedPane's coordinate space.     */    public int tabForCoordinate(JTabbedPane pane, int x, int y) {        ensureCurrentLayout();        Point p = new Point(x, y);                if (scrollableTabLayoutEnabled()) {            translatePointToTabPanel(x, y, p);        }        int tabCount = tabPane.getTabCount();        for (int i = 0; i < tabCount; i++) {            if (rects[i].contains(p.x, p.y)) {                return i;            }        }        return -1;    }        /**     * Returns the bounds of the specified tab in the coordinate space     * of the JTabbedPane component.  This is required because the tab rects     * are by default defined in the coordinate space of the component where     * they are rendered, which could be the JTabbedPane     * (for WRAP_TAB_LAYOUT) or a ScrollableTabPanel (SCROLL_TAB_LAYOUT).     * This method should be used whenever the tab rectangle must be relative     * to the JTabbedPane itself and the result should be placed in a     * designated Rectangle object (rather than instantiating and returning     * a new Rectangle each time). The tab index parameter must be a valid     * tabbed pane tab index (0 to tab count - 1, inclusive).  The destination     * rectangle parameter must be a valid <code>Rectangle</code> instance.     * The handling of invalid parameters is unspecified.     *     * @param tabIndex the index of the tab     * @param dest the rectangle where the result should be placed     * @return the resulting rectangle     *     * @since 1.4     */    protected Rectangle getTabBounds(int tabIndex, Rectangle dest) {        dest.width = rects[tabIndex].width;        dest.height = rects[tabIndex].height;                if (scrollableTabLayoutEnabled()) { // SCROLL_TAB_LAYOUT            // Need to translate coordinates based on viewport location &            // view position            Point vpp = tabScroller.viewport.getLocation();            Point viewp = tabScroller.viewport.getViewPosition();            dest.x = rects[tabIndex].x + vpp.x - viewp.x;            dest.y = rects[tabIndex].y + vpp.y - viewp.y;                    } else { // WRAP_TAB_LAYOUT            dest.x = rects[tabIndex].x;            dest.y = rects[tabIndex].y;        }        return dest;    }        /**     * Returns the tab index which intersects the specified point     * in the coordinate space of the component where the     * tabs are actually rendered, which could be the JTabbedPane     * (for WRAP_TAB_LAYOUT) or a ScrollableTabPanel (SCROLL_TAB_LAYOUT).     */    private int getTabAtLocation(int x, int y) {        ensureCurrentLayout();                int tabCount = tabPane.getTabCount();        for (int i = 0; i < tabCount; i++) {            if (rects[i].contains(x, y)) {                return i;            }        }        return -1;    }        /**     * Returns the index of the tab closest to the passed in location, note     * that the returned tab may not contain the location x,y.     */    private int getClosestTab(int x, int y) {        int min = 0;        int tabCount = Math.min(rects.length, tabPane.getTabCount());        int max = tabCount;        int tabPlacement = tabPane.getTabPlacement();        boolean useX = (tabPlacement == TOP || tabPlacement == BOTTOM);        int want = (useX) ? x : y;                while (min != max) {            int current = (max + min) / 2;            int minLoc;            int maxLoc;                        if (useX) {                minLoc = rects[current].x;                maxLoc = minLoc + rects[current].width;            } else {                minLoc = rects[current].y;                maxLoc = minLoc + rects[current].height;            }            if (want < minLoc) {                max = current;                if (min == max) {                    return Math.max(0, current - 1);                }            } else if (want >= maxLoc) {                min = current;                if (max - min <= 1) {                    return Math.max(current + 1, tabCount - 1);                }            } else {                return current;            }        }        return min;    }        /**     * Returns a point which is translated from the specified point in the     * JTabbedPane's coordinate space to the coordinate space of the     * ScrollableTabPanel.  This is used for SCROLL_TAB_LAYOUT ONLY.     */    private Point translatePointToTabPanel(int srcx, int srcy, Point dest) {        Point vpp = tabScroller.viewport.getLocation();        Point viewp = tabScroller.viewport.getViewPosition();        dest.x = srcx + vpp.x + viewp.x;        dest.y = srcy + vpp.y + viewp.y;        return dest;    }        // CloseTabbedPaneUI methods        protected Component getVisibleComponent() {        return visibleComponent;    }        protected void setVisibleComponent(Component component) {        if (visibleComponent != null && visibleComponent != component &&                visibleComponent.getParent() == tabPane) {            visibleComponent.setVisible(false);        }        if (component != null && !component.isVisible()) {            component.setVisible(true);        }        visibleComponent = component;    }        protected void assureRectsCreated(int tabCount) {        int rectArrayLen = rects.length;        if (tabCount != rectArrayLen ) {            Rectangle[] tempRectArray = new Rectangle[tabCount];            System.arraycopy(rects, 0, tempRectArray, 0,                    Math.min(rectArrayLen, tabCount));            rects = tempRectArray;            for (int rectIndex = rectArrayLen; rectIndex < tabCount; rectIndex++) {                rects[rectIndex] = new Rectangle();            }        }            }        protected void expandTabRunsArray() {        int rectLen = tabRuns.length;        int[] newArray = new int[rectLen+10];        System.arraycopy(tabRuns, 0, newArray, 0, runCount);        tabRuns = newArray;    }        protected int getRunForTab(int tabCount, int tabIndex) {        for (int i = 0; i < runCount; i++) {            int first = tabRuns[i];            int last = lastTabInRun(tabCount, i);            if (tabIndex >= first && tabIndex <= last) {                return i;            }        }        return 0;    }        protected int lastTabInRun(int tabCount, int run) {        if (runCount == 1) {            return tabCount - 1;        }        int nextRun = (run == runCount - 1? 0 : run + 1);        if (tabRuns[nextRun] == 0) {            return tabCount - 1;        }        return tabRuns[nextRun]-1;    }        protected int getTabRunOverlay(int tabPlacement) {        return tabRunOverlay;    }        protected int getTabRunIndent(int tabPlacement, int run) {        return 0;    }        protected boolean shouldPadTabRun(int tabPlacement, int run) {        return runCount > 1;    }        protected boolean shouldRotateTabRuns(int tabPlacement) {        return true;    }        protected Icon getIconForTab(int tabIndex) {        return (!tabPane.isEnabled() || !tabPane.isEnabledAt(tabIndex))?            tabPane.getDisabledIconAt(tabIndex) : tabPane.getIconAt(tabIndex);    }    

⌨️ 快捷键说明

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