- Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathBorderFactory.java
763 lines (716 loc) · 31.4 KB
/
BorderFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
packagejavax.swing;
importjava.awt.BasicStroke;
importjava.awt.Color;
importjava.awt.Font;
importjava.awt.Paint;
importjavax.swing.border.*;
/**
* Factory class for vending standard <code>Border</code> objects. Wherever
* possible, this factory will hand out references to shared
* <code>Border</code> instances.
* For further information and examples see
* <a href="https://docs.oracle.com/javase/tutorial/uiswing/components/border.html">How
to Use Borders</a>,
* a section in <em>The Java Tutorial</em>.
*
* @author David Kloba
* @since 1.2
*/
publicclassBorderFactory
{
/** Don't let anyone instantiate this class */
privateBorderFactory() {
}
//// LineBorder ///////////////////////////////////////////////////////////////
/**
* Creates a line border with the specified color.
*
* @param color a <code>Color</code> to use for the line
* @return the <code>Border</code> object
*/
publicstaticBordercreateLineBorder(Colorcolor) {
returnnewLineBorder(color, 1);
}
/**
* Creates a line border with the specified color
* and width. The width applies to all four sides of the
* border. To specify widths individually for the top,
* bottom, left, and right, use
* {@link #createMatteBorder(int,int,int,int,Color)}.
*
* @param color a <code>Color</code> to use for the line
* @param thickness an integer specifying the width in pixels
* @return the <code>Border</code> object
*/
publicstaticBordercreateLineBorder(Colorcolor, intthickness) {
returnnewLineBorder(color, thickness);
}
/**
* Creates a line border with the specified color, thickness, and corner shape.
*
* @param color the color of the border
* @param thickness the thickness of the border
* @param rounded whether or not border corners should be round
* @return the {@code Border} object
*
* @see LineBorder#LineBorder(Color, int, boolean)
* @since 1.7
*/
publicstaticBordercreateLineBorder(Colorcolor, intthickness, booleanrounded) {
returnnewLineBorder(color, thickness, rounded);
}
//// BevelBorder /////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
staticfinalBordersharedRaisedBevel = newBevelBorder(BevelBorder.RAISED);
staticfinalBordersharedLoweredBevel = newBevelBorder(BevelBorder.LOWERED);
/**
* Creates a border with a raised beveled edge, using
* brighter shades of the component's current background color
* for highlighting, and darker shading for shadows.
* (In a raised border, highlights are on top and shadows
* are underneath.)
*
* @return the <code>Border</code> object
*/
publicstaticBordercreateRaisedBevelBorder() {
returncreateSharedBevel(BevelBorder.RAISED);
}
/**
* Creates a border with a lowered beveled edge, using
* brighter shades of the component's current background color
* for highlighting, and darker shading for shadows.
* (In a lowered border, shadows are on top and highlights
* are underneath.)
*
* @return the <code>Border</code> object
*/
publicstaticBordercreateLoweredBevelBorder() {
returncreateSharedBevel(BevelBorder.LOWERED);
}
/**
* Creates a beveled border of the specified type, using
* brighter shades of the component's current background color
* for highlighting, and darker shading for shadows.
* (In a lowered border, shadows are on top and highlights
* are underneath.)
*
* @param type an integer specifying either
* <code>BevelBorder.LOWERED</code> or
* <code>BevelBorder.RAISED</code>
* @return the <code>Border</code> object
*/
publicstaticBordercreateBevelBorder(inttype) {
returncreateSharedBevel(type);
}
/**
* Creates a beveled border of the specified type, using
* the specified highlighting and shadowing. The outer
* edge of the highlighted area uses a brighter shade of
* the highlight color. The inner edge of the shadow area
* uses a brighter shade of the shadow color.
*
* @param type an integer specifying either
* <code>BevelBorder.LOWERED</code> or
* <code>BevelBorder.RAISED</code>
* @param highlight a <code>Color</code> object for highlights
* @param shadow a <code>Color</code> object for shadows
* @return the <code>Border</code> object
*/
publicstaticBordercreateBevelBorder(inttype, Colorhighlight, Colorshadow) {
returnnewBevelBorder(type, highlight, shadow);
}
/**
* Creates a beveled border of the specified type, using
* the specified colors for the inner and outer highlight
* and shadow areas.
*
* @param type an integer specifying either
* <code>BevelBorder.LOWERED</code> or
* <code>BevelBorder.RAISED</code>
* @param highlightOuter a <code>Color</code> object for the
* outer edge of the highlight area
* @param highlightInner a <code>Color</code> object for the
* inner edge of the highlight area
* @param shadowOuter a <code>Color</code> object for the
* outer edge of the shadow area
* @param shadowInner a <code>Color</code> object for the
* inner edge of the shadow area
* @return the <code>Border</code> object
*/
publicstaticBordercreateBevelBorder(inttype,
ColorhighlightOuter, ColorhighlightInner,
ColorshadowOuter, ColorshadowInner) {
returnnewBevelBorder(type, highlightOuter, highlightInner,
shadowOuter, shadowInner);
}
staticBordercreateSharedBevel(inttype) {
if(type == BevelBorder.RAISED) {
returnsharedRaisedBevel;
} elseif(type == BevelBorder.LOWERED) {
returnsharedLoweredBevel;
}
returnnull;
}
//// SoftBevelBorder ///////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
privatestaticBordersharedSoftRaisedBevel;
privatestaticBordersharedSoftLoweredBevel;
/**
* Creates a beveled border with a raised edge and softened corners,
* using brighter shades of the component's current background color
* for highlighting, and darker shading for shadows.
* In a raised border, highlights are on top and shadows are underneath.
*
* @return the {@code Border} object
*
* @since 1.7
*/
publicstaticBordercreateRaisedSoftBevelBorder() {
if (sharedSoftRaisedBevel == null) {
sharedSoftRaisedBevel = newSoftBevelBorder(BevelBorder.RAISED);
}
returnsharedSoftRaisedBevel;
}
/**
* Creates a beveled border with a lowered edge and softened corners,
* using brighter shades of the component's current background color
* for highlighting, and darker shading for shadows.
* In a lowered border, shadows are on top and highlights are underneath.
*
* @return the {@code Border} object
*
* @since 1.7
*/
publicstaticBordercreateLoweredSoftBevelBorder() {
if (sharedSoftLoweredBevel == null) {
sharedSoftLoweredBevel = newSoftBevelBorder(BevelBorder.LOWERED);
}
returnsharedSoftLoweredBevel;
}
/**
* Creates a beveled border of the specified type with softened corners,
* using brighter shades of the component's current background color
* for highlighting, and darker shading for shadows.
* The type is either {@link BevelBorder#RAISED} or {@link BevelBorder#LOWERED}.
*
* @param type a type of a bevel
* @return the {@code Border} object or {@code null}
* if the specified type is not valid
*
* @see BevelBorder#BevelBorder(int)
* @since 1.7
*/
publicstaticBordercreateSoftBevelBorder(inttype) {
if (type == BevelBorder.RAISED) {
returncreateRaisedSoftBevelBorder();
}
if (type == BevelBorder.LOWERED) {
returncreateLoweredSoftBevelBorder();
}
returnnull;
}
/**
* Creates a beveled border of the specified type with softened corners,
* using the specified highlighting and shadowing.
* The type is either {@link BevelBorder#RAISED} or {@link BevelBorder#LOWERED}.
* The outer edge of the highlight area uses
* a brighter shade of the {@code highlight} color.
* The inner edge of the shadow area uses
* a brighter shade of the {@code shadow} color.
*
* @param type a type of a bevel
* @param highlight a basic color of the highlight area
* @param shadow a basic color of the shadow area
* @return the {@code Border} object
*
* @see BevelBorder#BevelBorder(int, Color, Color)
* @since 1.7
*/
publicstaticBordercreateSoftBevelBorder(inttype, Colorhighlight, Colorshadow) {
returnnewSoftBevelBorder(type, highlight, shadow);
}
/**
* Creates a beveled border of the specified type with softened corners,
* using the specified colors for the inner and outer edges
* of the highlight and the shadow areas.
* The type is either {@link BevelBorder#RAISED} or {@link BevelBorder#LOWERED}.
* Note: The shadow inner and outer colors are switched
* for a lowered bevel border.
*
* @param type a type of a bevel
* @param highlightOuter a color of the outer edge of the highlight area
* @param highlightInner a color of the inner edge of the highlight area
* @param shadowOuter a color of the outer edge of the shadow area
* @param shadowInner a color of the inner edge of the shadow area
* @return the {@code Border} object
*
* @see BevelBorder#BevelBorder(int, Color, Color, Color, Color)
* @since 1.7
*/
publicstaticBordercreateSoftBevelBorder(inttype, ColorhighlightOuter, ColorhighlightInner, ColorshadowOuter, ColorshadowInner) {
returnnewSoftBevelBorder(type, highlightOuter, highlightInner, shadowOuter, shadowInner);
}
//// EtchedBorder ///////////////////////////////////////////////////////////
staticfinalBordersharedEtchedBorder = newEtchedBorder();
privatestaticBordersharedRaisedEtchedBorder;
/**
* Creates a border with an "etched" look using
* the component's current background color for
* highlighting and shading.
*
* @return the <code>Border</code> object
*/
publicstaticBordercreateEtchedBorder() {
returnsharedEtchedBorder;
}
/**
* Creates a border with an "etched" look using
* the specified highlighting and shading colors.
*
* @param highlight a <code>Color</code> object for the border highlights
* @param shadow a <code>Color</code> object for the border shadows
* @return the <code>Border</code> object
*/
publicstaticBordercreateEtchedBorder(Colorhighlight, Colorshadow) {
returnnewEtchedBorder(highlight, shadow);
}
/**
* Creates a border with an "etched" look using
* the component's current background color for
* highlighting and shading.
*
* @param type one of <code>EtchedBorder.RAISED</code>, or
* <code>EtchedBorder.LOWERED</code>
* @return the <code>Border</code> object
* @throws IllegalArgumentException if type is not either
* <code>EtchedBorder.RAISED</code> or
* <code>EtchedBorder.LOWERED</code>
* @since 1.3
*/
publicstaticBordercreateEtchedBorder(inttype) {
switch (type) {
caseEtchedBorder.RAISED:
if (sharedRaisedEtchedBorder == null) {
sharedRaisedEtchedBorder = newEtchedBorder
(EtchedBorder.RAISED);
}
returnsharedRaisedEtchedBorder;
caseEtchedBorder.LOWERED:
returnsharedEtchedBorder;
default:
thrownewIllegalArgumentException("type must be one of EtchedBorder.RAISED or EtchedBorder.LOWERED");
}
}
/**
* Creates a border with an "etched" look using
* the specified highlighting and shading colors.
*
* @param type one of <code>EtchedBorder.RAISED</code>, or
* <code>EtchedBorder.LOWERED</code>
* @param highlight a <code>Color</code> object for the border highlights
* @param shadow a <code>Color</code> object for the border shadows
* @return the <code>Border</code> object
* @since 1.3
*/
publicstaticBordercreateEtchedBorder(inttype, Colorhighlight,
Colorshadow) {
returnnewEtchedBorder(type, highlight, shadow);
}
//// TitledBorder ////////////////////////////////////////////////////////////
/**
* Creates a new titled border with the specified title,
* the default border type (determined by the current look and feel),
* the default text position (determined by the current look and feel),
* the default justification (leading), and the default
* font and text color (determined by the current look and feel).
*
* @param title a <code>String</code> containing the text of the title
* @return the <code>TitledBorder</code> object
*/
publicstaticTitledBordercreateTitledBorder(Stringtitle) {
returnnewTitledBorder(title);
}
/**
* Creates a new titled border with an empty title,
* the specified border object,
* the default text position (determined by the current look and feel),
* the default justification (leading), and the default
* font and text color (determined by the current look and feel).
*
* @param border the <code>Border</code> object to add the title to; if
* <code>null</code> the <code>Border</code> is determined
* by the current look and feel.
* @return the <code>TitledBorder</code> object
*/
publicstaticTitledBordercreateTitledBorder(Borderborder) {
returnnewTitledBorder(border);
}
/**
* Adds a title to an existing border,
* with default positioning (determined by the current look and feel),
* default justification (leading) and the default
* font and text color (determined by the current look and feel).
*
* @param border the <code>Border</code> object to add the title to
* @param title a <code>String</code> containing the text of the title
* @return the <code>TitledBorder</code> object
*/
publicstaticTitledBordercreateTitledBorder(Borderborder,
Stringtitle) {
returnnewTitledBorder(border, title);
}
/**
* Adds a title to an existing border, with the specified
* positioning and using the default
* font and text color (determined by the current look and feel).
*
* @param border the <code>Border</code> object to add the title to
* @param title a <code>String</code> containing the text of the title
* @param titleJustification an integer specifying the justification
* of the title -- one of the following:
*<ul>
*<li><code>TitledBorder.LEFT</code>
*<li><code>TitledBorder.CENTER</code>
*<li><code>TitledBorder.RIGHT</code>
*<li><code>TitledBorder.LEADING</code>
*<li><code>TitledBorder.TRAILING</code>
*<li><code>TitledBorder.DEFAULT_JUSTIFICATION</code> (leading)
*</ul>
* @param titlePosition an integer specifying the vertical position of
* the text in relation to the border -- one of the following:
*<ul>
*<li><code> TitledBorder.ABOVE_TOP</code>
*<li><code>TitledBorder.TOP</code> (sitting on the top line)
*<li><code>TitledBorder.BELOW_TOP</code>
*<li><code>TitledBorder.ABOVE_BOTTOM</code>
*<li><code>TitledBorder.BOTTOM</code> (sitting on the bottom line)
*<li><code>TitledBorder.BELOW_BOTTOM</code>
*<li><code>TitledBorder.DEFAULT_POSITION</code> (the title position
* is determined by the current look and feel)
*</ul>
* @return the <code>TitledBorder</code> object
*/
publicstaticTitledBordercreateTitledBorder(Borderborder,
Stringtitle,
inttitleJustification,
inttitlePosition) {
returnnewTitledBorder(border, title, titleJustification,
titlePosition);
}
/**
* Adds a title to an existing border, with the specified
* positioning and font, and using the default text color
* (determined by the current look and feel).
*
* @param border the <code>Border</code> object to add the title to
* @param title a <code>String</code> containing the text of the title
* @param titleJustification an integer specifying the justification
* of the title -- one of the following:
*<ul>
*<li><code>TitledBorder.LEFT</code>
*<li><code>TitledBorder.CENTER</code>
*<li><code>TitledBorder.RIGHT</code>
*<li><code>TitledBorder.LEADING</code>
*<li><code>TitledBorder.TRAILING</code>
*<li><code>TitledBorder.DEFAULT_JUSTIFICATION</code> (leading)
*</ul>
* @param titlePosition an integer specifying the vertical position of
* the text in relation to the border -- one of the following:
*<ul>
*<li><code> TitledBorder.ABOVE_TOP</code>
*<li><code>TitledBorder.TOP</code> (sitting on the top line)
*<li><code>TitledBorder.BELOW_TOP</code>
*<li><code>TitledBorder.ABOVE_BOTTOM</code>
*<li><code>TitledBorder.BOTTOM</code> (sitting on the bottom line)
*<li><code>TitledBorder.BELOW_BOTTOM</code>
*<li><code>TitledBorder.DEFAULT_POSITION</code> (the title position
* is determined by the current look and feel)
*</ul>
* @param titleFont a Font object specifying the title font
* @return the TitledBorder object
*/
publicstaticTitledBordercreateTitledBorder(Borderborder,
Stringtitle,
inttitleJustification,
inttitlePosition,
FonttitleFont) {
returnnewTitledBorder(border, title, titleJustification,
titlePosition, titleFont);
}
/**
* Adds a title to an existing border, with the specified
* positioning, font and color.
*
* @param border the <code>Border</code> object to add the title to
* @param title a <code>String</code> containing the text of the title
* @param titleJustification an integer specifying the justification
* of the title -- one of the following:
*<ul>
*<li><code>TitledBorder.LEFT</code>
*<li><code>TitledBorder.CENTER</code>
*<li><code>TitledBorder.RIGHT</code>
*<li><code>TitledBorder.LEADING</code>
*<li><code>TitledBorder.TRAILING</code>
*<li><code>TitledBorder.DEFAULT_JUSTIFICATION</code> (leading)
*</ul>
* @param titlePosition an integer specifying the vertical position of
* the text in relation to the border -- one of the following:
*<ul>
*<li><code> TitledBorder.ABOVE_TOP</code>
*<li><code>TitledBorder.TOP</code> (sitting on the top line)
*<li><code>TitledBorder.BELOW_TOP</code>
*<li><code>TitledBorder.ABOVE_BOTTOM</code>
*<li><code>TitledBorder.BOTTOM</code> (sitting on the bottom line)
*<li><code>TitledBorder.BELOW_BOTTOM</code>
*<li><code>TitledBorder.DEFAULT_POSITION</code> (the title position
* is determined by the current look and feel)
*</ul>
* @param titleFont a <code>Font</code> object specifying the title font
* @param titleColor a <code>Color</code> object specifying the title color
* @return the <code>TitledBorder</code> object
*/
publicstaticTitledBordercreateTitledBorder(Borderborder,
Stringtitle,
inttitleJustification,
inttitlePosition,
FonttitleFont,
ColortitleColor) {
returnnewTitledBorder(border, title, titleJustification,
titlePosition, titleFont, titleColor);
}
//// EmptyBorder ///////////////////////////////////////////////////////////
staticfinalBorderemptyBorder = newEmptyBorder(0, 0, 0, 0);
/**
* Creates an empty border that takes up no space. (The width
* of the top, bottom, left, and right sides are all zero.)
*
* @return the <code>Border</code> object
*/
publicstaticBordercreateEmptyBorder() {
returnemptyBorder;
}
/**
* Creates an empty border that takes up space but which does
* no drawing, specifying the width of the top, left, bottom, and
* right sides.
*
* @param top an integer specifying the width of the top,
* in pixels
* @param left an integer specifying the width of the left side,
* in pixels
* @param bottom an integer specifying the width of the bottom,
* in pixels
* @param right an integer specifying the width of the right side,
* in pixels
* @return the <code>Border</code> object
*/
publicstaticBordercreateEmptyBorder(inttop, intleft,
intbottom, intright) {
returnnewEmptyBorder(top, left, bottom, right);
}
//// CompoundBorder ////////////////////////////////////////////////////////
/**
* Creates a compound border with a <code>null</code> inside edge and a
* <code>null</code> outside edge.
*
* @return the <code>CompoundBorder</code> object
*/
publicstaticCompoundBordercreateCompoundBorder() {
returnnewCompoundBorder();
}
/**
* Creates a compound border specifying the border objects to use
* for the outside and inside edges.
*
* @param outsideBorder a <code>Border</code> object for the outer
* edge of the compound border
* @param insideBorder a <code>Border</code> object for the inner
* edge of the compound border
* @return the <code>CompoundBorder</code> object
*/
publicstaticCompoundBordercreateCompoundBorder(BorderoutsideBorder,
BorderinsideBorder) {
returnnewCompoundBorder(outsideBorder, insideBorder);
}
//// MatteBorder ////////////////////////////////////////////////////////
/**
* Creates a matte-look border using a solid color. (The difference between
* this border and a line border is that you can specify the individual
* border dimensions.)
*
* @param top an integer specifying the width of the top,
* in pixels
* @param left an integer specifying the width of the left side,
* in pixels
* @param bottom an integer specifying the width of the right side,
* in pixels
* @param right an integer specifying the width of the bottom,
* in pixels
* @param color a <code>Color</code> to use for the border
* @return the <code>MatteBorder</code> object
*/
publicstaticMatteBordercreateMatteBorder(inttop, intleft, intbottom, intright,
Colorcolor) {
returnnewMatteBorder(top, left, bottom, right, color);
}
/**
* Creates a matte-look border that consists of multiple tiles of a
* specified icon. Multiple copies of the icon are placed side-by-side
* to fill up the border area.
* <p>
* Note:<br>
* If the icon doesn't load, the border area is painted gray.
*
* @param top an integer specifying the width of the top,
* in pixels
* @param left an integer specifying the width of the left side,
* in pixels
* @param bottom an integer specifying the width of the right side,
* in pixels
* @param right an integer specifying the width of the bottom,
* in pixels
* @param tileIcon the <code>Icon</code> object used for the border tiles
* @return the <code>MatteBorder</code> object
*/
publicstaticMatteBordercreateMatteBorder(inttop, intleft, intbottom, intright,
IcontileIcon) {
returnnewMatteBorder(top, left, bottom, right, tileIcon);
}
//// StrokeBorder //////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/**
* Creates a border of the specified {@code stroke}.
* The component's foreground color will be used to render the border.
*
* @param stroke the {@link BasicStroke} object used to stroke a shape
* @return the {@code Border} object
*
* @throws NullPointerException if the specified {@code stroke} is {@code null}
*
* @since 1.7
*/
publicstaticBordercreateStrokeBorder(BasicStrokestroke) {
returnnewStrokeBorder(stroke);
}
/**
* Creates a border of the specified {@code stroke} and {@code paint}.
* If the specified {@code paint} is {@code null},
* the component's foreground color will be used to render the border.
*
* @param stroke the {@link BasicStroke} object used to stroke a shape
* @param paint the {@link Paint} object used to generate a color
* @return the {@code Border} object
*
* @throws NullPointerException if the specified {@code stroke} is {@code null}
*
* @since 1.7
*/
publicstaticBordercreateStrokeBorder(BasicStrokestroke, Paintpaint) {
returnnewStrokeBorder(stroke, paint);
}
//// DashedBorder //////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
privatestaticBordersharedDashedBorder;
/**
* Creates a dashed border of the specified {@code paint}.
* If the specified {@code paint} is {@code null},
* the component's foreground color will be used to render the border.
* The width of a dash line is equal to {@code 1}.
* The relative length of a dash line and
* the relative spacing between dash lines are equal to {@code 1}.
* A dash line is not rounded.
*
* @param paint the {@link Paint} object used to generate a color
* @return the {@code Border} object
*
* @since 1.7
*/
publicstaticBordercreateDashedBorder(Paintpaint) {
returncreateDashedBorder(paint, 1.0f, 1.0f, 1.0f, false);
}
/**
* Creates a dashed border of the specified {@code paint},
* relative {@code length}, and relative {@code spacing}.
* If the specified {@code paint} is {@code null},
* the component's foreground color will be used to render the border.
* The width of a dash line is equal to {@code 1}.
* A dash line is not rounded.
*
* @param paint the {@link Paint} object used to generate a color
* @param length the relative length of a dash line
* @param spacing the relative spacing between dash lines
* @return the {@code Border} object
*
* @throws IllegalArgumentException if the specified {@code length} is less than {@code 1}, or
* if the specified {@code spacing} is less than {@code 0}
* @since 1.7
*/
publicstaticBordercreateDashedBorder(Paintpaint, floatlength, floatspacing) {
returncreateDashedBorder(paint, 1.0f, length, spacing, false);
}
/**
* Creates a dashed border of the specified {@code paint}, {@code thickness},
* line shape, relative {@code length}, and relative {@code spacing}.
* If the specified {@code paint} is {@code null},
* the component's foreground color will be used to render the border.
*
* @param paint the {@link Paint} object used to generate a color
* @param thickness the width of a dash line
* @param length the relative length of a dash line
* @param spacing the relative spacing between dash lines
* @param rounded whether or not line ends should be round
* @return the {@code Border} object
*
* @throws IllegalArgumentException if the specified {@code thickness} is less than {@code 1}, or
* if the specified {@code length} is less than {@code 1}, or
* if the specified {@code spacing} is less than {@code 0}
* @since 1.7
*/
publicstaticBordercreateDashedBorder(Paintpaint, floatthickness, floatlength, floatspacing, booleanrounded) {
booleanshared = !rounded && (paint == null) && (thickness == 1.0f) && (length == 1.0f) && (spacing == 1.0f);
if (shared && (sharedDashedBorder != null)) {
returnsharedDashedBorder;
}
if (thickness < 1.0f) {
thrownewIllegalArgumentException("thickness is less than 1");
}
if (length < 1.0f) {
thrownewIllegalArgumentException("length is less than 1");
}
if (spacing < 0.0f) {
thrownewIllegalArgumentException("spacing is less than 0");
}
intcap = rounded ? BasicStroke.CAP_ROUND : BasicStroke.CAP_SQUARE;
intjoin = rounded ? BasicStroke.JOIN_ROUND : BasicStroke.JOIN_MITER;
float[] array = { thickness * (length - 1.0f), thickness * (spacing + 1.0f) };
Borderborder = createStrokeBorder(newBasicStroke(thickness, cap, join, thickness * 2.0f, array, 0.0f), paint);
if (shared) {
sharedDashedBorder = border;
}
returnborder;
}
}