comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java @ 2071:fd95bfbb2ec2

Allow styling of outline of areas. flys-artifacts/trunk@3575 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 03 Jan 2012 13:14:42 +0000
parents 1ae17b100973
children 51b9899f819d
comparison
equal deleted inserted replaced
2070:48fd8b06bce5 2071:fd95bfbb2ec2
75 /* 75 /*
76 * For further changes within the FLYS project, refer to the ChangeLog. 76 * For further changes within the FLYS project, refer to the ChangeLog.
77 */ 77 */
78 package de.intevation.flys.jfree; 78 package de.intevation.flys.jfree;
79 79
80 import java.awt.BasicStroke;
80 import java.awt.Color; 81 import java.awt.Color;
81 import java.awt.Graphics2D; 82 import java.awt.Graphics2D;
82 import java.awt.Paint; 83 import java.awt.Paint;
83 import java.awt.Shape; 84 import java.awt.Shape;
84 import java.awt.Stroke; 85 import java.awt.Stroke;
142 private transient Paint negativePaint; 143 private transient Paint negativePaint;
143 144
144 /** Display shapes at each point? */ 145 /** Display shapes at each point? */
145 private boolean shapesVisible; 146 private boolean shapesVisible;
146 147
148 /** Display shapes at each point? */
149 protected boolean drawOutline;
150
151 /** Which stroke to draw outline with? */
152 protected Stroke outlineStroke;
153
154 /** Which paint to draw outline with? */
155 protected Paint outlinePaint;
156
147 /** The shape to display in the legend item. */ 157 /** The shape to display in the legend item. */
148 private transient Shape legendShape; 158 private transient Shape legendShape;
159
160 protected boolean drawOriginalSeries;
149 161
150 //private XYDatasetToZeroMapper mapper; 162 //private XYDatasetToZeroMapper mapper;
151 163
152 /** 164 /**
153 * This flag controls whether or not the x-coordinates (in Java2D space) 165 * This flag controls whether or not the x-coordinates (in Java2D space)
187 "Null 'negativePaint' argument."); 199 "Null 'negativePaint' argument.");
188 } 200 }
189 this.positivePaint = positivePaint; 201 this.positivePaint = positivePaint;
190 this.negativePaint = negativePaint; 202 this.negativePaint = negativePaint;
191 this.shapesVisible = shapes; 203 this.shapesVisible = shapes;
192 this.legendShape = new Rectangle2D.Double(-3.0, -3.0, 10.0, 10.0); 204 this.legendShape = new Rectangle2D.Double(-3.0, -3.0, 10.0, 10.0);
193 this.roundXCoordinates = false; 205 this.roundXCoordinates = false;
194 } 206 this.drawOutline = true;
207 this.outlineStroke = new BasicStroke(1);
208 this.outlinePaint = Color.black;
209 this.drawOriginalSeries = false;
210 }
211
212
213 /**
214 * Sets color that is used if drawOutline is true.
215 */
216 public void setOutlinePaint(Paint outlinePaint) {
217 this.outlinePaint = outlinePaint;
218 }
219
220
221 /**
222 * Gets color which is used if drawOutline is true.
223 */
224 public Paint getOutlinePaint() {
225 return this.outlinePaint;
226 }
227
228
229 /**
230 * Sets Stroke that is used if drawOutline is true.
231 */
232 public void setOutlineStroke(Stroke stroke) {
233 this.outlineStroke = stroke;
234 }
235
236
237 /**
238 * Returns Stroke that is used if drawOutline is true.
239 */
240 public Stroke getOutlineStroke() {
241 return this.outlineStroke;
242 }
243
244
245 /**
246 * Whether or not to draw the 'Shape' of the area (in contrast to
247 * shapes at data items).
248 */
249 public void setDrawOutline(boolean doDrawOutline) {
250 this.drawOutline = doDrawOutline;
251 }
252
253
254 /**
255 * Returns whether or not to draw the shape of the outline.
256 */
257 public boolean getDrawOutline() {
258 return this.drawOutline;
259 }
260
195 261
196 /** 262 /**
197 * Returns the paint used to highlight positive differences. 263 * Returns the paint used to highlight positive differences.
198 * 264 *
199 * @return The paint (never <code>null</code>). 265 * @return The paint (never <code>null</code>).
353 419
354 XYItemRendererState state = super.initialise(g2, dataArea, plot, data, 420 XYItemRendererState state = super.initialise(g2, dataArea, plot, data,
355 info); 421 info);
356 state.setProcessVisibleItemsOnly(false); 422 state.setProcessVisibleItemsOnly(false);
357 return state; 423 return state;
358
359 } 424 }
360 425
361 /** 426 /**
362 * Returns <code>2</code>, the number of passes required by the renderer. 427 * Returns <code>2</code>, the number of passes required by the renderer.
363 * The {@link XYPlot} will run through the dataset this number of times. 428 * The {@link XYPlot} will run through the dataset this number of times.
1191 double l_x1 = x_domainAxis.valueToJava2D(l_x0, x_dataArea, 1256 double l_x1 = x_domainAxis.valueToJava2D(l_x0, x_dataArea,
1192 l_domainAxisLocation); 1257 l_domainAxisLocation);
1193 double l_y1 = x_rangeAxis.valueToJava2D(l_y0, x_dataArea, 1258 double l_y1 = x_rangeAxis.valueToJava2D(l_y0, x_dataArea,
1194 l_rangeAxisLocation); 1259 l_rangeAxisLocation);
1195 1260
1261 // These are the shapes of the series items.
1196 if (getShapesVisible()) { 1262 if (getShapesVisible()) {
1197 Shape l_shape = getItemShape(x_series, x_item); 1263 Shape l_shape = getItemShape(x_series, x_item);
1198 if (l_orientation == PlotOrientation.HORIZONTAL) { 1264 if (l_orientation == PlotOrientation.HORIZONTAL) {
1199 l_shape = ShapeUtilities.createTranslatedShape(l_shape, 1265 l_shape = ShapeUtilities.createTranslatedShape(l_shape,
1200 l_y1, l_x1); 1266 l_y1, l_x1);
1204 l_x1, l_y1); 1270 l_x1, l_y1);
1205 } 1271 }
1206 if (l_shape.intersects(x_dataArea)) { 1272 if (l_shape.intersects(x_dataArea)) {
1207 x_graphics.setPaint(getItemPaint(x_series, x_item)); 1273 x_graphics.setPaint(getItemPaint(x_series, x_item));
1208 x_graphics.fill(l_shape); 1274 x_graphics.fill(l_shape);
1275 /* TODO We could draw the shapes of single items here.
1276 if (drawOutline) {
1277 x_graphics.setPaint(this.outlinePaint);
1278 x_graphics.setStroke(this.outlineStroke);
1279 x_graphics.draw(l_shape);
1280 }
1281 */
1209 } 1282 }
1210 l_entityArea = l_shape; 1283 l_entityArea = l_shape;
1211 } 1284 } // if (getShapesVisible())
1212 1285
1213 // add an entity for the item... 1286 // add an entity for the item...
1214 if (null != l_entities) { 1287 if (null != l_entities) {
1215 if (null == l_entityArea) { 1288 if (null == l_entityArea) {
1216 l_entityArea = new Rectangle2D.Double((l_x1 - 2), (l_y1 - 2), 1289 l_entityArea = new Rectangle2D.Double((l_x1 - 2), (l_y1 - 2),
1263 } 1336 }
1264 1337
1265 if ((null != l_line) && l_line.intersects(x_dataArea)) { 1338 if ((null != l_line) && l_line.intersects(x_dataArea)) {
1266 x_graphics.setPaint(getItemPaint(x_series, x_item)); 1339 x_graphics.setPaint(getItemPaint(x_series, x_item));
1267 x_graphics.setStroke(getItemStroke(x_series, x_item)); 1340 x_graphics.setStroke(getItemStroke(x_series, x_item));
1268 x_graphics.draw(l_line); 1341 if (drawOriginalSeries) {
1342 x_graphics.setPaint(this.outlinePaint);
1343 x_graphics.setStroke(this.outlineStroke);
1344 x_graphics.draw(l_line);
1345 }
1269 } 1346 }
1270 } 1347 }
1271 1348
1272 /** 1349 /**
1273 * Determines if a dataset is degenerate. A degenerate dataset is a 1350 * Determines if a dataset is degenerate. A degenerate dataset is a
1328 * @param x_yValues a linked list of the y values (expects values to be 1405 * @param x_yValues a linked list of the y values (expects values to be
1329 * of type Double). 1406 * of type Double).
1330 */ 1407 */
1331 private void createPolygon (Graphics2D x_graphics, 1408 private void createPolygon (Graphics2D x_graphics,
1332 Rectangle2D x_dataArea, 1409 Rectangle2D x_dataArea,
1333 XYPlot x_plot, 1410 XYPlot x_plot,
1334 ValueAxis x_domainAxis, 1411 ValueAxis x_domainAxis,
1335 ValueAxis x_rangeAxis, 1412 ValueAxis x_rangeAxis,
1336 boolean x_positive, 1413 boolean x_positive,
1337 LinkedList x_xValues, 1414 LinkedList x_xValues,
1338 LinkedList x_yValues) { 1415 LinkedList x_yValues) {
1339 1416
1340 PlotOrientation l_orientation = x_plot.getOrientation(); 1417 PlotOrientation l_orientation = x_plot.getOrientation();
1341 RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge(); 1418 RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge();
1342 RectangleEdge l_rangeAxisLocation = x_plot.getRangeAxisEdge(); 1419 RectangleEdge l_rangeAxisLocation = x_plot.getRangeAxisEdge();
1343 1420
1405 1482
1406 if (l_path.intersects(x_dataArea)) { 1483 if (l_path.intersects(x_dataArea)) {
1407 x_graphics.setPaint(x_positive ? getPositivePaint() 1484 x_graphics.setPaint(x_positive ? getPositivePaint()
1408 : getNegativePaint()); 1485 : getNegativePaint());
1409 x_graphics.fill(l_path); 1486 x_graphics.fill(l_path);
1487 if (drawOutline) {
1488 x_graphics.setStroke(this.outlineStroke);
1489 x_graphics.setPaint(this.outlinePaint);
1490 x_graphics.draw(l_path);
1491 }
1410 } 1492 }
1411 } 1493 }
1412 1494
1413 /** 1495 /**
1414 * Returns a default legend item for the specified series. Subclasses 1496 * Returns a default legend item for the specified series. Subclasses
1449 Shape line = getLegendLine(); 1531 Shape line = getLegendLine();
1450 // Not-filled Shape: 1532 // Not-filled Shape:
1451 //result = new LegendItem(label, description, 1533 //result = new LegendItem(label, description,
1452 // toolTipText, urlText, line, stroke, paint); 1534 // toolTipText, urlText, line, stroke, paint);
1453 1535
1536 if (drawOutline) {
1537 // TODO Include outline style in legenditem (there is a constructor for that)
1538 }
1539
1454 // Filled Shape ("Area-Style"). 1540 // Filled Shape ("Area-Style").
1455 result = new LegendItem(label, description, 1541 result = new LegendItem(label, description,
1456 toolTipText, urlText, line, paint); 1542 toolTipText, urlText, line, paint);
1457 result.setLabelFont(lookupLegendTextFont(series)); 1543 result.setLabelFont(lookupLegendTextFont(series));
1458 Paint labelPaint = lookupLegendTextPaint(series); 1544 Paint labelPaint = lookupLegendTextPaint(series);
1548 this.positivePaint = SerialUtilities.readPaint(stream); 1634 this.positivePaint = SerialUtilities.readPaint(stream);
1549 this.negativePaint = SerialUtilities.readPaint(stream); 1635 this.negativePaint = SerialUtilities.readPaint(stream);
1550 this.legendShape = SerialUtilities.readShape(stream); 1636 this.legendShape = SerialUtilities.readShape(stream);
1551 } 1637 }
1552 } 1638 }
1639 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org