001/* BorderFactory.java --
002   Copyright (C) 2002, 2004  Free Software Foundation, Inc.
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038
039package javax.swing;
040
041import java.awt.Color;
042import java.awt.Font;
043
044import javax.swing.border.BevelBorder;
045import javax.swing.border.Border;
046import javax.swing.border.CompoundBorder;
047import javax.swing.border.EmptyBorder;
048import javax.swing.border.EtchedBorder;
049import javax.swing.border.LineBorder;
050import javax.swing.border.MatteBorder;
051import javax.swing.border.TitledBorder;
052
053/**
054 * A factory for commonly used borders.
055 *
056 * @author original author unknown
057 */
058public class BorderFactory
059{
060  private BorderFactory()
061  {
062    // Do nothing.
063  }
064
065  /**
066   * Creates a line border withe the specified color.
067   *
068   * @param color A color to use for the line.
069   *
070   * @return The Border object
071   */
072  public static Border createLineBorder(Color color)
073  {
074    return createLineBorder(color, 1);
075  }
076
077  /**
078   * Creates a line border withe the specified color and width. The width
079   * applies to all 4 sides of the border. To specify widths individually for
080   * the top, bottom, left, and right, use
081   * createMatteBorder(int,int,int,int,Color).
082   *
083   * @param color A color to use for the line.
084   * @param thickness An int specifying the width in pixels.
085   *
086   * @return The Border object
087   */
088  public static Border createLineBorder(Color color, int thickness)
089  {
090    return new LineBorder(color, thickness);
091  }
092
093  /**
094   * Created a border with a raised beveled edge, using brighter shades of
095   * the component's current background color for highlighting, and darker
096   * shading for shadows. (In a raised border, highlights are on top and
097   * shadows are underneath.)
098   *
099   * @return The Border object
100   */
101  public static Border createRaisedBevelBorder()
102  {
103    return new BevelBorder(BevelBorder.RAISED);
104  }
105
106  /**
107   * Created a border with a lowered beveled edge, using brighter shades of
108   * the component's current background color for highlighting, and darker
109   * shading for shadows. (In a lowered border, shadows are on top and
110   * highlights are underneath.)
111   *
112   * @return The Border object
113   */
114  public static Border createLoweredBevelBorder()
115  {
116    return new BevelBorder(BevelBorder.LOWERED);
117  }
118
119  /**
120   * Create a beveled border of the specified type, using brighter shades of
121   * the component's current background color for highlighting, and darker
122   * shading for shadows. (In a lowered border, shadows are on top and
123   * highlights are underneath.).
124   *
125   * @param type An int specifying either BevelBorder.LOWERED or
126   *     BevelBorder.RAISED
127   *
128   * @return The Border object
129   */
130  public static Border createBevelBorder(int type)
131  {
132    return new BevelBorder(type);
133  }
134
135  /**
136   * Create a beveled border of the specified type, using the specified
137   * highlighting and shadowing. The outer edge of the highlighted area uses
138   * a brighter shade of the highlight color. The inner edge of the shadow
139   * area uses a brighter shade of the shadaw color.
140   *
141   * @param type An int specifying either BevelBorder.LOWERED or
142   *     BevelBorder.RAISED
143   * @param highlight A Color object for highlights
144   * @param shadow A Color object for shadows
145   *
146   * @return The Border object
147   */
148  public static Border createBevelBorder(int type, Color highlight, Color shadow)
149  {
150    return new BevelBorder(type, highlight, shadow);
151  }
152
153  /**
154   * Create a beveled border of the specified type, using the specified colors
155   * for the inner and outer highlight and shadow areas.
156   *
157   * @param type An int specifying either BevelBorder.LOWERED or
158   *     BevelBorder.RAISED
159   * @param highlightOuter A Color object for the outer edge of the
160   *     highlight area
161   * @param highlightInner A Color object for the inner edge of the
162   *     highlight area
163   * @param shadowOuter A Color object for the outer edge of the shadow area
164   * @param shadowInner A Color object for the inner edge of the shadow area
165   *
166   * @return The Border object
167   */
168  public static Border createBevelBorder(int type, Color highlightOuter,
169                                         Color highlightInner,
170                                         Color shadowOuter, Color shadowInner)
171  {
172    return new BevelBorder(type, highlightOuter, highlightInner, shadowOuter,
173                           shadowInner);
174  }
175
176  /**
177   * Create a border with an "etched" look using the component's current
178   * background color for highlighting and shading.
179   *
180   * @return The Border object
181   */
182  public static Border createEtchedBorder()
183  {
184    return new EtchedBorder();
185  }
186
187  /**
188   * Create a border with an "etched" look using the component's current
189   * background color for highlighting and shading.
190   *
191   * @return The Border object
192   */
193  public static Border createEtchedBorder(int etchType)
194  {
195    return new EtchedBorder(etchType);
196  }
197
198  /**
199   * Create a border with an "etched" look using the specified highlighting and
200   * shading colors.
201   *
202   * @param highlight A Color object for the border highlights
203   * @param shadow A Color object for the border shadows
204   *
205   * @return The Border object
206   */
207  public static Border createEtchedBorder(Color highlight, Color shadow)
208  {
209    return new EtchedBorder(highlight, shadow);
210  }
211
212  /**
213   * Create a border with an "etched" look using the specified highlighting and
214   * shading colors.
215   *
216   * @param highlight A Color object for the border highlights
217   * @param shadow A Color object for the border shadows
218   *
219   * @return The Border object
220   */
221  public static Border createEtchedBorder(int etchType, Color highlight,
222                                          Color shadow)
223  {
224    return new EtchedBorder(etchType, highlight, shadow);
225  }
226
227  /**
228   * Create a new title border specifying the text of the title, using the
229   * default border (etched), using the default text position (sitting on the
230   * top line) and default justification (left) and using the default font and
231   * text color determined by the current look and feel.
232   *
233   * @param title A String containing the text of the title
234   *
235   * @return The TitledBorder object
236   */
237  public static TitledBorder createTitledBorder(String title)
238  {
239    return new TitledBorder(title);
240  }
241
242  /**
243   * Create a new title border with an empty title specifying the border
244   * object, using the default text position (sitting on the top line) and
245   * default justification (left) and using the default font, text color,
246   * and border determined by the current look and feel. (The Motif and Windows
247   * look and feels use an etched border; The Java look and feel use a
248   * gray border.)
249   *
250   * @param border The Border object to add the title to
251   *
252   * @return The TitledBorder object
253   */
254  public static TitledBorder createTitledBorder(Border border)
255  {
256    return new TitledBorder(border);
257  }
258
259  /**
260   * Add a title to an existing border, specifying the text of the title, using
261   * the default positioning (sitting on the top line) and default
262   * justification (left) and using the default font and text color determined
263   * by the current look and feel.
264   *
265   * @param border The Border object to add the title to
266   * @param title A String containing the text of the title
267   *
268   * @return The TitledBorder object
269   */
270  public static TitledBorder createTitledBorder(Border border, String title)
271  {
272    return new TitledBorder(border, title);
273  }
274
275  /**
276   * Add a title to an existing border, specifying the text of the title along
277   * with its positioning, using the default font and text color determined by
278   * the current look and feel.
279   *
280   * @param border The Border object to add the title to
281   * @param title A String containing the text of the title
282   * @param titleJustification An int specifying the left/right position of
283   *     the title -- one of TitledBorder.LEFT, TitledBorder.CENTER, or
284   *     TitledBorder.RIGHT, TitledBorder.DEFAULT_JUSTIFICATION (left).
285   * @param titlePosition An int specifying the vertical position of the text
286   *     in relation to the border -- one of: TitledBorder.ABOVE_TOP,
287   *     TitledBorder.TOP (sitting on the top line), TitledBorder.BELOW_TOP,
288   *     TitledBorder.ABOVE_BOTTOM, TitledBorder.BOTTOM (sitting on the bottom
289   *     line), TitledBorder.BELOW_BOTTOM, or TitledBorder.DEFAULT_POSITION
290   *     (top).
291   *
292   * @return The TitledBorder object
293   */
294  public static TitledBorder createTitledBorder(Border border, String title,
295                                                int titleJustification,
296                                                int titlePosition)
297  {
298    return new TitledBorder(border, title, titleJustification, titlePosition);
299  }
300
301  /**
302   * Add a title to an existing border, specifying the text of the title along
303   * with its positioning and font, using the default text color determined by
304   * the current look and feel.
305   *
306   * @param border - the Border object to add the title to
307   * @param title - a String containing the text of the title
308   * @param titleJustification - an int specifying the left/right position of
309   *     the title -- one of TitledBorder.LEFT, TitledBorder.CENTER, or
310   *     TitledBorder.RIGHT, TitledBorder.DEFAULT_JUSTIFICATION (left).
311   * @param titlePosition - an int specifying the vertical position of the
312   *     text in relation to the border -- one of: TitledBorder.ABOVE_TOP,
313   *     TitledBorder.TOP (sitting on the top line), TitledBorder.BELOW_TOP,
314   *     TitledBorder.ABOVE_BOTTOM, TitledBorder.BOTTOM (sitting on the bottom
315   *     line), TitledBorder.BELOW_BOTTOM, or TitledBorder.DEFAULT_POSITION (top).
316   * @param titleFont - a Font object specifying the title font
317   *
318   * @return The TitledBorder object
319   */
320  public static TitledBorder createTitledBorder(Border border, String title,
321                                                int titleJustification,
322                                                int titlePosition,
323                                                Font titleFont)
324  {
325    return new TitledBorder(border, title, titleJustification, titlePosition,
326                            titleFont);
327  }
328
329  /**
330   * Add a title to an existing border, specifying the text of the title along
331   * with its positioning, font, and color.
332   *
333   * @param border - the Border object to add the title to
334   * @param title - a String containing the text of the title
335   * @param titleJustification - an int specifying the left/right position of
336   *     the title -- one of TitledBorder.LEFT, TitledBorder.CENTER, or
337   *     TitledBorder.RIGHT, TitledBorder.DEFAULT_JUSTIFICATION (left).
338   * @param titlePosition - an int specifying the vertical position of the text
339   *     in relation to the border -- one of: TitledBorder.ABOVE_TOP,
340   *     TitledBorder.TOP (sitting on the top line), TitledBorder.BELOW_TOP,
341   *     TitledBorder.ABOVE_BOTTOM, TitledBorder.BOTTOM (sitting on the bottom
342   *     line), TitledBorder.BELOW_BOTTOM, or TitledBorder.DEFAULT_POSITION (top).
343   * @param titleFont - a Font object specifying the title font
344   * @param titleColor - a Color object specifying the title color
345   *
346   * @return The TitledBorder object
347   */
348  public static TitledBorder createTitledBorder(Border border, String title,
349                                                int titleJustification,
350                                                int titlePosition,
351                                                Font titleFont, Color titleColor)
352  {
353    return new TitledBorder(border, title, titleJustification, titlePosition,
354                            titleFont, titleColor);
355  }
356
357  /**
358   * Creates an empty border that takes up no space. (The width of the top,
359   * bottom, left, and right sides are all zero.)
360   *
361   * @return The Border object
362   */
363  public static Border createEmptyBorder()
364  {
365    return new EmptyBorder(0, 0, 0, 0);
366  }
367
368  /**
369   * Creates an empty border that takes up no space but which does no drawing,
370   * specifying the width of the top, left, bottom, and right sides.
371   *
372   * @param top An int specifying the width of the top in pixels
373   * @param left An int specifying the width of the left side in pixels
374   * @param bottom An int specifying the width of the right side in pixels
375   * @param right An int specifying the width of the bottom in pixels
376   *
377   * @return The Border object
378   */
379  public static Border createEmptyBorder(int top, int left, int bottom,
380                                         int right)
381  {
382    return new EmptyBorder(top, left, bottom, right);
383  }
384
385  /**
386   * Create a compound border with a null inside edge and a null outside edge.
387   *
388   * @return The CompoundBorder object
389   */
390  public static CompoundBorder createCompoundBorder()
391  {
392    return new CompoundBorder();
393  }
394
395  /**
396   * Create a compound border specifying the border objects to use for the
397   * outside and inside edges.
398   *
399   * @param outsideBorder A Border object for the outer edge of the
400   *     compound border
401   * @param insideBorder A Border object for the inner edge of the
402   *     compound border
403   *
404   * @return The CompoundBorder object
405   */
406  public static CompoundBorder createCompoundBorder(Border outsideBorder,
407                                                    Border insideBorder)
408  {
409    return new CompoundBorder(outsideBorder, insideBorder);
410  }
411
412  /**
413   * Create a matte-look border using a solid color. (The difference between
414   * this border and a line border is that you can specify the individual border
415   * dimensions.)
416   *
417   * @param top
418   *          An int specifying the width of the top in pixels
419   * @param left
420   *          An int specifying the width of the left side in pixels
421   * @param bottom
422   *          An int specifying the width of the right side in pixels
423   * @param right
424   *          An int specifying the width of the bottom in pixels
425   * @param color
426   *          A Color to use for the border
427   * @return The MatteBorder object
428   */
429  public static MatteBorder createMatteBorder(int top, int left, int bottom,
430                                              int right, Color color)
431  {
432    return new MatteBorder(top, left, bottom, right, color);
433  }
434
435  /**
436   * Create a matte-look border that consists of multiple tiles of a specified
437   * icon. Multiple copies of the icon are placed side-by-side to fill up the
438   * border area.
439   *
440   * Note:
441   * If the icon doesn't load, the border area is painted gray.
442   *
443   * @param top An int specifying the width of the top in pixels
444   * @param left An int specifying the width of the left side in pixels
445   * @param bottom An int specifying the width of the right side in pixels
446   * @param right An int specifying the width of the bottom in pixels
447   * @param tileIcon The Icon object used for the border tiles
448   *
449   * @return The MatteBorder object
450   */
451  public static MatteBorder createMatteBorder(int top, int left, int bottom,
452                                              int right, Icon tileIcon)
453  {
454    return new MatteBorder(top, left, bottom, right, tileIcon);
455  }
456}