comparison artifacts/src/main/java/org/dive4elements/river/jfree/EnhancedLineAndShapeRenderer.java @ 8856:5e38e2924c07 3.2.x

Fix code style.
author Tom Gottfried <tom@intevation.de>
date Thu, 18 Jan 2018 20:12:01 +0100
parents e4606eae8ea5
children eec4df8165a1 0a5239a1e46e
comparison
equal deleted inserted replaced
8855:d7c005e12af0 8856:5e38e2924c07
87 */ 87 */
88 public static void drawTextBox(Graphics2D g2, 88 public static void drawTextBox(Graphics2D g2,
89 String text, float textX, float textY, Color bgColor 89 String text, float textX, float textY, Color bgColor
90 ) { 90 ) {
91 Rectangle2D hotspotBox = g2.getFontMetrics().getStringBounds(text, g2); 91 Rectangle2D hotspotBox = g2.getFontMetrics().getStringBounds(text, g2);
92 float w = (float) hotspotBox.getWidth(), h = (float) hotspotBox.getHeight(); 92 float w = (float)hotspotBox.getWidth();
93 float h = (float)hotspotBox.getHeight();
93 hotspotBox.setRect(textX, textY-h, w, h); 94 hotspotBox.setRect(textX, textY-h, w, h);
94 Color oldColor = g2.getColor(); 95 Color oldColor = g2.getColor();
95 g2.setColor(bgColor); 96 g2.setColor(bgColor);
96 g2.fill(hotspotBox); 97 g2.fill(hotspotBox);
97 g2.setColor(oldColor); 98 g2.setColor(oldColor);
100 101
101 /** 102 /**
102 * 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
103 * be rendered with shape. 104 * be rendered with shape.
104 */ 105 */
105 public boolean getItemShapeVisible(XYDataset dataset, int series, int item){ 106 public boolean getItemShapeVisible(
107 XYDataset dataset,
108 int series,
109 int item
110 ){
106 if (super.getItemShapeVisible(series, item)) { 111 if (super.getItemShapeVisible(series, item)) {
107 return true; 112 return true;
108 } 113 }
109 114
110 if (isMinimumShapeVisible(series) && isMinimum(dataset, series, item)) { 115 if (isMinimumShapeVisible(series)
116 && isMinimum(dataset, series, item)
117 ) {
111 return true; 118 return true;
112 } 119 }
113 120
114 if (isMaximumShapeVisible(series) && isMaximum(dataset, series, item)) { 121 if (isMaximumShapeVisible(series)
122 && isMaximum(dataset, series, item)
123 ) {
115 return true; 124 return true;
116 } 125 }
117 126
118 return false; 127 return false;
119 } 128 }
213 Shape shape = null; 222 Shape shape = null;
214 223
215 // OPTIMIZE: instead of calculating minimum and maximum for every 224 // OPTIMIZE: instead of calculating minimum and maximum for every
216 // point, calculate it just once (assume that dataset 225 // point, calculate it just once (assume that dataset
217 // content does not change during rendering). 226 // content does not change during rendering).
218 // NOTE: Above OPTIMIZE might already be fulfilled to most extend. 227 // NOTE: Above OPTIMIZE might already be fulfilled to
228 // most extend.
219 boolean isMinimum = isMinimumShapeVisible(series) 229 boolean isMinimum = isMinimumShapeVisible(series)
220 && isMinimum(dataset, series, item); 230 && isMinimum(dataset, series, item);
221 231
222 boolean isMaximum = isMaximumShapeVisible(series) 232 boolean isMaximum = isMaximumShapeVisible(series)
223 && isMaximum(dataset, series, item); 233 && isMaximum(dataset, series, item);
297 // Draw label of line. 307 // Draw label of line.
298 if (dataset instanceof XYSeriesCollection 308 if (dataset instanceof XYSeriesCollection
299 && isShowLineLabel(series) 309 && isShowLineLabel(series)
300 && isMinimumX (dataset, series, item) 310 && isMinimumX (dataset, series, item)
301 ) { 311 ) {
302 XYSeries xYSeries = ((XYSeriesCollection) dataset).getSeries(series); 312 XYSeries xYSeries = ((XYSeriesCollection)dataset)
313 .getSeries(series);
303 String waterlevelLabel = (xYSeries instanceof HasLabel) 314 String waterlevelLabel = (xYSeries instanceof HasLabel)
304 ? ((HasLabel)xYSeries).getLabel() 315 ? ((HasLabel)xYSeries).getLabel()
305 : xYSeries.getKey().toString(); 316 : xYSeries.getKey().toString();
306 // TODO Force water of some German rivers to flow direction mountains. 317 // TODO Force water of some German rivers to flow
318 // direction mountains.
307 319
308 Font oldFont = g2.getFont(); 320 Font oldFont = g2.getFont();
309 321
310 Color oldColor = g2.getColor(); 322 Color oldColor = g2.getColor();
311 g2.setFont(this.getLineLabelFont(series)); 323 g2.setFont(this.getLineLabelFont(series));
328 0f, TextAnchor.CENTER_LEFT); 340 0f, TextAnchor.CENTER_LEFT);
329 while (JFreeUtil.collides(hotspot, entities, 341 while (JFreeUtil.collides(hotspot, entities,
330 CollisionFreeLineLabelEntity.class)) { 342 CollisionFreeLineLabelEntity.class)) {
331 xx += 5f; 343 xx += 5f;
332 hotspot = TextUtilities.calculateRotatedStringBounds( 344 hotspot = TextUtilities.calculateRotatedStringBounds(
333 waterlevelLabel, g2, (float)xx, (float)yy-3f, TextAnchor.CENTER_LEFT, 345 waterlevelLabel,
334 0f, TextAnchor.CENTER_LEFT); 346 g2,
347 (float)xx,
348 (float)yy-3f,
349 TextAnchor.CENTER_LEFT,
350 0f,
351 TextAnchor.CENTER_LEFT);
335 } 352 }
336 353
337 // Register to avoid collissions. 354 // Register to avoid collissions.
338 entities.add(new CollisionFreeLineLabelEntity(hotspot, 355 entities.add(new CollisionFreeLineLabelEntity(hotspot,
339 1, "", "")); 356 1, "", ""));

http://dive4elements.wald.intevation.org