1 7 8 package javax.swing.plaf.metal; 9 10 import javax.swing.*; 11 import javax.swing.border.*; 12 import javax.swing.plaf.*; 13 import javax.swing.plaf.basic.BasicBorders ; 14 import javax.swing.text.JTextComponent ; 15 16 import java.awt.Component ; 17 import java.awt.Insets ; 18 import java.awt.Dimension ; 19 import java.awt.Rectangle ; 20 import java.awt.Color ; 21 import java.awt.Dialog ; 22 import java.awt.Frame ; 23 import java.awt.Graphics ; 24 import java.awt.Window ; 25 import java.io.Serializable ; 26 27 28 33 34 public class MetalBorders { 35 36 40 static Object NO_BUTTON_ROLLOVER = new StringBuffer ("NoButtonRollover"); 41 42 43 public static class Flush3DBorder extends AbstractBorder implements UIResource{ 44 45 private static final Insets insets = new Insets (2, 2, 2, 2); 46 47 public void paintBorder(Component c, Graphics g, int x, int y, 48 int w, int h) { 49 if (c.isEnabled()) { 50 MetalUtils.drawFlush3DBorder(g, x, y, w, h); 51 } else { 52 MetalUtils.drawDisabledBorder(g, x, y, w, h); 53 } 54 } 55 public Insets getBorderInsets(Component c) { 56 return insets; 57 } 58 public Insets getBorderInsets(Component c, Insets newInsets) { 59 newInsets.top = insets.top; 60 newInsets.left = insets.left; 61 newInsets.bottom = insets.bottom; 62 newInsets.right = insets.right; 63 return newInsets; 64 } 65 } 66 67 public static class ButtonBorder extends AbstractBorder implements UIResource { 68 69 protected static Insets borderInsets = new Insets ( 3, 3, 3, 3 ); 70 71 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { 72 if (MetalLookAndFeel.usingOcean()) { 73 paintOceanBorder(c, g, x, y, w, h); 74 return; 75 } 76 AbstractButton button = (AbstractButton)c; 77 ButtonModel model = button.getModel(); 78 79 if ( model.isEnabled() ) { 80 boolean isPressed = model.isPressed() && model.isArmed(); 81 boolean isDefault = (button instanceof JButton && ((JButton)button).isDefaultButton()); 82 83 if (isPressed && isDefault) { 84 MetalUtils.drawDefaultButtonPressedBorder(g, x, y, w, h); 85 } else if (isPressed) { 86 MetalUtils.drawPressed3DBorder( g, x, y, w, h ); 87 } else if (isDefault) { 88 MetalUtils.drawDefaultButtonBorder( g, x, y, w, h, false); 89 } else { 90 MetalUtils.drawButtonBorder( g, x, y, w, h, false); 91 } 92 } else { MetalUtils.drawDisabledBorder( g, x, y, w-1, h-1 ); 94 } 95 } 96 97 private void paintOceanBorder(Component c, Graphics g, int x, int y, 98 int w, int h) { 99 AbstractButton button = (AbstractButton)c; 100 ButtonModel model = ((AbstractButton)c).getModel(); 101 102 g.translate(x, y); 103 if (MetalUtils.isToolBarButton(button)) { 104 if (model.isEnabled()) { 105 if (model.isPressed()) { 106 g.setColor(MetalLookAndFeel.getWhite()); 107 g.fillRect(1, h - 1, w - 1, 1); 108 g.fillRect(w - 1, 1, 1, h - 1); 109 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 110 g.drawRect(0, 0, w - 2, h - 2); 111 g.fillRect(1, 1, w - 3, 1); 112 } 113 else if (model.isSelected() || model.isRollover()) { 114 g.setColor(MetalLookAndFeel.getWhite()); 115 g.fillRect(1, h - 1, w - 1, 1); 116 g.fillRect(w - 1, 1, 1, h - 1); 117 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 118 g.drawRect(0, 0, w - 2, h - 2); 119 } 120 else { 121 g.setColor(MetalLookAndFeel.getWhite()); 122 g.drawRect(1, 1, w - 2, h - 2); 123 g.setColor(UIManager.getColor( 124 "Button.toolBarBorderBackground")); 125 g.drawRect(0, 0, w - 2, h - 2); 126 } 127 } 128 else { 129 g.setColor(UIManager.getColor( 130 "Button.disabledToolBarBorderBackground")); 131 g.drawRect(0, 0, w - 2, h - 2); 132 } 133 } 134 else if (model.isEnabled()) { 135 boolean pressed = model.isPressed(); 136 boolean armed = model.isArmed(); 137 138 if ((c instanceof JButton) && ((JButton)c).isDefaultButton()) { 139 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 140 g.drawRect(0, 0, w - 1, h - 1); 141 g.drawRect(1, 1, w - 3, h - 3); 142 } 143 else if (pressed) { 144 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 145 g.fillRect(0, 0, w, 2); 146 g.fillRect(0, 2, 2, h - 2); 147 g.fillRect(w - 1, 1, 1, h - 1); 148 g.fillRect(1, h - 1, w - 2, 1); 149 } 150 else if (model.isRollover() && button.getClientProperty( 151 NO_BUTTON_ROLLOVER) == null) { 152 g.setColor(MetalLookAndFeel.getPrimaryControl()); 153 g.drawRect(0, 0, w - 1, h - 1); 154 g.drawRect(2, 2, w - 5, h - 5); 155 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 156 g.drawRect(1, 1, w - 3, h - 3); 157 } 158 else { 159 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 160 g.drawRect(0, 0, w - 1, h - 1); 161 } 162 } 163 else { 164 g.setColor(MetalLookAndFeel.getInactiveControlTextColor()); 165 g.drawRect(0, 0, w - 1, h - 1); 166 if ((c instanceof JButton) && ((JButton)c).isDefaultButton()) { 167 g.drawRect(1, 1, w - 3, h - 3); 168 } 169 } 170 } 171 172 public Insets getBorderInsets( Component c ) { 173 return borderInsets; 174 } 175 public Insets getBorderInsets(Component c, Insets newInsets) { 176 newInsets.top = borderInsets.top; 177 newInsets.left = borderInsets.left; 178 newInsets.bottom = borderInsets.bottom; 179 newInsets.right = borderInsets.right; 180 return newInsets; 181 } 182 } 183 184 public static class InternalFrameBorder extends AbstractBorder implements UIResource { 185 186 private static final Insets insets = new Insets (5, 5, 5, 5); 187 188 private static final int corner = 14; 189 190 public void paintBorder(Component c, Graphics g, int x, int y, 191 int w, int h) { 192 193 Color background; 194 Color highlight; 195 Color shadow; 196 197 if (c instanceof JInternalFrame && ((JInternalFrame)c).isSelected()) { 198 background = MetalLookAndFeel.getPrimaryControlDarkShadow(); 199 highlight = MetalLookAndFeel.getPrimaryControlShadow(); 200 shadow = MetalLookAndFeel.getPrimaryControlInfo(); 201 } else { 202 background = MetalLookAndFeel.getControlDarkShadow(); 203 highlight = MetalLookAndFeel.getControlShadow(); 204 shadow = MetalLookAndFeel.getControlInfo(); 205 } 206 207 g.setColor(background); 208 g.drawLine( 1, 0, w-2, 0); 210 g.drawLine( 0, 1, 0, h-2); 211 g.drawLine( w-1, 1, w-1, h-2); 212 g.drawLine( 1, h-1, w-2, h-1); 213 214 for (int i = 1; i < 5; i++) { 216 g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1); 217 } 218 219 if (c instanceof JInternalFrame && 220 ((JInternalFrame)c).isResizable()) { 221 g.setColor(highlight); 222 g.drawLine( corner+1, 3, w-corner, 3); 224 g.drawLine( 3, corner+1, 3, h-corner); 225 g.drawLine( w-2, corner+1, w-2, h-corner); 226 g.drawLine( corner+1, h-2, w-corner, h-2); 227 228 g.setColor(shadow); 229 g.drawLine( corner, 2, w-corner-1, 2); 231 g.drawLine( 2, corner, 2, h-corner-1); 232 g.drawLine( w-3, corner, w-3, h-corner-1); 233 g.drawLine( corner, h-3, w-corner-1, h-3); 234 } 235 236 } 237 238 public Insets getBorderInsets(Component c) { 239 return insets; 240 } 241 public Insets getBorderInsets(Component c, Insets newInsets) { 242 newInsets.top = insets.top; 243 newInsets.left = insets.left; 244 newInsets.bottom = insets.bottom; 245 newInsets.right = insets.right; 246 return newInsets; 247 } 248 } 249 250 254 static class FrameBorder extends AbstractBorder implements UIResource { 255 256 private static final Insets insets = new Insets (5, 5, 5, 5); 257 258 private static final int corner = 14; 259 260 public void paintBorder(Component c, Graphics g, int x, int y, 261 int w, int h) { 262 263 Color background; 264 Color highlight; 265 Color shadow; 266 267 Window window = SwingUtilities.getWindowAncestor(c); 268 if (window != null && window.isActive()) { 269 background = MetalLookAndFeel.getPrimaryControlDarkShadow(); 270 highlight = MetalLookAndFeel.getPrimaryControlShadow(); 271 shadow = MetalLookAndFeel.getPrimaryControlInfo(); 272 } else { 273 background = MetalLookAndFeel.getControlDarkShadow(); 274 highlight = MetalLookAndFeel.getControlShadow(); 275 shadow = MetalLookAndFeel.getControlInfo(); 276 } 277 278 g.setColor(background); 279 g.drawLine( x+1, y+0, x+w-2, y+0); 281 g.drawLine( x+0, y+1, x+0, y +h-2); 282 g.drawLine( x+w-1, y+1, x+w-1, y+h-2); 283 g.drawLine( x+1, y+h-1, x+w-2, y+h-1); 284 285 for (int i = 1; i < 5; i++) { 287 g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1); 288 } 289 290 if ((window instanceof Frame ) && ((Frame ) window).isResizable()) { 291 g.setColor(highlight); 292 g.drawLine( corner+1, 3, w-corner, 3); 294 g.drawLine( 3, corner+1, 3, h-corner); 295 g.drawLine( w-2, corner+1, w-2, h-corner); 296 g.drawLine( corner+1, h-2, w-corner, h-2); 297 298 g.setColor(shadow); 299 g.drawLine( corner, 2, w-corner-1, 2); 301 g.drawLine( 2, corner, 2, h-corner-1); 302 g.drawLine( w-3, corner, w-3, h-corner-1); 303 g.drawLine( corner, h-3, w-corner-1, h-3); 304 } 305 306 } 307 308 public Insets getBorderInsets(Component c) { 309 return insets; 310 } 311 312 public Insets getBorderInsets(Component c, Insets newInsets) 313 { 314 newInsets.top = insets.top; 315 newInsets.left = insets.left; 316 newInsets.bottom = insets.bottom; 317 newInsets.right = insets.right; 318 return newInsets; 319 } 320 } 321 322 326 static class DialogBorder extends AbstractBorder implements UIResource 327 { 328 private static final Insets insets = new Insets (5, 5, 5, 5); 329 private static final int corner = 14; 330 331 protected Color getActiveBackground() 332 { 333 return MetalLookAndFeel.getPrimaryControlDarkShadow(); 334 } 335 336 protected Color getActiveHighlight() 337 { 338 return MetalLookAndFeel.getPrimaryControlShadow(); 339 } 340 341 protected Color getActiveShadow() 342 { 343 return MetalLookAndFeel.getPrimaryControlInfo(); 344 } 345 346 protected Color getInactiveBackground() 347 { 348 return MetalLookAndFeel.getControlDarkShadow(); 349 } 350 351 protected Color getInactiveHighlight() 352 { 353 return MetalLookAndFeel.getControlShadow(); 354 } 355 356 protected Color getInactiveShadow() 357 { 358 return MetalLookAndFeel.getControlInfo(); 359 } 360 361 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) 362 { 363 Color background; 364 Color highlight; 365 Color shadow; 366 367 Window window = SwingUtilities.getWindowAncestor(c); 368 if (window != null && window.isActive()) { 369 background = getActiveBackground(); 370 highlight = getActiveHighlight(); 371 shadow = getActiveShadow(); 372 } else { 373 background = getInactiveBackground(); 374 highlight = getInactiveHighlight(); 375 shadow = getInactiveShadow(); 376 } 377 378 g.setColor(background); 379 g.drawLine( x + 1, y + 0, x + w-2, y + 0); 381 g.drawLine( x + 0, y + 1, x + 0, y + h - 2); 382 g.drawLine( x + w - 1, y + 1, x + w - 1, y + h - 2); 383 g.drawLine( x + 1, y + h - 1, x + w - 2, y + h - 1); 384 385 for (int i = 1; i < 5; i++) { 387 g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1); 388 } 389 390 391 if ((window instanceof Dialog ) && ((Dialog ) window).isResizable()) { 392 g.setColor(highlight); 393 g.drawLine( corner+1, 3, w-corner, 3); 395 g.drawLine( 3, corner+1, 3, h-corner); 396 g.drawLine( w-2, corner+1, w-2, h-corner); 397 g.drawLine( corner+1, h-2, w-corner, h-2); 398 399 g.setColor(shadow); 400 g.drawLine( corner, 2, w-corner-1, 2); 402 g.drawLine( 2, corner, 2, h-corner-1); 403 g.drawLine( w-3, corner, w-3, h-corner-1); 404 g.drawLine( corner, h-3, w-corner-1, h-3); 405 } 406 407 } 408 409 public Insets getBorderInsets(Component c) { 410 return insets; 411 } 412 413 public Insets getBorderInsets(Component c, Insets newInsets) 414 { 415 newInsets.top = insets.top; 416 newInsets.left = insets.left; 417 newInsets.bottom = insets.bottom; 418 newInsets.right = insets.right; 419 return newInsets; 420 } 421 } 422 423 427 static class ErrorDialogBorder extends DialogBorder implements UIResource 428 { 429 protected Color getActiveBackground() { 430 return UIManager.getColor("OptionPane.errorDialog.border.background"); 431 } 432 } 433 434 435 440 static class QuestionDialogBorder extends DialogBorder implements UIResource 441 { 442 protected Color getActiveBackground() { 443 return UIManager.getColor("OptionPane.questionDialog.border.background"); 444 } 445 } 446 447 448 452 static class WarningDialogBorder extends DialogBorder implements UIResource 453 { 454 protected Color getActiveBackground() { 455 return UIManager.getColor("OptionPane.warningDialog.border.background"); 456 } 457 } 458 459 460 464 public static class PaletteBorder extends AbstractBorder implements UIResource { 465 private static final Insets insets = new Insets (1, 1, 1, 1); 466 int titleHeight = 0; 467 468 public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { 469 470 g.translate(x,y); 471 g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); 472 g.drawLine(0, 1, 0, h-2); 473 g.drawLine(1, h-1, w-2, h-1); 474 g.drawLine(w-1, 1, w-1, h-2); 475 g.drawLine( 1, 0, w-2, 0); 476 g.drawRect(1,1, w-3, h-3); 477 g.translate(-x,-y); 478 479 } 480 481 public Insets getBorderInsets(Component c) { 482 return insets; 483 } 484 485 public Insets getBorderInsets(Component c, Insets newInsets) { 486 newInsets.top = insets.top; 487 newInsets.left = insets.left; 488 newInsets.bottom = insets.bottom; 489 newInsets.right = insets.right; 490 return newInsets; 491 } 492 } 493 494 public static class OptionDialogBorder extends AbstractBorder implements UIResource { 495 private static final Insets insets = new Insets (3, 3, 3, 3); 496 int titleHeight = 0; 497 498 public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { 499 500 g.translate(x,y); 501 502 int messageType = JOptionPane.PLAIN_MESSAGE; 503 if (c instanceof JInternalFrame) { 504 Object obj = ((JInternalFrame) c).getClientProperty( 505 "JInternalFrame.messageType"); 506 if (obj != null && (obj instanceof Integer )) { 507 messageType = ((Integer ) obj).intValue(); 508 } 509 } 510 511 Color borderColor; 512 513 switch (messageType) { 514 case(JOptionPane.ERROR_MESSAGE): 515 borderColor = UIManager.getColor( 516 "OptionPane.errorDialog.border.background"); 517 break; 518 case(JOptionPane.QUESTION_MESSAGE): 519 borderColor = UIManager.getColor( 520 "OptionPane.questionDialog.border.background"); 521 break; 522 case(JOptionPane.WARNING_MESSAGE): 523 borderColor = UIManager.getColor( 524 "OptionPane.warningDialog.border.background"); 525 break; 526 case(JOptionPane.INFORMATION_MESSAGE): 527 case(JOptionPane.PLAIN_MESSAGE): 528 default: 529 borderColor = MetalLookAndFeel.getPrimaryControlDarkShadow(); 530 break; 531 } 532 533 g.setColor(borderColor); 534 535 g.drawLine( 1, 0, w-2, 0); 537 g.drawLine( 0, 1, 0, h-2); 538 g.drawLine( w-1, 1, w-1, h-2); 539 g.drawLine( 1, h-1, w-2, h-1); 540 541 for (int i = 1; i < 3; i++) { 543 g.drawRect(i, i, w-(i*2)-1, h-(i*2)-1); 544 } 545 546 g.translate(-x,-y); 547 548 } 549 550 public Insets getBorderInsets(Component c) { 551 return insets; 552 } 553 554 public Insets getBorderInsets(Component c, Insets newInsets) { 555 newInsets.top = insets.top; 556 newInsets.left = insets.left; 557 newInsets.bottom = insets.bottom; 558 newInsets.right = insets.right; 559 return newInsets; 560 } 561 } 562 563 564 public static class MenuBarBorder extends AbstractBorder implements UIResource { 565 protected static Insets borderInsets = new Insets ( 1, 0, 1, 0 ); 566 567 public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { 568 g.translate( x, y ); 569 570 if (MetalLookAndFeel.usingOcean()) { 571 if (!MetalToolBarUI.doesMenuBarBorderToolBar((JMenuBar)c)) { 574 g.setColor(MetalLookAndFeel.getControl()); 575 g.drawLine(0, h - 2, w, h - 2); 576 g.setColor(UIManager.getColor("MenuBar.borderColor")); 577 g.drawLine(0, h - 1, w, h - 1); 578 } 579 } 580 else { 581 g.setColor( MetalLookAndFeel.getControlShadow() ); 582 g.drawLine( 0, h-1, w, h-1 ); 583 } 584 585 g.translate( -x, -y ); 586 587 } 588 589 public Insets getBorderInsets( Component c ) { 590 return getBorderInsets(c, new Insets (0, 0, 0, 0)); 591 } 592 593 public Insets getBorderInsets(Component c, Insets newInsets) { 594 if (MetalLookAndFeel.usingOcean()) { 595 newInsets.set(0, 0, 2, 0); 596 } 597 else { 598 newInsets.top = borderInsets.top; 599 newInsets.left = borderInsets.left; 600 newInsets.bottom = borderInsets.bottom; 601 newInsets.right = borderInsets.right; 602 } 603 return newInsets; 604 } 605 } 606 607 public static class MenuItemBorder extends AbstractBorder implements UIResource { 608 protected static Insets borderInsets = new Insets ( 2, 2, 2, 2 ); 609 610 public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { 611 JMenuItem b = (JMenuItem) c; 612 ButtonModel model = b.getModel(); 613 614 g.translate( x, y ); 615 616 if ( c.getParent() instanceof JMenuBar ) { 617 if ( model.isArmed() || model.isSelected() ) { 618 g.setColor( MetalLookAndFeel.getControlDarkShadow() ); 619 g.drawLine( 0, 0, w - 2, 0 ); 620 g.drawLine( 0, 0, 0, h - 1 ); 621 g.drawLine( w - 2, 2, w - 2, h - 1 ); 622 623 g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() ); 624 g.drawLine( w - 1, 1, w - 1, h - 1 ); 625 626 g.setColor( MetalLookAndFeel.getMenuBackground() ); 627 g.drawLine( w - 1, 0, w - 1, 0 ); 628 } 629 } else { 630 if ( model.isArmed() || ( c instanceof JMenu && model.isSelected() ) ) { 631 g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() ); 632 g.drawLine( 0, 0, w - 1, 0 ); 633 634 g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() ); 635 g.drawLine( 0, h - 1, w - 1, h - 1 ); 636 } else { 637 g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() ); 638 g.drawLine( 0, 0, 0, h - 1 ); 639 } 640 } 641 642 g.translate( -x, -y ); 643 } 644 645 public Insets getBorderInsets( Component c ) { 646 return borderInsets; 647 } 648 649 public Insets getBorderInsets(Component c, Insets newInsets) { 650 newInsets.top = borderInsets.top; 651 newInsets.left = borderInsets.left; 652 newInsets.bottom = borderInsets.bottom; 653 newInsets.right = borderInsets.right; 654 return newInsets; 655 } 656 } 657 658 public static class PopupMenuBorder extends AbstractBorder implements UIResource { 659 protected static Insets borderInsets = new Insets ( 3, 1, 2, 1 ); 660 661 public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { 662 g.translate( x, y ); 663 664 g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() ); 665 g.drawRect( 0, 0, w - 1, h - 1 ); 666 667 g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() ); 668 g.drawLine( 1, 1, w - 2, 1 ); 669 g.drawLine( 1, 2, 1, 2 ); 670 g.drawLine( 1, h - 2, 1, h - 2 ); 671 672 g.translate( -x, -y ); 673 674 } 675 676 public Insets getBorderInsets( Component c ) { 677 return borderInsets; 678 } 679 680 public Insets getBorderInsets(Component c, Insets newInsets) { 681 newInsets.top = borderInsets.top; 682 newInsets.left = borderInsets.left; 683 newInsets.bottom = borderInsets.bottom; 684 newInsets.right = borderInsets.right; 685 return newInsets; 686 } 687 } 688 689 690 public static class RolloverButtonBorder extends ButtonBorder { 691 692 public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) { 693 AbstractButton b = (AbstractButton) c; 694 ButtonModel model = b.getModel(); 695 696 if ( model.isRollover() && !( model.isPressed() && !model.isArmed() ) ) { 697 super.paintBorder( c, g, x, y, w, h ); 698 } 699 } 700 701 } 702 703 710 static class RolloverMarginBorder extends EmptyBorder { 711 712 public RolloverMarginBorder() { 713 super(3,3,3,3); } 715 716 public Insets getBorderInsets(Component c) { 717 return getBorderInsets(c, new Insets (0,0,0,0)); 718 } 719 720 public Insets getBorderInsets(Component c, Insets insets) { 721 Insets margin = null; 722 723 if (c instanceof AbstractButton) { 724 margin = ((AbstractButton)c).getMargin(); 725 } 726 if (margin == null || margin instanceof UIResource) { 727 insets.left = left; 729 insets.top = top; 730 insets.right = right; 731 insets.bottom = bottom; 732 } else { 733 insets.left = margin.left; 735 insets.top = margin.top; 736 insets.right = margin.right; 737 insets.bottom = margin.bottom; 738 } 739 return insets; 740 } 741 } 742 743 public static class ToolBarBorder extends AbstractBorder implements UIResource, SwingConstants 744 { 745 protected MetalBumps bumps = new MetalBumps ( 10, 10, 746 MetalLookAndFeel.getControlHighlight(), 747 MetalLookAndFeel.getControlDarkShadow(), 748 UIManager.getColor("ToolBar.background")); 749 750 public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) 751 { 752 g.translate( x, y ); 753 754 if ( ((JToolBar) c).isFloatable() ) 755 { 756 if ( ((JToolBar) c).getOrientation() == HORIZONTAL ) 757 { 758 int shift = MetalLookAndFeel.usingOcean() ? -1 : 0; 759 bumps.setBumpArea( 10, c.getSize().height - 4 ); 760 if( MetalUtils.isLeftToRight(c) ) { 761 bumps.paintIcon( c, g, 2, 2 + shift ); 762 } else { 763 bumps.paintIcon( c, g, c.getBounds().width-12, 764 2 + shift ); 765 } 766 } 767 else { 769 bumps.setBumpArea( c.getSize().width - 4, 10 ); 770 bumps.paintIcon( c, g, 2, 2 ); 771 } 772 773 } 774 775 if (((JToolBar) c).getOrientation() == HORIZONTAL && 776 MetalLookAndFeel.usingOcean()) { 777 g.setColor(MetalLookAndFeel.getControl()); 778 g.drawLine(0, h - 2, w, h - 2); 779 g.setColor(UIManager.getColor("ToolBar.borderColor")); 780 g.drawLine(0, h - 1, w, h - 1); 781 } 782 783 g.translate( -x, -y ); 784 } 785 786 public Insets getBorderInsets( Component c ) { 787 return getBorderInsets(c, new Insets (0,0,0,0)); 788 } 789 790 public Insets getBorderInsets(Component c, Insets newInsets) { 791 if (MetalLookAndFeel.usingOcean()) { 792 newInsets.set(1, 2, 3, 2); 793 } 794 else { 795 newInsets.top = newInsets.left = newInsets.bottom = newInsets.right = 2; 796 } 797 798 if ( ((JToolBar) c).isFloatable() ) { 799 if ( ((JToolBar) c).getOrientation() == HORIZONTAL ) { 800 if (c.getComponentOrientation().isLeftToRight()) { 801 newInsets.left = 16; 802 } else { 803 newInsets.right = 16; 804 } 805 } else { newInsets.top = 16; 807 } 808 } 809 810 Insets margin = ((JToolBar) c).getMargin(); 811 812 if ( margin != null ) { 813 newInsets.left += margin.left; 814 newInsets.top += margin.top; 815 newInsets.right += margin.right; 816 newInsets.bottom += margin.bottom; 817 } 818 819 return newInsets; 820 } 821 } 822 823 private static Border buttonBorder; 824 825 829 public static Border getButtonBorder() { 830 if (buttonBorder == null) { 831 buttonBorder = new BorderUIResource.CompoundBorderUIResource( 832 new MetalBorders.ButtonBorder (), 833 new BasicBorders.MarginBorder ()); 834 } 835 return buttonBorder; 836 } 837 838 private static Border textBorder; 839 840 844 public static Border getTextBorder() { 845 if (textBorder == null) { 846 textBorder = new BorderUIResource.CompoundBorderUIResource( 847 new MetalBorders.Flush3DBorder (), 848 new BasicBorders.MarginBorder ()); 849 } 850 return textBorder; 851 } 852 853 private static Border textFieldBorder; 854 855 859 public static Border getTextFieldBorder() { 860 if (textFieldBorder == null) { 861 textFieldBorder = new BorderUIResource.CompoundBorderUIResource( 862 new MetalBorders.TextFieldBorder (), 863 new BasicBorders.MarginBorder ()); 864 } 865 return textFieldBorder; 866 } 867 868 public static class TextFieldBorder extends Flush3DBorder { 869 870 public void paintBorder(Component c, Graphics g, int x, int y, 871 int w, int h) { 872 873 if (!(c instanceof JTextComponent )) { 874 if (c.isEnabled()) { 876 MetalUtils.drawFlush3DBorder(g, x, y, w, h); 877 } else { 878 MetalUtils.drawDisabledBorder(g, x, y, w, h); 879 } 880 return; 881 } 882 883 if (c.isEnabled() && ((JTextComponent )c).isEditable()) { 884 MetalUtils.drawFlush3DBorder(g, x, y, w, h); 885 } else { 886 MetalUtils.drawDisabledBorder(g, x, y, w, h); 887 } 888 889 } 890 } 891 892 public static class ScrollPaneBorder extends AbstractBorder implements UIResource { 893 894 private static final Insets insets = new Insets (1, 1, 2, 2); 895 896 public void paintBorder(Component c, Graphics g, int x, int y, 897 int w, int h) { 898 899 JScrollPane scroll = (JScrollPane)c; 900 JComponent colHeader = scroll.getColumnHeader(); 901 int colHeaderHeight = 0; 902 if (colHeader != null) 903 colHeaderHeight = colHeader.getHeight(); 904 905 JComponent rowHeader = scroll.getRowHeader(); 906 int rowHeaderWidth = 0; 907 if (rowHeader != null) 908 rowHeaderWidth = rowHeader.getWidth(); 909 910 911 g.translate( x, y); 912 913 g.setColor( MetalLookAndFeel.getControlDarkShadow() ); 914 g.drawRect( 0, 0, w-2, h-2 ); 915 g.setColor( MetalLookAndFeel.getControlHighlight() ); 916 917 g.drawLine( w-1, 1, w-1, h-1); 918 g.drawLine( 1, h-1, w-1, h-1); 919 920 g.setColor( MetalLookAndFeel.getControl() ); 921 g.drawLine( w-2, 2+colHeaderHeight, w-2, 2+colHeaderHeight ); 922 g.drawLine( 1+rowHeaderWidth, h-2, 1+rowHeaderWidth, h-2 ); 923 924 g.translate( -x, -y); 925 926 } 927 928 public Insets getBorderInsets(Component c) { 929 return insets; 930 } 931 } 932 933 private static Border toggleButtonBorder; 934 935 939 public static Border getToggleButtonBorder() { 940 if (toggleButtonBorder == null) { 941 toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource( 942 new MetalBorders.ToggleButtonBorder (), 943 new BasicBorders.MarginBorder ()); 944 } 945 return toggleButtonBorder; 946 } 947 948 951 public static class ToggleButtonBorder extends ButtonBorder { 952 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { 953 AbstractButton button = (AbstractButton)c; 954 ButtonModel model = button.getModel(); 955 if (MetalLookAndFeel.usingOcean()) { 956 if(model.isArmed()) { 957 super.paintBorder(c, g, x, y, w, h); 958 } 959 else { 960 MetalUtils.drawPressed3DBorder( g, x, y, w + 1, h + 1 ); 961 } 962 return; 963 } 964 if (! c.isEnabled() ) { 965 MetalUtils.drawDisabledBorder( g, x, y, w-1, h-1 ); 966 } else { 967 if ( model.isPressed() && model.isArmed() ) { 968 MetalUtils.drawPressed3DBorder( g, x, y, w, h ); 969 } else if ( model.isSelected() ) { 970 MetalUtils.drawDark3DBorder( g, x, y, w, h ); 971 } else { 972 MetalUtils.drawFlush3DBorder( g, x, y, w, h ); 973 } 974 } 975 } 976 } 977 978 982 public static class TableHeaderBorder extends javax.swing.border.AbstractBorder { 983 protected Insets editorBorderInsets = new Insets ( 2, 2, 2, 0 ); 984 985 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { 986 g.translate( x, y ); 987 988 g.setColor( MetalLookAndFeel.getControlDarkShadow() ); 989 g.drawLine( w-1, 0, w-1, h-1 ); 990 g.drawLine( 1, h-1, w-1, h-1 ); 991 g.setColor( MetalLookAndFeel.getControlHighlight() ); 992 g.drawLine( 0, 0, w-2, 0 ); 993 g.drawLine( 0, 0, 0, h-2 ); 994 995 g.translate( -x, -y ); 996 } 997 998 public Insets getBorderInsets( Component c ) { 999 return editorBorderInsets; 1000 } 1001 } 1002 1003 1007 public static Border getDesktopIconBorder() { 1008 return new BorderUIResource.CompoundBorderUIResource( 1009 new LineBorder(MetalLookAndFeel.getControlDarkShadow(), 1), 1010 new MatteBorder (2,2,1,2, MetalLookAndFeel.getControl())); 1011 } 1012 1013 static Border getToolBarRolloverBorder() { 1014 if (MetalLookAndFeel.usingOcean()) { 1015 return new CompoundBorder( 1016 new MetalBorders.ButtonBorder (), 1017 new MetalBorders.RolloverMarginBorder ()); 1018 } 1019 return new CompoundBorder(new MetalBorders.RolloverButtonBorder (), 1020 new MetalBorders.RolloverMarginBorder ()); 1021 } 1022 1023 static Border getToolBarNonrolloverBorder() { 1024 if (MetalLookAndFeel.usingOcean()) { 1025 new CompoundBorder( 1026 new MetalBorders.ButtonBorder (), 1027 new MetalBorders.RolloverMarginBorder ()); 1028 } 1029 return new CompoundBorder(new MetalBorders.ButtonBorder (), 1030 new MetalBorders.RolloverMarginBorder ()); 1031 } 1032} 1033 1034 | Popular Tags |