1 30 31 package com.jgoodies.forms.factories; 32 33 import java.awt.Component ; 34 import java.awt.Graphics ; 35 import java.awt.Insets ; 36 import java.util.StringTokenizer ; 37 38 import javax.swing.border.Border ; 39 40 import com.jgoodies.forms.layout.ConstantSize; 41 import com.jgoodies.forms.layout.Sizes; 42 43 61 public final class Borders { 62 63 64 66 69 public static final Border EMPTY_BORDER = 70 new javax.swing.border.EmptyBorder (0, 0, 0, 0); 71 72 75 public static final Border DLU2_BORDER = 76 createEmptyBorder(Sizes.DLUY2, 77 Sizes.DLUX2, 78 Sizes.DLUY2, 79 Sizes.DLUX2); 80 81 84 public static final Border DLU4_BORDER = 85 createEmptyBorder(Sizes.DLUY4, 86 Sizes.DLUX4, 87 Sizes.DLUY4, 88 Sizes.DLUX4); 89 90 93 public static final Border DLU7_BORDER = 94 createEmptyBorder(Sizes.DLUY7, 95 Sizes.DLUX7, 96 Sizes.DLUY7, 97 Sizes.DLUX7); 98 99 102 public static final Border DLU14_BORDER = 103 createEmptyBorder(Sizes.DLUY14, 104 Sizes.DLUX14, 105 Sizes.DLUY14, 106 Sizes.DLUX14); 107 108 114 public static final Border BUTTON_BAR_GAP_BORDER = 115 createEmptyBorder(Sizes.DLUY6, Sizes.ZERO, Sizes.ZERO, Sizes.ZERO); 116 117 123 public static final Border DIALOG_BORDER = 124 DLU7_BORDER; 125 126 132 public static final Border TABBED_DIALOG_BORDER = 133 DLU4_BORDER; 134 135 136 138 148 public static Border createEmptyBorder(ConstantSize top, ConstantSize left, 149 ConstantSize bottom, ConstantSize right) { 150 return new EmptyBorder(top, left, bottom, right); 151 } 152 153 161 public static Border createEmptyBorder(String encodedSizes) { 162 StringTokenizer tokenizer = new StringTokenizer (encodedSizes, ", "); 163 int tokenCount = tokenizer.countTokens(); 164 if (tokenCount != 4) { 165 throw new IllegalArgumentException ( 166 "The border requires 4 sizes, but '" + encodedSizes + 167 "' has " + tokenCount + "."); 168 } 169 ConstantSize top = Sizes.constant(tokenizer.nextToken(), false); 170 ConstantSize left = Sizes.constant(tokenizer.nextToken(), true); 171 ConstantSize bottom = Sizes.constant(tokenizer.nextToken(), false); 172 ConstantSize right = Sizes.constant(tokenizer.nextToken(), true); 173 return createEmptyBorder(top, left, bottom, right); 174 } 175 176 180 public static final class EmptyBorder implements Border { 181 182 private final ConstantSize top; 183 private final ConstantSize left; 184 private final ConstantSize bottom; 185 private final ConstantSize right; 186 187 EmptyBorder(ConstantSize top, 188 ConstantSize left, 189 ConstantSize bottom, 190 ConstantSize right) { 191 this.top = top; 192 this.left = left; 193 this.bottom = bottom; 194 this.right = right; 195 } 196 197 208 public void paintBorder(Component c, Graphics g, 209 int x, int y, int width, int height) { 210 } 212 213 217 public Insets getBorderInsets(Component c) { 218 return new Insets (top.getPixelSize(c), 219 left.getPixelSize(c), 220 bottom.getPixelSize(c), 221 right.getPixelSize(c)); 222 } 223 224 229 public boolean isBorderOpaque() { 230 return false; 231 } 232 233 } 234 235 236 } 237 | Popular Tags |