Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/jfree/EnhancedLineAndShapeRenderer.java @ 9186:eec4df8165a1
Implemented 'ShowLineLabel' for area themes.
author | gernotbelger |
---|---|
date | Thu, 28 Jun 2018 10:47:04 +0200 |
parents | 5e38e2924c07 |
children |
comparison
equal
deleted
inserted
replaced
9185:4778333ea2cd | 9186:eec4df8165a1 |
---|---|
43 * | 43 * |
44 */ | 44 */ |
45 private static final long serialVersionUID = 1L; | 45 private static final long serialVersionUID = 1L; |
46 | 46 |
47 /** Own log. */ | 47 /** Own log. */ |
48 private static final Logger log = | 48 private static final Logger log = Logger.getLogger(EnhancedLineAndShapeRenderer.class); |
49 Logger.getLogger(EnhancedLineAndShapeRenderer.class); | |
50 | 49 |
51 protected BooleanList isMinimumShapeVisible; | 50 protected BooleanList isMinimumShapeVisible; |
52 protected BooleanList isMaximumShapeVisible; | 51 protected BooleanList isMaximumShapeVisible; |
53 protected BooleanList showLineLabel; | 52 protected BooleanList showLineLabel; |
54 | 53 |
59 protected Map<Integer, Font> lineLabelFonts; | 58 protected Map<Integer, Font> lineLabelFonts; |
60 protected Map<Integer, Color> lineLabelTextColors; | 59 protected Map<Integer, Color> lineLabelTextColors; |
61 protected BooleanList showLineLabelBG; | 60 protected BooleanList showLineLabelBG; |
62 protected Map<Integer, Color> lineLabelBGColors; | 61 protected Map<Integer, Color> lineLabelBGColors; |
63 | 62 |
64 | 63 public EnhancedLineAndShapeRenderer(final boolean lines, final boolean shapes) { |
65 public EnhancedLineAndShapeRenderer(boolean lines, boolean shapes) { | |
66 super(lines, shapes); | 64 super(lines, shapes); |
67 this.isMinimumShapeVisible = new BooleanList(); | 65 this.isMinimumShapeVisible = new BooleanList(); |
68 this.isMaximumShapeVisible = new BooleanList(); | 66 this.isMaximumShapeVisible = new BooleanList(); |
69 this.showLineLabel = new BooleanList(); | 67 this.showLineLabel = new BooleanList(); |
70 this.showLineLabelBG = new BooleanList(); | 68 this.showLineLabelBG = new BooleanList(); |
71 this.seriesMinimum = new HashMap<Integer, Double>(); | 69 this.seriesMinimum = new HashMap<>(); |
72 this.seriesMaximum = new HashMap<Integer, Double>(); | 70 this.seriesMaximum = new HashMap<>(); |
73 this.seriesMinimumX = new HashMap<Integer, Double>(); | 71 this.seriesMinimumX = new HashMap<>(); |
74 this.lineLabelFonts = new HashMap<Integer, Font>(); | 72 this.lineLabelFonts = new HashMap<>(); |
75 this.lineLabelTextColors = new HashMap<Integer, Color>(); | 73 this.lineLabelTextColors = new HashMap<>(); |
76 this.lineLabelBGColors = new HashMap<Integer, Color>(); | 74 this.lineLabelBGColors = new HashMap<>(); |
77 } | 75 } |
78 | |
79 | 76 |
80 /** | 77 /** |
81 * Draw a background-box of a text to render. | 78 * Draw a background-box of a text to render. |
82 * @param g2 graphics device to use | 79 * |
83 * @param text text to draw | 80 * @param g2 |
84 * @param textX x-position for text | 81 * graphics device to use |
85 * @param textY y-position for text | 82 * @param text |
86 * @param bgColor color to fill box with. | 83 * text to draw |
87 */ | 84 * @param textX |
88 public static void drawTextBox(Graphics2D g2, | 85 * x-position for text |
89 String text, float textX, float textY, Color bgColor | 86 * @param textY |
90 ) { | 87 * y-position for text |
91 Rectangle2D hotspotBox = g2.getFontMetrics().getStringBounds(text, g2); | 88 * @param bgColor |
92 float w = (float)hotspotBox.getWidth(); | 89 * color to fill box with. |
93 float h = (float)hotspotBox.getHeight(); | 90 */ |
94 hotspotBox.setRect(textX, textY-h, w, h); | 91 public static void drawTextBox(final Graphics2D g2, final String text, final float textX, final float textY, final Color bgColor) { |
95 Color oldColor = g2.getColor(); | 92 final Rectangle2D hotspotBox = g2.getFontMetrics().getStringBounds(text, g2); |
93 final float w = (float) hotspotBox.getWidth(); | |
94 final float h = (float) hotspotBox.getHeight(); | |
95 hotspotBox.setRect(textX, textY - h, w, h); | |
96 final Color oldColor = g2.getColor(); | |
96 g2.setColor(bgColor); | 97 g2.setColor(bgColor); |
97 g2.fill(hotspotBox); | 98 g2.fill(hotspotBox); |
98 g2.setColor(oldColor); | 99 g2.setColor(oldColor); |
99 } | 100 } |
100 | 101 |
101 | |
102 /** | 102 /** |
103 * Whether or not a specific item in a series (maybe the maxima) should | 103 * Whether or not a specific item in a series (maybe the maxima) should |
104 * be rendered with shape. | 104 * be rendered with shape. |
105 */ | 105 */ |
106 public boolean getItemShapeVisible( | 106 private boolean getItemShapeVisible(final XYDataset dataset, final int series, final int item) { |
107 XYDataset dataset, | |
108 int series, | |
109 int item | |
110 ){ | |
111 if (super.getItemShapeVisible(series, item)) { | 107 if (super.getItemShapeVisible(series, item)) { |
112 return true; | 108 return true; |
113 } | 109 } |
114 | 110 |
115 if (isMinimumShapeVisible(series) | 111 if (isMinimumShapeVisible(series) && isMinimum(dataset, series, item)) { |
116 && isMinimum(dataset, series, item) | |
117 ) { | |
118 return true; | 112 return true; |
119 } | 113 } |
120 | 114 |
121 if (isMaximumShapeVisible(series) | 115 if (isMaximumShapeVisible(series) && isMaximum(dataset, series, item)) { |
122 && isMaximum(dataset, series, item) | |
123 ) { | |
124 return true; | 116 return true; |
125 } | 117 } |
126 | 118 |
127 return false; | 119 return false; |
128 } | 120 } |
129 | 121 |
130 | |
131 /** | 122 /** |
132 * Rectangle used to draw maximums shape. | 123 * Rectangle used to draw maximums shape. |
133 */ | 124 */ |
134 public Shape getMaximumShape(int series, int column) { | 125 private Shape getMaximumShape(final int series, final int column) { |
135 return new Rectangle2D.Double(-5d, -5d, 10d, 10d); | 126 return new Rectangle2D.Double(-5d, -5d, 10d, 10d); |
136 } | 127 } |
137 | 128 |
138 | |
139 /** | 129 /** |
140 * Rectangle used to draw minimums shape. | 130 * Rectangle used to draw minimums shape. |
141 */ | 131 */ |
142 public Shape getMinimumShape(int series, int column) { | 132 private Shape getMinimumShape(final int series, final int column) { |
143 return new Rectangle2D.Double(-5d, -5d, 10d, 10d); | 133 return new Rectangle2D.Double(-5d, -5d, 10d, 10d); |
144 } | 134 } |
145 | 135 |
146 | |
147 /** Get fill paint for the maximum indicators. */ | 136 /** Get fill paint for the maximum indicators. */ |
148 public Paint getMaximumFillPaint(int series, int column) { | 137 private Paint getMaximumFillPaint(final int series, final int column) { |
149 Paint p = getItemPaint(series, column); | 138 final Paint p = getItemPaint(series, column); |
150 | 139 |
151 if (p instanceof Color) { | 140 if (p instanceof Color) { |
152 Color c = (Color) p; | 141 final Color c = (Color) p; |
153 Color b = c; | 142 Color b = c; |
154 | 143 |
155 for (int i = 0; i < 2; i++) { | 144 for (int i = 0; i < 2; i++) { |
156 b = b.darker(); | 145 b = b.darker(); |
157 } | 146 } |
161 | 150 |
162 log.warn("Item paint is no instance of Color!"); | 151 log.warn("Item paint is no instance of Color!"); |
163 return p; | 152 return p; |
164 } | 153 } |
165 | 154 |
166 | |
167 /** Get fill paint for the minimum indicators. */ | 155 /** Get fill paint for the minimum indicators. */ |
168 public Paint getMinimumFillPaint(int series, int column) { | 156 private Paint getMinimumFillPaint(final int series, final int column) { |
169 Paint p = getItemPaint(series, column); | 157 final Paint p = getItemPaint(series, column); |
170 | 158 |
171 if (p instanceof Color) { | 159 if (p instanceof Color) { |
172 Color c = (Color) p; | 160 final Color c = (Color) p; |
173 Color b = c; | 161 Color b = c; |
174 | 162 |
175 for (int i = 0; i < 2; i++) { | 163 for (int i = 0; i < 2; i++) { |
176 b = b.darker(); | 164 b = b.darker(); |
177 } | 165 } |
180 } | 168 } |
181 | 169 |
182 log.warn("Item paint is no instance of Color!"); | 170 log.warn("Item paint is no instance of Color!"); |
183 return p; | 171 return p; |
184 } | 172 } |
185 | |
186 | 173 |
187 /** | 174 /** |
188 * Overrides XYLineAndShapeRenderer.drawSecondaryPass() to call an adapted | 175 * Overrides XYLineAndShapeRenderer.drawSecondaryPass() to call an adapted |
189 * method getItemShapeVisible() which now takes an XYDataset. So, 99% of | 176 * method getItemShapeVisible() which now takes an XYDataset. So, 99% of |
190 * code equal the code in XYLineAndShapeRenderer. | 177 * code equal the code in XYLineAndShapeRenderer. |
191 */ | 178 */ |
192 @Override | 179 @Override |
193 protected void drawSecondaryPass( | 180 protected void drawSecondaryPass(final Graphics2D g2, final XYPlot plot, final XYDataset dataset, final int pass, final int series, final int item, |
194 Graphics2D g2, | 181 final ValueAxis domainAxis, final Rectangle2D dataArea, final ValueAxis rangeAxis, final CrosshairState crosshairState, |
195 XYPlot plot, | 182 final EntityCollection entities) { |
196 XYDataset dataset, | |
197 int pass, | |
198 int series, | |
199 int item, | |
200 ValueAxis domainAxis, | |
201 Rectangle2D dataArea, | |
202 ValueAxis rangeAxis, | |
203 CrosshairState crosshairState, | |
204 EntityCollection entities | |
205 ) { | |
206 Shape entityArea = null; | 183 Shape entityArea = null; |
207 | 184 |
208 // get the data point... | 185 // get the data point... |
209 double x1 = dataset.getXValue(series, item); | 186 final double x1 = dataset.getXValue(series, item); |
210 double y1 = dataset.getYValue(series, item); | 187 final double y1 = dataset.getYValue(series, item); |
211 if (Double.isNaN(y1) || Double.isNaN(x1)) { | 188 if (Double.isNaN(y1) || Double.isNaN(x1)) { |
212 return; | 189 return; |
213 } | 190 } |
214 | 191 |
215 PlotOrientation orientation = plot.getOrientation(); | 192 final PlotOrientation orientation = plot.getOrientation(); |
216 RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); | 193 final RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); |
217 RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); | 194 final RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); |
218 double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); | 195 final double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); |
219 double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); | 196 final double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); |
220 | 197 |
221 if (getItemShapeVisible(dataset, series, item)) { | 198 if (getItemShapeVisible(dataset, series, item)) { |
222 Shape shape = null; | 199 Shape shape = null; |
223 | 200 |
224 // OPTIMIZE: instead of calculating minimum and maximum for every | 201 // OPTIMIZE: instead of calculating minimum and maximum for every |
225 // point, calculate it just once (assume that dataset | 202 // point, calculate it just once (assume that dataset |
226 // content does not change during rendering). | 203 // content does not change during rendering). |
227 // NOTE: Above OPTIMIZE might already be fulfilled to | 204 // NOTE: Above OPTIMIZE might already be fulfilled to |
228 // most extend. | 205 // most extend. |
229 boolean isMinimum = isMinimumShapeVisible(series) | 206 final boolean isMinimum = isMinimumShapeVisible(series) && isMinimum(dataset, series, item); |
230 && isMinimum(dataset, series, item); | 207 |
231 | 208 final boolean isMaximum = isMaximumShapeVisible(series) && isMaximum(dataset, series, item); |
232 boolean isMaximum = isMaximumShapeVisible(series) | |
233 && isMaximum(dataset, series, item); | |
234 | 209 |
235 if (isMinimum) { | 210 if (isMinimum) { |
236 log.debug("Create a Minimum shape."); | 211 log.debug("Create a Minimum shape."); |
237 shape = getMinimumShape(series, item); | 212 shape = getMinimumShape(series, item); |
238 } | 213 } else if (isMaximum) { |
239 else if (isMaximum) { | |
240 log.debug("Create a Maximum shape."); | 214 log.debug("Create a Maximum shape."); |
241 shape = getMaximumShape(series, item); | 215 shape = getMaximumShape(series, item); |
242 } | 216 } else { |
243 else { | |
244 shape = getItemShape(series, item); | 217 shape = getItemShape(series, item); |
245 } | 218 } |
246 | 219 |
247 if (orientation == PlotOrientation.HORIZONTAL) { | 220 if (orientation == PlotOrientation.HORIZONTAL) { |
248 shape = ShapeUtilities.createTranslatedShape(shape, transY1, | 221 shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); |
249 transX1); | 222 } else if (orientation == PlotOrientation.VERTICAL) { |
250 } | 223 shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); |
251 else if (orientation == PlotOrientation.VERTICAL) { | |
252 shape = ShapeUtilities.createTranslatedShape(shape, transX1, | |
253 transY1); | |
254 } | 224 } |
255 entityArea = shape; | 225 entityArea = shape; |
256 if (shape.intersects(dataArea)) { | 226 if (shape.intersects(dataArea)) { |
257 if (getItemShapeFilled(series, item)) { | 227 if (getItemShapeFilled(series, item)) { |
258 if (getUseFillPaint()) { | 228 if (getUseFillPaint()) { |
259 g2.setPaint(getItemFillPaint(series, item)); | 229 g2.setPaint(getItemFillPaint(series, item)); |
260 } | 230 } else { |
261 else { | |
262 g2.setPaint(getItemPaint(series, item)); | 231 g2.setPaint(getItemPaint(series, item)); |
263 } | 232 } |
264 g2.fill(shape); | 233 g2.fill(shape); |
265 } | 234 } |
266 if (getDrawOutlines()) { | 235 if (getDrawOutlines()) { |
267 if (getUseOutlinePaint()) { | 236 if (getUseOutlinePaint()) { |
268 g2.setPaint(getItemOutlinePaint(series, item)); | 237 g2.setPaint(getItemOutlinePaint(series, item)); |
269 } | 238 } else { |
270 else { | |
271 g2.setPaint(getItemPaint(series, item)); | 239 g2.setPaint(getItemPaint(series, item)); |
272 } | 240 } |
273 g2.setStroke(getItemOutlineStroke(series, item)); | 241 g2.setStroke(getItemOutlineStroke(series, item)); |
274 g2.draw(shape); | 242 g2.draw(shape); |
275 } | 243 } |
278 g2.setPaint(getMinimumFillPaint(series, item)); | 246 g2.setPaint(getMinimumFillPaint(series, item)); |
279 g2.fill(shape); | 247 g2.fill(shape); |
280 g2.setPaint(getItemOutlinePaint(series, item)); | 248 g2.setPaint(getItemOutlinePaint(series, item)); |
281 g2.setStroke(getItemOutlineStroke(series, item)); | 249 g2.setStroke(getItemOutlineStroke(series, item)); |
282 g2.draw(shape); | 250 g2.draw(shape); |
283 } | 251 } else if (isMaximum) { |
284 else if (isMaximum) { | |
285 g2.setPaint(getMaximumFillPaint(series, item)); | 252 g2.setPaint(getMaximumFillPaint(series, item)); |
286 g2.fill(shape); | 253 g2.fill(shape); |
287 g2.setPaint(getItemOutlinePaint(series, item)); | 254 g2.setPaint(getItemOutlinePaint(series, item)); |
288 g2.setStroke(getItemOutlineStroke(series, item)); | 255 g2.setStroke(getItemOutlineStroke(series, item)); |
289 g2.draw(shape); | 256 g2.draw(shape); |
297 xx = transY1; | 264 xx = transY1; |
298 yy = transX1; | 265 yy = transX1; |
299 } | 266 } |
300 | 267 |
301 // Draw the item label if there is one... | 268 // Draw the item label if there is one... |
302 if (isItemLabelVisible(series, item)) { | 269 if (isItemLabelVisible(series, item)) |
303 drawItemLabel(g2, orientation, dataset, series, item, xx, yy, | 270 drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0)); |
304 (y1 < 0.0)); | |
305 } | |
306 | 271 |
307 // Draw label of line. | 272 // Draw label of line. |
308 if (dataset instanceof XYSeriesCollection | 273 if (dataset instanceof XYSeriesCollection && isShowLineLabel(series) && isMinimumX(dataset, series, item)) { |
309 && isShowLineLabel(series) | 274 final XYSeries xYSeries = ((XYSeriesCollection) dataset).getSeries(series); |
310 && isMinimumX (dataset, series, item) | 275 final String waterlevelLabel = (xYSeries instanceof HasLabel) ? ((HasLabel) xYSeries).getLabel() : xYSeries.getKey().toString(); |
311 ) { | |
312 XYSeries xYSeries = ((XYSeriesCollection)dataset) | |
313 .getSeries(series); | |
314 String waterlevelLabel = (xYSeries instanceof HasLabel) | |
315 ? ((HasLabel)xYSeries).getLabel() | |
316 : xYSeries.getKey().toString(); | |
317 // TODO Force water of some German rivers to flow | 276 // TODO Force water of some German rivers to flow |
318 // direction mountains. | 277 // direction mountains. |
319 | 278 |
320 Font oldFont = g2.getFont(); | 279 final Font labelFont = this.getLineLabelFont(series); |
321 | 280 final Color labelColor = this.getLineLabelTextColor(series); |
322 Color oldColor = g2.getColor(); | 281 final boolean showBG = isShowLineLabelBG(series); |
323 g2.setFont(this.getLineLabelFont(series)); | 282 final Color bgColor = getLineLabelBGColor(series); |
324 g2.setColor(this.getLineLabelTextColor(series)); | 283 |
325 g2.setBackground(Color.black); | 284 drawLineLabel(g2, dataArea, entities, xx, yy, labelFont, labelColor, showBG, bgColor, waterlevelLabel); |
326 | 285 } |
327 // Try to always display label if the data is visible. | 286 |
328 if (!isPointInRect(dataArea, xx, yy)) { | 287 final int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); |
329 // Move into the data area. | 288 final int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); |
330 xx = Math.max(xx, dataArea.getMinX()); | 289 updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation); |
331 xx = Math.min(xx, dataArea.getMaxX()); | |
332 yy = Math.max(yy, dataArea.getMinY()); | |
333 yy = Math.min(yy, dataArea.getMaxY()); | |
334 } | |
335 | |
336 // Move to right until no collisions exist anymore | |
337 Shape hotspot = TextUtilities.calculateRotatedStringBounds( | |
338 waterlevelLabel, g2, (float)xx, (float)yy-3f, | |
339 TextAnchor.CENTER_LEFT, | |
340 0f, TextAnchor.CENTER_LEFT); | |
341 while (JFreeUtil.collides(hotspot, entities, | |
342 CollisionFreeLineLabelEntity.class)) { | |
343 xx += 5f; | |
344 hotspot = TextUtilities.calculateRotatedStringBounds( | |
345 waterlevelLabel, | |
346 g2, | |
347 (float)xx, | |
348 (float)yy-3f, | |
349 TextAnchor.CENTER_LEFT, | |
350 0f, | |
351 TextAnchor.CENTER_LEFT); | |
352 } | |
353 | |
354 // Register to avoid collissions. | |
355 entities.add(new CollisionFreeLineLabelEntity(hotspot, | |
356 1, "", "")); | |
357 | |
358 // Fill background. | |
359 if (isShowLineLabelBG(series)) { | |
360 drawTextBox(g2, waterlevelLabel, (float)xx, (float)yy-3f, | |
361 getLineLabelBGColor(series)); | |
362 } | |
363 | |
364 g2.drawString(waterlevelLabel, (float)xx, (float)yy-3f); | |
365 | |
366 g2.setFont(oldFont); | |
367 g2.setColor(oldColor); | |
368 } | |
369 | |
370 int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); | |
371 int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); | |
372 updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, | |
373 rangeAxisIndex, transX1, transY1, orientation); | |
374 | 290 |
375 // Add an entity for the item, but only if it falls within the data | 291 // Add an entity for the item, but only if it falls within the data |
376 // area... | 292 // area... |
377 if (entities != null && isPointInRect(dataArea, xx, yy)) { | 293 if (entities != null && isPointInRect(dataArea, xx, yy)) { |
378 addEntity(entities, entityArea, dataset, series, item, xx, yy); | 294 addEntity(entities, entityArea, dataset, series, item, xx, yy); |
379 } | 295 } |
380 } | 296 } |
381 | 297 |
298 public static void drawLineLabel(final Graphics2D g2, final Rectangle2D dataArea, final EntityCollection entities, final double labelX, final double labelY, | |
299 final Font font, | |
300 final Color fgColor, | |
301 final boolean showBG, final Color bgColor, final String label) { | |
302 | |
303 final Font oldFont = g2.getFont(); | |
304 final Color oldColor = g2.getColor(); | |
305 | |
306 g2.setFont(font); | |
307 g2.setColor(fgColor); | |
308 g2.setBackground(Color.black); | |
309 | |
310 // Try to always display label if the data is visible. | |
311 double posX = labelX; | |
312 double posY = labelY; | |
313 if (!isPointInRect(dataArea, posX, posY)) { | |
314 // Move into the data area. | |
315 posX = Math.max(posX, dataArea.getMinX()); | |
316 posX = Math.min(posX, dataArea.getMaxX()); | |
317 posY = Math.max(posY, dataArea.getMinY()); | |
318 posY = Math.min(posY, dataArea.getMaxY()); | |
319 } | |
320 | |
321 // Move to right until no collisions exist anymore | |
322 Shape hotspot = TextUtilities.calculateRotatedStringBounds(label, g2, (float) posX, (float) posY - 3f, TextAnchor.CENTER_LEFT, 0f, | |
323 TextAnchor.CENTER_LEFT); | |
324 while (JFreeUtil.collides(hotspot, entities, CollisionFreeLineLabelEntity.class)) { | |
325 posX += 5f; | |
326 hotspot = TextUtilities.calculateRotatedStringBounds(label, g2, (float) posX, (float) posY - 3f, TextAnchor.CENTER_LEFT, 0f, | |
327 TextAnchor.CENTER_LEFT); | |
328 } | |
329 | |
330 // Register to avoid collissions. | |
331 entities.add(new CollisionFreeLineLabelEntity(hotspot, 1, "", "")); | |
332 | |
333 // Fill background. | |
334 if (showBG) | |
335 drawTextBox(g2, label, (float) posX, (float) posY - 3f, bgColor); | |
336 | |
337 g2.drawString(label, (float) posX, (float) posY - 3f); | |
338 | |
339 g2.setFont(oldFont); | |
340 g2.setColor(oldColor); | |
341 } | |
382 | 342 |
383 /** | 343 /** |
384 * Sets whether or not the minimum should be rendered with shape. | 344 * Sets whether or not the minimum should be rendered with shape. |
385 */ | 345 */ |
386 public void setIsMinimumShapeVisisble(int series, boolean isVisible) { | 346 public void setIsMinimumShapeVisisble(final int series, final boolean isVisible) { |
387 this.isMinimumShapeVisible.setBoolean(series, isVisible); | 347 this.isMinimumShapeVisible.setBoolean(series, isVisible); |
388 } | 348 } |
389 | 349 |
390 | |
391 /** | 350 /** |
392 * Whether or not the minimum should be rendered with shape. | 351 * Whether or not the minimum should be rendered with shape. |
393 */ | 352 */ |
394 public boolean isMinimumShapeVisible(int series) { | 353 private boolean isMinimumShapeVisible(final int series) { |
395 if (this.isMinimumShapeVisible.size() <= series) { | 354 if (this.isMinimumShapeVisible.size() <= series) { |
396 return false; | 355 return false; |
397 } | 356 } |
398 | 357 |
399 return isMinimumShapeVisible.getBoolean(series); | 358 return this.isMinimumShapeVisible.getBoolean(series); |
400 } | 359 } |
401 | |
402 | 360 |
403 /** | 361 /** |
404 * Sets whether or not the maximum should be rendered with shape. | 362 * Sets whether or not the maximum should be rendered with shape. |
405 */ | 363 */ |
406 public void setIsMaximumShapeVisible(int series, boolean isVisible) { | 364 public void setIsMaximumShapeVisible(final int series, final boolean isVisible) { |
407 this.isMaximumShapeVisible.setBoolean(series, isVisible); | 365 this.isMaximumShapeVisible.setBoolean(series, isVisible); |
408 } | 366 } |
409 | 367 |
410 | |
411 /** | 368 /** |
412 * Whether or not the maximum should be rendered with shape. | 369 * Whether or not the maximum should be rendered with shape. |
413 */ | 370 */ |
414 public boolean isMaximumShapeVisible(int series) { | 371 private boolean isMaximumShapeVisible(final int series) { |
415 if (this.isMaximumShapeVisible.size() <= series) { | 372 if (this.isMaximumShapeVisible.size() <= series) { |
416 return false; | 373 return false; |
417 } | 374 } |
418 | 375 |
419 return isMaximumShapeVisible.getBoolean(series); | 376 return this.isMaximumShapeVisible.getBoolean(series); |
420 } | 377 } |
421 | 378 |
422 /** Whether or not a label should be shown for series. */ | 379 /** Whether or not a label should be shown for series. */ |
423 public boolean isShowLineLabel(int series) { | 380 private boolean isShowLineLabel(final int series) { |
424 if (this.showLineLabel.size() <= series) { | 381 if (this.showLineLabel.size() <= series) { |
425 return false; | 382 return false; |
426 } | 383 } |
427 | 384 |
428 return showLineLabel.getBoolean(series); | 385 return this.showLineLabel.getBoolean(series); |
429 } | 386 } |
430 | |
431 | 387 |
432 /** Sets whether or not a label should be shown for series. */ | 388 /** Sets whether or not a label should be shown for series. */ |
433 public void setShowLineLabel(boolean showLineLabel, int series) { | 389 public void setShowLineLabel(final boolean showLineLabel, final int series) { |
434 this.showLineLabel.setBoolean(series, showLineLabel); | 390 this.showLineLabel.setBoolean(series, showLineLabel); |
435 } | 391 } |
436 | 392 |
437 | |
438 /** Whether or not a label should be shown for series. */ | 393 /** Whether or not a label should be shown for series. */ |
439 public boolean isShowLineLabelBG(int series) { | 394 private boolean isShowLineLabelBG(final int series) { |
440 if (this.showLineLabelBG.size() <= series) { | 395 if (this.showLineLabelBG.size() <= series) { |
441 return false; | 396 return false; |
442 } | 397 } |
443 | 398 |
444 return showLineLabelBG.getBoolean(series); | 399 return this.showLineLabelBG.getBoolean(series); |
445 } | 400 } |
446 | 401 |
447 | 402 public void setShowLineLabelBG(final int series, final boolean doShow) { |
448 public void setShowLineLabelBG(int series, boolean doShow) { | |
449 this.showLineLabelBG.setBoolean(series, doShow); | 403 this.showLineLabelBG.setBoolean(series, doShow); |
450 } | 404 } |
451 | 405 |
452 public Color getLineLabelBGColor(int series) { | 406 private Color getLineLabelBGColor(final int series) { |
453 if (this.lineLabelBGColors.size() <= series) { | 407 if (this.lineLabelBGColors.size() <= series) { |
454 return null; | 408 return null; |
455 } | 409 } |
456 | 410 |
457 return this.lineLabelBGColors.get(series); | 411 return this.lineLabelBGColors.get(series); |
458 } | 412 } |
459 | 413 |
460 public void setLineLabelBGColor(int series, Color color) { | 414 public void setLineLabelBGColor(final int series, final Color color) { |
461 this.lineLabelBGColors.put(series, color); | 415 this.lineLabelBGColors.put(series, color); |
462 } | 416 } |
463 | 417 |
464 public Color getLineLabelTextColor(int series) { | 418 private Color getLineLabelTextColor(final int series) { |
465 if (this.lineLabelTextColors.size() <= series) { | 419 if (this.lineLabelTextColors.size() <= series) { |
466 return null; | 420 return null; |
467 } | 421 } |
468 | 422 |
469 return this.lineLabelTextColors.get(series); | 423 return this.lineLabelTextColors.get(series); |
470 } | 424 } |
471 | 425 |
472 public void setLineLabelTextColor(int series, Color color) { | 426 public void setLineLabelTextColor(final int series, final Color color) { |
473 this.lineLabelTextColors.put(series, color); | 427 this.lineLabelTextColors.put(series, color); |
474 } | 428 } |
475 | 429 |
476 public void setLineLabelFont(Font font, int series) { | 430 public void setLineLabelFont(final Font font, final int series) { |
477 this.lineLabelFonts.put(series, font); | 431 this.lineLabelFonts.put(series, font); |
478 } | 432 } |
479 | 433 |
480 public Font getLineLabelFont(int series) { | 434 private Font getLineLabelFont(final int series) { |
481 return this.lineLabelFonts.get(series); | 435 return this.lineLabelFonts.get(series); |
482 } | 436 } |
483 | |
484 | 437 |
485 /** | 438 /** |
486 * True if the given item of given dataset has the smallest | 439 * True if the given item of given dataset has the smallest |
487 * X value within this set. | 440 * X value within this set. |
488 */ | 441 */ |
489 public boolean isMinimumX(XYDataset dataset, int series, int item) { | 442 private boolean isMinimumX(final XYDataset dataset, final int series, final int item) { |
490 return dataset.getXValue(series, item) == getMinimumX(dataset, series); | 443 return dataset.getXValue(series, item) == getMinimumX(dataset, series); |
491 } | 444 } |
492 | |
493 | 445 |
494 /** | 446 /** |
495 * Get Minimum X Value of a given series in a dataset. | 447 * Get Minimum X Value of a given series in a dataset. |
496 * The value is stored for later use if queried the first time. | 448 * The value is stored for later use if queried the first time. |
497 */ | 449 */ |
498 public double getMinimumX(XYDataset dataset, int series) { | 450 private double getMinimumX(final XYDataset dataset, final int series) { |
499 Integer key = Integer.valueOf(series); | 451 final Integer key = Integer.valueOf(series); |
500 Double old = seriesMinimumX.get(key); | 452 final Double old = this.seriesMinimumX.get(key); |
501 | 453 |
502 if (old != null) { | 454 if (old != null) { |
503 return old.doubleValue(); | 455 return old.doubleValue(); |
504 } | 456 } |
505 | 457 |
506 log.debug("Compute minimum of Series: " + series); | 458 log.debug("Compute minimum of Series: " + series); |
507 | 459 |
508 double min = Double.MAX_VALUE; | 460 double min = Double.MAX_VALUE; |
509 | 461 |
510 for (int i = 0, n = dataset.getItemCount(series); i < n; i++) { | 462 for (int i = 0, n = dataset.getItemCount(series); i < n; i++) { |
511 double tmpValue = dataset.getXValue(series, i); | 463 final double tmpValue = dataset.getXValue(series, i); |
512 | 464 |
513 if (tmpValue < min) { | 465 if (tmpValue < min) { |
514 min = tmpValue; | 466 min = tmpValue; |
515 } | 467 } |
516 } | 468 } |
517 | 469 |
518 seriesMinimumX.put(key, Double.valueOf(min)); | 470 this.seriesMinimumX.put(key, Double.valueOf(min)); |
519 | 471 |
520 return min; | 472 return min; |
521 } | 473 } |
522 | |
523 | 474 |
524 /** | 475 /** |
525 * True if the given item of given dataset has the smallest | 476 * True if the given item of given dataset has the smallest |
526 * Y value within this set. | 477 * Y value within this set. |
527 */ | 478 */ |
528 public boolean isMinimum(XYDataset dataset, int series, int item) { | 479 private boolean isMinimum(final XYDataset dataset, final int series, final int item) { |
529 return dataset.getYValue(series, item) == getMinimum(dataset, series); | 480 return dataset.getYValue(series, item) == getMinimum(dataset, series); |
530 } | 481 } |
531 | |
532 | 482 |
533 /** | 483 /** |
534 * Get Minimum Y Value of a given series in a dataset. | 484 * Get Minimum Y Value of a given series in a dataset. |
535 * The value is stored for later use if queried the first time. | 485 * The value is stored for later use if queried the first time. |
536 */ | 486 */ |
537 public double getMinimum(XYDataset dataset, int series) { | 487 private double getMinimum(final XYDataset dataset, final int series) { |
538 Integer key = Integer.valueOf(series); | 488 final Integer key = Integer.valueOf(series); |
539 Double old = seriesMinimum.get(key); | 489 final Double old = this.seriesMinimum.get(key); |
540 | 490 |
541 if (old != null) { | 491 if (old != null) { |
542 return old.doubleValue(); | 492 return old.doubleValue(); |
543 } | 493 } |
544 | 494 |
545 log.debug("Compute minimum of Series: " + series); | 495 log.debug("Compute minimum of Series: " + series); |
546 | 496 |
547 double min = Double.MAX_VALUE; | 497 double min = Double.MAX_VALUE; |
548 | 498 |
549 for (int i = 0, n = dataset.getItemCount(series); i < n; i++) { | 499 for (int i = 0, n = dataset.getItemCount(series); i < n; i++) { |
550 double tmpValue = dataset.getYValue(series, i); | 500 final double tmpValue = dataset.getYValue(series, i); |
551 | 501 |
552 if (tmpValue < min) { | 502 if (tmpValue < min) { |
553 min = tmpValue; | 503 min = tmpValue; |
554 } | 504 } |
555 } | 505 } |
556 | 506 |
557 seriesMinimum.put(key, Double.valueOf(min)); | 507 this.seriesMinimum.put(key, Double.valueOf(min)); |
558 | 508 |
559 return min; | 509 return min; |
560 } | 510 } |
561 | |
562 | 511 |
563 /** | 512 /** |
564 * True if the given item of given dataset has the biggest | 513 * True if the given item of given dataset has the biggest |
565 * Y value within this set. | 514 * Y value within this set. |
566 */ | 515 */ |
567 public boolean isMaximum(XYDataset dataset, int series, int item) { | 516 private boolean isMaximum(final XYDataset dataset, final int series, final int item) { |
568 return dataset.getYValue(series, item) == getMaximum(dataset, series); | 517 return dataset.getYValue(series, item) == getMaximum(dataset, series); |
569 } | 518 } |
570 | |
571 | 519 |
572 /** | 520 /** |
573 * Get maximum Y Value of a given series in a dataset. | 521 * Get maximum Y Value of a given series in a dataset. |
574 * The value is stored for later use if queried the first time. | 522 * The value is stored for later use if queried the first time. |
575 */ | 523 */ |
576 public double getMaximum(XYDataset dataset, int series) { | 524 private double getMaximum(final XYDataset dataset, final int series) { |
577 Integer key = Integer.valueOf(series); | 525 final Integer key = Integer.valueOf(series); |
578 Double old = seriesMaximum.get(key); | 526 final Double old = this.seriesMaximum.get(key); |
579 | 527 |
580 if (old != null) { | 528 if (old != null) { |
581 return old.doubleValue(); | 529 return old.doubleValue(); |
582 } | 530 } |
583 | 531 |
584 log.debug("Compute maximum of Series: " + series); | 532 log.debug("Compute maximum of Series: " + series); |
585 | 533 |
586 double max = -Double.MAX_VALUE; | 534 double max = -Double.MAX_VALUE; |
587 | 535 |
588 for (int i = 0, n = dataset.getItemCount(series); i < n; i++) { | 536 for (int i = 0, n = dataset.getItemCount(series); i < n; i++) { |
589 double tmpValue = dataset.getYValue(series, i); | 537 final double tmpValue = dataset.getYValue(series, i); |
590 | 538 |
591 if (tmpValue > max) { | 539 if (tmpValue > max) { |
592 max = tmpValue; | 540 max = tmpValue; |
593 } | 541 } |
594 } | 542 } |
595 | 543 |
596 seriesMaximum.put(key, Double.valueOf(max)); | 544 this.seriesMaximum.put(key, Double.valueOf(max)); |
597 | 545 |
598 return max; | 546 return max; |
599 } | 547 } |
600 } | 548 } |
601 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |