KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * RangePolicyHighestValues.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  * Range policy implementation that will force a viewport that only shows the
29  * highest values that are in the range of maximum - x.
30  * </p>
31  *
32  * @author zoola
33  *
34  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
35  *
36  * @version $Revision: 1.2 $
37  *
38  */

39 public final class RangePolicyHighestValues extends ARangePolicy {
40
41   /** The value range for the highest values to show. */
42   private double m_highestValueRangeToShow;
43
44   /**
45    * Creates a range policy with an unconfigured range ({@link Range#RANGE_UNBOUNDED})
46    * that will show the 50 hightest values.
47    * <p>
48    */

49   public RangePolicyHighestValues() {
50     this(50);
51   }
52
53   /**
54    * Creates a range policy with an unconfigured range ({@link Range#RANGE_UNBOUNDED})
55    * that will show the given amount of highest values.
56    * <p>
57    */

58   public RangePolicyHighestValues(final int amountHighestValues) {
59     super();
60     this.m_highestValueRangeToShow = amountHighestValues;
61   }
62
63   /**
64    * Constructor with a range and the value range for the highest values to show
65    * only.
66    * <p>
67    *
68    * @param range
69    * unused, maximum bound is always returned.
70    *
71    * @param highestValueRangeToShow
72    * the value range for the highest values to show.
73    */

74   public RangePolicyHighestValues(final Range range, final double highestValueRangeToShow) {
75     super(range);
76     this.m_highestValueRangeToShow = highestValueRangeToShow;
77   }
78
79   /**
80    * Returns the maximum of the chart always.
81    * <p>
82    *
83    * @return Returns the maximum of the chart always.
84    *
85    * @param chartMin
86    * ignored.
87    *
88    * @param chartMax
89    * returned always.
90    *
91    * @see info.monitorenter.gui.chart.IRangePolicy#getMax(double, double)
92    */

93   public double getMax(final double chartMin, final double chartMax) {
94     return chartMax;
95   }
96
97   /**
98    * Returns the maximum of the chart - interal highestValueRangeToShow or
99    * chartMin if greater.
100    * <p>
101    *
102    *
103    * @param chartMin
104    * used for return value if chartMax - highestValuesToShow is smaller
105    * than this minimum of the chart.
106    *
107    * @param chartMax
108    * upper bound to compute down to the start of the latest highest
109    * values.
110    *
111    * @return the maximum of the chart - interal highestValueRangeToShow or
112    * chartMin if greater.
113    *
114    * @see info.monitorenter.gui.chart.IRangePolicy#getMin(double, double)
115    */

116   public double getMin(final double chartMin, final double chartMax) {
117     return Math.max(chartMax - this.m_highestValueRangeToShow, chartMin);
118   }
119
120 }
121
Popular Tags