1 19 23 24 package org.netbeans.swing.tabcontrol.plaf; 25 26 import javax.swing.*; 27 import java.awt.*; 28 import org.netbeans.swing.tabcontrol.TabDisplayer; 29 30 35 final class WinVistaEditorTabCellRenderer extends AbstractTabCellRenderer { 36 private static final int TOP_INSET = 0; 38 private static final int LEFT_INSET = 3; 39 private static final int RIGHT_INSET = 0; 40 static final int BOTTOM_INSET = 0; 41 42 private static final TabPainter leftClip = new WinVistaLeftClipPainter(); 45 private static final TabPainter rightClip = new WinVistaRightClipPainter(); 46 private static final TabPainter normal = new WinVistaPainter(); 47 48 51 public WinVistaEditorTabCellRenderer() { 52 super(leftClip, normal, rightClip, new Dimension(32, 42)); 53 } 54 55 58 public int getPixelsToAddToSelection() { 59 return 0; 60 } 61 62 public Dimension getPadding() { 63 Dimension d = super.getPadding(); 64 d.width = isShowCloseButton() && !Boolean.getBoolean("nb.tabs.suppressCloseButton") ? 32 : 16; 65 return d; 66 } 67 68 private static final Color getUnselFillBrightUpperColor() { 69 Color result = UIManager.getColor("tab_unsel_fill_bright_upper"); if (result == null) { 71 result = new Color(235,235,235); 72 } 73 return result; 74 } 75 76 private static final Color getUnselFillDarkUpperColor() { 77 Color result = UIManager.getColor("tab_unsel_fill_dark_upper"); if (result == null) { 79 result = new Color(229, 229, 229); 80 } 81 return result; 82 } 83 84 private static final Color getUnselFillBrightLowerColor() { 85 Color result = UIManager.getColor("tab_unsel_fill_bright_lower"); if (result == null) { 87 result = new Color(214,214,214); 88 } 89 return result; 90 } 91 92 private static final Color getUnselFillDarkLowerColor() { 93 Color result = UIManager.getColor("tab_unsel_fill_dark_lower"); if (result == null) { 95 result = new Color(203, 203, 203); 96 } 97 return result; 98 } 99 100 private static final Color getSelFillColor() { 101 Color result = UIManager.getColor("tab_sel_fill"); if (result == null) { 103 result = new Color(244,244,244); 104 } 105 return result; 106 } 107 108 private static final Color getFocusFillUpperColor() { 109 Color result = UIManager.getColor("tab_focus_fill_upper"); if (result == null) { 111 result = new Color(242, 249, 252); 112 } 113 return result; 114 } 115 116 private static final Color getFocusFillBrightLowerColor() { 117 Color result = UIManager.getColor("tab_focus_fill_bright_lower"); if (result == null) { 119 result = new Color(225, 241, 249); 120 } 121 return result; 122 } 123 124 private static final Color getFocusFillDarkLowerColor() { 125 Color result = UIManager.getColor("tab_focus_fill_dark_lower"); if (result == null) { 127 result = new Color(216, 236, 246); 128 } 129 return result; 130 } 131 132 private static final Color getMouseOverFillBrightUpperColor() { 133 Color result = UIManager.getColor("tab_mouse_over_fill_bright_upper"); if (result == null) { 135 result = new Color(223,242,252); 136 } 137 return result; 138 } 139 140 private static final Color getMouseOverFillDarkUpperColor() { 141 Color result = UIManager.getColor("tab_mouse_over_fill_dark_upper"); if (result == null) { 143 result = new Color(214,239,252); 144 } 145 return result; 146 } 147 148 private static final Color getMouseOverFillBrightLowerColor() { 149 Color result = UIManager.getColor("tab_mouse_over_fill_bright_lower"); if (result == null) { 151 result = new Color(189,228,250); 152 } 153 return result; 154 } 155 156 private static final Color getMouseOverFillDarkLowerColor() { 157 Color result = UIManager.getColor("tab_mouse_over_fill_dark_lower"); if (result == null) { 159 result = new Color(171,221,248); 160 } 161 return result; 162 } 163 164 private static final Color getTxtColor() { 165 Color result = UIManager.getColor("TabbedPane.foreground"); if (result == null) { 167 result = new Color(0, 0, 0); 168 } 169 return result; 170 } 171 172 static final Color getBorderColor() { 173 Color result = UIManager.getColor("tab_border"); if (result == null) { 175 result = new Color(137,140,149); 176 } 177 return result; 178 } 179 180 private static final Color getSelBorderColor() { 181 Color result = UIManager.getColor("tab_sel_border"); if (result == null) { 183 result = new Color(60,127,177); 184 } 185 return result; 186 } 187 188 private static final Color getBorderInnerColor() { 189 Color result = UIManager.getColor("tab_border_inner"); if (result == null) { 191 result = new Color(255,255,255); 192 } 193 return result; 194 } 195 196 197 198 199 200 201 202 public Color getSelectedActivatedForeground() { 203 return getTxtColor(); 204 } 205 206 public Color getSelectedForeground() { 207 return getTxtColor(); 208 } 209 210 211 212 private static void paintTabGradient( Graphics g, WinVistaEditorTabCellRenderer ren, Polygon poly ) { 213 Rectangle rect = poly.getBounds(); 214 boolean selected = ren.isSelected(); 215 boolean focused = selected && ren.isActive(); 216 boolean attention = ren.isAttention(); 217 boolean mouseOver = ren.isArmed(); 218 if (focused && !attention) { 219 rect.height++; 220 ColorUtil.vistaFillRectGradient((Graphics2D) g, rect, 221 getFocusFillUpperColor(), 222 getFocusFillBrightLowerColor(), getFocusFillDarkLowerColor() ); 223 } else if (selected && !attention) { 224 rect.height++; 225 g.setColor(getSelFillColor()); 226 g.fillPolygon( poly ); 227 } else if (mouseOver && !attention) { 228 ColorUtil.vistaFillRectGradient((Graphics2D) g, rect, 229 getMouseOverFillBrightUpperColor(), getMouseOverFillDarkUpperColor(), 230 getMouseOverFillBrightLowerColor(), getMouseOverFillDarkLowerColor() ); 231 } else if (attention) { 232 Color a = new Color (255, 255, 128); 233 Color b = new Color (230, 200, 64); 234 ColorUtil.xpFillRectGradient((Graphics2D) g, rect, 235 a, b); 236 } else { 237 ColorUtil.vistaFillRectGradient((Graphics2D) g, rect, 238 getUnselFillBrightUpperColor(), getUnselFillDarkUpperColor(), 239 getUnselFillBrightLowerColor(), getUnselFillDarkLowerColor() ); 240 } 241 242 } 243 244 protected int getCaptionYAdjustment() { 245 return 0; 246 } 247 248 protected int getIconYAdjustment() { 249 return -2; 250 } 251 252 private static class WinVistaPainter implements TabPainter { 253 254 public Insets getBorderInsets(Component c) { 255 return new Insets(TOP_INSET, LEFT_INSET, BOTTOM_INSET, RIGHT_INSET); 256 } 257 258 public void getCloseButtonRectangle(JComponent jc, 259 final Rectangle rect, 260 Rectangle bounds) { 261 262 WinVistaEditorTabCellRenderer ren = (WinVistaEditorTabCellRenderer) jc; 263 264 if (!ren.isShowCloseButton()) { 265 rect.x = -100; 266 rect.y = -100; 267 rect.width = 0; 268 rect.height = 0; 269 return; 270 } 271 String iconPath = findIconPath(ren); 272 Icon icon = TabControlButtonFactory.getIcon(iconPath); 273 int iconWidth = icon.getIconWidth(); 274 int iconHeight = icon.getIconHeight(); 275 rect.x = bounds.x + bounds.width - iconWidth - 2; 276 rect.y = bounds.y + (Math.max(0, bounds.height / 2 - iconHeight / 2)); 277 rect.width = iconWidth; 278 rect.height = iconHeight; 279 } 280 281 282 286 private String findIconPath( WinVistaEditorTabCellRenderer renderer ) { 287 if( renderer.inCloseButton() && renderer.isPressed() ) { 288 return "org/netbeans/swing/tabcontrol/resources/vista_close_pressed.png"; } 290 if( renderer.inCloseButton() ) { 291 return "org/netbeans/swing/tabcontrol/resources/vista_close_rollover.png"; } 293 return "org/netbeans/swing/tabcontrol/resources/vista_close_enabled.png"; } 295 296 public Polygon getInteriorPolygon(Component c) { 297 WinVistaEditorTabCellRenderer ren = (WinVistaEditorTabCellRenderer) c; 298 299 Insets ins = getBorderInsets(c); 300 Polygon p = new Polygon(); 301 int x = 0; 302 int y = 0; 303 304 int width = ren.isRightmost() ? c.getWidth() - 1 : c.getWidth(); 305 int height = c.getHeight() - ins.bottom; 306 307 p.addPoint(x, y + ins.top); 309 p.addPoint(x + width, y + ins.top); 310 p.addPoint(x + width, y + height - 1); 311 p.addPoint(x, y + height - 1); 312 return p; 313 } 314 315 public boolean isBorderOpaque() { 316 return true; 317 } 318 319 public void paintBorder(Component c, Graphics g, int x, int y, 320 int width, int height) { 321 WinVistaEditorTabCellRenderer ren = (WinVistaEditorTabCellRenderer) c; 322 323 g.translate(x, y); 324 325 Color borderColor = ((ren.isActive() && ren.isSelected()) 326 || ren.isArmed()) ? getSelBorderColor() : getBorderColor(); 327 g.setColor(borderColor); 328 int left = 0; 329 if (ren.isLeftmost() ) 331 g.drawLine(0, 0, 0, height - 1); 332 g.drawLine(0, 0, width - 1, 0); 334 if( (ren.isActive() && ren.isNextTabSelected()) || ren.isNextTabArmed() ) 336 g.setColor( getSelBorderColor() ); 337 g.drawLine(width - 1, 0, width - 1, height - 2); 338 g.setColor(getBorderColor()); 340 if( !ren.isSelected() ) { 341 g.drawLine(0, height - 1, width - 1, height - 1); 342 } else { 343 g.drawLine(width - 1, height-1, width - 1, height - 1); 344 } 345 346 g.setColor(getBorderInnerColor()); 348 g.drawLine(1, 1, width-2, 1); 350 if( ren.isSelected() ) 351 height++; 352 if (ren.isLeftmost()) 354 g.drawLine(1, 1, 1, height - 2); 355 else 356 g.drawLine(0, 1, 0, height - 2); 357 g.drawLine(width-2, 1, width-2, height - 2); 359 360 g.translate(-x, -y); 361 } 362 363 364 public void paintInterior(Graphics g, Component c) { 365 WinVistaEditorTabCellRenderer ren = (WinVistaEditorTabCellRenderer) c; 366 Polygon poly = getInteriorPolygon(ren); 367 paintTabGradient( g, ren, poly ); 368 369 Rectangle r = new Rectangle(); 371 getCloseButtonRectangle(ren, r, new Rectangle(0, 0, 372 ren.getWidth(), 373 ren.getHeight())); 374 375 if (!g.hitClip(r.x, r.y, r.width, r.height)) { 376 return; 377 } 378 379 String iconPath = findIconPath( ren ); 381 Icon icon = TabControlButtonFactory.getIcon( iconPath ); 382 icon.paintIcon(ren, g, r.x, r.y); 383 } 384 385 public boolean supportsCloseButton(JComponent renderer) { 386 return renderer instanceof TabDisplayer ? 387 ((TabDisplayer) renderer).isShowCloseButton() : true; 388 } 389 390 } 391 392 private static class WinVistaLeftClipPainter implements TabPainter { 393 394 public Insets getBorderInsets(Component c) { 395 return new Insets(TOP_INSET, LEFT_INSET, BOTTOM_INSET, RIGHT_INSET); 396 } 397 398 public Polygon getInteriorPolygon(Component c) { 399 WinVistaEditorTabCellRenderer ren = (WinVistaEditorTabCellRenderer) c; 400 401 Insets ins = getBorderInsets(c); 402 Polygon p = new Polygon(); 403 int x = 0; 404 int y = 0; 405 406 int width = ren.isRightmost() ? c.getWidth() - 1 : c.getWidth(); 407 int height = c.getHeight() - ins.bottom; 408 409 p.addPoint(x, y + ins.top); 411 p.addPoint(x + width, y + ins.top); 412 p.addPoint(x + width, y + height - 1); 413 p.addPoint(x, y + height - 1); 414 return p; 415 } 416 417 public void paintBorder(Component c, Graphics g, int x, int y, 418 int width, int height) { 419 420 WinVistaEditorTabCellRenderer ren = (WinVistaEditorTabCellRenderer) c; 421 g.translate(x, y); 422 423 Color borderColor = ((ren.isActive() && ren.isSelected()) 424 || ren.isArmed()) ? getSelBorderColor() : getBorderColor(); 425 g.setColor(borderColor); 426 int left = 0; 427 g.drawLine(0, 0, width - 1, 0); 431 if( (ren.isActive() && ren.isNextTabSelected()) || ren.isNextTabArmed() ) 433 g.setColor( getSelBorderColor() ); 434 g.drawLine(width - 1, 0, width - 1, height - 2); 435 g.setColor(getBorderColor()); 437 if( !ren.isSelected() ) { 438 g.drawLine(0, height - 1, width - 1, height - 1); 439 } else { 440 g.drawLine(width - 1, height-1, width - 1, height - 1); 441 } 442 443 g.setColor(getBorderInnerColor()); 445 g.drawLine(0, 1, width-2, 1); 447 if( ren.isSelected() ) 448 height++; 449 g.drawLine(width-2, 1, width-2, height - 2); 453 454 g.translate(-x, -y); 455 } 456 457 public void paintInterior(Graphics g, Component c) { 458 WinVistaEditorTabCellRenderer ren = (WinVistaEditorTabCellRenderer) c; 459 460 Polygon poly = getInteriorPolygon(ren); 461 paintTabGradient( g, ren, poly ); 462 } 463 464 public boolean isBorderOpaque() { 465 return true; 466 } 467 468 public boolean supportsCloseButton(JComponent renderer) { 469 return false; 470 } 471 472 public void getCloseButtonRectangle(JComponent jc, 473 final Rectangle rect, 474 Rectangle bounds) { 475 rect.setBounds(-20, -20, 0, 0); 476 } 477 478 } 479 480 private static class WinVistaRightClipPainter implements TabPainter { 481 482 public Insets getBorderInsets(Component c) { 483 return new Insets(TOP_INSET, LEFT_INSET, BOTTOM_INSET, RIGHT_INSET); 484 } 485 486 public boolean isBorderOpaque() { 487 return true; 488 } 489 490 public Polygon getInteriorPolygon(Component c) { 491 WinVistaEditorTabCellRenderer ren = (WinVistaEditorTabCellRenderer) c; 492 493 Insets ins = getBorderInsets(c); 494 Polygon p = new Polygon(); 495 int x = 0; 496 int y = 0; 497 498 int width = c.getWidth() + 1; 499 int height = c.getHeight() - ins.bottom; 500 501 p.addPoint(x, y + ins.top); 503 p.addPoint(x + width, y + ins.top); 504 p.addPoint(x + width, y + height - 1); 505 p.addPoint(x, y + height - 1); 506 return p; 507 } 508 509 public void paintBorder(Component c, Graphics g, int x, int y, 510 int width, int height) { 511 WinVistaEditorTabCellRenderer ren = (WinVistaEditorTabCellRenderer) c; 512 513 g.translate(x, y); 514 515 Color borderColor = ((ren.isActive() && ren.isSelected()) 516 || ren.isArmed()) ? getSelBorderColor() : getBorderColor(); 517 g.setColor(borderColor); 518 int left = 0; 519 g.drawLine(0, 0, width, 0); 523 g.setColor(getBorderColor()); 527 if( !ren.isSelected() ) { 528 g.drawLine(0, height - 1, width - 1, height - 1); 529 } else { 530 g.drawLine(width - 1, height-1, width - 1, height - 1); 531 } 532 533 g.setColor(getBorderInnerColor()); 535 g.drawLine(1, 1, width, 1); 537 if( ren.isSelected() ) 538 height++; 539 g.drawLine(0, 1, 0, height - 2); 541 544 g.translate(-x, -y); 545 } 546 547 public void paintInterior(Graphics g, Component c) { 548 WinVistaEditorTabCellRenderer ren = (WinVistaEditorTabCellRenderer) c; 549 550 Polygon poly = getInteriorPolygon(ren); 551 paintTabGradient( g, ren, poly ); 552 } 553 554 public boolean supportsCloseButton(JComponent renderer) { 555 return false; 556 } 557 558 public void getCloseButtonRectangle(JComponent jc, 559 final Rectangle rect, 560 Rectangle bounds) { 561 rect.setBounds(-20, -20, 0, 0); 562 } 563 } 564 } 565 | Popular Tags |