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

📄 basictabbedpaneui.java

📁 JAVA 所有包
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
          case RIGHT:              nudge = tabRect.height % 2;              break;          case TOP:          default:              nudge = isSelected? -1 : 1;;        }        return nudge;    }    protected void paintFocusIndicator(Graphics g, int tabPlacement,                                       Rectangle[] rects, int tabIndex,                                        Rectangle iconRect, Rectangle textRect,                                       boolean isSelected) {        Rectangle tabRect = rects[tabIndex];        if (tabPane.hasFocus() && isSelected) {            int x, y, w, h;            g.setColor(focus);            switch(tabPlacement) {              case LEFT:                  x = tabRect.x + 3;                  y = tabRect.y + 3;                  w = tabRect.width - 5;                  h = tabRect.height - 6;                  break;              case RIGHT:                  x = tabRect.x + 2;                  y = tabRect.y + 3;                  w = tabRect.width - 5;                  h = tabRect.height - 6;                  break;              case BOTTOM:                  x = tabRect.x + 3;                  y = tabRect.y + 2;                  w = tabRect.width - 6;                  h = tabRect.height - 5;                  break;              case TOP:              default:                  x = tabRect.x + 3;                  y = tabRect.y + 3;                  w = tabRect.width - 6;                  h = tabRect.height - 5;            }            BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);        }    }    /**      * this function draws the border around each tab      * note that this function does now draw the background of the tab.      * that is done elsewhere      */    protected void paintTabBorder(Graphics g, int tabPlacement,                                  int tabIndex,                                  int x, int y, int w, int h,                                   boolean isSelected ) {        g.setColor(lightHighlight);          switch (tabPlacement) {          case LEFT:              g.drawLine(x+1, y+h-2, x+1, y+h-2); // bottom-left highlight              g.drawLine(x, y+2, x, y+h-3); // left highlight              g.drawLine(x+1, y+1, x+1, y+1); // top-left highlight              g.drawLine(x+2, y, x+w-1, y); // top highlight              g.setColor(shadow);              g.drawLine(x+2, y+h-2, x+w-1, y+h-2); // bottom shadow              g.setColor(darkShadow);              g.drawLine(x+2, y+h-1, x+w-1, y+h-1); // bottom dark shadow              break;          case RIGHT:              g.drawLine(x, y, x+w-3, y); // top highlight              g.setColor(shadow);              g.drawLine(x, y+h-2, x+w-3, y+h-2); // bottom shadow              g.drawLine(x+w-2, y+2, x+w-2, y+h-3); // right shadow              g.setColor(darkShadow);              g.drawLine(x+w-2, y+1, x+w-2, y+1); // top-right dark shadow              g.drawLine(x+w-2, y+h-2, x+w-2, y+h-2); // bottom-right dark shadow              g.drawLine(x+w-1, y+2, x+w-1, y+h-3); // right dark shadow              g.drawLine(x, y+h-1, x+w-3, y+h-1); // bottom dark shadow              break;                        case BOTTOM:              g.drawLine(x, y, x, y+h-3); // left highlight              g.drawLine(x+1, y+h-2, x+1, y+h-2); // bottom-left highlight              g.setColor(shadow);              g.drawLine(x+2, y+h-2, x+w-3, y+h-2); // bottom shadow              g.drawLine(x+w-2, y, x+w-2, y+h-3); // right shadow              g.setColor(darkShadow);              g.drawLine(x+2, y+h-1, x+w-3, y+h-1); // bottom dark shadow              g.drawLine(x+w-2, y+h-2, x+w-2, y+h-2); // bottom-right dark shadow              g.drawLine(x+w-1, y, x+w-1, y+h-3); // right dark shadow              break;          case TOP:          default:                         g.drawLine(x, y+2, x, y+h-1); // left highlight              g.drawLine(x+1, y+1, x+1, y+1); // top-left highlight              g.drawLine(x+2, y, x+w-3, y); // top highlight                            g.setColor(shadow);                g.drawLine(x+w-2, y+2, x+w-2, y+h-1); // right shadow              g.setColor(darkShadow);               g.drawLine(x+w-1, y+2, x+w-1, y+h-1); // right dark-shadow              g.drawLine(x+w-2, y+1, x+w-2, y+1); // top-right shadow        }    }    protected void paintTabBackground(Graphics g, int tabPlacement,                                      int tabIndex,                                      int x, int y, int w, int h,                                       boolean isSelected ) {        g.setColor(!isSelected || selectedColor == null?                    tabPane.getBackgroundAt(tabIndex) : selectedColor);        switch(tabPlacement) {          case LEFT:              g.fillRect(x+1, y+1, w-1, 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);              break;          case TOP:          default:              g.fillRect(x+1, y+1, w-3, h-1);        }    }    protected void paintContentBorder(Graphics g, int tabPlacement, int selectedIndex) {        int width = tabPane.getWidth();        int height = tabPane.getHeight();        Insets insets = tabPane.getInsets();        Insets tabAreaInsets = getTabAreaInsets(tabPlacement);        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);	      if (tabsOverlapBorder) {		  x -= tabAreaInsets.right;	      }              w -= (x - insets.left);              break;          case RIGHT:              w -= calculateTabAreaWidth(tabPlacement, runCount, maxTabWidth);	      if (tabsOverlapBorder) {		  w += tabAreaInsets.left;	      }              break;                      case BOTTOM:               h -= calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);	      if (tabsOverlapBorder) {		  h += tabAreaInsets.top;	      }              break;          case TOP:          default:              y += calculateTabAreaHeight(tabPlacement, runCount, maxTabHeight);	      if (tabsOverlapBorder) {		  y -= tabAreaInsets.bottom;	      }              h -= (y - insets.top);        }             if ( tabPane.getTabCount() > 0 && (contentOpaque || tabPane.isOpaque()) ) {            // Fill region behind content area            Color color = UIManager.getColor("TabbedPane.contentAreaColor");            if (color != null) {                g.setColor(color);            }            else if ( selectedColor == null || selectedIndex == -1 ) {                g.setColor(tabPane.getBackground());            }            else {                g.setColor(selectedColor);            }            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) {        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) {

⌨️ 快捷键说明

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