Source for javax.swing.BorderFactory

   1: /* BorderFactory.java --
   2:    Copyright (C) 2002, 2004  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;
  40: 
  41: import java.awt.Color;
  42: import java.awt.Font;
  43: 
  44: import javax.swing.border.BevelBorder;
  45: import javax.swing.border.Border;
  46: import javax.swing.border.CompoundBorder;
  47: import javax.swing.border.EmptyBorder;
  48: import javax.swing.border.EtchedBorder;
  49: import javax.swing.border.LineBorder;
  50: import javax.swing.border.MatteBorder;
  51: import javax.swing.border.TitledBorder;
  52: 
  53: public class BorderFactory
  54: {
  55:   private BorderFactory()
  56:   {
  57:     // Do nothing.
  58:   }
  59: 
  60:   /**
  61:    * Creates a line border withe the specified color.
  62:    *
  63:    * @param color A color to use for the line.
  64:    *
  65:    * @return The Border object
  66:    */
  67:   public static Border createLineBorder(Color color)
  68:   {
  69:     return null;
  70:   }
  71: 
  72:   /**
  73:    * Creates a line border withe the specified color and width. The width
  74:    * applies to all 4 sides of the border. To specify widths individually for
  75:    * the top, bottom, left, and right, use
  76:    * createMatteBorder(int,int,int,int,Color).
  77:    *
  78:    * @param color A color to use for the line.
  79:    * @param thickness An int specifying the width in pixels.
  80:    *
  81:    * @return The Border object
  82:    */
  83:   public static Border createLineBorder(Color color, int thickness)
  84:   {
  85:     return new LineBorder(color, thickness);
  86:   }
  87: 
  88:   /**
  89:    * Created a border with a raised beveled edge, using brighter shades of
  90:    * the component's current background color for highlighting, and darker
  91:    * shading for shadows. (In a raised border, highlights are on top and
  92:    * shadows are underneath.)
  93:    *
  94:    * @return The Border object
  95:    */
  96:   public static Border createRaisedBevelBorder()
  97:   {
  98:     return new BevelBorder(BevelBorder.RAISED);
  99:   }
 100: 
 101:   /**
 102:    * Created a border with a lowered beveled edge, using brighter shades of
 103:    * the component's current background color for highlighting, and darker
 104:    * shading for shadows. (In a lowered border, shadows are on top and
 105:    * highlights are underneath.)
 106:    *
 107:    * @return The Border object
 108:    */
 109:   public static Border createLoweredBevelBorder()
 110:   {
 111:     return new BevelBorder(BevelBorder.LOWERED);
 112:   }
 113: 
 114:   /**
 115:    * Create a beveled border of the specified type, using brighter shades of
 116:    * the component's current background color for highlighting, and darker
 117:    * shading for shadows. (In a lowered border, shadows are on top and
 118:    * highlights are underneath.).
 119:    *
 120:    * @param type An int specifying either BevelBorder.LOWERED or
 121:    *     BevelBorder.RAISED
 122:    *
 123:    * @return The Border object
 124:    */
 125:   public static Border createBevelBorder(int type)
 126:   {
 127:     return new BevelBorder(type);
 128:   }
 129: 
 130:   /**
 131:    * Create a beveled border of the specified type, using the specified
 132:    * highlighting and shadowing. The outer edge of the highlighted area uses
 133:    * a brighter shade of the highlight color. The inner edge of the shadow
 134:    * area uses a brighter shade of the shadaw color.
 135:    *
 136:    * @param type An int specifying either BevelBorder.LOWERED or
 137:    *     BevelBorder.RAISED
 138:    * @param highlight A Color object for highlights
 139:    * @param shadow A Color object for shadows
 140:    *
 141:    * @return The Border object
 142:    */
 143:   public static Border createBevelBorder(int type, Color highlight, Color shadow)
 144:   {
 145:     return new BevelBorder(type, highlight, shadow);
 146:   }
 147: 
 148:   /**
 149:    * Create a beveled border of the specified type, using the specified colors
 150:    * for the inner and outer highlight and shadow areas.
 151:    *
 152:    * @param type An int specifying either BevelBorder.LOWERED or
 153:    *     BevelBorder.RAISED
 154:    * @param highlightOuter A Color object for the outer edge of the
 155:    *     highlight area
 156:    * @param highlightInner A Color object for the inner edge of the
 157:    *     highlight area
 158:    * @param shadowOuter A Color object for the outer edge of the shadow area
 159:    * @param shadowInner A Color object for the inner edge of the shadow area
 160:    *
 161:    * @return The Border object
 162:    */
 163:   public static Border createBevelBorder(int type, Color highlightOuter,
 164:                                          Color highlightInner,
 165:                                          Color shadowOuter, Color shadowInner)
 166:   {
 167:     return new BevelBorder(type, highlightOuter, highlightInner, shadowOuter,
 168:                            shadowInner);
 169:   }
 170: 
 171:   /**
 172:    * Create a border with an "etched" look using the component's current
 173:    * background color for highlighting and shading.
 174:    *
 175:    * @return The Border object
 176:    */
 177:   public static Border createEtchedBorder()
 178:   {
 179:     return new EtchedBorder();
 180:   }
 181: 
 182:   /**
 183:    * Create a border with an "etched" look using the component's current
 184:    * background color for highlighting and shading.
 185:    *
 186:    * @return The Border object
 187:    */
 188:   public static Border createEtchedBorder(int etchType)
 189:   {
 190:     return new EtchedBorder(etchType);
 191:   }
 192: 
 193:   /**
 194:    * Create a border with an "etched" look using the specified highlighting and
 195:    * shading colors.
 196:    *
 197:    * @param highlight A Color object for the border highlights
 198:    * @param shadow A Color object for the border shadows
 199:    *
 200:    * @return The Border object
 201:    */
 202:   public static Border createEtchedBorder(Color highlight, Color shadow)
 203:   {
 204:     return new EtchedBorder(highlight, shadow);
 205:   }
 206: 
 207:   /**
 208:    * Create a border with an "etched" look using the specified highlighting and
 209:    * shading colors.
 210:    *
 211:    * @param highlight A Color object for the border highlights
 212:    * @param shadow A Color object for the border shadows
 213:    *
 214:    * @return The Border object
 215:    */
 216:   public static Border createEtchedBorder(int etchType, Color highlight,
 217:                                           Color shadow)
 218:   {
 219:     return new EtchedBorder(etchType, highlight, shadow);
 220:   }
 221: 
 222:   /**
 223:    * Create a new title border specifying the text of the title, using the
 224:    * default border (etched), using the default text position (sitting on the
 225:    * top line) and default justification (left) and using the default font and
 226:    * text color determined by the current look and feel.
 227:    *
 228:    * @param title A String containing the text of the title
 229:    *
 230:    * @return The TitledBorder object
 231:    */
 232:   public static TitledBorder createTitledBorder(String title)
 233:   {
 234:     return new TitledBorder(title);
 235:   }
 236: 
 237:   /**
 238:    * Create a new title border with an empty title specifying the border
 239:    * object, using the default text position (sitting on the top line) and
 240:    * default justification (left) and using the default font, text color,
 241:    * and border determined by the current look and feel. (The Motif and Windows
 242:    * look and feels use an etched border; The Java look and feel use a
 243:    * gray border.)
 244:    *
 245:    * @param border The Border object to add the title to
 246:    *
 247:    * @return The TitledBorder object
 248:    */
 249:   public static TitledBorder createTitledBorder(Border border)
 250:   {
 251:     return new TitledBorder(border);
 252:   }
 253: 
 254:   /**
 255:    * Add a title to an existing border, specifying the text of the title, using
 256:    * the default positioning (sitting on the top line) and default
 257:    * justification (left) and using the default font and text color determined
 258:    * by the current look and feel.
 259:    *
 260:    * @param order The Border object to add the title to
 261:    * @param title A String containing the text of the title
 262:    *
 263:    * @return The TitledBorder object
 264:    */
 265:   public static TitledBorder createTitledBorder(Border border, String title)
 266:   {
 267:     return new TitledBorder(border, title);
 268:   }
 269: 
 270:   /**
 271:    * Add a title to an existing border, specifying the text of the title along
 272:    * with its positioning, using the default font and text color determined by
 273:    * the current look and feel.
 274:    *
 275:    * @param border The Border object to add the title to
 276:    * @param title A String containing the text of the title
 277:    * @param titleJustification An int specifying the left/right position of
 278:    *     the title -- one of TitledBorder.LEFT, TitledBorder.CENTER, or
 279:    *     TitledBorder.RIGHT, TitledBorder.DEFAULT_JUSTIFICATION (left).
 280:    * @param titlePosition An int specifying the vertical position of the text
 281:    *     in relation to the border -- one of: TitledBorder.ABOVE_TOP,
 282:    *     TitledBorder.TOP (sitting on the top line), TitledBorder.BELOW_TOP,
 283:    *     TitledBorder.ABOVE_BOTTOM, TitledBorder.BOTTOM (sitting on the bottom
 284:    *     line), TitledBorder.BELOW_BOTTOM, or TitledBorder.DEFAULT_POSITION
 285:    *     (top).
 286:    *
 287:    * @return The TitledBorder object
 288:    */
 289:   public static TitledBorder createTitledBorder(Border border, String title,
 290:                                                 int titleJustification,
 291:                                                 int titlePosition)
 292:   {
 293:     return new TitledBorder(border, title, titleJustification, titlePosition);
 294:   }
 295: 
 296:   /**
 297:    * Add a title to an existing border, specifying the text of the title along
 298:    * with its positioning and font, using the default text color determined by
 299:    * the current look and feel.
 300:    *
 301:    * @param border - the Border object to add the title to
 302:    * @param title - a String containing the text of the title
 303:    * @param titleJustification - an int specifying the left/right position of
 304:    *     the title -- one of TitledBorder.LEFT, TitledBorder.CENTER, or
 305:    *     TitledBorder.RIGHT, TitledBorder.DEFAULT_JUSTIFICATION (left).
 306:    * @param titlePosition - an int specifying the vertical position of the
 307:    *     text in relation to the border -- one of: TitledBorder.ABOVE_TOP,
 308:    *     TitledBorder.TOP (sitting on the top line), TitledBorder.BELOW_TOP,
 309:    *     TitledBorder.ABOVE_BOTTOM, TitledBorder.BOTTOM (sitting on the bottom
 310:    *     line), TitledBorder.BELOW_BOTTOM, or TitledBorder.DEFAULT_POSITION (top).
 311:    * @param titleFont - a Font object specifying the title font
 312:    *
 313:    * @return The TitledBorder object
 314:    */
 315:   public static TitledBorder createTitledBorder(Border border, String title,
 316:                                                 int titleJustification,
 317:                                                 int titlePosition,
 318:                                                 Font titleFont)
 319:   {
 320:     return new TitledBorder(border, title, titleJustification, titlePosition,
 321:                             titleFont);
 322:   }
 323: 
 324:   /**
 325:    * Add a title to an existing border, specifying the text of the title along
 326:    * with its positioning, font, and color.
 327:    *
 328:    * @param border - the Border object to add the title to
 329:    * @param title - a String containing the text of the title
 330:    * @param titleJustification - an int specifying the left/right position of
 331:    *     the title -- one of TitledBorder.LEFT, TitledBorder.CENTER, or
 332:    *     TitledBorder.RIGHT, TitledBorder.DEFAULT_JUSTIFICATION (left).
 333:    * @param titlePosition - an int specifying the vertical position of the text
 334:    *     in relation to the border -- one of: TitledBorder.ABOVE_TOP,
 335:    *     TitledBorder.TOP (sitting on the top line), TitledBorder.BELOW_TOP,
 336:    *     TitledBorder.ABOVE_BOTTOM, TitledBorder.BOTTOM (sitting on the bottom
 337:    *     line), TitledBorder.BELOW_BOTTOM, or TitledBorder.DEFAULT_POSITION (top).
 338:    * @param titleFont - a Font object specifying the title font
 339:    * @param titleColor - a Color object specifying the title color
 340:    *
 341:    * @return The TitledBorder object
 342:    */
 343:   public static TitledBorder createTitledBorder(Border border, String title,
 344:                                                 int titleJustification,
 345:                                                 int titlePosition,
 346:                                                 Font titleFont, Color titleColor)
 347:   {
 348:     return new TitledBorder(border, title, titleJustification, titlePosition,
 349:                             titleFont, titleColor);
 350:   }
 351: 
 352:   /**
 353:    * Creates an empty border that takes up no space. (The width of the top,
 354:    * bottom, left, and right sides are all zero.)
 355:    *
 356:    * @return The Border object
 357:    */
 358:   public static Border createEmptyBorder()
 359:   {
 360:     return new EmptyBorder(0, 0, 0, 0);
 361:   }
 362: 
 363:   /**
 364:    * Creates an empty border that takes up no space but which does no drawing,
 365:    * specifying the width of the top, left, bottom, and right sides.
 366:    *
 367:    * @param top An int specifying the width of the top in pixels
 368:    * @param left An int specifying the width of the left side in pixels
 369:    * @param bottom An int specifying the width of the right side in pixels
 370:    * @param right An int specifying the width of the bottom in pixels
 371:    *
 372:    * @return The Border object
 373:    */
 374:   public static Border createEmptyBorder(int top, int left, int bottom,
 375:                                          int right)
 376:   {
 377:     return new EmptyBorder(top, left, bottom, right);
 378:   }
 379: 
 380:   /**
 381:    * Create a compound border with a null inside edge and a null outside edge.
 382:    *
 383:    * @return The CompoundBorder object
 384:    */
 385:   public static CompoundBorder createCompoundBorder()
 386:   {
 387:     return new CompoundBorder();
 388:   }
 389: 
 390:   /**
 391:    * Create a compound border specifying the border objects to use for the
 392:    * outside and inside edges.
 393:    *
 394:    * @param outsideBorder A Border object for the outer edge of the
 395:    *     compound border
 396:    * @param insideBorder A Border object for the inner edge of the
 397:    *     compound border
 398:    *
 399:    * @return The CompoundBorder object
 400:    */
 401:   public static CompoundBorder createCompoundBorder(Border outsideBorder,
 402:                                                     Border insideBorder)
 403:   {
 404:     return new CompoundBorder(outsideBorder, insideBorder);
 405:   }
 406: 
 407:   /**
 408:    * Create a matte-look border using a solid color. (The difference between
 409:    * this border and a line border is that you can specify the individual border
 410:    * dimensions.)
 411:    * 
 412:    * @param top
 413:    *          An int specifying the width of the top in pixels
 414:    * @param left
 415:    *          An int specifying the width of the left side in pixels
 416:    * @param bottom
 417:    *          An int specifying the width of the right side in pixels
 418:    * @param right
 419:    *          An int specifying the width of the bottom in pixels
 420:    * @param color
 421:    *          A Color to use for the border
 422:    * @return The MatteBorder object
 423:    */
 424:   public static MatteBorder createMatteBorder(int top, int left, int bottom,
 425:                                               int right, Color color)
 426:   {
 427:     return new MatteBorder(top, left, bottom, right, color);
 428:   }
 429: 
 430:   /**
 431:    * Create a matte-look border that consists of multiple tiles of a specified
 432:    * icon. Multiple copies of the icon are placed side-by-side to fill up the
 433:    * border area.
 434:    *
 435:    * Note:
 436:    * If the icon doesn't load, the border area is painted gray.
 437:    *
 438:    * @param top An int specifying the width of the top in pixels
 439:    * @param left An int specifying the width of the left side in pixels
 440:    * @param bottom An int specifying the width of the right side in pixels
 441:    * @param right An int specifying the width of the bottom in pixels
 442:    * @param tileIcon The Icon object used for the border tiles
 443:    *
 444:    * @return The MatteBorder object
 445:    */
 446:   public static MatteBorder createMatteBorder(int top, int left, int bottom,
 447:                                               int right, Icon tileIcon)
 448:   {
 449:     return new MatteBorder(top, left, bottom, right, tileIcon);
 450:   }
 451: }