001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.api.visual.border;
042:
043: import org.netbeans.api.visual.widget.Scene;
044: import org.netbeans.modules.visual.border.*;
045: import org.netbeans.modules.visual.util.GeomUtil;
046:
047: import java.awt.*;
048:
049: /**
050: * This class is a factory of all built-in implementation of borders.
051: * Instances of built-in borders can be shared by multiple widgets.
052: *
053: * @author David Kaspar
054: */
055: // TODO - check insets values
056: public final class BorderFactory {
057:
058: private static final Border BORDER_EMPTY = new EmptyBorder(0, 0, 0,
059: 0, false);
060: private static final Border BORDER_LINE = createLineBorder(1);
061:
062: private BorderFactory() {
063: }
064:
065: /**
066: * Creates an default empty border with 0px layout.
067: * The instance can be shared by multiple widgets.
068: * @return the empty border
069: */
070: public static Border createEmptyBorder() {
071: return BORDER_EMPTY;
072: }
073:
074: /**
075: * Creates an empty border with specific thickness.
076: * The instance can be shared by multiple widgets.
077: * @param thickness the border thickness
078: * @return the empty border
079: */
080: public static Border createEmptyBorder(int thickness) {
081: return thickness > 0 ? createEmptyBorder(thickness, thickness,
082: thickness, thickness) : BORDER_EMPTY;
083: }
084:
085: /**
086: * Creates an empty border with specific thickness.
087: * The instance can be shared by multiple widgets.
088: * @param horizontal the horizontal thickness
089: * @param vertical the vertical thickness
090: * @return the empty border
091: */
092: public static Border createEmptyBorder(int horizontal, int vertical) {
093: return createEmptyBorder(vertical, horizontal, vertical,
094: horizontal);
095: }
096:
097: /**
098: * Creates an empty border with specific thickness.
099: * The instance can be shared by multiple widgets.
100: * @param top the top inset
101: * @param left the left inset
102: * @param bottom the bottom inset
103: * @param right the right inset
104: * @return the empty border
105: */
106: public static Border createEmptyBorder(int top, int left,
107: int bottom, int right) {
108: return new EmptyBorder(top, left, bottom, right, false);
109: }
110:
111: /**
112: * Creates an opaque border with specific thickness.
113: * The instance can be shared by multiple widgets.
114: * @param top the top inset
115: * @param left the left inset
116: * @param bottom the bottom inset
117: * @param right the right inset
118: * @return the empty border
119: */
120: public static Border createOpaqueBorder(int top, int left,
121: int bottom, int right) {
122: return new EmptyBorder(top, left, bottom, right, true);
123: }
124:
125: /**
126: * Creates a composite border that consists of a list of specified borders - one embedded to another.
127: * The instance can be shared by multiple widgets.
128: * @param borders the list of borders
129: * @return the composite border
130: */
131: public static Border createCompositeBorder(Border... borders) {
132: return new CompositeBorder(borders);
133: }
134:
135: /**
136: * Creates a layout from a Swing border.
137: * The instance can be shared by multiple widgets but cannot be used in multiple scenes.
138: * @param scene the scene where the border is used.
139: * @param border the Swing border
140: * @return the border
141: */
142: public static Border createSwingBorder(Scene scene,
143: javax.swing.border.Border border) {
144: assert scene != null && scene.getView() != null
145: && border != null;
146: return new SwingBorder(scene, border);
147: }
148:
149: /**
150: * Creates a line border with default style.
151: * The instance can be shared by multiple widgets.
152: * @return the line border
153: */
154: public static Border createLineBorder() {
155: return BORDER_LINE;
156: }
157:
158: /**
159: * Creates a line border with specific thickness. The line is still one pixel but the layout insets are calculated from thickness.
160: * The instance can be shared by multiple widgets.
161: * @param thickness the border thickness
162: * @return the line border
163: */
164: public static Border createLineBorder(int thickness) {
165: return createLineBorder(thickness, null);
166: }
167:
168: /**
169: * Creates a line border with specific thickness and color. The line is still one pixel but the layout insets are calculated from thickness.
170: * The instance can be shared by multiple widgets.
171: * @param thickness the border thickness
172: * @param color the line color
173: * @return the line border
174: */
175: public static Border createLineBorder(int thickness, Color color) {
176: return new LineBorder(thickness, thickness, thickness,
177: thickness, color != null ? color : Color.BLACK);
178: }
179:
180: /**
181: * Creates a line border with specific insets and color. The line is still one pixel but the layout insets are specified.
182: * The instance can be shared by multiple widgets.
183: * @param top the top inset
184: * @param left the left inset
185: * @param bottom the bottom inset
186: * @param right the right inset
187: * @param color the line color
188: * @return the line border
189: */
190: public static Border createLineBorder(int top, int left,
191: int bottom, int right, Color color) {
192: return new LineBorder(top, left, bottom, right,
193: color != null ? color : Color.BLACK);
194: }
195:
196: /**
197: * Creates a bevel border.
198: * The instance can be shared by multiple widgets.
199: * @param raised if true, then it is a raised-bevel border; if false, then it is a lowered-bevel layout
200: * @return the bevel border
201: */
202: public static Border createBevelBorder(boolean raised) {
203: return createBevelBorder(raised, null);
204: }
205:
206: /**
207: * Creates a bevel border.
208: * The instance can be shared by multiple widgets.
209: * @param raised if true, then it is a raised-bevel layout; if false, then it is a lowered-bevel border
210: * @param color the border color
211: * @return the bevel border
212: */
213: public static Border createBevelBorder(boolean raised, Color color) {
214: return new BevelBorder(raised, color != null ? color
215: : Color.GRAY);
216: }
217:
218: /**
219: * Creates an image layout. The border is painted using a supplied Image. The image is split into 3x3 regions defined by insets.
220: * The middle regions are tiled for supplying variable width and height of border. Central region is not painted.
221: * The instance can be shared by multiple widgets.
222: * @param insets the border insets
223: * @param image the border image
224: * @return the image border
225: */
226: public static Border createImageBorder(Insets insets, Image image) {
227: return createImageBorder(insets, insets, image);
228: }
229:
230: /**
231: * Creates an image layout. The border is painted using a supplied Image. The image is split into 3x3 regions defined by imageInsets.
232: * The middle regions are tiled for supplying variable width and height of border. Central region is not painted.
233: * The insets of the border is specified by borderInsets.
234: * The instance can be shared by multiple widgets.
235: * @param borderInsets the border insets
236: * @param imageInsets the image insets
237: * @param image the border image
238: * @return the image border
239: */
240: public static Border createImageBorder(Insets borderInsets,
241: Insets imageInsets, Image image) {
242: assert borderInsets != null && imageInsets != null
243: && image != null;
244: return new ImageBorder(borderInsets, imageInsets, image);
245: }
246:
247: /**
248: * Creates an rounded-rectangle border with a specified style. Insets are calculated from arcWidth and arcHeight.
249: * The instance can be shared by multiple widgets.
250: * @param arcWidth the arc width
251: * @param arcHeight the arc height
252: * @param fillColor the fill color
253: * @param drawColor the draw color
254: * @return the rounded border
255: */
256: public static Border createRoundedBorder(int arcWidth,
257: int arcHeight, Color fillColor, Color drawColor) {
258: return createRoundedBorder(arcWidth, arcHeight, arcWidth,
259: arcHeight, fillColor, drawColor);
260: }
261:
262: /**
263: * Creates an rounded-rectangle border with a specified style.
264: * The instance can be shared by multiple widgets.
265: * @param arcWidth the arc width
266: * @param arcHeight the arc height
267: * @param insetWidth the inset width
268: * @param insetHeight the inset height
269: * @param fillColor the fill color
270: * @param drawColor the draw color
271: * @return the rounded border
272: */
273: public static Border createRoundedBorder(int arcWidth,
274: int arcHeight, int insetWidth, int insetHeight,
275: Color fillColor, Color drawColor) {
276: return new RoundedBorder(arcWidth, arcHeight, insetWidth,
277: insetHeight, fillColor, drawColor);
278: }
279:
280: /**
281: * Creates a resize border. Usually used as resizing handles for ResizeAction. It renders a bounding rectangle with 8-direction squares.
282: * The instance can be shared by multiple widgets.
283: * @param thickness the thickness of the border
284: * @return the resize border
285: */
286: public static Border createResizeBorder(int thickness) {
287: return createResizeBorder(thickness, null, false);
288: }
289:
290: /**
291: * Creates a resize border. Usually used as resizing handles for ResizeAction. It renders a bounding rectangle with 8-direction squares.
292: * The instance can be shared by multiple widgets.
293: * @param thickness the thickness of the border
294: * @param color the border color
295: * @param outer if true, then the rectangle encapsulate the squares too; if false, then the rectangle encapsulates the widget client area only
296: * @return the resize border
297: */
298: public static Border createResizeBorder(int thickness, Color color,
299: boolean outer) {
300: return new ResizeBorder(thickness, color != null ? color
301: : Color.BLACK, outer);
302: }
303:
304: /**
305: * Creates a resize border rendered with dashed stroke.
306: * The instance can be shared by multiple widgets.
307: * @param color the border color
308: * @param width the inset width
309: * @param height the inset height
310: * @return the dashed border
311: */
312: public static Border createDashedBorder(Color color, int width,
313: int height) {
314: return createDashedBorder(color, width, height, false);
315: }
316:
317: /**
318: * Creates a resize border rendered with dashed stroke.
319: * The instance can be shared by multiple widgets.
320: * @param color the border color
321: * @param width the inset width
322: * @param height the inset height
323: * @param squares the
324: * @return the dashed border
325: */
326: public static Border createDashedBorder(Color color, int width,
327: int height, boolean squares) {
328: if (!squares)
329: return new FancyDashedBorder(color != null ? color
330: : Color.BLACK, width, height);
331: else
332: return new DashedBorder(
333: color != null ? color : Color.BLACK, width, height);
334: }
335:
336: /**
337: * Creates a resize border rendered with fancy dashed stroke.
338: * The instance can be shared by multiple widgets.
339: * @param color the border color
340: * @param width the inset width
341: * @param height the inset height
342: * @return the fancy dashed border
343: * @deprecated use createDashedBorder (color, width, height, true) method instead
344: */
345: public static Border createFancyDashedBorder(Color color,
346: int width, int height) {
347: GeomUtil.LOG
348: .warning("BorderFactory.createFancyDashedBorder() method is deprecated. Use BorderFactory.createDashedBorder(color,width,height,true) method instead."); // NOI18N
349: return new FancyDashedBorder(color != null ? color
350: : Color.BLACK, width, height);
351: }
352:
353: }
|