View Javadoc

1   /*
2    * Copyright (c) 2003-2008 by Cosylab d. d.
3    *
4    * This file is part of CosyBeans-Common.
5    *
6    * CosyBeans-Common is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * CosyBeans-Common is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with CosyBeans-Common.  If not, see <http://www.gnu.org/licenses/>.
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   * @author Miha
36   *
37   * To change the template for this generated type comment go to
38   * Window - Preferences - Java - Code Generation - Code and Comments
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              //lpp.centerX=size/2;
66              //lpp.centerY=size/2;
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  }