1 /*
2  * aTunes
3  * Copyright (C) Alex Aranda, Sylvain Gaudard and contributors
4  *
5  * See http://www.atunes.org/wiki/index.php?title=Contributing for information about contributors
6  *
7  * http://www.atunes.org
8  * http://sourceforge.net/projects/atunes
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  */
20 
21 package net.sourceforge.atunes.gui.images;
22 
23 import java.awt.AlphaComposite;
24 import java.awt.Color;
25 import java.awt.Graphics2D;
26 import java.awt.Rectangle;
27 import java.awt.RenderingHints;
28 import java.awt.geom.Ellipse2D;
29 import java.awt.geom.RoundRectangle2D;
30 import java.awt.image.BufferedImage;
31 
32 import javax.swing.ImageIcon;
33 
34 /**
35  * Icon for device
36  *
37  * @author alex
38  *
39  */
40 public class DeviceImageIcon extends CachedIconFactory {
41 
42     /**
43 	 *
44 	 */
45     private static final long serialVersionUID = 3899061042448834823L;
46 
47     private static final int WIDTH = 16;
48     private static final int HEIGHT = 16;
49 
50     @Override
createIcon(final Color color)51     protected ImageIcon createIcon(final Color color) {
52 	int marginX = 3;
53 	int marginY = 1;
54 	int arc = 4;
55 
56 	int internalMarginX = 5;
57 	int internalMarginY = 3;
58 
59 	int circleDiameter = HEIGHT / 4;
60 
61 	BufferedImage bi = new BufferedImage(WIDTH, HEIGHT,
62 		BufferedImage.TYPE_4BYTE_ABGR);
63 	Graphics2D g = bi.createGraphics();
64 	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
65 		RenderingHints.VALUE_ANTIALIAS_ON);
66 	g.setPaint(color);
67 
68 	g.fill(new RoundRectangle2D.Float(marginX, marginY,
69 		WIDTH - 2 * marginX, HEIGHT - 2 * marginY, arc, arc));
70 	g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR));
71 	g.fill(new Rectangle(internalMarginX, internalMarginY, WIDTH - 2
72 		* internalMarginX, HEIGHT / 2 - internalMarginY - 1));
73 	g.fill(new Ellipse2D.Float(WIDTH / 2 - circleDiameter / 2, HEIGHT
74 		- internalMarginY - circleDiameter, circleDiameter,
75 		circleDiameter));
76 
77 	g.dispose();
78 	return new ImageIcon(bi);
79     }
80 }
81