1 19 20 package org.netbeans.swing.tabcontrol.plaf; 21 22 import java.awt.Color ; 23 import java.awt.Component ; 24 import java.awt.Dimension ; 25 import java.awt.Font ; 26 import java.awt.FontMetrics ; 27 import java.awt.Graphics ; 28 import java.awt.Graphics2D ; 29 import java.awt.Insets ; 30 import java.awt.Paint ; 31 import java.awt.Rectangle ; 32 import org.netbeans.swing.tabcontrol.TabDisplayer; 33 34 import javax.swing.plaf.ComponentUI ; 35 import java.util.HashMap ; 36 import java.util.Map ; 37 import javax.swing.Icon ; 38 import javax.swing.JComponent ; 39 import javax.swing.UIManager ; 40 import org.openide.awt.HtmlRenderer; 41 42 48 public final class WinClassicViewTabDisplayerUI extends AbstractViewTabDisplayerUI { 49 50 private static final boolean isGenericUI = 51 !"Windows".equals(UIManager.getLookAndFeel().getID()); 53 private static final Color GTK_TABBED_PANE_BACKGROUND_1 = new Color (255, 255, 255); 54 55 58 59 private static final int BUMP_X_PAD = isGenericUI ? 0 : 3; 60 private static final int BUMP_WIDTH = isGenericUI ? 0 : 3; 61 private static final int TXT_X_PAD = isGenericUI ? 3 : BUMP_X_PAD + BUMP_WIDTH + 5; 62 private static final int TXT_Y_PAD = 3; 63 64 private static final int ICON_X_PAD = 2; 65 66 private static Map <Integer , String []> buttonIconPaths; 67 68 69 72 73 private Dimension prefSize; 74 75 79 private Rectangle tempRect = new Rectangle (); 80 81 84 private WinClassicViewTabDisplayerUI(TabDisplayer displayer) { 85 super(displayer); 86 prefSize = new Dimension (100, 19); 87 } 88 89 public static ComponentUI createUI(JComponent c) { 90 return new WinClassicViewTabDisplayerUI((TabDisplayer) c); 91 } 92 93 public Dimension getPreferredSize(JComponent c) { 94 FontMetrics fm = getTxtFontMetrics(); 95 int height = fm == null ? 96 19 : fm.getAscent() + 2 * fm.getDescent() + 2; 97 Insets insets = c.getInsets(); 98 prefSize.height = height + insets.bottom + insets.top; 99 return prefSize; 100 } 101 102 105 public void paint(Graphics g, JComponent c) { 106 107 ColorUtil.setupAntialiasing(g); 108 109 Color col = c.getBackground(); 110 if (col != null) { 111 g.setColor (col); 112 g.fillRect (0, 0, c.getWidth(), c.getHeight()); 113 } 114 paintOverallBorder(g, c); 115 super.paint(g, c); 116 } 117 118 121 protected void paintOverallBorder(Graphics g, JComponent c) { 122 if (isGenericUI) { 123 return; 124 } 125 Rectangle r = c.getBounds(); 126 g.setColor(UIManager.getColor("InternalFrame.borderDarkShadow")); g.drawLine(0, r.height - 1, r.width - 1, r.height - 1); 128 } 129 130 protected Font getTxtFont() { 131 if (isGenericUI) { 132 Font result = UIManager.getFont("controlFont"); 133 if (result != null) { 134 return result; 135 } 136 } 137 return super.getTxtFont(); 138 } 139 140 protected void paintTabContent(Graphics g, int index, String text, int x, 141 int y, int width, int height) { 142 height--; 144 y -= 2; FontMetrics fm = getTxtFontMetrics(); 146 g.setFont(getTxtFont()); 148 int txtWidth = width; 149 if (isSelected(index)) { 150 Component buttons = getControlButtons(); 151 if( null != buttons ) { 152 Dimension buttonsSize = buttons.getPreferredSize(); 153 txtWidth = width - (buttonsSize.width + ICON_X_PAD + 2*TXT_X_PAD); 154 buttons.setLocation( x + txtWidth+2*TXT_X_PAD, y + (height-buttonsSize.height)/2+1 ); 155 } 156 } else { 157 txtWidth = width - 2 * TXT_X_PAD; 158 } 159 drawBump(g, index, x + 4, y + 6, BUMP_WIDTH, height - 8); 161 162 Color txtC = UIManager.getColor("TabbedPane.foreground"); 165 HtmlRenderer.renderString(text, g, x + TXT_X_PAD, y + fm.getAscent() 166 + TXT_Y_PAD, 167 txtWidth, height, getTxtFont(), 168 txtC, 169 HtmlRenderer.STYLE_TRUNCATE, true); 170 } 171 172 protected void paintTabBorder(Graphics g, int index, int x, int y, 173 int width, int height) { 174 175 height--; 177 boolean isSelected = isSelected(index); 178 179 g.translate(x, y); 180 181 g.setColor(UIManager.getColor("InternalFrame.borderShadow")); g.drawLine(0, height - 1, width - 2, height - 1); 183 g.drawLine(width - 1, height - 1, width - 1, 0); 184 185 g.setColor(isSelected ? UIManager.getColor( 186 "InternalFrame.borderHighlight") : UIManager.getColor("InternalFrame.borderLight")); g.drawLine(0, 0, 0, height - 1); 189 g.drawLine(1, 0, width - 2, 0); 190 191 g.translate(-x, -y); 192 } 193 194 protected void paintTabBackground(Graphics g, int index, int x, int y, 195 int width, int height) { 196 height--; 198 ((Graphics2D ) g).setPaint( 199 getBackgroundPaint(g, index, x, y, width, height)); 200 if (isFocused(index)) { 201 g.fillRect(x, y, width, height); 202 } else { 203 g.fillRect(x + 1, y + 1, width - 2, height - 2); 204 } 205 } 206 207 private Paint getBackgroundPaint(Graphics g, int index, int x, int y, 208 int width, int height) { 209 boolean selected = isSelected(index); 211 boolean focused = isFocused(index); 212 boolean attention = isAttention(index); 213 214 Paint result = null; 215 if (focused && !attention) { 216 result = ColorUtil.getGradientPaint(x, y, getSelGradientColor(), x + width, y, getSelGradientColor2()); 217 } else if (selected && !attention) { 218 result = UIManager.getColor("TabbedPane.background"); } else if (attention) { 220 result = WinClassicEditorTabCellRenderer.ATTENTION_COLOR; 221 } else { 222 result = UIManager.getColor("tab_unsel_fill"); 223 } 224 return result; 225 } 226 227 230 private void drawBump(Graphics g, int index, int x, int y, int width, 231 int height) { 232 if (isGenericUI) { 233 return; 235 } 236 237 Color highlightC, bodyC, shadowC; 239 if (isFocused(index)) { 240 bodyC = new Color (210, 220, 243); highlightC = bodyC.brighter(); 242 shadowC = bodyC.darker(); 243 } else if (isSelected(index)) { 244 highlightC = 245 UIManager.getColor("InternalFrame.borderHighlight"); bodyC = UIManager.getColor("InternalFrame.borderLight"); shadowC = UIManager.getColor("InternalFrame.borderShadow"); } else { 249 highlightC = UIManager.getColor("InternalFrame.borderLight"); bodyC = UIManager.getColor("tab_unsel_fill"); 251 shadowC = UIManager.getColor("InternalFrame.borderShadow"); } 253 for (int i = 0; i < width / 3; i++, x += 3) { 255 g.setColor(highlightC); 256 g.drawLine(x, y, x, y + height - 1); 257 g.drawLine(x, y, x + 1, y); 258 g.setColor(bodyC); 259 g.drawLine(x + 1, y + 1, x + 1, y + height - 2); 260 g.setColor(shadowC); 261 g.drawLine(x + 2, y, x + 2, y + height - 1); 262 g.drawLine(x, y + height - 1, x + 1, y + height - 1); 263 } 264 } 265 266 private static final Color getSelGradientColor() { 267 if ("GTK".equals(UIManager.getLookAndFeel().getID())) { return GTK_TABBED_PANE_BACKGROUND_1; } else { 270 return UIManager.getColor("winclassic_tab_sel_gradient"); } 272 } 273 274 private static final Color getSelGradientColor2() { 275 return UIManager.getColor("TabbedPane.background"); } 277 278 private static void initIcons() { 279 if( null == buttonIconPaths ) { 280 buttonIconPaths = new HashMap <Integer , String []>(7); 281 282 String [] iconPaths = new String [4]; 284 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/win_bigclose_enabled.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/win_bigclose_pressed.png"; iconPaths[TabControlButton.STATE_DISABLED] = "org/netbeans/swing/tabcontrol/resources/win_bigclose_disabled.png"; iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/win_bigclose_rollover.png"; buttonIconPaths.put( TabControlButton.ID_CLOSE_BUTTON, iconPaths ); 289 290 iconPaths = new String [4]; 292 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/win_slideright_enabled.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/win_slideright_pressed.png"; iconPaths[TabControlButton.STATE_DISABLED] = iconPaths[TabControlButton.STATE_DEFAULT]; 295 iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/win_slideright_rollover.png"; buttonIconPaths.put( TabControlButton.ID_SLIDE_RIGHT_BUTTON, iconPaths ); 297 298 iconPaths = new String [4]; 299 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/win_slideleft_enabled.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/win_slideleft_pressed.png"; iconPaths[TabControlButton.STATE_DISABLED] = iconPaths[TabControlButton.STATE_DEFAULT]; 302 iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/win_slideleft_rollover.png"; buttonIconPaths.put( TabControlButton.ID_SLIDE_LEFT_BUTTON, iconPaths ); 304 305 iconPaths = new String [4]; 306 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/win_slidebottom_enabled.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/win_slidebottom_pressed.png"; iconPaths[TabControlButton.STATE_DISABLED] = iconPaths[TabControlButton.STATE_DEFAULT]; 309 iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/win_slidebottom_rollover.png"; buttonIconPaths.put( TabControlButton.ID_SLIDE_DOWN_BUTTON, iconPaths ); 311 312 iconPaths = new String [4]; 313 iconPaths[TabControlButton.STATE_DEFAULT] = "org/netbeans/swing/tabcontrol/resources/win_pin_enabled.png"; iconPaths[TabControlButton.STATE_PRESSED] = "org/netbeans/swing/tabcontrol/resources/win_pin_pressed.png"; iconPaths[TabControlButton.STATE_DISABLED] = iconPaths[TabControlButton.STATE_DEFAULT]; 316 iconPaths[TabControlButton.STATE_ROLLOVER] = "org/netbeans/swing/tabcontrol/resources/win_pin_rollover.png"; buttonIconPaths.put( TabControlButton.ID_PIN_BUTTON, iconPaths ); 318 } 319 } 320 321 public Icon getButtonIcon(int buttonId, int buttonState) { 322 Icon res = null; 323 initIcons(); 324 String [] paths = buttonIconPaths.get( buttonId ); 325 if( null != paths && buttonState >=0 && buttonState < paths.length ) { 326 res = TabControlButtonFactory.getIcon( paths[buttonState] ); 327 } 328 return res; 329 } 330 } 331 | Popular Tags |