KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > gui > chart > rangepolicies > RangePolicyForcedPoint


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

22 package info.monitorenter.gui.chart.rangepolicies;
23
24 import info.monitorenter.util.Range;
25
26 /**
27  * <p>
28  * A range policy that forces the chart always to display the constructor given
29  * point regardless of the actual bounds of the traces within the chart.
30  * </p>
31  *
32  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
33  *
34  * @version $Revision: 1.2 $
35  *
36  */

37 public final class RangePolicyForcedPoint extends RangePolicyMinimumViewport {
38
39   /**
40    * Creates a range policy that ensures zero to be visible.
41    * <p>
42    */

43   public RangePolicyForcedPoint() {
44     super(new Range(0, 0));
45   }
46
47   /**
48    * Creates a range policy backed by the given point in the dimension this
49    * policy is used (x or y).
50    * <p>
51    *
52    * @param point
53    * the point that always has to be shown.
54    */

55   public RangePolicyForcedPoint(final double point) {
56     super(new Range(point, point));
57   }
58
59   /**
60    * This method is an invariant of the super class contract: only the minimum
61    * value of the given range is used to enforce visibility.
62    * <p>
63    *
64    * Use {@link #setPoint(double)} instead.
65    *
66    * @param range
67    * the internal range that may be taken into account for returning
68    * bounds from
69    * {@link info.monitorenter.gui.chart.IRangePolicy#getMax(double, double)}
70    * and
71    * {@link info.monitorenter.gui.chart.IRangePolicy#getMax(double, double)}.
72    */

73   public void setRange(final Range range) {
74     double min = range.getMin();
75     if (min != range.getMax()) {
76       super.setRange(new Range(min, min));
77     } else {
78       super.setRange(range);
79     }
80   }
81
82   /**
83    * Sets the point to ensure to be visible.
84    * <p>
85    *
86    * @param point
87    * the point to ensure to be visible.
88    */

89   public void setPoint(final double point) {
90     super.setRange(new Range(point, point));
91   }
92 }
93
Popular Tags