KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > gui > chart > LabeledValue


1 /*
2  *
3  * LabeledValue.java jchart2d
4  * Copyright (C) Achim Westermann, created on 12.07.2005, 22:15:11
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  * If you modify or optimize the code in a useful way please let me know.
21  * Achim.Westermann@gmx.de
22  *
23  */

24 package info.monitorenter.gui.chart;
25
26 /**
27  * A double value along with it's label.
28  * <p>
29  *
30  * Very primitive class comparable to a c struct.
31  * <p>
32  *
33  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
34  *
35  * @version $Revision: 1.1 $
36  */

37 public class LabeledValue {
38
39   /** The flag showing if this label is a major tick. */
40   protected boolean m_isMajorTick = false;
41
42   /** The label. */
43   protected String JavaDoc m_label;
44
45   /** The corresponding value. */
46   protected double m_value;
47
48   /**
49    * Internal defcon.
50    * <p>
51    */

52   protected LabeledValue() {
53     // nop
54
}
55
56   /**
57    * Creates an instance with the given valu and the label for it.
58    * <p>
59    *
60    * @param value
61    * the value of this label.
62    *
63    * @param label
64    * the String representation of this label.
65    */

66   LabeledValue(final double value, final String JavaDoc label) {
67     this.m_value = value;
68     this.m_label = label;
69   }
70
71   /**
72    * Returns the label String.
73    * <p>
74    *
75    * @return the label String.
76    */

77   String JavaDoc getLabel() {
78     return this.m_label;
79   }
80
81   /**
82    * Returns the value of this label.
83    * <p>
84    *
85    * @return the value of this label.
86    */

87   double getValue() {
88     return this.m_value;
89   }
90
91   /**
92    * Returns true if this label is a major tick, false else.
93    * <p>
94    *
95    * @return true if this label is a major tick, false else.
96    *
97    * @see AAxis#setMajorTickSpacing(double)
98    *
99    * @see AAxis#setMinorTickSpacing(double)
100    */

101   boolean isMajorTick() {
102     return this.m_isMajorTick;
103   }
104
105   /**
106    * Sets the label String.
107    * <p>
108    *
109    * @param label
110    * the label String.
111    */

112   void setLabel(final String JavaDoc label) {
113     this.m_label = label;
114   }
115
116   /**
117    * Set this label as a major tick.
118    * <p>
119    *
120    * @param isMajorTick
121    * the major tick state to set.
122    *
123    * @see AAxis#setMajorTickSpacing(double)
124    *
125    * @see AAxis#setMinorTickSpacing(double)
126    */

127   void setMajorTick(final boolean isMajorTick) {
128     this.m_isMajorTick = isMajorTick;
129   }
130
131   /**
132    * Returns the concatenation of the label string, ':' and the value's String
133    * representation.
134    * <p>
135    *
136    * @return the concatenation of the label string, ':' and the value's String
137    * representation.
138    *
139    * @see java.lang.Object#toString()
140    */

141   public String JavaDoc toString() {
142     return new StringBuffer JavaDoc().append(this.m_label).append(" : ").append(this.m_value).toString();
143   }
144 }
145
Popular Tags