1 7 package javax.swing; 8 9 import java.awt.Color ; 10 import java.awt.Font ; 11 import javax.swing.JComponent ; 12 import javax.swing.border.*; 13 14 26 public class BorderFactory 27 { 28 29 30 private BorderFactory() { 31 } 32 33 34 41 public static Border createLineBorder(Color color) { 42 return new LineBorder(color, 1); 43 } 44 45 56 public static Border createLineBorder(Color color, int thickness) { 57 return new LineBorder(color, thickness); 58 } 59 60 65 static final Border sharedRaisedBevel = new BevelBorder(BevelBorder.RAISED); 68 static final Border sharedLoweredBevel = new BevelBorder(BevelBorder.LOWERED); 69 70 79 public static Border createRaisedBevelBorder() { 80 return createSharedBevel(BevelBorder.RAISED); 81 } 82 83 92 public static Border createLoweredBevelBorder() { 93 return createSharedBevel(BevelBorder.LOWERED); 94 } 95 96 108 public static Border createBevelBorder(int type) { 109 return createSharedBevel(type); 110 } 111 112 126 public static Border createBevelBorder(int type, Color highlight, Color shadow) { 127 return new BevelBorder(type, highlight, shadow); 128 } 129 130 151 public static Border createBevelBorder(int type, 152 Color highlightOuter, Color highlightInner, 153 Color shadowOuter, Color shadowInner) { 154 return new BevelBorder(type, highlightOuter, highlightInner, 155 shadowOuter, shadowInner); 156 } 157 158 static Border createSharedBevel(int type) { 159 if(type == BevelBorder.RAISED) { 160 return sharedRaisedBevel; 161 } else if(type == BevelBorder.LOWERED) { 162 return sharedLoweredBevel; 163 } 164 return null; 165 } 166 static final Border sharedEtchedBorder = new EtchedBorder(); 168 private static Border sharedRaisedEtchedBorder; 169 170 177 public static Border createEtchedBorder() { 178 return sharedEtchedBorder; 179 } 180 181 189 public static Border createEtchedBorder(Color highlight, Color shadow) { 190 return new EtchedBorder(highlight, shadow); 191 } 192 193 206 public static Border createEtchedBorder(int type) { 207 switch (type) { 208 case EtchedBorder.RAISED: 209 if (sharedRaisedEtchedBorder == null) { 210 sharedRaisedEtchedBorder = new EtchedBorder 211 (EtchedBorder.RAISED); 212 } 213 return sharedRaisedEtchedBorder; 214 case EtchedBorder.LOWERED: 215 return sharedEtchedBorder; 216 default: 217 throw new IllegalArgumentException ("type must be one of EtchedBorder.RAISED or EtchedBorder.LOWERED"); 218 } 219 } 220 221 232 public static Border createEtchedBorder(int type, Color highlight, 233 Color shadow) { 234 return new EtchedBorder(type, highlight, shadow); 235 } 236 237 248 public static TitledBorder createTitledBorder(String title) { 249 return new TitledBorder(title); 250 } 251 252 263 public static TitledBorder createTitledBorder(Border border) { 264 return new TitledBorder(border); 265 } 266 267 277 public static TitledBorder createTitledBorder(Border border, 278 String title) { 279 return new TitledBorder(border, title); 280 } 281 282 312 public static TitledBorder createTitledBorder(Border border, 313 String title, 314 int titleJustification, 315 int titlePosition) { 316 return new TitledBorder(border, title, titleJustification, 317 titlePosition); 318 } 319 320 351 public static TitledBorder createTitledBorder(Border border, 352 String title, 353 int titleJustification, 354 int titlePosition, 355 Font titleFont) { 356 return new TitledBorder(border, title, titleJustification, 357 titlePosition, titleFont); 358 } 359 360 391 public static TitledBorder createTitledBorder(Border border, 392 String title, 393 int titleJustification, 394 int titlePosition, 395 Font titleFont, 396 Color titleColor) { 397 return new TitledBorder(border, title, titleJustification, 398 titlePosition, titleFont, titleColor); 399 } 400 final static Border emptyBorder = new EmptyBorder(0, 0, 0, 0); 402 403 409 public static Border createEmptyBorder() { 410 return emptyBorder; 411 } 412 413 428 public static Border createEmptyBorder(int top, int left, 429 int bottom, int right) { 430 return new EmptyBorder(top, left, bottom, right); 431 } 432 433 440 public static CompoundBorder createCompoundBorder() { 441 return new CompoundBorder(); 442 } 443 444 454 public static CompoundBorder createCompoundBorder(Border outsideBorder, 455 Border insideBorder) { 456 return new CompoundBorder(outsideBorder, insideBorder); 457 } 458 459 476 public static MatteBorder createMatteBorder(int top, int left, int bottom, int right, 477 Color color) { 478 return new MatteBorder(top, left, bottom, right, color); 479 } 480 481 500 public static MatteBorder createMatteBorder(int top, int left, int bottom, int right, 501 Icon tileIcon) { 502 return new MatteBorder(top, left, bottom, right, tileIcon); 503 } 504 } 505 | Popular Tags |