38 * @author Tom Santos
39 * @author Steve Wilson
40 */
41
42
43 class MetalBumps implements Icon {
44
45 static final Color ALPHA = new Color(0, 0, 0, 0);
46
47 protected int xBumps;
48 protected int yBumps;
49 protected Color topColor;
50 protected Color shadowColor;
51 protected Color backColor;
52
53 private static final Object METAL_BUMPS = new Object();
54 protected BumpBuffer buffer;
55
56 /**
57 * Creates MetalBumps of the specified size with the specified colors.
58 * If <code>newBackColor</code> is null, the background will be
59 * transparent.
60 */
61 public MetalBumps( int width, int height,
62 Color newTopColor, Color newShadowColor, Color newBackColor ) {
63 setBumpArea( width, height );
64 setBumpColors( newTopColor, newShadowColor, newBackColor );
65 }
66
67 private static BumpBuffer createBuffer(GraphicsConfiguration gc,
68 Color topColor, Color shadowColor, Color backColor) {
69 AppContext context = AppContext.getAppContext();
70 @SuppressWarnings("unchecked")
71 List<BumpBuffer> buffers = (List<BumpBuffer>) context.get(METAL_BUMPS);
72 if (buffers == null) {
73 buffers = new ArrayList<BumpBuffer>();
74 context.put(METAL_BUMPS, buffers);
75 }
76 for (BumpBuffer buffer : buffers) {
77 if (buffer.hasSameConfiguration(gc, topColor, shadowColor, backColor)) {
78 return buffer;
163 }
164
165 public boolean hasSameConfiguration(GraphicsConfiguration gc,
166 Color aTopColor, Color aShadowColor,
167 Color aBackColor) {
168 if (this.gc != null) {
169 if (!this.gc.equals(gc)) {
170 return false;
171 }
172 }
173 else if (gc != null) {
174 return false;
175 }
176 return topColor.equals( aTopColor ) &&
177 shadowColor.equals( aShadowColor ) &&
178 backColor.equals( aBackColor );
179 }
180
181 /**
182 * Returns the Image containing the bumps appropriate for the passed in
183 * <code>GraphicsConfiguration</code>.
184 */
185 public Image getImage() {
186 return image;
187 }
188
189 /**
190 * Paints the bumps into the current image.
191 */
192 private void fillBumpBuffer() {
193 Graphics g = image.getGraphics();
194
195 g.setColor( backColor );
196 g.fillRect( 0, 0, IMAGE_SIZE, IMAGE_SIZE );
197
198 g.setColor(topColor);
199 for (int x = 0; x < IMAGE_SIZE; x+=4) {
200 for (int y = 0; y < IMAGE_SIZE; y+=4) {
201 g.drawLine( x, y, x, y );
202 g.drawLine( x+2, y+2, x+2, y+2);
203 }
204 }
205
206 g.setColor(shadowColor);
207 for (int x = 0; x < IMAGE_SIZE; x+=4) {
208 for (int y = 0; y < IMAGE_SIZE; y+=4) {
209 g.drawLine( x+1, y+1, x+1, y+1 );
210 g.drawLine( x+3, y+3, x+3, y+3);
211 }
212 }
213 g.dispose();
214 }
215
216 /**
217 * Creates the image appropriate for the passed in
218 * <code>GraphicsConfiguration</code>, which may be null.
219 */
220 private void createImage() {
221 if (gc != null) {
222 image = gc.createCompatibleImage(IMAGE_SIZE, IMAGE_SIZE,
223 (backColor != MetalBumps.ALPHA) ? Transparency.OPAQUE :
224 Transparency.BITMASK);
225 }
226 else {
227 int cmap[] = { backColor.getRGB(), topColor.getRGB(),
228 shadowColor.getRGB() };
229 IndexColorModel icm = new IndexColorModel(8, 3, cmap, 0, false,
230 (backColor == MetalBumps.ALPHA) ? 0 : -1,
231 DataBuffer.TYPE_BYTE);
232 image = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE,
233 BufferedImage.TYPE_BYTE_INDEXED, icm);
234 }
235 }
236 }
|
38 * @author Tom Santos
39 * @author Steve Wilson
40 */
41
42
43 class MetalBumps implements Icon {
44
45 static final Color ALPHA = new Color(0, 0, 0, 0);
46
47 protected int xBumps;
48 protected int yBumps;
49 protected Color topColor;
50 protected Color shadowColor;
51 protected Color backColor;
52
53 private static final Object METAL_BUMPS = new Object();
54 protected BumpBuffer buffer;
55
56 /**
57 * Creates MetalBumps of the specified size with the specified colors.
58 * If {@code newBackColor} is null, the background will be
59 * transparent.
60 */
61 public MetalBumps( int width, int height,
62 Color newTopColor, Color newShadowColor, Color newBackColor ) {
63 setBumpArea( width, height );
64 setBumpColors( newTopColor, newShadowColor, newBackColor );
65 }
66
67 private static BumpBuffer createBuffer(GraphicsConfiguration gc,
68 Color topColor, Color shadowColor, Color backColor) {
69 AppContext context = AppContext.getAppContext();
70 @SuppressWarnings("unchecked")
71 List<BumpBuffer> buffers = (List<BumpBuffer>) context.get(METAL_BUMPS);
72 if (buffers == null) {
73 buffers = new ArrayList<BumpBuffer>();
74 context.put(METAL_BUMPS, buffers);
75 }
76 for (BumpBuffer buffer : buffers) {
77 if (buffer.hasSameConfiguration(gc, topColor, shadowColor, backColor)) {
78 return buffer;
163 }
164
165 public boolean hasSameConfiguration(GraphicsConfiguration gc,
166 Color aTopColor, Color aShadowColor,
167 Color aBackColor) {
168 if (this.gc != null) {
169 if (!this.gc.equals(gc)) {
170 return false;
171 }
172 }
173 else if (gc != null) {
174 return false;
175 }
176 return topColor.equals( aTopColor ) &&
177 shadowColor.equals( aShadowColor ) &&
178 backColor.equals( aBackColor );
179 }
180
181 /**
182 * Returns the Image containing the bumps appropriate for the passed in
183 * {@code GraphicsConfiguration}.
184 */
185 public Image getImage() {
186 return image;
187 }
188
189 /**
190 * Paints the bumps into the current image.
191 */
192 private void fillBumpBuffer() {
193 Graphics g = image.getGraphics();
194
195 g.setColor( backColor );
196 g.fillRect( 0, 0, IMAGE_SIZE, IMAGE_SIZE );
197
198 g.setColor(topColor);
199 for (int x = 0; x < IMAGE_SIZE; x+=4) {
200 for (int y = 0; y < IMAGE_SIZE; y+=4) {
201 g.drawLine( x, y, x, y );
202 g.drawLine( x+2, y+2, x+2, y+2);
203 }
204 }
205
206 g.setColor(shadowColor);
207 for (int x = 0; x < IMAGE_SIZE; x+=4) {
208 for (int y = 0; y < IMAGE_SIZE; y+=4) {
209 g.drawLine( x+1, y+1, x+1, y+1 );
210 g.drawLine( x+3, y+3, x+3, y+3);
211 }
212 }
213 g.dispose();
214 }
215
216 /**
217 * Creates the image appropriate for the passed in
218 * {@code GraphicsConfiguration}, which may be null.
219 */
220 private void createImage() {
221 if (gc != null) {
222 image = gc.createCompatibleImage(IMAGE_SIZE, IMAGE_SIZE,
223 (backColor != MetalBumps.ALPHA) ? Transparency.OPAQUE :
224 Transparency.BITMASK);
225 }
226 else {
227 int cmap[] = { backColor.getRGB(), topColor.getRGB(),
228 shadowColor.getRGB() };
229 IndexColorModel icm = new IndexColorModel(8, 3, cmap, 0, false,
230 (backColor == MetalBumps.ALPHA) ? 0 : -1,
231 DataBuffer.TYPE_BYTE);
232 image = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE,
233 BufferedImage.TYPE_BYTE_INDEXED, icm);
234 }
235 }
236 }
|