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.tools;
25
26 import java.io.File;
27
28 import java.awt.Color;
29 import java.awt.Graphics2D;
30
31 import java.awt.image.BufferedImage;
32
33 import java.util.Iterator;
34
35 import javax.imageio.ImageIO;
36
37 import org.dishevelled.iconbundle.IconSize;
38 import org.dishevelled.iconbundle.IconState;
39 import org.dishevelled.iconbundle.IconBundle;
40 import org.dishevelled.iconbundle.IconTextDirection;
41
42
43
44
45
46
47 public final class ShowAllVariants
48 implements Runnable
49 {
50
51 private String fileName;
52
53
54 private boolean drawBorders;
55
56
57 private IconBundle iconBundle;
58
59
60
61
62
63
64
65
66
67
68 public ShowAllVariants(final IconBundle iconBundle, final String fileName, final boolean drawBorders)
69 {
70 this.iconBundle = iconBundle;
71 this.fileName = fileName;
72 this.drawBorders = drawBorders;
73 }
74
75
76
77 public void run()
78 {
79 int w = 0;
80 int h = 0;
81
82 int maxHeight = 0;
83 int horizontalGap = 4;
84 int verticalGap = 4;
85
86 for (Iterator i = IconSize.VALUES.iterator(); i.hasNext(); )
87 {
88 IconSize size = (IconSize) i.next();
89 w += size.getWidth();
90 w += horizontalGap;
91
92 if (size.getHeight() > maxHeight)
93 {
94 maxHeight = size.getHeight();
95 }
96 }
97
98 w *= IconTextDirection.VALUES.size();
99 h = IconState.VALUES.size() * (maxHeight + verticalGap);
100
101 BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
102 Graphics2D g = image.createGraphics();
103
104 int x = 0;
105 int y = 0;
106 maxHeight = 0;
107 for (Iterator i = IconState.VALUES.iterator(); i.hasNext(); )
108 {
109 IconState state = (IconState) i.next();
110 for (Iterator j = IconSize.VALUES.iterator(); j.hasNext(); )
111 {
112 IconSize size = (IconSize) j.next();
113 for (Iterator k = IconTextDirection.VALUES.iterator(); k.hasNext(); )
114 {
115 IconTextDirection direction = (IconTextDirection) k.next();
116
117 g.drawImage(iconBundle.getImage(null, direction, state, size),
118 x, y, Color.WHITE, null);
119
120 if (drawBorders)
121 {
122 g.setPaint(Color.BLACK);
123 g.drawRect(x, y, size.getWidth(), size.getHeight());
124 }
125
126 x += size.getWidth();
127 x += horizontalGap;
128
129 if (size.getHeight() > maxHeight)
130 {
131 maxHeight = size.getHeight();
132 }
133 }
134 }
135 x = 0;
136 y += maxHeight;
137 y += verticalGap;
138 maxHeight = 0;
139 }
140
141 try
142 {
143 ImageIO.write(image, "png", new File(fileName));
144 }
145 catch (Exception e)
146 {
147
148 }
149 }
150 }