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.JInternalFrame;
  49: import javax.swing.JMenu;
  50: import javax.swing.JMenuBar;
  51: import javax.swing.JMenuItem;
  52: import javax.swing.JTextField;
  53: import javax.swing.border.AbstractBorder;
  54: import javax.swing.border.Border;
  55: import javax.swing.plaf.BorderUIResource;
  56: import javax.swing.plaf.UIResource;
  57: import javax.swing.plaf.basic.BasicBorders;
  58: 
  59: 
  60: /**
  61:  * This factory class creates borders for the different Swing components
  62:  * UI.
  63:  *
  64:  * @author Roman Kennke (roman@kennke.org)
  65:  */
  66: public class MetalBorders
  67: {
  68: 
  69:   /** The shared instance for getButtonBorder(). */
  70:   private static Border buttonBorder;
  71: 
  72:   /** The shared instance for getRolloverButtonBorder(). */
  73:   private static Border toolbarButtonBorder;
  74: 
  75:   /** The shared instance for getTextFieldBorder(). */
  76:   private static Border textFieldBorder;
  77: 
  78:   /**
  79:    * A MarginBorder that gets shared by multiple components.
  80:    * Created on demand by the private helper function {@link
  81:    * #getMarginBorder()}.
  82:    */
  83:   private static BasicBorders.MarginBorder marginBorder;
  84: 
  85:   /**
  86:    * The border that is drawn around Swing buttons.
  87:    */
  88:   public static class ButtonBorder
  89:     extends AbstractBorder
  90:     implements UIResource
  91:   {
  92:     /** The borders insets. */
  93:     protected static Insets borderInsets = new Insets(3, 3, 3, 3);
  94: 
  95:     /**
  96:      * Creates a new instance of ButtonBorder.
  97:      */
  98:     public ButtonBorder()
  99:     {
 100:     }
 101: 
 102:     /**
 103:      * Paints the button border.
 104:      *
 105:      * @param c the component for which we paint the border
 106:      * @param g the Graphics context to use
 107:      * @param x the X coordinate of the upper left corner of c
 108:      * @param y the Y coordinate of the upper left corner of c
 109:      * @param w the width of c
 110:      * @param h the height of c
 111:      */
 112:     public void paintBorder(Component c, Graphics g, int x, int y, int w,
 113:                             int h)
 114:     {
 115:       ButtonModel bmodel = null;
 116:       
 117:       if (c instanceof AbstractButton)
 118:         bmodel = ((AbstractButton) c).getModel();
 119: 
 120:       Color darkShadow = MetalLookAndFeel.getControlDarkShadow();
 121:       Color shadow = MetalLookAndFeel.getControlShadow();
 122:       Color light = MetalLookAndFeel.getWhite();
 123:       Color middle = MetalLookAndFeel.getControl();
 124: 
 125:       // draw dark border
 126:       g.setColor(darkShadow);
 127:       g.drawRect(x, y, w - 2, h - 2);
 128: 
 129:       if (!bmodel.isPressed())
 130:         {
 131:           // draw light border
 132:           g.setColor(light);
 133:           g.drawRect(x + 1, y + 1, w - 2, h - 2);
 134: 
 135:           // draw crossing pixels of both borders
 136:           g.setColor(middle);
 137:           g.drawRect(x + 1, y + h - 2, 0, 0);
 138:           g.drawRect(x + w - 2, y + 1, 0, 0);
 139:         }
 140:       else
 141:         {
 142:           // draw light border
 143:           g.setColor(light);
 144:           g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
 145:           g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
 146: 
 147:           // draw shadow border
 148:           g.setColor(middle);
 149:           g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
 150:           g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
 151: 
 152:           // draw crossing pixels of both borders
 153:           g.setColor(shadow);
 154:           g.drawRect(x + 1, y + h - 2, 0, 0);
 155:           g.drawRect(x + w - 2, y + 1, 0, 0);
 156:         }
 157:     }
 158: 
 159:     /**
 160:      * Returns the insets of the ButtonBorder.
 161:      *
 162:      * @param c the component for which the border is used
 163:      *
 164:      * @return the insets of the ButtonBorder
 165:      */
 166:     public Insets getBorderInsets(Component c)
 167:     {
 168:       return getBorderInsets(c, null);
 169:     }
 170: 
 171:     /**
 172:      * Returns the insets of the ButtonBorder in the specified Insets object.
 173:      *
 174:      * @param c the component for which the border is used
 175:      * @param newInsets the insets object where to put the values
 176:      *
 177:      * @return the insets of the ButtonBorder
 178:      */
 179:     public Insets getBorderInsets(Component c, Insets newInsets)
 180:     {
 181:       if (newInsets == null)
 182:         newInsets = new Insets(0, 0, 0, 0);
 183: 
 184:       AbstractButton b = (AbstractButton) c;
 185:       newInsets.bottom = borderInsets.bottom;
 186:       newInsets.left = borderInsets.left;
 187:       newInsets.right = borderInsets.right;
 188:       newInsets.top = borderInsets.top;
 189:       return newInsets;
 190:     }
 191:   }
 192: 
 193:   /**
 194:    * A simple 3D border.
 195:    */
 196:   public static class Flush3DBorder extends AbstractBorder
 197:     implements UIResource
 198:   {
 199:     /**
 200:      * Creates a new border instance.
 201:      */
 202:     public Flush3DBorder()
 203:     {
 204:     }
 205:     
 206:     /**
 207:      * Returns the border insets.
 208:      * 
 209:      * @param c  the component (ignored).
 210:      * 
 211:      * @return The border insets.
 212:      */
 213:     public Insets getBorderInsets(Component c)
 214:     {
 215:       return getBorderInsets(c, null);
 216:     }
 217:     
 218:     /**
 219:      * Returns the border insets.
 220:      * 
 221:      * @param c  the component (ignored).
 222:      * @return The border insets.
 223:      */
 224:     public Insets getBorderInsets(Component c, Insets newInsets)
 225:     {
 226:       if (newInsets == null)
 227:         newInsets = new Insets(2, 2, 2, 2);
 228:       else
 229:         {
 230:           newInsets.top = 2;
 231:           newInsets.left = 2;
 232:           newInsets.bottom = 2;
 233:           newInsets.right = 2;
 234:         }
 235:       return newInsets;  
 236:     }
 237:     
 238:     /**
 239:      * Paints the border for the specified component.
 240:      * 
 241:      * @param c  the component (ignored).
 242:      * @param g  the graphics device.
 243:      * @param x  the x-coordinate.
 244:      * @param y  the y-coordinate.
 245:      * @param w  the width.
 246:      * @param h  the height.
 247:      */
 248:     public void paintBorder(Component c, Graphics g, int x, int y, int w, 
 249:         int h)
 250:     {              
 251:       Color savedColor = g.getColor();
 252:       g.setColor(MetalLookAndFeel.getControlDarkShadow());
 253:       g.drawRect(x, y, w - 2, h - 2);
 254:       g.setColor(MetalLookAndFeel.getControlHighlight());
 255:       g.drawRect(x + 1, y + 1, w - 2, h - 2);
 256:       g.setColor(MetalLookAndFeel.getControl());
 257:       g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
 258:       g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
 259:       g.setColor(savedColor);
 260:     }
 261:     
 262:   }
 263:     
 264:   /**
 265:    * A border used for the {@link JTextField} component.
 266:    */
 267:   public static class TextFieldBorder extends Flush3DBorder
 268:     implements UIResource
 269:   {
 270:     /**
 271:      * Creates a new border instance.
 272:      */
 273:     public TextFieldBorder()
 274:     {
 275:     }
 276:     
 277:     /**
 278:      * Paints the border for the specified component.
 279:      * 
 280:      * @param c  the component (ignored).
 281:      * @param g  the graphics device.
 282:      * @param x  the x-coordinate.
 283:      * @param y  the y-coordinate.
 284:      * @param w  the width.
 285:      * @param h  the height.
 286:      */
 287:     public void paintBorder(Component c, Graphics g, int x, int y, int w, 
 288:         int h)
 289:     {        
 290:       if (c.isEnabled())
 291:         super.paintBorder(c, g, x, y, w, h);
 292:       else
 293:         {
 294:           Color savedColor = g.getColor();
 295:           g.setColor(MetalLookAndFeel.getControlShadow());
 296:           g.drawRect(x, y, w - 1, h - 1);
 297:           g.setColor(savedColor);
 298:         }
 299:     }
 300:     
 301:   }
 302: 
 303:   /**
 304:    * A border used when painting {@link JInternalFrame} instances.
 305:    */
 306:   public static class InternalFrameBorder extends AbstractBorder
 307:     implements UIResource
 308:   {
 309:     /**
 310:      * Creates a new border instance.
 311:      */
 312:     public InternalFrameBorder()
 313:     {
 314:     }
 315:     
 316:     /**
 317:      * Returns the border insets.
 318:      * 
 319:      * @param c  the component (ignored).
 320:      * 
 321:      * @return The border insets.
 322:      */
 323:     public Insets getBorderInsets(Component c)
 324:     {
 325:       return getBorderInsets(c, null);
 326:     }
 327:     
 328:     /**
 329:      * Returns the border insets.
 330:      * 
 331:      * @param c  the component (ignored).
 332:      * @return The border insets.
 333:      */
 334:     public Insets getBorderInsets(Component c, Insets newInsets)
 335:     {
 336:       if (newInsets == null)
 337:         newInsets = new Insets(5, 5, 5, 5);
 338:       else
 339:         {
 340:           newInsets.top = 5;
 341:           newInsets.left = 5;
 342:           newInsets.bottom = 5;
 343:           newInsets.right = 5;
 344:         }
 345:       return newInsets;  
 346:     }
 347:     
 348:     /**
 349:      * Paints the border for the specified component.
 350:      * 
 351:      * @param c  the component.
 352:      * @param g  the graphics device.
 353:      * @param x  the x-coordinate.
 354:      * @param y  the y-coordinate.
 355:      * @param w  the width.
 356:      * @param h  the height.
 357:      */
 358:     public void paintBorder(Component c, Graphics g, int x, int y, int w, 
 359:         int h)
 360:     {
 361:         
 362:       JInternalFrame f = (JInternalFrame) c;
 363:       if (f.isSelected())
 364:         g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
 365:       else
 366:         g.setColor(MetalLookAndFeel.getControlDarkShadow());
 367:       
 368:       // fill the border background
 369:       g.fillRect(x, y, w, 5);
 370:       g.fillRect(x, y, 5, h);
 371:       g.fillRect(x + w - 5, y, 5, h);
 372:       g.fillRect(x, y + h - 5, w, 5);
 373:       
 374:       // draw a dot in each corner
 375:       g.setColor(MetalLookAndFeel.getControl());
 376:       g.fillRect(x, y, 1, 1);
 377:       g.fillRect(x + w - 1, y, 1, 1);
 378:       g.fillRect(x + w - 1, y + h - 1, 1, 1);
 379:       g.fillRect(x, y + h - 1, 1, 1);
 380:       
 381:       // draw the lines
 382:       g.setColor(MetalLookAndFeel.getBlack());
 383:       g.drawLine(x + 14, y + 2, x + w - 15, y + 2);
 384:       g.drawLine(x + 14, y + h - 3, x + w - 15, y + h - 3);
 385:       g.drawLine(x + 2, y + 14, x + 2, y + h - 15);
 386:       g.drawLine(x + w - 3, y + 14, x + w - 3, y + h - 15);
 387:       
 388:       // draw the line highlights
 389:       g.setColor(MetalLookAndFeel.getControl());
 390:       g.drawLine(x + 15, y + 3, x + w - 14, y + 3);
 391:       g.drawLine(x + 15, y + h - 2, x + w - 14, y + h - 2);
 392:       g.drawLine(x + 3, y + 15, x + 3, y + h - 14);
 393:       g.drawLine(x + w - 2, y + 15, x + w - 2, y + h - 14);
 394:     }
 395:     
 396:   }
 397: 
 398:   /**
 399:    * A border used for {@link JMenu} and {@link JMenuItem} components.
 400:    */
 401:   public static class MenuItemBorder
 402:       extends AbstractBorder
 403:       implements UIResource
 404:   {
 405:     /** The border insets. */
 406:     protected static Insets borderInsets = new Insets(2, 2, 2, 2);
 407:     
 408:     // TODO: find where the real colors come from
 409:     private static Color borderColorDark = new Color(102, 102, 153);
 410:     private static Color borderColorLight = new Color(255, 255, 255);
 411:     
 412:     /**
 413:      * Creates a new border instance.
 414:      */
 415:     public MenuItemBorder()
 416:     {
 417:     }
 418:     
 419:     /**
 420:      * Paints the border for the component.  A border is painted only if the
 421:      * component is a selected {@link JMenu} or an armed {@link JMenuItem}.
 422:      * 
 423:      * @param c  the component.
 424:      * @param g  the graphics device.
 425:      * @param x  the x-coordinate of the border area.
 426:      * @param y  the y-coordinate of the border area.
 427:      * @param w  the width of the border area.
 428:      * @param h  the height of the border area.
 429:      */
 430:     public void paintBorder(Component c, Graphics g, int x, int y, int w,
 431:         int h)
 432:     {
 433:       if (c instanceof JMenu) {
 434:         JMenu menu = (JMenu) c;
 435:         if (menu.isSelected())
 436:         {
 437:           g.setColor(borderColorDark);
 438:           g.drawLine(x, y, x, y + h);
 439:           g.drawLine(x, y, x + w, y);
 440:           g.drawLine(x + w - 2, y + 1, x + w - 2, y + h);
 441:           g.setColor(borderColorLight);
 442:           g.drawLine(x + w - 1, y + 1, x + w - 1, y + h);
 443:         }
 444:       }
 445:       else if (c instanceof JMenuItem)
 446:       {
 447:         JMenuItem item = (JMenuItem) c;
 448:         if (item.isArmed()) 
 449:         {
 450:           g.setColor(borderColorDark);
 451:           g.drawLine(x, y, x + w, y);
 452:           g.setColor(borderColorLight);
 453:           g.drawLine(x, y + h - 1, x + w, y + h - 1);
 454:         }          
 455:       }
 456:     }
 457:     
 458:     /**
 459:      * Returns the border insets.
 460:      * 
 461:      * @param c  the component (ignored).
 462:      * 
 463:      * @return The border insets.
 464:      */
 465:     public Insets getBorderInsets(Component c)
 466:     {
 467:       return borderInsets;
 468:     }
 469:     
 470:     /**
 471:      * Populates <code>insets</code> with the border insets, then returns it.
 472:      * 
 473:      * @param c  the component (ignored).
 474:      * @param insets  the object to populate with the border insets.
 475:      * 
 476:      * @return The border insets.
 477:      * 
 478:      * @throws NullPointerException if <code>insets</code> is <code>null</code>.
 479:      */
 480:     public Insets getBorderInsets(Component c, Insets insets)
 481:     {
 482:       insets.left = borderInsets.left;
 483:       insets.top = borderInsets.top;
 484:       insets.bottom = borderInsets.bottom;
 485:       insets.right = borderInsets.right;
 486:       return insets;
 487:     }
 488:   }
 489: 
 490:   /**
 491:    * A border used for {@link JMenuBar} components.
 492:    */
 493:   public static class MenuBarBorder
 494:       extends AbstractBorder
 495:       implements UIResource
 496:   {
 497:     /** The border insets. */
 498:     protected static Insets borderInsets = new Insets(1, 0, 1, 0);
 499:     
 500:     // TODO: find where this color really comes from
 501:     private static Color borderColor = new Color(153, 153, 153);
 502:     
 503:     /**
 504:      * Creates a new border instance.
 505:      */
 506:     public MenuBarBorder()
 507:     {
 508:     }
 509:     
 510:     /**
 511:      * Paints the border for the component.  A border is painted only if the
 512:      * component is a selected {@link JMenu} or an armed {@link JMenuItem}.
 513:      * 
 514:      * @param c  the component.
 515:      * @param g  the graphics device.
 516:      * @param x  the x-coordinate of the border area.
 517:      * @param y  the y-coordinate of the border area.
 518:      * @param w  the width of the border area.
 519:      * @param h  the height of the border area.
 520:      */
 521:     public void paintBorder(Component c, Graphics g, int x, int y, int w,
 522:         int h)
 523:     {
 524:       g.setColor(borderColor);
 525:       g.drawLine(x, y + h - 1, x + w, y + h - 1);
 526:     }
 527:     
 528:     /**
 529:      * Returns the border insets.
 530:      * 
 531:      * @param c  the component (ignored).
 532:      * 
 533:      * @return The border insets.
 534:      */
 535:     public Insets getBorderInsets(Component c)
 536:     {
 537:       return borderInsets;
 538:     }
 539:     
 540:     /**
 541:      * Populates <code>insets</code> with the border insets, then returns it.
 542:      * 
 543:      * @param c  the component (ignored).
 544:      * @param insets  the object to populate with the border insets.
 545:      * 
 546:      * @return The border insets.
 547:      * 
 548:      * @throws NullPointerException if <code>insets</code> is <code>null</code>.
 549:      */
 550:     public Insets getBorderInsets(Component c, Insets insets)
 551:     {
 552:       insets.left = borderInsets.left;
 553:       insets.top = borderInsets.top;
 554:       insets.bottom = borderInsets.bottom;
 555:       insets.right = borderInsets.right;
 556:       return insets;
 557:     }
 558:   }
 559: 
 560:   /**
 561:    * A border for JScrollPanes.
 562:    */
 563:   public static class ScrollPaneBorder
 564:     extends AbstractBorder
 565:     implements UIResource
 566:   {
 567:     /** The border insets. */
 568:     private static Insets insets = new Insets(1, 1, 2, 2);
 569:     
 570:     /**
 571:      * Constructs a new ScrollPaneBorder.
 572:      */
 573:     public ScrollPaneBorder()
 574:     {
 575:     }
 576:     
 577:     /**
 578:      * Returns the insets of the border for the Component <code>c</code>.
 579:      *
 580:      * @param c the Component for which we return the border insets
 581:      */
 582:     public Insets getBorderInsets(Component c)
 583:     {
 584:       return insets;
 585:     }
 586: 
 587:     /**
 588:      * Paints the border.
 589:      *
 590:      * @param c the Component for which the border is painted
 591:      * @param g the Graphics context
 592:      * @param x the X coordinate of the upper left corner of the border
 593:      * @param y the Y coordinate of the upper left corner of the border
 594:      * @param w the width of the border
 595:      * @param h the height of the border
 596:      */
 597:     public void paintBorder(Component c, Graphics g, int x, int y,
 598:                             int w, int h)
 599:     {
 600:       Color darkShadow = MetalLookAndFeel.getControlDarkShadow();
 601:       Color shadow = MetalLookAndFeel.getControlShadow();
 602:       Color light = MetalLookAndFeel.getWhite();
 603:       Color middle = MetalLookAndFeel.getControl();
 604: 
 605:       // paint top border line
 606:       g.setColor(darkShadow);
 607:       g.drawLine(x, y, x + w - 2, y);
 608: 
 609:       // paint left border line
 610:       g.drawLine(x, y, x, y + h - 2);
 611:  
 612:       // paint right inner border line
 613:       g.drawLine(x + w - 2, y, x + w - 2, y + h + 1);
 614: 
 615:       // paint bottom inner border line
 616:       g.drawLine(x + 2, y + h - 2, x + w - 2, y + h - 2);
 617: 
 618:       // draw right outer border line
 619:       g.setColor(light);
 620:       g.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
 621: 
 622:       // draw bottom outer border line
 623:       g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
 624: 
 625:       // paint the lighter points
 626:       g.setColor(middle);
 627:       g.drawLine(x + w - 1, y, x + w - 1, y);
 628:       g.drawLine(x + w - 2, y + 2, x + w - 2, y + 2);
 629:       g.drawLine(x, y + h - 1, x, y + h - 1);
 630:       g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
 631: 
 632:     }
 633:     
 634:   }
 635:   
 636:   /**
 637:    * This border is used in Toolbar buttons as inner border.
 638:    */
 639:   static class RolloverMarginBorder extends AbstractBorder
 640:   {
 641:     /** The borders insets. */
 642:     protected static Insets borderInsets = new Insets(3, 3, 3, 3);
 643: 
 644:     /**
 645:      * Creates a new instance of RolloverBorder.
 646:      */
 647:     public RolloverMarginBorder()
 648:     {
 649:     }
 650:     
 651:     /**
 652:      * Returns the insets of the RolloverBorder.
 653:      *
 654:      * @param c the component for which the border is used
 655:      *
 656:      * @return the insets of the RolloverBorder
 657:      */
 658:     public Insets getBorderInsets(Component c)
 659:     {
 660:       return getBorderInsets(c, null);
 661:     }
 662: 
 663:     /**
 664:      * Returns the insets of the RolloverMarginBorder in the specified
 665:      * Insets object.
 666:      *
 667:      * @param c the component for which the border is used
 668:      * @param newInsets the insets object where to put the values
 669:      *
 670:      * @return the insets of the RolloverMarginBorder
 671:      */
 672:     public Insets getBorderInsets(Component c, Insets newInsets)
 673:     {
 674:       if (newInsets == null)
 675:         newInsets = new Insets(0, 0, 0, 0);
 676: 
 677:       AbstractButton b = (AbstractButton) c;
 678:       Insets margin = b.getMargin();
 679:       newInsets.bottom = borderInsets.bottom;
 680:       newInsets.left = borderInsets.left;
 681:       newInsets.right = borderInsets.right;
 682:       newInsets.top = borderInsets.top;
 683:       return newInsets;
 684:     }
 685:   }
 686: 
 687:   /**
 688:    * A border implementation for popup menus.
 689:    */
 690:   public static class PopupMenuBorder
 691:     extends AbstractBorder
 692:     implements UIResource
 693:   {
 694: 
 695:     /** The border's insets. */
 696:     protected static Insets borderInsets = new Insets(2, 2, 1, 1);
 697: 
 698:     /**
 699:      * Constructs a new PopupMenuBorder.
 700:      */
 701:     public PopupMenuBorder()
 702:     {
 703:     }
 704:     
 705:     /**
 706:      * Returns the insets of the border, creating a new Insets instance
 707:      * with each call.
 708:      *
 709:      * @param c the component for which we return the border insets
 710:      *          (not used here)
 711:      */
 712:     public Insets getBorderInsets(Component c)
 713:     {
 714:       return getBorderInsets(c, null);
 715:     }
 716:     
 717:     /**
 718:      * Returns the insets of the border, using the supplied Insets instance.
 719:      *
 720:      * @param c the component for which we return the border insets
 721:      *          (not used here)
 722:      * @param i the Insets instance to fill with the Insets values
 723:      */
 724:     public Insets getBorderInsets(Component c, Insets i)
 725:     {
 726:       Insets insets;
 727:       if (i == null)
 728:         insets = new Insets(borderInsets.top, borderInsets.left,
 729:                             borderInsets.bottom, borderInsets.right);
 730:       else
 731:         {
 732:           insets = i;
 733:           insets.top = borderInsets.top;
 734:           insets.left = borderInsets.left;
 735:           insets.bottom = borderInsets.bottom;
 736:           insets.right = borderInsets.right;
 737:         }
 738:       
 739:       return insets;
 740:     }
 741: 
 742:     /**
 743:      * Paints the border for component <code>c</code> using the
 744:      * Graphics context <code>g</code> with the dimension
 745:      * <code>x, y, w, h</code>.
 746:      *
 747:      * @param c the component for which we paint the border
 748:      * @param g the Graphics context to use
 749:      * @param x the X coordinate of the upper left corner of c
 750:      * @param y the Y coordinate of the upper left corner of c
 751:      * @param w the width of c
 752:      * @param h the height of c
 753:      */
 754:     public void paintBorder(Component c, Graphics g, int x, int y, int w,
 755:                             int h)
 756:     {
 757:       Color darkShadow = MetalLookAndFeel.getPrimaryControlDarkShadow();
 758:       Color light = MetalLookAndFeel.getPrimaryControlHighlight();
 759: 
 760:       // draw dark outer border
 761:       g.setColor(darkShadow);
 762:       g.drawRect(x, y, w - 1, h - 1);
 763:       
 764:       // draw highlighted inner border (only top and left)
 765:       g.setColor(light);
 766:       g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
 767:       g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
 768:     }
 769:     
 770:   }
 771: 
 772:   /**
 773:    * Returns a border for Swing buttons in the Metal Look &amp; Feel.
 774:    *
 775:    * @return a border for Swing buttons in the Metal Look &amp; Feel
 776:    */
 777:   public static Border getButtonBorder()
 778:   {
 779:     if (buttonBorder == null)
 780:       {
 781:         Border outer = new ButtonBorder();
 782:         Border inner = getMarginBorder();
 783:         buttonBorder = new BorderUIResource.CompoundBorderUIResource
 784:             (outer, inner);
 785:       }
 786:     return buttonBorder;
 787:   }
 788: 
 789:   /**
 790:    * Returns a border for use by the {@link JTextField} component.
 791:    * 
 792:    * @return A border.
 793:    * 
 794:    * @since 1.3
 795:    */
 796:   public static Border getTextFieldBorder()
 797:   {
 798:     if (textFieldBorder == null)
 799:       textFieldBorder = new TextFieldBorder();
 800:     return textFieldBorder;
 801:   }
 802: 
 803:   /**
 804:    * Returns a border for Toolbar buttons in the Metal Look &amp; Feel.
 805:    *
 806:    * @return a border for Toolbar buttons in the Metal Look &amp; Feel
 807:    */
 808:   static Border getToolbarButtonBorder()
 809:   {
 810:     if (toolbarButtonBorder == null)
 811:       {
 812:         Border outer = new ButtonBorder();
 813:         Border inner = new RolloverMarginBorder();
 814:         toolbarButtonBorder = new BorderUIResource.CompoundBorderUIResource
 815:           (outer, inner);
 816:       }
 817:     return toolbarButtonBorder;
 818:   }
 819: 
 820:   /**
 821:    * Returns a shared instance of {@link BasicBorders.MarginBorder}.
 822:    *
 823:    * @return a shared instance of {@link BasicBorders.MarginBorder}
 824:    */
 825:   static Border getMarginBorder()
 826:   {
 827:     if (marginBorder == null)
 828:       marginBorder = new BasicBorders.MarginBorder();
 829:     return marginBorder;
 830:   }
 831: }