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

📄 basictabbedpaneui.java

📁 JAVA的一些源码 JAVA2 STANDARD EDITION DEVELOPMENT KIT 5.0
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        Rectangle selRect = selectedIndex < 0? null :                               getTabBounds(selectedIndex, calcRect);        g.setColor(lightHighlight);        // Draw unbroken line if tabs are not on TOP, OR        // selected tab is not in run adjacent to content, OR        // selected tab is not visible (SCROLL_TAB_LAYOUT)        //        if (tabPlacement != TOP || selectedIndex < 0 ||             (selRect.y + selRect.height + 1 < y) ||            (selRect.x < x || selRect.x > x + w)) {            g.drawLine(x, y, x+w-2, y);        } else {            // Break line to show visual connection to selected tab            g.drawLine(x, y, selRect.x - 1, y);            if (selRect.x + selRect.width < x + w - 2) {                g.drawLine(selRect.x + selRect.width, y,                            x+w-2, y);            } else {                g.setColor(shadow);                 g.drawLine(x+w-2, y, x+w-2, y);            }        }    }    protected void paintContentBorderLeftEdge(Graphics g, int tabPlacement,                                               int selectedIndex,                                               int x, int y, int w, int h) {         Rectangle selRect = selectedIndex < 0? null :                               getTabBounds(selectedIndex, calcRect);        g.setColor(lightHighlight);         // Draw unbroken line if tabs are not on LEFT, OR        // selected tab is not in run adjacent to content, OR        // selected tab is not visible (SCROLL_TAB_LAYOUT)        //        if (tabPlacement != LEFT || selectedIndex < 0 ||            (selRect.x + selRect.width + 1 < x) ||            (selRect.y < y || selRect.y > y + h)) {            g.drawLine(x, y, x, y+h-2);        } else {            // Break line to show visual connection to selected tab            g.drawLine(x, y, x, selRect.y - 1);            if (selRect.y + selRect.height < y + h - 2) {                g.drawLine(x, selRect.y + selRect.height,                            x, y+h-2);            }         }    }    protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement,                                               int selectedIndex,                                               int x, int y, int w, int h) {         Rectangle selRect = selectedIndex < 0? null :                               getTabBounds(selectedIndex, calcRect);        g.setColor(shadow);        // Draw unbroken line if tabs are not on BOTTOM, OR        // selected tab is not in run adjacent to content, OR        // selected tab is not visible (SCROLL_TAB_LAYOUT)        //        if (tabPlacement != BOTTOM || selectedIndex < 0 ||             (selRect.y - 1 > h) ||             (selRect.x < x || selRect.x > x + w)) {            g.drawLine(x+1, y+h-2, x+w-2, y+h-2);            g.setColor(darkShadow);            g.drawLine(x, y+h-1, x+w-1, y+h-1);        } else {            // Break line to show visual connection to selected tab            g.drawLine(x+1, y+h-2, selRect.x - 1, y+h-2);            g.setColor(darkShadow);            g.drawLine(x, y+h-1, selRect.x - 1, y+h-1);            if (selRect.x + selRect.width < x + w - 2) {                g.setColor(shadow);                g.drawLine(selRect.x + selRect.width, y+h-2, x+w-2, y+h-2);                g.setColor(darkShadow);                g.drawLine(selRect.x + selRect.width, y+h-1, x+w-1, y+h-1);            }         }    }    protected void paintContentBorderRightEdge(Graphics g, int tabPlacement,                                               int selectedIndex,                                               int x, int y, int w, int h) {        Rectangle selRect = selectedIndex < 0? null :                               getTabBounds(selectedIndex, calcRect);        g.setColor(shadow);        // Draw unbroken line if tabs are not on RIGHT, OR        // selected tab is not in run adjacent to content, OR        // selected tab is not visible (SCROLL_TAB_LAYOUT)        //        if (tabPlacement != RIGHT || selectedIndex < 0 ||             (selRect.x - 1 > w) ||             (selRect.y < y || selRect.y > y + h)) {            g.drawLine(x+w-2, y+1, x+w-2, y+h-3);            g.setColor(darkShadow);            g.drawLine(x+w-1, y, x+w-1, y+h-1);        } else {            // Break line to show visual connection to selected tab            g.drawLine(x+w-2, y+1, x+w-2, selRect.y - 1);            g.setColor(darkShadow);            g.drawLine(x+w-1, y, x+w-1, selRect.y - 1);            if (selRect.y + selRect.height < y + h - 2) {                g.setColor(shadow);                g.drawLine(x+w-2, selRect.y + selRect.height,                            x+w-2, y+h-2);                g.setColor(darkShadow);                g.drawLine(x+w-1, selRect.y + selRect.height,                            x+w-1, y+h-2);            }         }    }    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) {        return tabForCoordinate(pane, x, y, true);    }    private int tabForCoordinate(JTabbedPane pane, int x, int y,                                 boolean validateIfNecessary) {        if (validateIfNecessary) {            ensureCurrentLayout();        }        if (isRunsDirty) {            // We didn't recalculate the layout, runs and tabCount may not            // line up, bail.            return -1;        }        Point p = new Point(x, y);        if (scrollableTabLayoutEnabled()) {            translatePointToTabPanel(x, y, p);            Rectangle viewRect = tabScroller.viewport.getViewRect();            if (!viewRect.contains(p)) {                return -1;            }        }        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 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;    }// BasicTabbedPaneUI 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);    }    /**      * Returns the text View object required to render stylized text (HTML) for     * the specified tab or null if no specialized text rendering is needed

⌨️ 快捷键说明

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