0N/A/*
3909N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage javax.swing;
0N/A
2965N/Aimport java.awt.BasicStroke;
0N/Aimport java.awt.Color;
0N/Aimport java.awt.Font;
2965N/Aimport java.awt.Paint;
0N/Aimport javax.swing.border.*;
0N/A
0N/A/**
0N/A * Factory class for vending standard <code>Border</code> objects. Wherever
0N/A * possible, this factory will hand out references to shared
0N/A * <code>Border</code> instances.
0N/A * For further information and examples see
0N/A * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/border.html">How
0N/A to Use Borders</a>,
0N/A * a section in <em>The Java Tutorial</em>.
0N/A *
0N/A * @author David Kloba
0N/A */
0N/Apublic class BorderFactory
0N/A{
0N/A
0N/A /** Don't let anyone instantiate this class */
0N/A private BorderFactory() {
0N/A }
0N/A
0N/A
0N/A//// LineBorder ///////////////////////////////////////////////////////////////
0N/A /**
0N/A * Creates a line border withe the specified color.
0N/A *
0N/A * @param color a <code>Color</code> to use for the line
0N/A * @return the <code>Border</code> object
0N/A */
0N/A public static Border createLineBorder(Color color) {
0N/A return new LineBorder(color, 1);
0N/A }
0N/A
0N/A /**
0N/A * Creates a line border with the specified color
0N/A * and width. The width applies to all four sides of the
0N/A * border. To specify widths individually for the top,
0N/A * bottom, left, and right, use
0N/A * {@link #createMatteBorder(int,int,int,int,Color)}.
0N/A *
0N/A * @param color a <code>Color</code> to use for the line
0N/A * @param thickness an integer specifying the width in pixels
0N/A * @return the <code>Border</code> object
0N/A */
0N/A public static Border createLineBorder(Color color, int thickness) {
0N/A return new LineBorder(color, thickness);
0N/A }
0N/A
2452N/A /**
2452N/A * Creates a line border with the specified color, thickness, and corner shape.
2452N/A *
2452N/A * @param color the color of the border
2452N/A * @param thickness the thickness of the border
2452N/A * @param rounded whether or not border corners should be round
2452N/A * @return the {@code Border} object
2452N/A *
2452N/A * @see LineBorder#LineBorder(Color, int, boolean)
2452N/A * @since 1.7
2452N/A */
2452N/A public static Border createLineBorder(Color color, int thickness, boolean rounded) {
2452N/A return new LineBorder(color, thickness, rounded);
2452N/A }
0N/A
0N/A//// BevelBorder /////////////////////////////////////////////////////////////
0N/A///////////////////////////////////////////////////////////////////////////////
0N/A static final Border sharedRaisedBevel = new BevelBorder(BevelBorder.RAISED);
0N/A static final Border sharedLoweredBevel = new BevelBorder(BevelBorder.LOWERED);
0N/A
0N/A /**
0N/A * Creates a border with a raised beveled edge, using
0N/A * brighter shades of the component's current background color
0N/A * for highlighting, and darker shading for shadows.
0N/A * (In a raised border, highlights are on top and shadows
0N/A * are underneath.)
0N/A *
0N/A * @return the <code>Border</code> object
0N/A */
0N/A public static Border createRaisedBevelBorder() {
0N/A return createSharedBevel(BevelBorder.RAISED);
0N/A }
0N/A
0N/A /**
0N/A * Creates a border with a lowered beveled edge, using
0N/A * brighter shades of the component's current background color
0N/A * for highlighting, and darker shading for shadows.
0N/A * (In a lowered border, shadows are on top and highlights
0N/A * are underneath.)
0N/A *
0N/A * @return the <code>Border</code> object
0N/A */
0N/A public static Border createLoweredBevelBorder() {
0N/A return createSharedBevel(BevelBorder.LOWERED);
0N/A }
0N/A
0N/A /**
0N/A * Creates a beveled border of the specified type, using
0N/A * brighter shades of the component's current background color
0N/A * for highlighting, and darker shading for shadows.
0N/A * (In a lowered border, shadows are on top and highlights
0N/A * are underneath.)
0N/A *
0N/A * @param type an integer specifying either
0N/A * <code>BevelBorder.LOWERED</code> or
0N/A * <code>BevelBorder.RAISED</code>
0N/A * @return the <code>Border</code> object
0N/A */
0N/A public static Border createBevelBorder(int type) {
0N/A return createSharedBevel(type);
0N/A }
0N/A
0N/A /**
0N/A * Creates a beveled border of the specified type, using
0N/A * the specified highlighting and shadowing. The outer
0N/A * edge of the highlighted area uses a brighter shade of
0N/A * the highlight color. The inner edge of the shadow area
0N/A * uses a brighter shade of the shadow color.
0N/A *
0N/A * @param type an integer specifying either
0N/A * <code>BevelBorder.LOWERED</code> or
0N/A * <code>BevelBorder.RAISED</code>
0N/A * @param highlight a <code>Color</code> object for highlights
0N/A * @param shadow a <code>Color</code> object for shadows
0N/A * @return the <code>Border</code> object
0N/A */
0N/A public static Border createBevelBorder(int type, Color highlight, Color shadow) {
0N/A return new BevelBorder(type, highlight, shadow);
0N/A }
0N/A
0N/A /**
0N/A * Creates a beveled border of the specified type, using
0N/A * the specified colors for the inner and outer highlight
0N/A * and shadow areas.
0N/A *
0N/A * @param type an integer specifying either
0N/A * <code>BevelBorder.LOWERED</code> or
0N/A * <code>BevelBorder.RAISED</code>
0N/A * @param highlightOuter a <code>Color</code> object for the
0N/A * outer edge of the highlight area
0N/A * @param highlightInner a <code>Color</code> object for the
0N/A * inner edge of the highlight area
0N/A * @param shadowOuter a <code>Color</code> object for the
0N/A * outer edge of the shadow area
0N/A * @param shadowInner a <code>Color</code> object for the
0N/A * inner edge of the shadow area
0N/A * @return the <code>Border</code> object
0N/A */
0N/A public static Border createBevelBorder(int type,
0N/A Color highlightOuter, Color highlightInner,
0N/A Color shadowOuter, Color shadowInner) {
0N/A return new BevelBorder(type, highlightOuter, highlightInner,
0N/A shadowOuter, shadowInner);
0N/A }
0N/A
0N/A static Border createSharedBevel(int type) {
0N/A if(type == BevelBorder.RAISED) {
0N/A return sharedRaisedBevel;
0N/A } else if(type == BevelBorder.LOWERED) {
0N/A return sharedLoweredBevel;
0N/A }
0N/A return null;
0N/A }
2452N/A
2452N/A//// SoftBevelBorder ///////////////////////////////////////////////////////////
2452N/A////////////////////////////////////////////////////////////////////////////////
2452N/A
2452N/A private static Border sharedSoftRaisedBevel;
2452N/A private static Border sharedSoftLoweredBevel;
2452N/A
2452N/A /**
2452N/A * Creates a beveled border with a raised edge and softened corners,
2452N/A * using brighter shades of the component's current background color
2452N/A * for highlighting, and darker shading for shadows.
2452N/A * In a raised border, highlights are on top and shadows are underneath.
2452N/A *
2452N/A * @return the {@code Border} object
2452N/A *
2452N/A * @since 1.7
2452N/A */
2452N/A public static Border createRaisedSoftBevelBorder() {
2452N/A if (sharedSoftRaisedBevel == null) {
2452N/A sharedSoftRaisedBevel = new SoftBevelBorder(BevelBorder.RAISED);
2452N/A }
2452N/A return sharedSoftRaisedBevel;
2452N/A }
2452N/A
2452N/A /**
2452N/A * Creates a beveled border with a lowered edge and softened corners,
2452N/A * using brighter shades of the component's current background color
2452N/A * for highlighting, and darker shading for shadows.
2452N/A * In a lowered border, shadows are on top and highlights are underneath.
2452N/A *
2452N/A * @return the {@code Border} object
2452N/A *
2452N/A * @since 1.7
2452N/A */
2452N/A public static Border createLoweredSoftBevelBorder() {
2452N/A if (sharedSoftLoweredBevel == null) {
2452N/A sharedSoftLoweredBevel = new SoftBevelBorder(BevelBorder.LOWERED);
2452N/A }
2452N/A return sharedSoftLoweredBevel;
2452N/A }
2452N/A
2452N/A /**
2452N/A * Creates a beveled border of the specified type with softened corners,
2452N/A * using brighter shades of the component's current background color
2452N/A * for highlighting, and darker shading for shadows.
2452N/A * The type is either {@link BevelBorder#RAISED} or {@link BevelBorder#LOWERED}.
2452N/A *
2452N/A * @param type a type of a bevel
2452N/A * @return the {@code Border} object or {@code null}
2452N/A * if the specified type is not valid
2452N/A *
2452N/A * @see BevelBorder#BevelBorder(int)
2452N/A * @since 1.7
2452N/A */
2452N/A public static Border createSoftBevelBorder(int type) {
2452N/A if (type == BevelBorder.RAISED) {
2452N/A return createRaisedSoftBevelBorder();
2452N/A }
2452N/A if (type == BevelBorder.LOWERED) {
2452N/A return createLoweredSoftBevelBorder();
2452N/A }
2452N/A return null;
2452N/A }
2452N/A
2452N/A /**
2452N/A * Creates a beveled border of the specified type with softened corners,
2452N/A * using the specified highlighting and shadowing.
2452N/A * The type is either {@link BevelBorder#RAISED} or {@link BevelBorder#LOWERED}.
2452N/A * The outer edge of the highlight area uses
2452N/A * a brighter shade of the {@code highlight} color.
2452N/A * The inner edge of the shadow area uses
2452N/A * a brighter shade of the {@code shadow} color.
2452N/A *
2452N/A * @param type a type of a bevel
2452N/A * @param highlight a basic color of the highlight area
2452N/A * @param shadow a basic color of the shadow area
2452N/A * @return the {@code Border} object
2452N/A *
2452N/A * @see BevelBorder#BevelBorder(int, Color, Color)
2452N/A * @since 1.7
2452N/A */
2452N/A public static Border createSoftBevelBorder(int type, Color highlight, Color shadow) {
3096N/A return new SoftBevelBorder(type, highlight, shadow);
2452N/A }
2452N/A
2452N/A /**
2452N/A * Creates a beveled border of the specified type with softened corners,
2452N/A * using the specified colors for the inner and outer edges
2452N/A * of the highlight and the shadow areas.
2452N/A * The type is either {@link BevelBorder#RAISED} or {@link BevelBorder#LOWERED}.
2452N/A * Note: The shadow inner and outer colors are switched
2452N/A * for a lowered bevel border.
2452N/A *
2452N/A * @param type a type of a bevel
2452N/A * @param highlightOuter a color of the outer edge of the highlight area
2452N/A * @param highlightInner a color of the inner edge of the highlight area
2452N/A * @param shadowOuter a color of the outer edge of the shadow area
2452N/A * @param shadowInner a color of the inner edge of the shadow area
2452N/A * @return the {@code Border} object
2452N/A *
2452N/A * @see BevelBorder#BevelBorder(int, Color, Color, Color, Color)
2452N/A * @since 1.7
2452N/A */
2452N/A public static Border createSoftBevelBorder(int type, Color highlightOuter, Color highlightInner, Color shadowOuter, Color shadowInner) {
3096N/A return new SoftBevelBorder(type, highlightOuter, highlightInner, shadowOuter, shadowInner);
2452N/A }
2452N/A
0N/A//// EtchedBorder ///////////////////////////////////////////////////////////
2452N/A
0N/A static final Border sharedEtchedBorder = new EtchedBorder();
0N/A private static Border sharedRaisedEtchedBorder;
0N/A
0N/A /**
0N/A * Creates a border with an "etched" look using
0N/A * the component's current background color for
0N/A * highlighting and shading.
0N/A *
0N/A * @return the <code>Border</code> object
0N/A */
0N/A public static Border createEtchedBorder() {
0N/A return sharedEtchedBorder;
0N/A }
0N/A
0N/A /**
0N/A * Creates a border with an "etched" look using
0N/A * the specified highlighting and shading colors.
0N/A *
0N/A * @param highlight a <code>Color</code> object for the border highlights
0N/A * @param shadow a <code>Color</code> object for the border shadows
0N/A * @return the <code>Border</code> object
0N/A */
0N/A public static Border createEtchedBorder(Color highlight, Color shadow) {
0N/A return new EtchedBorder(highlight, shadow);
0N/A }
0N/A
0N/A /**
0N/A * Creates a border with an "etched" look using
0N/A * the component's current background color for
0N/A * highlighting and shading.
0N/A *
0N/A * @param type one of <code>EtchedBorder.RAISED</code>, or
0N/A * <code>EtchedBorder.LOWERED</code>
0N/A * @return the <code>Border</code> object
0N/A * @exception IllegalArgumentException if type is not either
0N/A * <code>EtchedBorder.RAISED</code> or
0N/A * <code>EtchedBorder.LOWERED</code>
0N/A * @since 1.3
0N/A */
0N/A public static Border createEtchedBorder(int type) {
0N/A switch (type) {
0N/A case EtchedBorder.RAISED:
0N/A if (sharedRaisedEtchedBorder == null) {
0N/A sharedRaisedEtchedBorder = new EtchedBorder
0N/A (EtchedBorder.RAISED);
0N/A }
0N/A return sharedRaisedEtchedBorder;
0N/A case EtchedBorder.LOWERED:
0N/A return sharedEtchedBorder;
0N/A default:
0N/A throw new IllegalArgumentException("type must be one of EtchedBorder.RAISED or EtchedBorder.LOWERED");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Creates a border with an "etched" look using
0N/A * the specified highlighting and shading colors.
0N/A *
0N/A * @param type one of <code>EtchedBorder.RAISED</code>, or
0N/A * <code>EtchedBorder.LOWERED</code>
0N/A * @param highlight a <code>Color</code> object for the border highlights
0N/A * @param shadow a <code>Color</code> object for the border shadows
0N/A * @return the <code>Border</code> object
0N/A * @since 1.3
0N/A */
0N/A public static Border createEtchedBorder(int type, Color highlight,
0N/A Color shadow) {
0N/A return new EtchedBorder(type, highlight, shadow);
0N/A }
0N/A
0N/A//// TitledBorder ////////////////////////////////////////////////////////////
0N/A /**
0N/A * Creates a new titled border with the specified title,
0N/A * the default border type (determined by the current look and feel),
0N/A * the default text position (sitting on the top line),
0N/A * the default justification (leading), and the default
0N/A * font and text color (determined by the current look and feel).
0N/A *
0N/A * @param title a <code>String</code> containing the text of the title
0N/A * @return the <code>TitledBorder</code> object
0N/A */
0N/A public static TitledBorder createTitledBorder(String title) {
0N/A return new TitledBorder(title);
0N/A }
0N/A
0N/A /**
0N/A * Creates a new titled border with an empty title,
0N/A * the specified border object,
0N/A * the default text position (sitting on the top line),
0N/A * the default justification (leading), and the default
0N/A * font and text color (determined by the current look and feel).
0N/A *
0N/A * @param border the <code>Border</code> object to add the title to; if
0N/A * <code>null</code> the <code>Border</code> is determined
0N/A * by the current look and feel.
0N/A * @return the <code>TitledBorder</code> object
0N/A */
0N/A public static TitledBorder createTitledBorder(Border border) {
0N/A return new TitledBorder(border);
0N/A }
0N/A
0N/A /**
0N/A * Adds a title to an existing border,
0N/A * with default positioning (sitting on the top line),
0N/A * default justification (leading) and the default
0N/A * font and text color (determined by the current look and feel).
0N/A *
0N/A * @param border the <code>Border</code> object to add the title to
0N/A * @param title a <code>String</code> containing the text of the title
0N/A * @return the <code>TitledBorder</code> object
0N/A */
0N/A public static TitledBorder createTitledBorder(Border border,
0N/A String title) {
0N/A return new TitledBorder(border, title);
0N/A }
0N/A
0N/A /**
0N/A * Adds a title to an existing border, with the specified
0N/A * positioning and using the default
0N/A * font and text color (determined by the current look and feel).
0N/A *
0N/A * @param border the <code>Border</code> object to add the title to
0N/A * @param title a <code>String</code> containing the text of the title
0N/A * @param titleJustification an integer specifying the justification
0N/A * of the title -- one of the following:
0N/A *<ul>
0N/A *<li><code>TitledBorder.LEFT</code>
0N/A *<li><code>TitledBorder.CENTER</code>
0N/A *<li><code>TitledBorder.RIGHT</code>
0N/A *<li><code>TitledBorder.LEADING</code>
0N/A *<li><code>TitledBorder.TRAILING</code>
0N/A *<li><code>TitledBorder.DEFAULT_JUSTIFICATION</code> (leading)
0N/A *</ul>
0N/A * @param titlePosition an integer specifying the vertical position of
0N/A * the text in relation to the border -- one of the following:
0N/A *<ul>
0N/A *<li><code> TitledBorder.ABOVE_TOP</code>
0N/A *<li><code>TitledBorder.TOP</code> (sitting on the top line)
0N/A *<li><code>TitledBorder.BELOW_TOP</code>
0N/A *<li><code>TitledBorder.ABOVE_BOTTOM</code>
0N/A *<li><code>TitledBorder.BOTTOM</code> (sitting on the bottom line)
0N/A *<li><code>TitledBorder.BELOW_BOTTOM</code>
0N/A *<li><code>TitledBorder.DEFAULT_POSITION</code> (top)
0N/A *</ul>
0N/A * @return the <code>TitledBorder</code> object
0N/A */
0N/A public static TitledBorder createTitledBorder(Border border,
0N/A String title,
0N/A int titleJustification,
0N/A int titlePosition) {
0N/A return new TitledBorder(border, title, titleJustification,
0N/A titlePosition);
0N/A }
0N/A
0N/A /**
0N/A * Adds a title to an existing border, with the specified
0N/A * positioning and font, and using the default text color
0N/A * (determined by the current look and feel).
0N/A *
0N/A * @param border the <code>Border</code> object to add the title to
0N/A * @param title a <code>String</code> containing the text of the title
0N/A * @param titleJustification an integer specifying the justification
0N/A * of the title -- one of the following:
0N/A *<ul>
0N/A *<li><code>TitledBorder.LEFT</code>
0N/A *<li><code>TitledBorder.CENTER</code>
0N/A *<li><code>TitledBorder.RIGHT</code>
0N/A *<li><code>TitledBorder.LEADING</code>
0N/A *<li><code>TitledBorder.TRAILING</code>
0N/A *<li><code>TitledBorder.DEFAULT_JUSTIFICATION</code> (leading)
0N/A *</ul>
0N/A * @param titlePosition an integer specifying the vertical position of
0N/A * the text in relation to the border -- one of the following:
0N/A *<ul>
0N/A *<li><code> TitledBorder.ABOVE_TOP</code>
0N/A *<li><code>TitledBorder.TOP</code> (sitting on the top line)
0N/A *<li><code>TitledBorder.BELOW_TOP</code>
0N/A *<li><code>TitledBorder.ABOVE_BOTTOM</code>
0N/A *<li><code>TitledBorder.BOTTOM</code> (sitting on the bottom line)
0N/A *<li><code>TitledBorder.BELOW_BOTTOM</code>
0N/A *<li><code>TitledBorder.DEFAULT_POSITION</code> (top)
0N/A *</ul>
0N/A * @param titleFont a Font object specifying the title font
0N/A * @return the TitledBorder object
0N/A */
0N/A public static TitledBorder createTitledBorder(Border border,
0N/A String title,
0N/A int titleJustification,
0N/A int titlePosition,
0N/A Font titleFont) {
0N/A return new TitledBorder(border, title, titleJustification,
0N/A titlePosition, titleFont);
0N/A }
0N/A
0N/A /**
0N/A * Adds a title to an existing border, with the specified
0N/A * positioning, font and color.
0N/A *
0N/A * @param border the <code>Border</code> object to add the title to
0N/A * @param title a <code>String</code> containing the text of the title
0N/A * @param titleJustification an integer specifying the justification
0N/A * of the title -- one of the following:
0N/A *<ul>
0N/A *<li><code>TitledBorder.LEFT</code>
0N/A *<li><code>TitledBorder.CENTER</code>
0N/A *<li><code>TitledBorder.RIGHT</code>
0N/A *<li><code>TitledBorder.LEADING</code>
0N/A *<li><code>TitledBorder.TRAILING</code>
0N/A *<li><code>TitledBorder.DEFAULT_JUSTIFICATION</code> (leading)
0N/A *</ul>
0N/A * @param titlePosition an integer specifying the vertical position of
0N/A * the text in relation to the border -- one of the following:
0N/A *<ul>
0N/A *<li><code> TitledBorder.ABOVE_TOP</code>
0N/A *<li><code>TitledBorder.TOP</code> (sitting on the top line)
0N/A *<li><code>TitledBorder.BELOW_TOP</code>
0N/A *<li><code>TitledBorder.ABOVE_BOTTOM</code>
0N/A *<li><code>TitledBorder.BOTTOM</code> (sitting on the bottom line)
0N/A *<li><code>TitledBorder.BELOW_BOTTOM</code>
0N/A *<li><code>TitledBorder.DEFAULT_POSITION</code> (top)
0N/A *</ul>
0N/A * @param titleFont a <code>Font</code> object specifying the title font
0N/A * @param titleColor a <code>Color</code> object specifying the title color
0N/A * @return the <code>TitledBorder</code> object
0N/A */
0N/A public static TitledBorder createTitledBorder(Border border,
0N/A String title,
0N/A int titleJustification,
0N/A int titlePosition,
0N/A Font titleFont,
0N/A Color titleColor) {
0N/A return new TitledBorder(border, title, titleJustification,
0N/A titlePosition, titleFont, titleColor);
0N/A }
0N/A//// EmptyBorder ///////////////////////////////////////////////////////////
0N/A final static Border emptyBorder = new EmptyBorder(0, 0, 0, 0);
0N/A
0N/A /**
0N/A * Creates an empty border that takes up no space. (The width
0N/A * of the top, bottom, left, and right sides are all zero.)
0N/A *
0N/A * @return the <code>Border</code> object
0N/A */
0N/A public static Border createEmptyBorder() {
0N/A return emptyBorder;
0N/A }
0N/A
0N/A /**
0N/A * Creates an empty border that takes up space but which does
0N/A * no drawing, specifying the width of the top, left, bottom, and
0N/A * right sides.
0N/A *
0N/A * @param top an integer specifying the width of the top,
0N/A * in pixels
0N/A * @param left an integer specifying the width of the left side,
0N/A * in pixels
0N/A * @param bottom an integer specifying the width of the bottom,
0N/A * in pixels
0N/A * @param right an integer specifying the width of the right side,
0N/A * in pixels
0N/A * @return the <code>Border</code> object
0N/A */
0N/A public static Border createEmptyBorder(int top, int left,
0N/A int bottom, int right) {
0N/A return new EmptyBorder(top, left, bottom, right);
0N/A }
0N/A
0N/A//// CompoundBorder ////////////////////////////////////////////////////////
0N/A /**
0N/A * Creates a compound border with a <code>null</code> inside edge and a
0N/A * <code>null</code> outside edge.
0N/A *
0N/A * @return the <code>CompoundBorder</code> object
0N/A */
0N/A public static CompoundBorder createCompoundBorder() {
0N/A return new CompoundBorder();
0N/A }
0N/A
0N/A /**
0N/A * Creates a compound border specifying the border objects to use
0N/A * for the outside and inside edges.
0N/A *
0N/A * @param outsideBorder a <code>Border</code> object for the outer
0N/A * edge of the compound border
0N/A * @param insideBorder a <code>Border</code> object for the inner
0N/A * edge of the compound border
0N/A * @return the <code>CompoundBorder</code> object
0N/A */
0N/A public static CompoundBorder createCompoundBorder(Border outsideBorder,
0N/A Border insideBorder) {
0N/A return new CompoundBorder(outsideBorder, insideBorder);
0N/A }
0N/A
0N/A//// MatteBorder ////////////////////////////////////////////////////////
0N/A /**
0N/A * Creates a matte-look border using a solid color. (The difference between
0N/A * this border and a line border is that you can specify the individual
0N/A * border dimensions.)
0N/A *
0N/A * @param top an integer specifying the width of the top,
0N/A * in pixels
0N/A * @param left an integer specifying the width of the left side,
0N/A * in pixels
0N/A * @param bottom an integer specifying the width of the right side,
0N/A * in pixels
0N/A * @param right an integer specifying the width of the bottom,
0N/A * in pixels
0N/A * @param color a <code>Color</code> to use for the border
0N/A * @return the <code>MatteBorder</code> object
0N/A */
0N/A public static MatteBorder createMatteBorder(int top, int left, int bottom, int right,
0N/A Color color) {
0N/A return new MatteBorder(top, left, bottom, right, color);
0N/A }
0N/A
0N/A /**
0N/A * Creates a matte-look border that consists of multiple tiles of a
0N/A * specified icon. Multiple copies of the icon are placed side-by-side
0N/A * to fill up the border area.
0N/A * <p>
0N/A * Note:<br>
0N/A * If the icon doesn't load, the border area is painted gray.
0N/A *
0N/A * @param top an integer specifying the width of the top,
0N/A * in pixels
0N/A * @param left an integer specifying the width of the left side,
0N/A * in pixels
0N/A * @param bottom an integer specifying the width of the right side,
0N/A * in pixels
0N/A * @param right an integer specifying the width of the bottom,
0N/A * in pixels
0N/A * @param tileIcon the <code>Icon</code> object used for the border tiles
0N/A * @return the <code>MatteBorder</code> object
0N/A */
0N/A public static MatteBorder createMatteBorder(int top, int left, int bottom, int right,
0N/A Icon tileIcon) {
0N/A return new MatteBorder(top, left, bottom, right, tileIcon);
0N/A }
2965N/A
2965N/A//// StrokeBorder //////////////////////////////////////////////////////////////
2965N/A////////////////////////////////////////////////////////////////////////////////
2965N/A
2965N/A /**
2965N/A * Creates a border of the specified {@code stroke}.
2965N/A * The component's foreground color will be used to render the border.
2965N/A *
2965N/A * @param stroke the {@link BasicStroke} object used to stroke a shape
2965N/A * @return the {@code Border} object
2965N/A *
2965N/A * @throws NullPointerException if the specified {@code stroke} is {@code null}
2965N/A *
2965N/A * @since 1.7
2965N/A */
2965N/A public static Border createStrokeBorder(BasicStroke stroke) {
2965N/A return new StrokeBorder(stroke);
2965N/A }
2965N/A
2965N/A /**
2965N/A * Creates a border of the specified {@code stroke} and {@code paint}.
2965N/A * If the specified {@code paint} is {@code null},
2965N/A * the component's foreground color will be used to render the border.
2965N/A *
2965N/A * @param stroke the {@link BasicStroke} object used to stroke a shape
2965N/A * @param paint the {@link Paint} object used to generate a color
2965N/A * @return the {@code Border} object
2965N/A *
2965N/A * @throws NullPointerException if the specified {@code stroke} is {@code null}
2965N/A *
2965N/A * @since 1.7
2965N/A */
2965N/A public static Border createStrokeBorder(BasicStroke stroke, Paint paint) {
2965N/A return new StrokeBorder(stroke, paint);
2965N/A }
2965N/A
2965N/A//// DashedBorder //////////////////////////////////////////////////////////////
2965N/A////////////////////////////////////////////////////////////////////////////////
2965N/A
2965N/A private static Border sharedDashedBorder;
2965N/A
2965N/A /**
2965N/A * Creates a dashed border of the specified {@code paint}.
2965N/A * If the specified {@code paint} is {@code null},
2965N/A * the component's foreground color will be used to render the border.
2965N/A * The width of a dash line is equal to {@code 1}.
2965N/A * The relative length of a dash line and
2965N/A * the relative spacing between dash lines are equal to {@code 1}.
2965N/A * A dash line is not rounded.
2965N/A *
2965N/A * @param paint the {@link Paint} object used to generate a color
2965N/A * @return the {@code Border} object
2965N/A *
2965N/A * @since 1.7
2965N/A */
2965N/A public static Border createDashedBorder(Paint paint) {
2965N/A return createDashedBorder(paint, 1.0f, 1.0f, 1.0f, false);
2965N/A }
2965N/A
2965N/A /**
2965N/A * Creates a dashed border of the specified {@code paint},
2965N/A * relative {@code length}, and relative {@code spacing}.
2965N/A * If the specified {@code paint} is {@code null},
2965N/A * the component's foreground color will be used to render the border.
2965N/A * The width of a dash line is equal to {@code 1}.
2965N/A * A dash line is not rounded.
2965N/A *
2965N/A * @param paint the {@link Paint} object used to generate a color
2965N/A * @param length the relative length of a dash line
2965N/A * @param spacing the relative spacing between dash lines
2965N/A * @return the {@code Border} object
2965N/A *
2965N/A * @throws IllegalArgumentException if the specified {@code length} is less than {@code 1}, or
2965N/A * if the specified {@code spacing} is less than {@code 0}
2965N/A * @since 1.7
2965N/A */
2965N/A public static Border createDashedBorder(Paint paint, float length, float spacing) {
2965N/A return createDashedBorder(paint, 1.0f, length, spacing, false);
2965N/A }
2965N/A
2965N/A /**
2965N/A * Creates a dashed border of the specified {@code paint}, {@code thickness},
2965N/A * line shape, relative {@code length}, and relative {@code spacing}.
2965N/A * If the specified {@code paint} is {@code null},
2965N/A * the component's foreground color will be used to render the border.
2965N/A *
2965N/A * @param paint the {@link Paint} object used to generate a color
2965N/A * @param thickness the width of a dash line
2965N/A * @param length the relative length of a dash line
2965N/A * @param spacing the relative spacing between dash lines
2965N/A * @param rounded whether or not line ends should be round
2965N/A * @return the {@code Border} object
2965N/A *
2965N/A * @throws IllegalArgumentException if the specified {@code thickness} is less than {@code 1}, or
2965N/A * if the specified {@code length} is less than {@code 1}, or
2965N/A * if the specified {@code spacing} is less than {@code 0}
2965N/A * @since 1.7
2965N/A */
2965N/A public static Border createDashedBorder(Paint paint, float thickness, float length, float spacing, boolean rounded) {
2965N/A boolean shared = !rounded && (paint == null) && (thickness == 1.0f) && (length == 1.0f) && (spacing == 1.0f);
2965N/A if (shared && (sharedDashedBorder != null)) {
2965N/A return sharedDashedBorder;
2965N/A }
2965N/A if (thickness < 1.0f) {
2965N/A throw new IllegalArgumentException("thickness is less than 1");
2965N/A }
2965N/A if (length < 1.0f) {
2965N/A throw new IllegalArgumentException("length is less than 1");
2965N/A }
2965N/A if (spacing < 0.0f) {
2965N/A throw new IllegalArgumentException("spacing is less than 0");
2965N/A }
2965N/A int cap = rounded ? BasicStroke.CAP_ROUND : BasicStroke.CAP_SQUARE;
2965N/A int join = rounded ? BasicStroke.JOIN_ROUND : BasicStroke.JOIN_MITER;
2965N/A float[] array = { thickness * (length - 1.0f), thickness * (spacing + 1.0f) };
2965N/A Border border = createStrokeBorder(new BasicStroke(thickness, cap, join, thickness * 2.0f, array, 0.0f), paint);
2965N/A if (shared) {
2965N/A sharedDashedBorder = border;
2965N/A }
2965N/A return border;
2965N/A }
0N/A}