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.awt.Color;
27 import java.awt.Shape;
28 import java.awt.Stroke;
29 import java.awt.BasicStroke;
30
31 import java.awt.geom.Ellipse2D;
32 import java.awt.geom.Rectangle2D;
33
34 import java.util.List;
35
36 import org.dishevelled.commandline.Usage;
37 import org.dishevelled.commandline.Switch;
38 import org.dishevelled.commandline.Argument;
39 import org.dishevelled.commandline.ArgumentList;
40 import org.dishevelled.commandline.CommandLine;
41 import org.dishevelled.commandline.CommandLineParser;
42 import org.dishevelled.commandline.CommandLineParseException;
43
44 import org.dishevelled.commandline.argument.FloatArgument;
45 import org.dishevelled.commandline.argument.StringArgument;
46 import org.dishevelled.commandline.argument.DoubleArgument;
47 import org.dishevelled.commandline.argument.IntegerListArgument;
48
49 import org.dishevelled.iconbundle.IconBundle;
50
51 import org.dishevelled.iconbundle.impl.ShapeIconBundle;
52
53
54
55
56
57
58 public final class ShapeVariants
59 {
60
61
62
63
64
65
66 public static void main(final String[] args)
67 {
68 CommandLine commandLine = null;
69 ArgumentList arguments = null;
70 try
71 {
72 commandLine = new CommandLine(args);
73
74 Argument<Double> x = new DoubleArgument("x", "x", "x coordinate", true);
75 Argument<Double> y = new DoubleArgument("y", "y", "y coordinate", true);
76 Argument<Double> w = new DoubleArgument("w", "width", "width", true);
77 Argument<Double> h = new DoubleArgument("h", "height", "height", true);
78 Argument<String> s = new StringArgument("s", "shape", "shape, one of { ellipse, rectangle }", true);
79 Argument<Float> t = new FloatArgument("t", "stroke", "stroke", true);
80 Argument<List<Integer>> f = new IntegerListArgument("f", "fill-color", "fill color, in int RGBA format: R,G,B,A", true);
81 Argument<List<Integer>> k = new IntegerListArgument("k", "stroke-color", "stroke color, in int RGBA format: R,G,B,A", true);
82 Argument<String> o = new StringArgument("o", "output", "output file name", true);
83 Argument<Boolean> b = new Switch("b", "draw-borders", "true to draw borders");
84
85 arguments = new ArgumentList(new Argument[] { x, y, w, h, s, t, f, k, o, b });
86
87 CommandLineParser.parse(commandLine, arguments);
88
89 Shape shape = null;
90 if ("ellipse".equals(s.getValue()))
91 {
92 shape = new Ellipse2D.Double(x.getValue(), y.getValue(), w.getValue(), h.getValue());
93 }
94 else if ("rectangle".equals(s.getValue()))
95 {
96 shape = new Rectangle2D.Double(x.getValue(), y.getValue(), w.getValue(), h.getValue());
97 }
98 else
99 {
100 throw new CommandLineParseException("shape " + s.getValue() + " not recognized");
101 }
102
103 Stroke stroke = new BasicStroke(t.getValue());
104 Color fillColor = new Color(f.getValue().get(0), f.getValue().get(1), f.getValue().get(2), f.getValue().get(3));
105 Color strokeColor = new Color(k.getValue().get(0), k.getValue().get(1), k.getValue().get(2), k.getValue().get(3));
106
107 IconBundle iconBundle = new ShapeIconBundle(shape, stroke, fillColor, strokeColor);
108
109 Runnable sav = new ShowAllVariants(iconBundle, o.getValue(), b.getValue());
110 sav.run();
111 }
112 catch (CommandLineParseException e)
113 {
114 Usage.usage("java -jar shape-variants.jar [args]\n\nShape Variants", e, commandLine, arguments, System.err);
115 }
116 }
117 }