Source for javax.swing.plaf.metal.MetalBorders

   1: /* MetalBorders.java
   2:    Copyright (C) 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package javax.swing.plaf.metal;
  40: 
  41: import java.awt.Color;
  42: import java.awt.Component;
  43: import java.awt.Graphics;
  44: import java.awt.Insets;
  45: 
  46: import javax.swing.AbstractButton;
  47: import javax.swing.ButtonModel;
  48: import javax.swing.JButton;
  49: import javax.swing.JInternalFrame;
  50: import javax.swing.JMenu;
  51: import javax.swing.JMenuBar;
  52: import javax.swing.JMenuItem;
  53: import javax.swing.JOptionPane;
  54: import javax.swing.JScrollPane;
  55: import javax.swing.JTextField;
  56: import javax.swing.JToggleButton;
  57: import javax.swing.JToolBar;
  58: import javax.swing.SwingConstants;
  59: import javax.swing.UIDefaults;
  60: import javax.swing.UIManager;
  61: import javax.swing.border.AbstractBorder;
  62: import javax.swing.border.Border;
  63: import javax.swing.plaf.BorderUIResource;
  64: import javax.swing.plaf.UIResource;
  65: import javax.swing.plaf.basic.BasicBorders;
  66: import javax.swing.text.JTextComponent;
  67: 
  68: 
  69: /**
  70:  * A factory class that creates borders for the different Swing components.
  71:  *
  72:  * @author Roman Kennke (roman@kennke.org)
  73:  */
  74: public class MetalBorders
  75: {
  76: 
  77:   /** The shared instance for getButtonBorder(). */
  78:   private static Border buttonBorder;
  79: 
  80:   /** The shared instance for getToggleButtonBorder(). */
  81:   private static Border toggleButtonBorder;
  82: 
  83:   /** The shared instance for getDesktopIconBorder(). */
  84:   private static Border desktopIconBorder;
  85: 
  86:   /** The shared instance for getRolloverButtonBorder(). */
  87:   private static Border toolbarButtonBorder;
  88: 
  89:   /** The shared instance for getTextFieldBorder(). */
  90:   private static Border textFieldBorder;
  91: 
  92:   /** The shared instance for getTextBorder(). */
  93:   private static Border textBorder;
  94: 
  95:   /** The shared instance for getRolloverBorder(). */
  96:   private static Border rolloverBorder;
  97: 
  98:   /**
  99:    * A MarginBorder that gets shared by multiple components.
 100:    * Created on demand by the private helper function {@link
 101:    * #getMarginBorder()}.
 102:    */
 103:   private static BasicBorders.MarginBorder marginBorder;
 104: 
 105:   /**
 106:    * A border used for {@link JButton} components.
 107:    */
 108:   public static class ButtonBorder extends AbstractBorder implements UIResource
 109:   {
 110:     /** The borders insets. */
 111:     protected static Insets borderInsets = new Insets(3, 3, 3, 3);
 112: 
 113:     /**
 114:      * Creates a new instance of <code>ButtonBorder</code>.
 115:      */
 116:     public ButtonBorder()
 117:     {
 118:       // Nothing to do here.
 119:     }
 120: 
 121:     /**
 122:      * Paints the button border.
 123:      *
 124:      * @param c the component for which we paint the border
 125:      * @param g the Graphics context to use
 126:      * @param x the X coordinate of the upper left corner of c
 127:      * @param y the Y coordinate of the upper left corner of c
 128:      * @param w the width of c
 129:      * @param h the height of c
 130:      */
 131:     public void paintBorder(Component c, Graphics g, int x, int y, int w,
 132:                             int h)
 133:     {
 134:       ButtonModel bmodel = null;
 135:       
 136:       if (c instanceof AbstractButton)
 137:         bmodel = ((AbstractButton) c).getModel();
 138: 
 139:       Color darkShadow = MetalLookAndFeel.getControlDarkShadow();
 140:       Color shadow = MetalLookAndFeel.getControlShadow();
 141:       Color light = MetalLookAndFeel.getWhite();
 142:       Color middle = MetalLookAndFeel.getControl();
 143: 
 144:       if (c.isEnabled())
 145:       {
 146:         // draw dark border
 147:         g.setColor(darkShadow);
 148:         g.drawRect(x, y, w - 2, h - 2);
 149: 
 150:         if (!bmodel.isPressed())
 151:           {
 152:             // draw light border
 153:             g.setColor(light);
 154:             g.drawRect(x + 1, y + 1, w - 2, h - 2);
 155: 
 156:             // draw crossing pixels of both borders
 157:             g.setColor(middle);
 158:             g.drawRect(x + 1, y + h - 2, 0, 0);
 159:             g.drawRect(x + w - 2, y + 1, 0, 0);
 160:           }
 161:         else
 162:           {
 163:             // draw light border
 164:             g.setColor(light);
 165:             g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
 166:             g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
 167: 
 168:             // draw shadow border
 169:             g.setColor(middle);
 170:             g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
 171:             g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
 172:  
 173:             // draw crossing pixels of both borders
 174:             g.setColor(shadow);
 175:             g.drawRect(x + 1, y + h - 2, 0, 0);
 176:             g.drawRect(x + w - 2, y + 1, 0, 0);
 177:           }
 178:       }
 179:       else 
 180:         {
 181:           // draw disabled border
 182:           g.setColor(MetalLookAndFeel.getInactiveControlTextColor());
 183:           g.drawRect(x, y, w - 2, h - 2);          
 184:         }
 185:     }
 186: 
 187:     /**
 188:      * Returns the insets of the <code>ButtonBorder</code>.
 189:      *
 190:      * @param c the component for which the border is used
 191:      *
 192:      * @return The insets of the ButtonBorder
 193:      */
 194:     public Insets getBorderInsets(Component c)
 195:     {
 196:       return getBorderInsets(c, null);
 197:     }
 198: 
 199:     /**
 200:      * Returns the insets of the <code>ButtonBorder</code> in the specified 
 201:      * <code>newInsets</code> object.
 202:      *
 203:      * @param c the component for which the border is used
 204:      * @param newInsets the insets object where to put the values (if 
 205:      *        <code>null</code>, a new instance is created).
 206:      *
 207:      * @return The insets.
 208:      */
 209:     public Insets getBorderInsets(Component c, Insets newInsets)
 210:     {
 211:       if (newInsets == null)
 212:         newInsets = new Insets(0, 0, 0, 0);
 213: 
 214:       newInsets.bottom = borderInsets.bottom;
 215:       newInsets.left = borderInsets.left;
 216:       newInsets.right = borderInsets.right;
 217:       newInsets.top = borderInsets.top;
 218:       return newInsets;
 219:     }
 220:   }
 221: 
 222:   /**
 223:    * A border used when painting {@link JInternalFrame} instances.
 224:    */
 225:   static class DesktopIconBorder extends AbstractBorder
 226:     implements UIResource
 227:   {
 228:     /**
 229:      * Creates a new border instance.
 230:      */
 231:     public DesktopIconBorder()
 232:     {
 233:       // Nothing to do here.
 234:     }
 235:     
 236:     /**
 237:      * Returns the border insets.
 238:      * 
 239:      * @param c  the component (ignored).
 240:      * 
 241:      * @return The border insets.
 242:      */
 243:     public Insets getBorderInsets(Component c)
 244:     {
 245:       return getBorderInsets(c, null);
 246:     }
 247:     
 248:     /**
 249:      * Returns the border insets.
 250:      * 
 251:      * @param c  the component (ignored).
 252:      * @return The border insets.
 253:      */
 254:     public Insets getBorderInsets(Component c, Insets newInsets)
 255:     {
 256:       if (newInsets == null)
 257:         newInsets = new Insets(3, 3, 2, 3);
 258:       else
 259:         {
 260:           newInsets.top = 3;
 261:           newInsets.left = 3;
 262:           newInsets.bottom = 2;
 263:           newInsets.right = 3;
 264:         }
 265:       return newInsets;  
 266:     }
 267:     
 268:     /**
 269:      * Paints the border for the specified component.
 270:      * 
 271:      * @param c  the component.
 272:      * @param g  the graphics device.
 273:      * @param x  the x-coordinate.
 274:      * @param y  the y-coordinate.
 275:      * @param w  the width.
 276:      * @param h  the height.
 277:      */
 278:     public void paintBorder(Component c, Graphics g, int x, int y, int w, 
 279:         int h)
 280:     {
 281:       g.setColor(MetalLookAndFeel.getControlDarkShadow());      
 282:       g.drawRect(x, y, w - 1, h - 1); 
 283:     }
 284:     
 285:   }
 286: 
 287:   /**
 288:    * A simple 3D border.
 289:    */
 290:   public static class Flush3DBorder extends AbstractBorder
 291:     implements UIResource
 292:   {
 293:     /**
 294:      * Creates a new border instance.
 295:      */
 296:     public Flush3DBorder()
 297:     {
 298:       // Nothing to do here.
 299:     }
 300:     
 301:     /**
 302:      * Returns the border insets.
 303:      * 
 304:      * @param c  the component (ignored).
 305:      * 
 306:      * @return The border insets.
 307:      */
 308:     public Insets getBorderInsets(Component c)
 309:     {
 310:       return getBorderInsets(c, null);
 311:     }
 312:     
 313:     /**
 314:      * Returns the border insets.
 315:      * 
 316:      * @param c  the component (ignored).
 317:      * @return The border insets.
 318:      */
 319:     public Insets getBorderInsets(Component c, Insets newInsets)
 320:     {
 321:       if (newInsets == null)
 322:         newInsets = new Insets(2, 2, 2, 2);
 323:       else
 324:         {
 325:           newInsets.top = 2;
 326:           newInsets.left = 2;
 327:           newInsets.bottom = 2;
 328:           newInsets.right = 2;
 329:         }
 330:       return newInsets;  
 331:     }
 332:     
 333:     /**
 334:      * Paints the border for the specified component.
 335:      * 
 336:      * @param c  the component (ignored).
 337:      * @param g  the graphics device.
 338:      * @param x  the x-coordinate.
 339:      * @param y  the y-coordinate.
 340:      * @param w  the width.
 341:      * @param h  the height.
 342:      */
 343:     public void paintBorder(Component c, Graphics g, int x, int y, int w, 
 344:         int h)
 345:     {              
 346:       Color savedColor = g.getColor();
 347:       g.setColor(MetalLookAndFeel.getControlDarkShadow());
 348:       g.drawRect(x, y, w - 2, h - 2);
 349:       g.setColor(MetalLookAndFeel.getControlHighlight());
 350:       g.drawRect(x + 1, y + 1, w - 2, h - 2);
 351:       g.setColor(MetalLookAndFeel.getControl());
 352:       g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
 353:       g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
 354:       g.setColor(savedColor);
 355:     }
 356:     
 357:   }
 358:     
 359:   /**
 360:    * A border used for a {@link JInternalFrame} when it is being used as a 
 361:    * palette.
 362:    * 
 363:    * @since 1.3
 364:    */
 365:   public static class PaletteBorder extends AbstractBorder
 366:     implements UIResource
 367:   {
 368:     /**
 369:      * Creates a new <code>PaletteBorder</code>.
 370:      */
 371:     public PaletteBorder()
 372:     {
 373:       // Nothing to do here.
 374:     }
 375:     
 376:     /**
 377:      * Returns the border insets.
 378:      * 
 379:      * @param c  the component (ignored).
 380:      * 
 381:      * @return The border insets.
 382:      */
 383:     public Insets getBorderInsets(Component c)
 384:     {
 385:       return getBorderInsets(c, null);
 386:     }
 387: 
 388:     /**
 389:      * Returns the border insets.
 390:      * 
 391:      * @param c  the component (ignored).
 392:      * @param newInsets  the insets object that, if non-<code>null</code>, will 
 393:      *                   be populated with the result from this method.
 394:      * 
 395:      * @return The border insets.
 396:      */
 397:     public Insets getBorderInsets(Component c, Insets newInsets)
 398:     {        
 399:       if (newInsets == null)
 400:         newInsets = new Insets(1, 1, 1, 1);
 401:       else
 402:         {
 403:           newInsets.top = 1;
 404:           newInsets.left = 1;
 405:           newInsets.bottom = 1;
 406:           newInsets.right = 1;
 407:         }
 408:       return newInsets;  
 409:     }
 410:     
 411:     /**
 412:      * Paints the border for the specified component.
 413:      * 
 414:      * @param c  the component (ignored).
 415:      * @param g  the graphics device.
 416:      * @param x  the x-coordinate.
 417:      * @param y  the y-coordinate.
 418:      * @param w  the width.
 419:      * @param h  the height.
 420:      */
 421:     public void paintBorder(Component c, Graphics g, int x, int y, int w, 
 422:             int h)
 423:     {
 424:       Color savedColor = g.getColor();
 425:       
 426:       // draw the outline
 427:       g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
 428:       g.drawRect(x, y, w - 1, h - 1);
 429:       
 430:       // put a dot in each corner
 431:       g.setColor(MetalLookAndFeel.getControl());
 432:       g.fillRect(x, y, 1, 1);
 433:       g.fillRect(x + w - 1, y, 1, 1);
 434:       g.fillRect(x + w - 1, y + h - 1, 1, 1);
 435:       g.fillRect(x, y + h - 1, 1, 1);      
 436:       g.setColor(savedColor);
 437:     }
 438: 
 439:   }
 440:     
 441:   /**
 442:    * A border used for the {@link JTextField} component.
 443:    */
 444:   public static class TextFieldBorder extends Flush3DBorder
 445:     implements UIResource
 446:   {
 447:     /**
 448:      * Creates a new border instance.
 449:      */
 450:     public TextFieldBorder()
 451:     {
 452:       // Nothing to do here.
 453:     }
 454:     
 455:     /**
 456:      * Paints the border for the specified component.
 457:      * 
 458:      * @param c  the component (ignored).
 459:      * @param g  the graphics device.
 460:      * @param x  the x-coordinate.
 461:      * @param y  the y-coordinate.
 462:      * @param w  the width.
 463:      * @param h  the height.
 464:      */
 465:     public void paintBorder(Component c, Graphics g, int x, int y, int w, 
 466:         int h)
 467:     {
 468:       boolean enabledTextBorder;
 469:       if (c instanceof JTextComponent)
 470:     {
 471:       JTextComponent tc = (JTextComponent) c;
 472:       enabledTextBorder = tc.isEnabled() && tc.isEditable();
 473:     }
 474:       else
 475:     enabledTextBorder = false;
 476: 
 477:       if (enabledTextBorder)
 478:         super.paintBorder(c, g, x, y, w, h);
 479:       else
 480:         {
 481:           Color savedColor = g.getColor();
 482:           g.setColor(MetalLookAndFeel.getControlShadow());
 483:           g.drawRect(x, y, w - 1, h - 1);
 484:           g.setColor(savedColor);
 485:         }
 486:     }
 487:     
 488:   }
 489: 
 490:   /**
 491:    * A border used for the {@link JInternalFrame} component.
 492:    */
 493:   public static class InternalFrameBorder extends AbstractBorder
 494:     implements UIResource
 495:   {
 496:     /**
 497:      * Creates a new border instance.
 498:      */
 499:     public InternalFrameBorder()
 500:     {
 501:       // Nothing to do here.
 502:     }
 503:     
 504:     /**
 505:      * Returns the border insets.
 506:      * 
 507:      * @param c  the component (ignored).
 508:      * 
 509:      * @return The border insets.
 510:      */
 511:     public Insets getBorderInsets(Component c)
 512:     {
 513:       return getBorderInsets(c, null);
 514:     }
 515:     
 516:     /**
 517:      * Returns the border insets.
 518:      * 
 519:      * @param c  the component (ignored).
 520:      * @return The border insets.
 521:      */
 522:     public Insets getBorderInsets(Component c, Insets newInsets)
 523:     {
 524:       if (newInsets == null)
 525:         newInsets = new Insets(5, 5, 5, 5);
 526:       else
 527:         {
 528:           newInsets.top = 5;
 529:           newInsets.left = 5;
 530:           newInsets.bottom = 5;
 531:           newInsets.right = 5;
 532:         }
 533:       return newInsets;  
 534:     }
 535:     
 536:     /**
 537:      * Paints the border for the specified component.
 538:      * 
 539:      * @param c  the component.
 540:      * @param g  the graphics device.
 541:      * @param x  the x-coordinate.
 542:      * @param y  the y-coordinate.
 543:      * @param w  the width.
 544:      * @param h  the height.
 545:      */
 546:     public void paintBorder(Component c, Graphics g, int x, int y, int w, 
 547:         int h)
 548:     {
 549:         
 550:       JInternalFrame f = (JInternalFrame) c;
 551:       if (f.isSelected())
 552:         g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
 553:       else
 554:         g.setColor(MetalLookAndFeel.getControlDarkShadow());
 555:       
 556:       // fill the border background
 557:       g.fillRect(x, y, w, 5);
 558:       g.fillRect(x, y, 5, h);
 559:       g.fillRect(x + w - 5, y, 5, h);
 560:       g.fillRect(x, y + h - 5, w, 5);
 561:       
 562:       // draw a dot in each corner
 563:       g.setColor(MetalLookAndFeel.getControl());
 564:       g.fillRect(x, y, 1, 1);
 565:       g.fillRect(x + w - 1, y, 1, 1);
 566:       g.fillRect(x + w - 1, y + h - 1, 1, 1);
 567:       g.fillRect(x, y + h - 1, 1, 1);
 568:       
 569:       // draw the lines
 570:       g.setColor(MetalLookAndFeel.getBlack());
 571:       g.drawLine(x + 14, y + 2, x + w - 15, y + 2);
 572:       g.drawLine(x + 14, y + h - 3, x + w - 15, y + h - 3);
 573:       g.drawLine(x + 2, y + 14, x + 2, y + h - 15);
 574:       g.drawLine(x + w - 3, y + 14, x + w - 3, y + h - 15);
 575:       
 576:       // draw the line highlights
 577:       if (f.isSelected())
 578:         g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
 579:       else 
 580:         g.setColor(MetalLookAndFeel.getControlShadow());
 581:       g.drawLine(x + 15, y + 3, x + w - 14, y + 3);
 582:       g.drawLine(x + 15, y + h - 2, x + w - 14, y + h - 2);
 583:       g.drawLine(x + 3, y + 15, x + 3, y + h - 14);
 584:       g.drawLine(x + w - 2, y + 15, x + w - 2, y + h - 14);
 585:     }
 586:     
 587:   }
 588: 
 589:   /**
 590:    * A border used for {@link JInternalFrame} components that are
 591:    * presented as dialogs (by the {@link JOptionPane} class).
 592:    */
 593:   public static class OptionDialogBorder extends AbstractBorder
 594:     implements UIResource
 595:   {
 596:       
 597:     /**
 598:      * Creates a new border instance.
 599:      */
 600:     public OptionDialogBorder()
 601:     {
 602:       // Nothing to do here.
 603:     }
 604:     
 605:     /**
 606:      * Returns the border insets.
 607:      * 
 608:      * @param c  the component (ignored).
 609:      * 
 610:      * @return The border insets.
 611:      */
 612:     public Insets getBorderInsets(Component c)
 613:     {
 614:       return getBorderInsets(c, null);
 615:     }
 616:     
 617:     /**
 618:      * Returns the border insets.
 619:      * 
 620:      * @param c  the component (ignored).
 621:      * @return The border insets.
 622:      */
 623:     public Insets getBorderInsets(Component c, Insets newInsets)
 624:     {
 625:       if (newInsets == null)
 626:         newInsets = new Insets(3, 3, 3, 3);
 627:       else
 628:         {
 629:           newInsets.top = 3;
 630:           newInsets.left = 3;
 631:           newInsets.bottom = 3;
 632:           newInsets.right = 3;
 633:         }
 634:       return newInsets;  
 635:     }
 636:         
 637:     /**
 638:      * Paints the border for the specified component.
 639:      * 
 640:      * @param c  the component.
 641:      * @param g  the graphics device.
 642:      * @param x  the x-coordinate.
 643:      * @param y  the y-coordinate.
 644:      * @param w  the width.
 645:      * @param h  the height.
 646:      */
 647:     public void paintBorder(Component c, Graphics g, int x, int y, int w, 
 648:         int h)
 649:     {
 650:         
 651:       JInternalFrame f = (JInternalFrame) c;
 652:       g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
 653:       if (f.getContentPane() instanceof JOptionPane)
 654:         {
 655:           JOptionPane pane = (JOptionPane) f.getContentPane();
 656:           int type = pane.getMessageType();
 657:           UIDefaults defaults = UIManager.getLookAndFeelDefaults();
 658:           if (type == JOptionPane.QUESTION_MESSAGE)
 659:             {
 660:               Color bc = defaults.getColor(
 661:                   "OptionPane.questionDialog.border.background");
 662:               if (bc != null)
 663:                 g.setColor(bc);
 664:             }
 665:           if (type == JOptionPane.WARNING_MESSAGE)
 666:             {
 667:               Color bc = defaults.getColor(
 668:                   "OptionPane.warningDialog.border.background");
 669:               if (bc != null)
 670:                 g.setColor(bc);              
 671:             }
 672:           else if (type == JOptionPane.ERROR_MESSAGE)
 673:             {
 674:               Color bc = defaults.getColor(
 675:                   "OptionPane.errorDialog.border.background");
 676:               if (bc != null)
 677:                 g.setColor(bc);              
 678:             }
 679:         }
 680:       
 681:       // fill the border background
 682:       g.fillRect(x, y, w, 3);
 683:       g.fillRect(x, y, 3, h);
 684:       g.fillRect(x + w - 3, y, 3, h);
 685:       g.fillRect(x, y + h - 3, w, 3);
 686:       
 687:       // draw a dot in each corner
 688:       g.setColor(MetalLookAndFeel.getControl());
 689:       g.fillRect(x, y, 1, 1);
 690:       g.fillRect(x + w - 1, y, 1, 1);
 691:       g.fillRect(x + w - 1, y + h - 1, 1, 1);
 692:       g.fillRect(x, y + h - 1, 1, 1);
 693:       
 694:     }
 695:     
 696:   }
 697: 
 698:   /**
 699:    * A border used for {@link JMenu} and {@link JMenuItem} components.
 700:    */
 701:   public static class MenuItemBorder extends AbstractBorder
 702:     implements UIResource
 703:   {
 704:     /** The border insets. */
 705:     protected static Insets borderInsets = new Insets(1, 1, 1, 1);
 706:     
 707:     /**
 708:      * Creates a new border instance.
 709:      */
 710:     public MenuItemBorder()
 711:     {
 712:       // Nothing to do here.
 713:     }
 714:     
 715:     /**
 716:      * Paints the border for the component.  A border is painted only if the
 717:      * component is a selected {@link JMenu} or an armed {@link JMenuItem}.
 718:      * 
 719:      * @param c  the component.
 720:      * @param g  the graphics device.
 721:      * @param x  the x-coordinate of the border area.
 722:      * @param y  the y-coordinate of the border area.
 723:      * @param w  the width of the border area.
 724:      * @param h  the height of the border area.
 725:      */
 726:     public void paintBorder(Component c, Graphics g, int x, int y, int w,
 727:         int h)
 728:     {
 729:       Color dark = MetalLookAndFeel.getPrimaryControlDarkShadow();
 730:       Color light = MetalLookAndFeel.getPrimaryControlHighlight();
 731:       if (c instanceof JMenu) {
 732:         JMenu menu = (JMenu) c;
 733:         if (menu.isSelected())
 734:         {
 735:           g.setColor(dark);
 736:           g.drawLine(x, y, x, y + h);
 737:           g.drawLine(x, y, x + w, y);
 738:           g.drawLine(x + w - 2, y + 1, x + w - 2, y + h);
 739:           g.setColor(light);
 740:           g.drawLine(x + w - 1, y + 1, x + w - 1, y + h);
 741:         }
 742:       }
 743:       else if (c instanceof JMenuItem)
 744:       {
 745:         JMenuItem item = (JMenuItem) c;
 746:         if (item.isArmed()) 
 747:           {
 748:             g.setColor(dark);
 749:             g.drawLine(x, y, x + w, y);
 750:             g.setColor(light);
 751:             g.drawLine(x, y + h - 1, x + w, y + h - 1);
 752:           }
 753:         else
 754:           {
 755:             // Normally we draw a light line on the left.
 756:             g.setColor(light);
 757:             g.drawLine(x, y, x, y + h);
 758:           }
 759:       }
 760:     }
 761:     
 762:     /**
 763:      * Returns the border insets.
 764:      * 
 765:      * @param c  the component (ignored).
 766:      * 
 767:      * @return The border insets.
 768:      */
 769:     public Insets getBorderInsets(Component c)
 770:     {
 771:       return borderInsets;
 772:     }
 773:     
 774:     /**
 775:      * Populates <code>insets</code> with the border insets, then returns it.
 776:      * 
 777:      * @param c  the component (ignored).
 778:      * @param insets  the object to populate with the border insets.
 779:      * 
 780:      * @return The border insets.
 781:      * 
 782:      * @throws NullPointerException if <code>insets</code> is <code>null</code>.
 783:      */
 784:     public Insets getBorderInsets(Component c, Insets insets)
 785:     {
 786:       insets.left = borderInsets.left;
 787:       insets.top = borderInsets.top;
 788:       insets.bottom = borderInsets.bottom;
 789:       insets.right = borderInsets.right;
 790:       return insets;
 791:     }
 792:   }
 793: 
 794:   /**
 795:    * A border used for {@link JMenuBar} components.
 796:    */
 797:   public static class MenuBarBorder
 798:       extends AbstractBorder
 799:       implements UIResource
 800:   {
 801:     /** The border insets. */
 802:     protected static Insets borderInsets = new Insets(1, 0, 1, 0);
 803:     
 804:     // TODO: find where this color really comes from
 805:     private static Color borderColor = new Color(153, 153, 153);
 806:     
 807:     /**
 808:      * Creates a new border instance.
 809:      */
 810:     public MenuBarBorder()
 811:     {
 812:       // Nothing to do here.
 813:     }
 814:     
 815:     /**
 816:      * Paints the border for the component.  A border is painted only if the
 817:      * component is a selected {@link JMenu} or an armed {@link JMenuItem}.
 818:      * 
 819:      * @param c  the component.
 820:      * @param g  the graphics device.
 821:      * @param x  the x-coordinate of the border area.
 822:      * @param y  the y-coordinate of the border area.
 823:      * @param w  the width of the border area.
 824:      * @param h  the height of the border area.
 825:      */
 826:     public void paintBorder(Component c, Graphics g, int x, int y, int w,
 827:         int h)
 828:     {
 829:       g.setColor(borderColor);
 830:       g.drawLine(x, y + h - 1, x + w, y + h - 1);
 831:     }
 832:     
 833:     /**
 834:      * Returns the border insets.
 835:      * 
 836:      * @param c  the component (ignored).
 837:      * 
 838:      * @return The border insets.
 839:      */
 840:     public Insets getBorderInsets(Component c)
 841:     {
 842:       return borderInsets;
 843:     }
 844:     
 845:     /**
 846:      * Populates <code>insets</code> with the border insets, then returns it.
 847:      * 
 848:      * @param c  the component (ignored).
 849:      * @param insets  the object to populate with the border insets.
 850:      * 
 851:      * @return The border insets.
 852:      * 
 853:      * @throws NullPointerException if <code>insets</code> is <code>null</code>.
 854:      */
 855:     public Insets getBorderInsets(Component c, Insets insets)
 856:     {
 857:       insets.left = borderInsets.left;
 858:       insets.top = borderInsets.top;
 859:       insets.bottom = borderInsets.bottom;
 860:       insets.right = borderInsets.right;
 861:       return insets;
 862:     }
 863:   }
 864: 
 865:   /**
 866:    * A border for {@link JScrollPane} components.
 867:    */
 868:   public static class ScrollPaneBorder
 869:     extends AbstractBorder
 870:     implements UIResource
 871:   {
 872:     /** The border insets. */
 873:     private static Insets insets = new Insets(1, 1, 2, 2);
 874:     
 875:     /**
 876:      * Constructs a new ScrollPaneBorder.
 877:      */
 878:     public ScrollPaneBorder()
 879:     {
 880:       // Nothing to do here.
 881:     }
 882:     
 883:     /**
 884:      * Returns the insets of the border for the Component <code>c</code>.
 885:      *
 886:      * @param c the Component for which we return the border insets
 887:      */
 888:     public Insets getBorderInsets(Component c)
 889:     {
 890:       return insets;
 891:     }
 892: 
 893:     /**
 894:      * Paints the border.
 895:      *
 896:      * @param c the Component for which the border is painted
 897:      * @param g the Graphics context
 898:      * @param x the X coordinate of the upper left corner of the border
 899:      * @param y the Y coordinate of the upper left corner of the border
 900:      * @param w the width of the border
 901:      * @param h the height of the border
 902:      */
 903:     public void paintBorder(Component c, Graphics g, int x, int y,
 904:                             int w, int h)
 905:     {
 906:       Color darkShadow = MetalLookAndFeel.getControlDarkShadow();
 907:       Color shadow = MetalLookAndFeel.getControlShadow();
 908:       Color light = MetalLookAndFeel.getWhite();
 909:       Color middle = MetalLookAndFeel.getControl();
 910: 
 911:       // paint top border line
 912:       g.setColor(darkShadow);
 913:       g.drawLine(x, y, x + w - 2, y);
 914: 
 915:       // paint left border line
 916:       g.drawLine(x, y, x, y + h - 2);
 917:  
 918:       // paint right inner border line
 919:       g.drawLine(x + w - 2, y, x + w - 2, y + h + 1);
 920: 
 921:       // paint bottom inner border line
 922:       g.drawLine(x + 2, y + h - 2, x + w - 2, y + h - 2);
 923: 
 924:       // draw right outer border line
 925:       g.setColor(light);
 926:       g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
 927: 
 928:       // draw bottom outer border line
 929:       g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
 930: 
 931:       // paint the lighter points
 932:       g.setColor(middle);
 933:       g.drawLine(x + w - 1, y, x + w - 1, y);
 934:       g.drawLine(x + w - 2, y + 2, x + w - 2, y + 2);
 935:       g.drawLine(x, y + h - 1, x, y + h - 1);
 936:       g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
 937: 
 938:     }
 939:     
 940:   }
 941:   
 942:   /**
 943:    * A button border that is only visible when the mouse pointer is within 
 944:    * the button's bounds.
 945:    */
 946:   public static class RolloverButtonBorder
 947:     extends MetalBorders.ButtonBorder
 948:   {
 949:     /**
 950:      * Creates a new border instance.
 951:      */
 952:     public RolloverButtonBorder()
 953:     {
 954:       // Nothing to do here.
 955:     }
 956:     
 957:     /**
 958:      * Paints the border.
 959:      * 
 960:      * @param c  the component.
 961:      * @param g  the graphics device.
 962:      * @param x  the x-coordinate.
 963:      * @param y  the y-coordinate.
 964:      * @param w  the width.
 965:      * @param h  the height.
 966:      */
 967:     public void paintBorder(Component c, Graphics g, int x, int y, int w, 
 968:             int h)
 969:     {
 970:       boolean mouseIsOver = false;
 971:       if (c instanceof AbstractButton)
 972:         {
 973:           ButtonModel bmodel = ((AbstractButton) c).getModel();
 974:           mouseIsOver = bmodel.isRollover();
 975:         }
 976:       if (mouseIsOver)
 977:         super.paintBorder(c, g, x, y, w, h);
 978:     }
 979:   }
 980:   
 981:   /**
 982:    * This border is used in Toolbar buttons as inner border.
 983:    */
 984:   static class RolloverMarginBorder extends AbstractBorder
 985:   {
 986:     /** The borders insets. */
 987:     protected static Insets borderInsets = new Insets(3, 3, 3, 3);
 988: 
 989:     /**
 990:      * Creates a new instance of RolloverBorder.
 991:      */
 992:     public RolloverMarginBorder()
 993:     {
 994:       // Nothing to do here.
 995:     }
 996:     
 997:     /**
 998:      * Returns the insets of the RolloverBorder.
 999:      *
1000:      * @param c the component for which the border is used
1001:      *
1002:      * @return the insets of the RolloverBorder
1003:      */
1004:     public Insets getBorderInsets(Component c)
1005:     {
1006:       return getBorderInsets(c, null);
1007:     }
1008: 
1009:     /**
1010:      * Returns the insets of the RolloverMarginBorder in the specified
1011:      * Insets object.
1012:      *
1013:      * @param c the component for which the border is used
1014:      * @param newInsets the insets object where to put the values
1015:      *
1016:      * @return the insets of the RolloverMarginBorder
1017:      */
1018:     public Insets getBorderInsets(Component c, Insets newInsets)
1019:     {
1020:       if (newInsets == null)
1021:         newInsets = new Insets(0, 0, 0, 0);
1022: 
1023:       AbstractButton b = (AbstractButton) c;
1024:       Insets margin = b.getMargin();
1025:       newInsets.bottom = borderInsets.bottom;
1026:       newInsets.left = borderInsets.left;
1027:       newInsets.right = borderInsets.right;
1028:       newInsets.top = borderInsets.top;
1029:       return newInsets;
1030:     }
1031:   }
1032: 
1033:   /**
1034:    * A border implementation for popup menus.
1035:    */
1036:   public static class PopupMenuBorder
1037:     extends AbstractBorder
1038:     implements UIResource
1039:   {
1040: 
1041:     /** The border's insets. */
1042:     protected static Insets borderInsets = new Insets(3, 1, 2, 1);
1043: 
1044:     /**
1045:      * Constructs a new PopupMenuBorder.
1046:      */
1047:     public PopupMenuBorder()
1048:     {
1049:       // Nothing to do here.
1050:     }
1051:     
1052:     /**
1053:      * Returns the insets of the border, creating a new Insets instance
1054:      * with each call.
1055:      *
1056:      * @param c the component for which we return the border insets
1057:      *          (not used here)
1058:      */
1059:     public Insets getBorderInsets(Component c)
1060:     {
1061:       return getBorderInsets(c, null);
1062:     }
1063:     
1064:     /**
1065:      * Returns the insets of the border, using the supplied Insets instance.
1066:      *
1067:      * @param c the component for which we return the border insets
1068:      *          (not used here)
1069:      * @param i the Insets instance to fill with the Insets values
1070:      */
1071:     public Insets getBorderInsets(Component c, Insets i)
1072:     {
1073:       Insets insets;
1074:       if (i == null)
1075:         insets = new Insets(borderInsets.top, borderInsets.left,
1076:                             borderInsets.bottom, borderInsets.right);
1077:       else
1078:         {
1079:           insets = i;
1080:           insets.top = borderInsets.top;
1081:           insets.left = borderInsets.left;
1082:           insets.bottom = borderInsets.bottom;
1083:           insets.right = borderInsets.right;
1084:         }
1085:       
1086:       return insets;
1087:     }
1088: 
1089:     /**
1090:      * Paints the border for component <code>c</code> using the
1091:      * Graphics context <code>g</code> with the dimension
1092:      * <code>x, y, w, h</code>.
1093:      *
1094:      * @param c the component for which we paint the border
1095:      * @param g the Graphics context to use
1096:      * @param x the X coordinate of the upper left corner of c
1097:      * @param y the Y coordinate of the upper left corner of c
1098:      * @param w the width of c
1099:      * @param h the height of c
1100:      */
1101:     public void paintBorder(Component c, Graphics g, int x, int y, int w,
1102:                             int h)
1103:     {
1104:       Color darkShadow = MetalLookAndFeel.getPrimaryControlDarkShadow();
1105:       Color light = MetalLookAndFeel.getPrimaryControlHighlight();
1106: 
1107:       // draw dark outer border
1108:       g.setColor(darkShadow);
1109:       g.drawRect(x, y, w - 1, h - 1);
1110:       
1111:       // draw highlighted inner border (only top and left)
1112:       g.setColor(light);
1113:       g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
1114:     }
1115:     
1116:   }
1117: 
1118:   /**
1119:    * A border used for the {@link JToggleButton} component.
1120:    * 
1121:    * @since 1.3
1122:    */
1123:   public static class ToggleButtonBorder
1124:     extends ButtonBorder 
1125:   {
1126:     /**
1127:      * Creates a new border instance.
1128:      */
1129:     public ToggleButtonBorder()
1130:     {
1131:       // Nothing to do here.
1132:     }
1133:     
1134:     /**
1135:      * Paints the toggle button border.
1136:      *
1137:      * @param c the component for which we paint the border
1138:      * @param g the Graphics context to use
1139:      * @param x the X coordinate of the upper left corner of c
1140:      * @param y the Y coordinate of the upper left corner of c
1141:      * @param w the width of c
1142:      * @param h the height of c
1143:      */
1144:     public void paintBorder(Component c, Graphics g, int x, int y, int w,
1145:                             int h)
1146:     {
1147:       ButtonModel bmodel = null;
1148:       
1149:       if (c instanceof AbstractButton)
1150:         bmodel = ((AbstractButton) c).getModel();
1151: 
1152:       Color darkShadow = MetalLookAndFeel.getControlDarkShadow();
1153:       Color shadow = MetalLookAndFeel.getControlShadow();
1154:       Color light = MetalLookAndFeel.getWhite();
1155:       Color middle = MetalLookAndFeel.getControl();
1156: 
1157:       if (c.isEnabled())
1158:         {
1159:           // draw dark border
1160:           g.setColor(darkShadow);
1161:           g.drawRect(x, y, w - 2, h - 2);
1162: 
1163:           if (!bmodel.isArmed())
1164:             {
1165:               // draw light border
1166:               g.setColor(light);
1167:               g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
1168:               g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
1169:               if (bmodel.isSelected())
1170:                 g.setColor(middle);
1171:               g.drawLine(x + 1, y + 1, x + w - 3, y + 1);
1172:               g.drawLine(x + 1, y + 1, x + 1, y + h - 3);
1173: 
1174:               // draw crossing pixels of both borders
1175:               g.setColor(shadow);
1176:               g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
1177:               g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
1178:             }
1179:           else
1180:             {
1181:               // draw light border
1182:               g.setColor(light);
1183:               g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
1184:               g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
1185: 
1186:               // draw shadow border
1187:               g.setColor(shadow);
1188:               g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
1189:               g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
1190:  
1191:               // draw crossing pixels of both borders
1192:               g.setColor(shadow);
1193:               g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
1194:               g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
1195:               
1196:             }
1197:           // draw corners
1198:           g.setColor(middle);
1199:           g.drawLine(x, y + h - 1, x, y + h - 1);
1200:           g.drawLine(x + w - 1, y, x + w - 1, y);
1201:         }
1202:       else 
1203:         {
1204:           // draw disabled border
1205:           g.setColor(MetalLookAndFeel.getControlDisabled());
1206:           g.drawRect(x, y, w - 2, h - 2);          
1207:         }
1208:     }
1209:   }
1210: 
1211:   /**
1212:    * A border used for the {@link JToolBar} component.
1213:    */
1214:   public static class ToolBarBorder extends AbstractBorder
1215:     implements UIResource, SwingConstants
1216:   {
1217:     /**
1218:      * Creates a new border instance.
1219:      */
1220:     public ToolBarBorder()
1221:     {
1222:       // Nothing to do here.
1223:     }
1224:     
1225:     /**
1226:      * Returns the border insets.
1227:      * 
1228:      * @param c  the component (ignored).
1229:      * 
1230:      * @return The border insets.
1231:      */
1232:     public Insets getBorderInsets(Component c)
1233:     {
1234:       return getBorderInsets(c, null);
1235:     }
1236:     
1237:     /**
1238:      * Returns the border insets.
1239:      * 
1240:      * @param c  the component (ignored).
1241:      * @return The border insets.
1242:      */
1243:     public Insets getBorderInsets(Component c, Insets newInsets)
1244:     {
1245:       JToolBar tb = (JToolBar) c;
1246:       if (tb.getOrientation() == JToolBar.HORIZONTAL)
1247:         {   
1248:           if (newInsets == null)
1249:             newInsets = new Insets(2, 16, 2, 2);
1250:           else
1251:             {
1252:               newInsets.top = 2;
1253:               newInsets.left = 16;
1254:               newInsets.bottom = 2;
1255:               newInsets.right = 2;
1256:             }
1257:           return newInsets;  
1258:         }
1259:       else // assume JToolBar.VERTICAL
1260:         { 
1261:           if (newInsets == null)
1262:             newInsets = new Insets(16, 2, 2, 2);
1263:           else
1264:             {
1265:               newInsets.top = 16;
1266:               newInsets.left = 2;
1267:               newInsets.bottom = 2;
1268:               newInsets.right = 2;
1269:             }
1270:           return newInsets;  
1271:         }
1272: 
1273:     }
1274:     
1275:     /**
1276:      * Paints the border for the specified component.
1277:      * 
1278:      * @param c  the component.
1279:      * @param g  the graphics device.
1280:      * @param x  the x-coordinate.
1281:      * @param y  the y-coordinate.
1282:      * @param w  the width.
1283:      * @param h  the height.
1284:      */
1285:     public void paintBorder(Component c, Graphics g, int x, int y, int w, 
1286:         int h)
1287:     {
1288:         
1289:       JToolBar tb = (JToolBar) c;
1290:       if (tb.getOrientation() == JToolBar.HORIZONTAL)
1291:         {
1292:            MetalUtils.fillMetalPattern(tb, g, x + 2, y + 2, x + 11, y + h - 5, 
1293:                   MetalLookAndFeel.getControlHighlight(), 
1294:                   MetalLookAndFeel.getControlDarkShadow());
1295:         }
1296:       else
1297:         { 
1298:           MetalUtils.fillMetalPattern(tb, g, x + 2, y + 2, x + w - 5, y + 11, 
1299:                   MetalLookAndFeel.getControlHighlight(), 
1300:                   MetalLookAndFeel.getControlDarkShadow());
1301:         }
1302:     }
1303:     
1304:   }
1305:   
1306:   /**
1307:    * A border for table header cells.
1308:    *
1309:    * @since 1.3
1310:    */
1311:   public static class TableHeaderBorder extends AbstractBorder
1312:   {
1313:     /**
1314:      * The insets of this border.
1315:      */
1316:     // TODO: According to tests that I have done, this is really the border
1317:     // that should be returned by getBorderInsets(). However, the name
1318:     // is very distracting. Is there any deeper meaning in it?
1319:     protected Insets editorBorderInsets;
1320: 
1321:     /**
1322:      * Creates a new instance of <code>TableHeaderBorder</code>.
1323:      */
1324:     public TableHeaderBorder()
1325:     {
1326:       editorBorderInsets = new Insets(1, 1, 1, 1);
1327:     }
1328: 
1329:     /**
1330:      * Return the insets of this border.
1331:      *
1332:      * @return the insets of this border
1333:      */
1334:     public Insets getBorderInsets(Component c)
1335:     {
1336:       return editorBorderInsets;
1337:     }
1338: 
1339:     /**
1340:      * Paints the border.
1341:      *
1342:      * @param c the component for which to paint the border
1343:      * @param g the graphics context to use
1344:      * @param x the x cooridinate of the border rectangle
1345:      * @param y the y cooridinate of the border rectangle
1346:      * @param w the width of the border rectangle
1347:      * @param h the height of the border rectangle
1348:      */
1349:     public void paintBorder(Component c, Graphics g, int x, int y, int w, int h)
1350:     {
1351:       Color dark = MetalLookAndFeel.getControlDarkShadow();
1352:       Color light = MetalLookAndFeel.getWhite();
1353:       Color old = g.getColor();
1354:       g.setColor(light);
1355:       g.drawLine(x, y, x + w - 2, y);
1356:       g.drawLine(x, y, x, y + h - 2);
1357:       g.setColor(dark);
1358:       g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
1359:       g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
1360:       g.setColor(old);
1361:     }
1362:   }
1363: 
1364:   /**
1365:    * Returns a border for Swing buttons in the Metal Look &amp; Feel.
1366:    *
1367:    * @return a border for Swing buttons in the Metal Look &amp; Feel
1368:    */
1369:   public static Border getButtonBorder()
1370:   {
1371:     if (buttonBorder == null)
1372:       {
1373:         Border outer = new ButtonBorder();
1374:         Border inner = getMarginBorder();
1375:         buttonBorder = new BorderUIResource.CompoundBorderUIResource
1376:             (outer, inner);
1377:       }
1378:     return buttonBorder;
1379:   }
1380:   
1381:   /**
1382:    * Returns a border for use with {@link JToggleButton} components.
1383:    *
1384:    * @return A border.
1385:    * 
1386:    * @since 1.3
1387:    */
1388:   public static Border getToggleButtonBorder()
1389:   {
1390:     if (toggleButtonBorder == null)
1391:       {
1392:         Border outer = new ToggleButtonBorder();
1393:         Border inner = getMarginBorder();
1394:         toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource
1395:             (outer, inner);
1396:       }
1397:     return toggleButtonBorder;
1398:   }
1399: 
1400:   /**
1401:    * Returns a border instance that is used with a {@link JInternalFrame} when
1402:    * it is in the iconified state.
1403:    * 
1404:    * @return A border.
1405:    * 
1406:    * @since 1.3
1407:    */
1408:   public static Border getDesktopIconBorder()
1409:   {
1410:     if (desktopIconBorder == null)
1411:       desktopIconBorder = new DesktopIconBorder();
1412:     return desktopIconBorder;      
1413:   }
1414: 
1415:   /**
1416:    * Returns a border for use by the {@link JTextField} component.
1417:    * 
1418:    * @return A border.
1419:    * 
1420:    * @since 1.3
1421:    */
1422:   public static Border getTextFieldBorder()
1423:   {
1424:     if (textFieldBorder == null)
1425:       {
1426:         Border inner = getMarginBorder();
1427:         Border outer = new TextFieldBorder();
1428:         textFieldBorder =
1429:           new BorderUIResource.CompoundBorderUIResource(outer, inner);
1430:       }
1431:     return textFieldBorder;
1432:   }
1433: 
1434:   /**
1435:    * Returns the border that is used for text components (except text fields,
1436:    * which use {@link #getTextFieldBorder}.
1437:    *
1438:    * @return the border that is used for text components
1439:    *
1440:    * @since 1.3
1441:    */
1442:   public static Border getTextBorder()
1443:   {
1444:     if (textBorder == null)
1445:       {
1446:         Border inner = getMarginBorder();
1447:         Border outer = new Flush3DBorder();
1448:         textBorder =
1449:           new BorderUIResource.CompoundBorderUIResource(outer, inner);
1450:       }
1451:     return textBorder;
1452:   }
1453: 
1454:   /**
1455:    * Returns a border for Toolbar buttons in the Metal Look &amp; Feel.
1456:    *
1457:    * @return a border for Toolbar buttons in the Metal Look &amp; Feel
1458:    */
1459:   static Border getToolbarButtonBorder()
1460:   {
1461:     if (toolbarButtonBorder == null)
1462:       {
1463:         Border outer = new ButtonBorder();
1464:         Border inner = new RolloverMarginBorder();
1465:         toolbarButtonBorder = new BorderUIResource.CompoundBorderUIResource
1466:           (outer, inner);
1467:       }
1468:     return toolbarButtonBorder;
1469:   }
1470: 
1471:   /**
1472:    * Returns a shared instance of {@link BasicBorders.MarginBorder}.
1473:    *
1474:    * @return a shared instance of {@link BasicBorders.MarginBorder}
1475:    */
1476:   static Border getMarginBorder()
1477:   {
1478:     if (marginBorder == null)
1479:       marginBorder = new BasicBorders.MarginBorder();
1480:     return marginBorder;
1481:   }
1482: 
1483:   /**
1484:    * Returns a shared instance of a compound border for rollover buttons.
1485:    * 
1486:    * @return A shared border instance.
1487:    */
1488:   static Border getRolloverBorder()
1489:   {
1490:     if (rolloverBorder == null)
1491:       {
1492:         Border outer = new MetalBorders.RolloverButtonBorder();
1493:         Border inner = MetalBorders.getMarginBorder();
1494:         rolloverBorder = new BorderUIResource.CompoundBorderUIResource(outer, 
1495:             inner);
1496:       }
1497:     return rolloverBorder;
1498:   }
1499: 
1500: }