1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.components.ledder;
21
22 import java.awt.Color;
23 import java.awt.Graphics2D;
24 import java.awt.GraphicsConfiguration;
25 import java.awt.GraphicsDevice;
26 import java.awt.GraphicsEnvironment;
27 import java.awt.Transparency;
28 import java.awt.geom.Rectangle2D;
29 import java.awt.image.BufferedImage;
30
31 import javax.swing.ImageIcon;
32
33
34
35
36
37
38
39
40 public class CustomLedIcon extends ImageIcon {
41
42 private static final long serialVersionUID = 1L;
43
44 public CustomLedIcon(Color c) {
45 this(c,16);
46 }
47 public CustomLedIcon(Color c, int size) {
48 this(c,size,1);
49 }
50
51 public CustomLedIcon(Color c, int size, int border) {
52 super();
53 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
54 GraphicsDevice gs = ge.getDefaultScreenDevice();
55 GraphicsConfiguration gc = gs.getDefaultConfiguration();
56 BufferedImage bufImg=gc.createCompatibleImage(size,size,Transparency.TRANSLUCENT);
57 Graphics2D g2 = (Graphics2D)bufImg.getGraphics();
58 g2.setPaint(new LedPaint(createDefaultParameters(c, size, border),size/2,size/2));
59 g2.fill(new Rectangle2D.Double(0, 0, size, size));
60 setImage(bufImg);
61 }
62
63 protected LedPaintParameters createDefaultParameters(Color color, int size, int border) {
64 LedPaintParameters lpp = new LedPaintParameters();
65
66
67 lpp.radius=size/2-border;
68 lpp.highlightFactor = 0.85;
69 lpp.highlightFocus = 3.0;
70 lpp.shadowIntensity = 1.0;
71 lpp.borderSize = 0.05*lpp.radius/6;
72 lpp.lightX = -0.20;
73 lpp.lightY = -0.50;
74 lpp.antialiasing = 6;
75 lpp.color=color;
76 return lpp;
77 }
78 }