View Javadoc

1   /*
2   
3       dsh-iconbundle-tools  Command line icon bundle tools.
4       Copyright (c) 2003-2013 held jointly by the individual authors.
5   
6       This library is free software; you can redistribute it and/or modify it
7       under the terms of the GNU Lesser General Public License as published
8       by the Free Software Foundation; either version 3 of the License, or (at
9       your option) any later version.
10  
11      This library is distributed in the hope that it will be useful, but WITHOUT
12      ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
13      FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14      License for more details.
15  
16      You should have received a copy of the GNU Lesser General Public License
17      along with this library;  if not, write to the Free Software Foundation,
18      Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
19  
20      > http://www.fsf.org/licensing/licenses/lgpl.html
21      > http://www.opensource.org/licenses/lgpl-license.php
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   * Shape variants.
55   *
56   * @author  Michael Heuer
57   */
58  public final class ShapeVariants
59  {
60  
61      /**
62       * Main.
63       *
64       * @param args command line arguments, ignored
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 }