KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  *
3  * RangePolicyMinimumViewport.java jchart2d
4  * Copyright (C) Achim Westermann, created on 20.04.2005, 11:12:12
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.rangepolicies;
25
26 import info.monitorenter.util.Range;
27
28 /**
29  * <p>
30  * A <code>{@link info.monitorenter.gui.chart.IRangePolicy}</code> implementation that
31  * guarantees a minimum displayed range (viewport) but will stretch if values of
32  * the corresponding <code>{@link info.monitorenter.gui.chart.Chart2D}</code> exceeds these
33  * constructor given bounds.
34  * </p>
35  * <p>
36  * To sum up the policy of this implementation this
37  * <code>{@link info.monitorenter.gui.chart.IRangePolicy}</code>
38  * <ol>
39  * <li>Guarantees to always display the constructor given range.
40  * <li>Guarantees to always display every value within the
41  * <code>{@link info.monitorenter.gui.chart.Chart2D}</code> (every
42  * <code>{@link info.monitorenter.gui.chart.TracePoint2D}</code> of the chart's
43  * <code>{@link info.monitorenter.gui.chart.ITrace2D}</code> instances).
44  * </ol>
45  * </p>
46  *
47  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
48  *
49  * @version $Revision: 1.1 $
50  */

51 public class RangePolicyMinimumViewport extends ARangePolicy {
52
53   /**
54    * <p>
55    * Constructs an instance that will always ensure that the given range will be
56    * displayed.
57    * </p>
58    *
59    * @param range
60    * the range that always should be visible.
61    */

62   public RangePolicyMinimumViewport(final Range range) {
63     super(range);
64   }
65
66   /**
67    * Returns the maximum of the chart or of the internal range if greater.
68    * <p>
69    *
70    * @param chartMin
71    * ignored.
72    *
73    * @param chartMax
74    * returned if greater than the value of the internal range.
75    *
76    * @return Math.max(this.range.getMax(), chartMax).
77    *
78    * @see info.monitorenter.gui.chart.IRangePolicy#getMax(double, double)
79    */

80   public double getMax(final double chartMin, final double chartMax) {
81     return Math.max(this.getRange().getMax(), chartMax);
82   }
83
84   /**
85    * @see info.monitorenter.gui.chart.IRangePolicy#getMin(double, double)
86    */

87   public double getMin(final double chartMin, final double chartMax) {
88     return Math.min(this.getRange().getMin(), chartMin);
89   }
90 }
91
Popular Tags