KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcckit > plot > PositionHint


1 /*
2  * Copyright 2003-2004, Franz-Josef Elmer, All rights reserved
3  *
4  * This library is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation; either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details
13  * (http://www.gnu.org/copyleft/lesser.html).
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package jcckit.plot;
20
21 import jcckit.graphic.GraphPoint;
22 import jcckit.util.ConfigParameters;
23
24 /**
25  * An immutable {@link Hint} capsulating two {@link GraphPoint GraphPoints}.
26  *
27  * @author Franz-Josef Elmer
28  */

29 public class PositionHint implements Hint {
30   /** Configuration parameter key. */
31   public static final String JavaDoc POSITION_KEY = "position",
32                              ORIGIN_KEY = "origin";
33   private final GraphPoint _position;
34   private final GraphPoint _origin;
35
36   /**
37    * Creates an instance from the specified configuration parameters.
38    * <table border=1 cellpadding=5>
39    * <tr><th>Key &amp; Default Value</th><th>Type</th><th>Mandatory</th>
40    * <th>Description</th></tr>
41    * <tr><td><tt>position = null</tt></td>
42    * <td><tt>double[]</tt></td><td>no</td>
43    * <td>Definition of position.</td></tr>
44    * <tr><td><tt>origin = position</tt> or (0,0) if <tt>position</tt>
45    * undefined</td>
46    * <td><tt>double[]</tt></td><td>no</td>
47    * <td>Definition of origin.</td></tr>
48    * </table>
49    */

50   public PositionHint(ConfigParameters config) {
51     double[] point = config.getDoubleArray(POSITION_KEY, null);
52     _position = point == null ? null : new GraphPoint(point);
53     _origin = new GraphPoint(config.getDoubleArray(ORIGIN_KEY, point));
54   }
55
56   /**
57    * Creates an instance based on two points.
58    * @param origin The origin.
59    * @param position The position.
60    */

61   public PositionHint(GraphPoint origin, GraphPoint position) {
62     _origin = origin;
63     _position = position;
64   }
65
66   /** Returns the position. */
67   public GraphPoint getPosition() {
68     return _position;
69   }
70
71   /** Returns the origin. */
72   public GraphPoint getOrigin() {
73     return _origin;
74   }
75 }
76
Popular Tags