1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dishevelled.iconbundle.tango;
25
26 import java.awt.Image;
27 import java.awt.Color;
28 import java.awt.Component;
29
30 import java.awt.image.BufferedImage;
31
32 import java.net.URL;
33
34 import javax.imageio.ImageIO;
35
36 import javax.swing.UIManager;
37
38 import org.dishevelled.iconbundle.IconSize;
39 import org.dishevelled.iconbundle.IconState;
40 import org.dishevelled.iconbundle.IconBundle;
41 import org.dishevelled.iconbundle.IconTextDirection;
42
43 import org.dishevelled.iconbundle.impl.IconBundleUtils;
44
45 import org.dishevelled.iconbundle.impl.svg.SVGIconBundleUtils;
46
47
48
49
50
51
52
53 final class TangoProjectIconBundle
54 implements IconBundle
55 {
56
57 private static final String BASE_URL = "/org/freedesktop/tango/";
58
59
60 private final String context;
61
62
63 private final String name;
64
65
66
67
68
69
70
71
72
73 TangoProjectIconBundle(final String context,
74 final String name)
75 {
76 this.context = context;
77 this.name = name;
78 }
79
80
81
82 public Image getImage(final Component component,
83 final IconTextDirection direction,
84 final IconState state,
85 final IconSize size)
86 {
87 if (direction == null)
88 {
89 throw new IllegalArgumentException("direction must not be null");
90 }
91 if (state == null)
92 {
93 throw new IllegalArgumentException("state must not be null");
94 }
95 if (size == null)
96 {
97 throw new IllegalArgumentException("size must not be null");
98 }
99
100 URL url = null;
101 BufferedImage image = null;
102
103 if (TangoProject.EXTRA_SMALL.equals(size) || TangoProject.SMALL.equals(size) || TangoProject.MEDIUM.equals(size))
104 {
105 try
106 {
107 url = this.getClass().getResource(BASE_URL + size.toString() + "/" + context + "/" + name + ".png");
108 image = ImageIO.read(url);
109 }
110 catch (Exception e)
111 {
112 System.err.println("couldn't find image for url=" + url);
113 System.err.println(" or=" + BASE_URL + size.toString() + "/" + context + "/" + name + ".png");
114 e.printStackTrace();
115
116 }
117 }
118 else
119 {
120 int width = size.getWidth();
121 int height = size.getHeight();
122
123 url = this.getClass().getResource(BASE_URL + "scalable/" + context + "/" + name + ".svg");
124 image = SVGIconBundleUtils.readSVG(url, width, height);
125 }
126
127 if (IconState.ACTIVE == state)
128 {
129 return IconBundleUtils.makeActive(image);
130 }
131 else if (IconState.MOUSEOVER == state)
132 {
133 return IconBundleUtils.makeMouseover(image);
134 }
135 else if (IconState.SELECTED == state)
136 {
137 Color selectionColor = UIManager.getColor("List.selectionBackground");
138 return IconBundleUtils.makeSelected(image, selectionColor);
139 }
140 else if (IconState.SELECTED_MOUSEOVER == state)
141 {
142 Color selectionColor = UIManager.getColor("List.selectionBackground");
143 return IconBundleUtils.makeSelectedMouseover(image, selectionColor);
144 }
145 else if (IconState.DRAGGING == state)
146 {
147 return IconBundleUtils.makeDragging(image);
148 }
149 else if (IconState.DISABLED == state)
150 {
151 return IconBundleUtils.makeDisabled(image);
152 }
153 else
154 {
155 return image;
156 }
157 }
158 }