metaltabbedpaneui.java
来自「java jdk 1.4的源码」· Java 代码 · 共 978 行 · 第 1/3 页
JAVA
978 行
// // Paint Border // g.setColor( darkShadow ); // Paint slant g.drawLine( 1, 5, 6, 0 ); // Paint top g.drawLine( 6, 0, right, 0 ); // Paint left if ( tabIndex != firstIndex ) { g.drawLine( 0, 0, 0, bottom ); } else { g.drawLine( 0, 6, 0, bottom ); } // Paint bottom if ( tabIndex == lastIndex ) { g.drawLine( 0, bottom, right, bottom ); } g.translate( -x, -y ); } protected void paintBottomTabBorder( int tabIndex, Graphics g, int x, int y, int w, int h, int btm, int rght, boolean isSelected ) { int tabCount = tabPane.getTabCount(); int currentRun = getRunForTab( tabCount, tabIndex ); int lastIndex = lastTabInRun( tabCount, currentRun ); int firstIndex = tabRuns[ currentRun ]; boolean leftToRight = MetalUtils.isLeftToRight(tabPane); int bottom = h - 1; int right = w - 1; // // Paint Gap // if ( shouldFillGap( currentRun, tabIndex, x, y ) ) { g.translate( x, y ); if ( leftToRight ) { g.setColor( getColorForGap( currentRun, x, y ) ); g.fillRect( 1, bottom - 4, 3, 5 ); g.fillRect( 4, bottom - 1, 2, 2 ); } else { g.setColor( getColorForGap( currentRun, x + w - 1, y ) ); g.fillRect( right - 3, bottom - 3, 3, 4 ); g.fillRect( right - 5, bottom - 1, 2, 2 ); g.drawLine( right - 1, bottom - 4, right - 1, bottom - 4 ); } g.translate( -x, -y ); } g.translate( x, y ); // // Paint Border // g.setColor( darkShadow ); if ( leftToRight ) { // Paint slant g.drawLine( 1, bottom - 5, 6, bottom ); // Paint bottom g.drawLine( 6, bottom, right, bottom ); // Paint right if ( tabIndex == lastIndex ) { g.drawLine( right, 0, right, bottom ); } // Paint left if ( tabIndex != tabRuns[ runCount - 1 ] ) { g.drawLine( 0, 0, 0, bottom ); } else { g.drawLine( 0, 0, 0, bottom - 6 ); } } else { // Paint slant g.drawLine( right - 1, bottom - 5, right - 6, bottom ); // Paint bottom g.drawLine( right - 6, bottom, 0, bottom ); // Paint right if ( tabIndex != tabRuns[ runCount - 1 ] ) { // not the first tab in the last run g.drawLine( right, 0, right, bottom ); } else { // the first tab in the last run g.drawLine( right, 0, right, bottom - 6 ); } // Paint left if ( tabIndex==lastIndex ) { // last tab in run g.drawLine( 0, 0, 0, bottom ); } } // // Paint Highlight // g.setColor( isSelected ? selectHighlight : highlight ); if ( leftToRight ) { // Paint slant g.drawLine( 1, bottom - 6, 6, bottom - 1 ); // Paint left g.drawLine( 1, 0, 1, bottom - 6 ); // paint highlight in the gap on tab behind this one // on the left end (where they all line up) if ( tabIndex==firstIndex && tabIndex!=tabRuns[runCount - 1] ) { // first tab in run but not first tab in last run if (tabPane.getSelectedIndex()==tabRuns[currentRun+1]) { // tab in front of selected tab g.setColor( selectHighlight ); } else { // tab in front of normal tab g.setColor( highlight ); } g.drawLine( 1, bottom - 4, 1, bottom ); } } else { // Paint left if ( tabIndex==lastIndex ) { // last tab in run g.drawLine( 1, 0, 1, bottom - 1 ); } else { g.drawLine( 0, 0, 0, bottom - 1 ); } } g.translate( -x, -y ); } protected void paintRightTabBorder( int tabIndex, Graphics g, int x, int y, int w, int h, int btm, int rght, boolean isSelected ) { int tabCount = tabPane.getTabCount(); int currentRun = getRunForTab( tabCount, tabIndex ); int lastIndex = lastTabInRun( tabCount, currentRun ); int firstIndex = tabRuns[ currentRun ]; g.translate( x, y ); int bottom = h - 1; int right = w - 1; // // Paint part of the tab above // if ( tabIndex != firstIndex ) { g.setColor( tabPane.getSelectedIndex() == tabIndex - 1 ? tabAreaBackground : tabPane.getBackgroundAt( tabIndex - 1 ) ); g.fillRect( right - 5, 0, 5, 3 ); g.fillRect( right - 2, 3, 2, 2 ); } // // Paint Highlight // g.setColor( isSelected ? selectHighlight : highlight ); // Paint slant g.drawLine( right - 6, 1, right - 1, 6 ); // Paint top g.drawLine( 0, 1, right - 6, 1 ); // Paint left if ( !isSelected ) { g.drawLine( 0, 1, 0, bottom ); } // // Paint Border // g.setColor( darkShadow ); // Paint slant g.drawLine( right - 6, 0, right, 6 ); // Paint top g.drawLine( 0, 0, right - 6, 0 ); // Paint right if ( tabIndex != firstIndex ) { g.drawLine( right, 0, right, bottom ); } else { g.drawLine( right, 6, right, bottom ); } // Paint bottom if ( tabIndex == lastIndex ) { g.drawLine( 0, bottom, right, bottom ); } g.translate( -x, -y ); } public void update( Graphics g, JComponent c ) { if ( c.isOpaque() ) { g.setColor( tabAreaBackground ); g.fillRect( 0, 0, c.getWidth(),c.getHeight() ); } paint( g, c ); } protected void paintTabBackground( Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected ) { int slantWidth = h / 2; if ( isSelected ) { g.setColor( selectColor ); } else { g.setColor( tabPane.getBackgroundAt( tabIndex ) ); } if (MetalUtils.isLeftToRight(tabPane)) { switch ( tabPlacement ) { case LEFT: g.fillRect( x + 5, y + 1, w - 5, h - 1); g.fillRect( x + 2, y + 4, 3, h - 4 ); break; case BOTTOM: g.fillRect( x + 2, y, w - 2, h - 4 ); g.fillRect( x + 5, y + (h - 1) - 3, w - 5, 3 ); break; case RIGHT: g.fillRect( x + 1, y + 1, w - 5, h - 1); g.fillRect( x + (w - 1) - 3, y + 5, 3, h - 5 ); break; case TOP: default: g.fillRect( x + 4, y + 2, (w - 1) - 3, (h - 1) - 1 ); g.fillRect( x + 2, y + 5, 2, h - 5 ); } } else { switch ( tabPlacement ) { case LEFT: g.fillRect( x + 5, y + 1, w - 5, h - 1); g.fillRect( x + 2, y + 4, 3, h - 4 ); break; case BOTTOM: g.fillRect( x, y, w - 5, h - 1 ); g.fillRect( x + (w - 1) - 4, y, 4, h - 5); g.fillRect( x + (w - 1) - 4, y + (h - 1) - 4, 2, 2); break; case RIGHT: g.fillRect( x + 1, y + 1, w - 5, h - 1); g.fillRect( x + (w - 1) - 3, y + 5, 3, h - 5 ); break; case TOP: default: g.fillRect( x, y + 2, (w - 1) - 3, (h - 1) - 1 ); g.fillRect( x + (w - 1) - 3, y + 4, 3, h - 4 ); } } } /** * Overridden to do nothing for the Java L&F. */ protected int getTabLabelShiftX( int tabPlacement, int tabIndex, boolean isSelected ) { return 0; } /** * Overridden to do nothing for the Java L&F. */ protected int getTabLabelShiftY( int tabPlacement, int tabIndex, boolean isSelected ) { return 0; } public void paint( Graphics g, JComponent c ) { int tabPlacement = tabPane.getTabPlacement(); Insets insets = c.getInsets(); Dimension size = c.getSize(); // Paint the background for the tab area if ( tabPane.isOpaque() ) { g.setColor( c.getBackground() ); switch ( tabPlacement ) { case LEFT: g.fillRect( insets.left, insets.top, calculateTabAreaWidth( tabPlacement, runCount, maxTabWidth ), size.height - insets.bottom - insets.top ); break; case BOTTOM: int totalTabHeight = calculateTabAreaHeight( tabPlacement, runCount, maxTabHeight ); g.fillRect( insets.left, size.height - insets.bottom - totalTabHeight, size.width - insets.left - insets.right, totalTabHeight ); break; case RIGHT: int totalTabWidth = calculateTabAreaWidth( tabPlacement, runCount, maxTabWidth );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?