KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > axis > SymbolicTickUnit


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * ---------------------
27  * SymbolicTickUnit.java
28  * ---------------------
29  * (C) Copyright 2002-2005, by Anthony Boulestreau.
30  *
31  * Original Author: Anthony Boulestreau;
32  * Contributor(s): David Gilbert (for Object Refinery Limited);
33  *
34  * $Id: SymbolicTickUnit.java,v 1.3 2005/05/19 13:58:11 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 01-May-2002 : Version 1, creation of SymbolicTickUnit to work with
39  * VerticalSymbolicAxis and HorizontalSymbolicAxis (AB);
40  * 01-Oct-2002 : Fixed errors reported by Checkstyle (DG):
41  * 08-Nov-2002 : Moved to new package com.jrefinery.chart.axis (DG);
42  * 26-Mar-2003 : Implemented Serializable (DG);
43  * 03-Dec-2003 : There is no need for using lists here; replaced by
44  * String-array (TM);
45  */

46
47 package org.jfree.chart.axis;
48
49 import java.io.Serializable JavaDoc;
50
51 /**
52  * A symbolic tick unit.
53  *
54  * @author Anthony Boulestreau
55  */

56 public class SymbolicTickUnit extends NumberTickUnit implements Serializable JavaDoc {
57
58     /** For serialization. */
59     private static final long serialVersionUID = -4836679837074745805L;
60     
61     /** The list of symbolic value to display instead of the numeric values */
62     private String JavaDoc[] symbolicValue;
63
64     /**
65      * Creates a new symbolic tick unit.
66      *
67      * @param size the size of the tick unit.
68      * @param sv the list of symbolic value to display instead of the numeric
69      * value.
70      */

71     public SymbolicTickUnit(double size, String JavaDoc[] sv) {
72         super(size, null);
73         this.symbolicValue = new String JavaDoc[sv.length];
74         System.arraycopy(sv, 0, this.symbolicValue, 0, sv.length);
75     }
76
77     /**
78      * Converts a value to a string, using the list of symbolic values.
79      * ex: if the symbolic value list is ["up", "down"] then 0 is convert to
80      * "up" and 1 to "down".
81      *
82      * @param value value to convert.
83      *
84      * @return The symbolic value.
85      */

86     public String JavaDoc valueToString(double value) {
87
88         if ((value < 0) || (value >= this.symbolicValue.length)) {
89             throw new IllegalArgumentException JavaDoc (
90                 "The value " + value
91                 + " does not have a corresponding symbolic value"
92             );
93         }
94         return this.symbolicValue[(int) value];
95     }
96
97     /**
98      * Returns the number of symbols in this unit.
99      *
100      * @return The symbol count.
101      */

102     public int getSymbolCount() {
103         return this.symbolicValue.length;
104     }
105     
106 }
107
Popular Tags