1:
57:
58: package ;
59:
60: import ;
61: import ;
62: import ;
63: import ;
64: import ;
65: import ;
66: import ;
67: import ;
68: import ;
69:
70: import ;
71: import ;
72: import ;
73: import ;
74: import ;
75: import ;
76: import ;
77: import ;
78: import ;
79: import ;
80: import ;
81: import ;
82: import ;
83:
84:
89: public class XYBubbleRenderer extends AbstractXYItemRenderer
90: implements XYItemRenderer,
91: Cloneable,
92: PublicCloneable,
93: Serializable {
94:
95:
96: public static final long serialVersionUID = -5221991598674249125L;
97:
98:
99: public static final int SCALE_ON_BOTH_AXES = 0;
100:
101:
102: public static final int SCALE_ON_DOMAIN_AXIS = 1;
103:
104:
105: public static final int SCALE_ON_RANGE_AXIS = 2;
106:
107:
108: private int scaleType;
109:
110:
113: public XYBubbleRenderer() {
114: this(SCALE_ON_BOTH_AXES);
115: }
116:
117:
124: public XYBubbleRenderer(int scaleType) {
125: super();
126: if (scaleType < 0 || scaleType > 2) {
127: throw new IllegalArgumentException("Invalid 'scaleType'.");
128: }
129: this.scaleType = scaleType;
130: }
131:
132:
138: public int getScaleType() {
139: return this.scaleType;
140: }
141:
142:
160: public void drawItem(Graphics2D g2, XYItemRendererState state,
161: Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot,
162: ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
163: int series, int item, CrosshairState crosshairState, int pass) {
164:
165: PlotOrientation orientation = plot.getOrientation();
166:
167:
168: double x = dataset.getXValue(series, item);
169: double y = dataset.getYValue(series, item);
170: double z = Double.NaN;
171: if (dataset instanceof XYZDataset) {
172: XYZDataset xyzData = (XYZDataset) dataset;
173: z = xyzData.getZValue(series, item);
174: }
175: if (!Double.isNaN(z)) {
176: RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
177: RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
178: double transX = domainAxis.valueToJava2D(x, dataArea,
179: domainAxisLocation);
180: double transY = rangeAxis.valueToJava2D(y, dataArea,
181: rangeAxisLocation);
182:
183: double transDomain = 0.0;
184: double transRange = 0.0;
185: double zero;
186:
187: switch(getScaleType()) {
188: case SCALE_ON_DOMAIN_AXIS:
189: zero = domainAxis.valueToJava2D(0.0, dataArea,
190: domainAxisLocation);
191: transDomain = domainAxis.valueToJava2D(z, dataArea,
192: domainAxisLocation) - zero;
193: transRange = transDomain;
194: break;
195: case SCALE_ON_RANGE_AXIS:
196: zero = rangeAxis.valueToJava2D(0.0, dataArea,
197: rangeAxisLocation);
198: transRange = zero - rangeAxis.valueToJava2D(z, dataArea,
199: rangeAxisLocation);
200: transDomain = transRange;
201: break;
202: default:
203: double zero1 = domainAxis.valueToJava2D(0.0, dataArea,
204: domainAxisLocation);
205: double zero2 = rangeAxis.valueToJava2D(0.0, dataArea,
206: rangeAxisLocation);
207: transDomain = domainAxis.valueToJava2D(z, dataArea,
208: domainAxisLocation) - zero1;
209: transRange = zero2 - rangeAxis.valueToJava2D(z, dataArea,
210: rangeAxisLocation);
211: }
212: transDomain = Math.abs(transDomain);
213: transRange = Math.abs(transRange);
214: Ellipse2D circle = null;
215: if (orientation == PlotOrientation.VERTICAL) {
216: circle = new Ellipse2D.Double(transX - transDomain / 2.0,
217: transY - transRange / 2.0, transDomain, transRange);
218: }
219: else if (orientation == PlotOrientation.HORIZONTAL) {
220: circle = new Ellipse2D.Double(transY - transRange / 2.0,
221: transX - transDomain / 2.0, transRange, transDomain);
222: }
223: g2.setPaint(getItemPaint(series, item));
224: g2.fill(circle);
225: g2.setStroke(new BasicStroke(1.0f));
226: g2.setPaint(Color.lightGray);
227: g2.draw(circle);
228:
229: if (isItemLabelVisible(series, item)) {
230: if (orientation == PlotOrientation.VERTICAL) {
231: drawItemLabel(g2, orientation, dataset, series, item,
232: transX, transY, false);
233: }
234: else if (orientation == PlotOrientation.HORIZONTAL) {
235: drawItemLabel(g2, orientation, dataset, series, item,
236: transY, transX, false);
237: }
238: }
239:
240:
241: EntityCollection entities = null;
242: if (info != null) {
243: entities = info.getOwner().getEntityCollection();
244: }
245:
246:
247: if (entities != null) {
248: String tip = null;
249: XYToolTipGenerator generator
250: = getToolTipGenerator(series, item);
251: if (generator != null) {
252: tip = generator.generateToolTip(dataset, series, item);
253: }
254: String url = null;
255: if (getURLGenerator() != null) {
256: url = getURLGenerator().generateURL(dataset, series, item);
257: }
258: XYItemEntity entity = new XYItemEntity(circle, dataset, series,
259: item, tip, url);
260: entities.add(entity);
261: }
262:
263: updateCrosshairValues(crosshairState, x, y, transX, transY,
264: orientation);
265: }
266:
267: }
268:
269:
278: public LegendItem getLegendItem(int datasetIndex, int series) {
279: LegendItem result = null;
280: XYPlot xyplot = getPlot();
281: if (xyplot != null) {
282: XYDataset dataset = xyplot.getDataset(datasetIndex);
283: if (dataset != null) {
284: if (getItemVisible(series, 0)) {
285: String label = getLegendItemLabelGenerator().generateLabel(
286: dataset, series);
287: String description = label;
288: String toolTipText = null;
289: if (getLegendItemToolTipGenerator() != null) {
290: toolTipText
291: = getLegendItemToolTipGenerator().generateLabel(
292: dataset, series);
293: }
294: String urlText = null;
295: if (getLegendItemURLGenerator() != null) {
296: urlText = getLegendItemURLGenerator().generateLabel(
297: dataset, series);
298: }
299: Shape shape = new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0);
300: Paint paint = getSeriesPaint(series);
301: Paint outlinePaint = getSeriesOutlinePaint(series);
302: Stroke outlineStroke = getSeriesOutlineStroke(series);
303: result = new LegendItem(label, description,
304: toolTipText, urlText, shape, paint,
305: outlineStroke, outlinePaint);
306: }
307: }
308:
309: }
310: return result;
311: }
312:
313:
320: public Object clone() throws CloneNotSupportedException {
321: return super.clone();
322: }
323:
324: }