KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > gui > chart > axis > AAxisTransformation


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

25 package info.monitorenter.gui.chart.axis;
26
27 import info.monitorenter.gui.chart.AAxis;
28 import info.monitorenter.gui.chart.labelformatters.ALabelFormatter;
29 import info.monitorenter.util.Range;
30
31 import java.awt.event.MouseEvent JavaDoc;
32
33 /**
34  * Base class for Axis implementations that transform the scale for changed
35  * display.
36  * <p>
37  *
38  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann</a>
39  *
40  *
41  * @version $Revision: 1.2 $
42  */

43 public abstract class AAxisTransformation extends AAxis {
44
45   /**
46    * Creates a default instance that will use a
47    * {@link info.monitorenter.gui.chart.labelformatters.LabelFormatterAutoUnits}
48    * for formatting labels.
49    * <p>
50    *
51    */

52   public AAxisTransformation() {
53     super();
54   }
55
56   /**
57    * Creates an instance that will the given label formatter for formatting
58    * labels.
59    * <p>
60    *
61    */

62   public AAxisTransformation(final ALabelFormatter formatter) {
63     super(formatter);
64   }
65
66   /**
67    * @see info.monitorenter.gui.chart.AAxis#getScaledValue(double)
68    */

69   protected final double getScaledValue(final double absolute) {
70     double result;
71     Range range = this.getRange();
72     double scaler = range.getExtent();
73
74     result = (transform(absolute) - range.getMin());
75     result = result / scaler;
76     if (result == Double.NaN || Double.isInfinite(result)) {
77       result = 0;
78     }
79     return result;
80   }
81
82   /**
83    * Template method for performing the axis transformation.
84    * <p>
85    *
86    * The argument should not be negative, so only normalized values (no chart
87    * values but their scaled values or pixel values) should be given here.
88    * <p>
89    *
90    *
91    * @param in
92    * the value to transform.
93    *
94    * @return the transformed value.
95    */

96   protected abstract double transform(final double in);
97
98   /**
99    * Template method for performing the reverse axis transformation.
100    * <p>
101    * This is the counterpart to {@link #transform(double)}.
102    * <p>
103    *
104    *
105    * @param in
106    * the transformed value.
107    *
108    * @return the normal value;
109    */

110   protected abstract double untransform(final double in);
111
112   /**
113    * @see info.monitorenter.gui.chart.AAxis#translateMousePosition(java.awt.event.MouseEvent)
114    */

115   protected final double translateMousePosition(final MouseEvent JavaDoc mouseEvent)
116       throws IllegalArgumentException JavaDoc {
117     return this.untransform(this.getAccessor().translateMousePosition(mouseEvent));
118   }
119
120   /**
121    * @see info.monitorenter.gui.chart.AAxis#getMax()
122    */

123   public double getMax() {
124     return this.transform(super.getMax());
125   }
126
127   /**
128    * @see info.monitorenter.gui.chart.AAxis#getMin()
129    */

130   public double getMin() {
131     return this.transform(super.getMin());
132   }
133 }
134
Popular Tags