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

📄 closetabbedpaneui.java

📁 eq跨平台查询工具源码 eq跨平台查询工具源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    /**     * Returns the text View object required to render stylized text (HTML) for     * the specified tab or null if no specialized text rendering is needed     * for this tab. This is provided to support html rendering inside tabs.     *     * @param tabIndex the index of the tab     * @return the text view to render the tab's text or null if no     *         specialized rendering is required     *     * @since 1.4     */    protected View getTextViewForTab(int tabIndex) {        if (htmlViews != null) {            return (View)htmlViews.elementAt(tabIndex);        }        return null;    }        protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) {        int height = 0;        View v = getTextViewForTab(tabIndex);        if (v != null) {            // html            height += (int)v.getPreferredSpan(View.Y_AXIS);        } else {            // plain text            height += fontHeight;        }        Icon icon = getIconForTab(tabIndex);        Insets tabInsets = getTabInsets(tabPlacement, tabIndex);                if (icon != null) {            height = Math.max(height, icon.getIconHeight());        }        height += tabInsets.top + tabInsets.bottom + 2;                        // TODO: CHANGED        return height;    }        protected int calculateMaxTabHeight(int tabPlacement) {        FontMetrics metrics = getFontMetrics();        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 + 2;    }        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;                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 += SwingUtilities.computeStringWidth(metrics, title);        }                // add the close button width        //width += (closeIcon.getIconWidth() + 2);        // TODO: CHANGED        return width + 15;    }        protected int calculateMaxTabWidth(int tabPlacement) {        FontMetrics metrics = getFontMetrics();        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 int calculateTabAreaHeight(int tabPlacement, int horizRunCount, int maxTabHeight) {        Insets tabAreaInsets = getTabAreaInsets(tabPlacement);        int tabRunOverlay = getTabRunOverlay(tabPlacement);        return (horizRunCount > 0?            horizRunCount * (maxTabHeight-tabRunOverlay) + tabRunOverlay +                tabAreaInsets.top + tabAreaInsets.bottom :            0);    }        protected int calculateTabAreaWidth(int tabPlacement, int vertRunCount, int maxTabWidth) {        Insets tabAreaInsets = getTabAreaInsets(tabPlacement);        int tabRunOverlay = getTabRunOverlay(tabPlacement);        return (vertRunCount > 0?            vertRunCount * (maxTabWidth-tabRunOverlay) + tabRunOverlay +                tabAreaInsets.left + tabAreaInsets.right :            0);    }        protected Insets getTabInsets(int tabPlacement, int tabIndex) {        return tabInsets;    }        protected Insets getSelectedTabPadInsets(int tabPlacement) {        rotateInsets(selectedTabPadInsets, currentPadInsets, tabPlacement);        return currentPadInsets;    }        protected Insets getTabAreaInsets(int tabPlacement) {        rotateInsets(tabAreaInsets, currentTabAreaInsets, tabPlacement);        return currentTabAreaInsets;    }        protected Insets getContentBorderInsets(int tabPlacement) {        return contentBorderInsets;    }        protected FontMetrics getFontMetrics() {        Font font = tabPane.getFont();        return tabPane.getFontMetrics(font);// Toolkit.getDefaultToolkit().getFontMetrics(font);    }            // Tab Navigation methods        protected void navigateSelectedTab(int direction) {        int tabPlacement = tabPane.getTabPlacement();        int current = tabPane.getSelectedIndex();        int tabCount = tabPane.getTabCount();        boolean leftToRight = isLeftToRight(tabPane);                // If we have no tabs then don't navigate.        if (tabCount <= 0) {            return;        }                int offset;        switch(tabPlacement) {            case NEXT:                selectNextTab(current);                break;            case PREVIOUS:                selectPreviousTab(current);                break;            case LEFT:            case RIGHT:                switch(direction) {                    case NORTH:                        selectPreviousTabInRun(current);                        break;                    case SOUTH:                        selectNextTabInRun(current);                        break;                    case WEST:                        offset = getTabRunOffset(tabPlacement, tabCount, current, false);                        selectAdjacentRunTab(tabPlacement, current, offset);                        break;                    case EAST:                        offset = getTabRunOffset(tabPlacement, tabCount, current, true);                        selectAdjacentRunTab(tabPlacement, current, offset);                        break;                    default:                }                break;            case BOTTOM:            case TOP:            default:                switch(direction) {                    case NORTH:                        offset = getTabRunOffset(tabPlacement, tabCount, current, false);                        selectAdjacentRunTab(tabPlacement, current, offset);                        break;                    case SOUTH:                        offset = getTabRunOffset(tabPlacement, tabCount, current, true);                        selectAdjacentRunTab(tabPlacement, current, offset);                        break;                    case EAST:                        if (leftToRight) {                            selectNextTabInRun(current);                        } else {                            selectPreviousTabInRun(current);                        }                        break;                    case WEST:                        if (leftToRight) {                            selectPreviousTabInRun(current);                        } else {                            selectNextTabInRun(current);                        }                        break;                    default:                }        }    }        protected void selectNextTabInRun(int current) {        int tabCount = tabPane.getTabCount();        int tabIndex = getNextTabIndexInRun(tabCount, current);                while(tabIndex != current && !tabPane.isEnabledAt(tabIndex)) {            tabIndex = getNextTabIndexInRun(tabCount, tabIndex);        }        tabPane.setSelectedIndex(tabIndex);    }        protected void selectPreviousTabInRun(int current) {        int tabCount = tabPane.getTabCount();        int tabIndex = getPreviousTabIndexInRun(tabCount, current);                while(tabIndex != current && !tabPane.isEnabledAt(tabIndex)) {            tabIndex = getPreviousTabIndexInRun(tabCount, tabIndex);        }        tabPane.setSelectedIndex(tabIndex);    }        protected void selectNextTab(int current) {        int tabIndex = getNextTabIndex(current);                while (tabIndex != current && !tabPane.isEnabledAt(tabIndex)) {            tabIndex = getNextTabIndex(tabIndex);        }        tabPane.setSelectedIndex(tabIndex);    }        protected void selectPreviousTab(int current) {        int tabIndex = getPreviousTabIndex(current);                while (tabIndex != current && !tabPane.isEnabledAt(tabIndex)) {            tabIndex = getPreviousTabIndex(tabIndex);        }        tabPane.setSelectedIndex(tabIndex);    }        protected void selectAdjacentRunTab(int tabPlacement,            int tabIndex, int offset) {        if ( runCount < 2 ) {            return;        }        int newIndex;        Rectangle r = rects[tabIndex];        switch(tabPlacement) {            case LEFT:            case RIGHT:                newIndex = getTabAtLocation(r.x + r.width/2 + offset,                        r.y + r.height/2);                break;            case BOTTOM:            case TOP:            default:                newIndex = getTabAtLocation(r.x + r.width/2,                        r.y + r.height/2 + offset);        }        if (newIndex != -1) {            while (!tabPane.isEnabledAt(newIndex) && newIndex != tabIndex) {                newIndex = getNextTabIndex(newIndex);            }            tabPane.setSelectedIndex(newIndex);        }    }        protected int getTabRunOffset(int tabPlacement, int tabCount,            int tabIndex, boolean forward) {        int run = getRunForTab(tabCount, tabIndex);        int offset;        switch(tabPlacement) {            case LEFT: {                if (run == 0) {                    offset = (forward?                        -(calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth)-maxTabWidth) :                        -maxTabWidth);                                    } else if (run == runCount - 1) {                    offset = (forward?                        maxTabWidth :                        calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth)-maxTabWidth);                } else {                    offset = (forward? maxTabWidth : -maxTabWidth);                }                break;             }            case RIGHT: {                if (run == 0) {                    offset = (forward?                        maxTabWidth :                        calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth)-maxTabWidth);                } else if (run == runCount - 1) {                    offset = (forward?                        -(calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth)-maxTabWidth) :                        -maxTabWidth);                } else {                    offset = (forward? maxTabWidth : -maxTabWidth);                }                break;            }            case BOTTOM: {                if (run == 0) {                    offset = (forward?                        maxTabHeight :                        calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight)-maxTabHeight);                } else if (run == runCount - 1) {                    offset = (forward?                        -(calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight)-maxTabHeight) :                        -maxTabHeight);                } else {                    offset = (forward? maxTabHeight : -maxTabHeight);                }                break;            }            case TOP:            default: {                if (run == 0) {                    offset = (forward?                        -(calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight)-maxTabHeight) :                        -maxTabHeight);                } else if (run == runCount - 1) {                    offset = (forward?                        maxTabHeight :                        calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight)-maxTabHeight);                } else {                    offset = (forward? maxTabHeight : -maxTabHeight);                }            }        }        return offset;    }        protected int getPreviousTabIndex(int base) {        int tabIndex = (base - 1 >= 0? base - 1 : tabPane.getTabCount() - 1);        return (tabIndex >= 0? tabIndex : 0);    }        protected int getNextTabIndex(int base) {        return (base+1)%tabPane.getTabCount();    }        protected int getNextTabIndexInRun(int tabCount, int base) {        if (runCount < 2) {            return getNextTabIndex(base);        }        int currentRun = getRunForTab(tabCount, base);        int next = getNextTabIndex(base);        if (next == tabRuns[getNextTabRun(currentRun)]) {            return tabRuns[currentRun];        }        return next;    }        protected int getPreviousTabIndexInRun(int tabCount, int base) {        if (runCount < 2) {            return getPreviousTabIndex(base);        }        int currentRun = getRunForTab(tabCount, base);        if (base == tabRuns[currentRun]) {            int previous = tabRuns[getNextTabRun(currentRun)]-1;            return (previous != -1? previous : tabCount-1);        }        return getPreviousTabIndex(base);    }        protected int getPreviousTabRun(int baseRun) {        int runIndex = (baseRun - 1 >= 0? baseRun - 1 : runCount - 1);        return (runIndex >= 0? runIndex : 0);    }        protected int getNextTabRun(int baseRun) {        return (baseRun+1)%runCount;    }        protected static void rotateInsets(Insets topInsets, Insets targetInsets, int targetPlacement) {                switch(targetPlacement) {            case LEFT:                targetInsets.top = topInsets.left;                targetInsets.left = topInsets.top;                targetInsets

⌨️ 快捷键说明

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