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