Debian Codegraph @

src/dr/app/gui/chart/JChart.java

raw symbols SCIP
1 /*
2 * JChart.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.gui.chart;
27
28 import javax.swing.*;
29 import java.awt.*;
30 import java.awt.event.MouseAdapter;
31 import java.awt.event.MouseEvent;
32 import java.awt.event.MouseMotionAdapter;
33 import java.awt.geom.*;
34 import java.util.ArrayList;
35 import java.util.List;
36
37 public class JChart extends JPanel {
38
39 private static final boolean DEBUG = true;
40 /**
41 *
42 */
43 private static final long serialVersionUID = -7064065852204509247L;
44 private Axis yAxis, xAxis;
45 private List<Plot> plots = new ArrayList<Plot>();
46
47 private Paint plotBackgroundPaint = Color.white;
48
49 private Stroke originStroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
50 private Paint originPaint = Color.lightGray;
51
52 private Stroke frameStroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
53 private Paint framePaint = Color.black;
54
55 private Stroke axisStroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
56 private Paint axisPaint = Color.black;
57
58 private Font labelFont = new Font("Helvetica", Font.PLAIN, 12);
59 private Paint labelPaint = Color.black;
60
61 private Rectangle2D plotBounds = null;
62
63 private Rectangle2D dragRectangle = null;
64
65 private double majorTickSize = 4;
66 private double minorTickSize = 2;
67
68 private double xTickLabelOffset;
69 private double yTickLabelOffset;
70
71 private boolean showLegend = false;
72 private int legendAlignment = SwingConstants.NORTH_EAST;
73
74 private double xScale, yScale, xOffset, yOffset;
75
76 private double aspectRatio;
77 private boolean useAspectRatio = false;
78
79 public JChart(Axis xAxis, Axis yAxis) {
80 this(null, xAxis, yAxis);
81 }
82
83 public JChart(Axis xAxis, Axis yAxis, double aspectRatio) {
84 this(null, xAxis, yAxis);
85 this.aspectRatio = aspectRatio;
86 this.useAspectRatio = true;
87 }
88
89 public JChart(Plot plot, Axis xAxis, Axis yAxis) {
90
91 setOpaque(false);
92
93 this.xAxis = xAxis;
94 this.yAxis = yAxis;
95
96 if (plot != null) {
97 addPlot(plot);
98 }
99
100 this.aspectRatio = 1.0;
101 this.useAspectRatio = false;
102
103 addMouseListener(new MListener());
104 addMouseMotionListener(new MMListener());
105
106 }
107
108 public void setXAxis(Axis xAxis) {
109 this.xAxis = xAxis;
110 for (Object plot : plots) {
111 Plot p = (Plot) plot;
112 p.setAxes(xAxis, yAxis);
113 }
114 recalibrate();
115 repaint();
116 }
117
118 public Axis getXAxis() {
119 return xAxis;
120 }
121
122 public void setYAxis(Axis yAxis) {
123 this.yAxis = yAxis;
124 for (Plot p : plots) {
125 p.setAxes(xAxis, yAxis);
126 }
127 recalibrate();
128 repaint();
129 }
130
131 public Axis getYAxis() {
132 return yAxis;
133 }
134
135 public void setFontSize(int size) {
136 labelFont = new Font("Helvetica", Font.PLAIN, size);
137 }
138
139 public void addPlot(Plot plot) {
140 plot.setAxes(xAxis, yAxis);
141 plot.setChart(this);
142 plot.setPlotNumber(plots.size());
143 plots.add(plot);
144 recalibrate();
145 repaint();
146 }
147
148 public void removePlot(Plot plot) {
149 plots.remove(plot);
150 xAxis.setRange(Double.POSITIVE_INFINITY,Double.NEGATIVE_INFINITY);
151 yAxis.setRange(Double.POSITIVE_INFINITY,Double.NEGATIVE_INFINITY);
152 for (Plot p : plots) {
153 p.setAxes(xAxis, yAxis);
154 }
155 recalibrate();
156 repaint();
157 }
158
159 public void removeAllPlots() {
160 plots.clear();
161 xAxis.setRange(Double.POSITIVE_INFINITY,Double.NEGATIVE_INFINITY);
162 yAxis.setRange(Double.POSITIVE_INFINITY,Double.NEGATIVE_INFINITY);
163 recalibrate();
164 repaint();
165 }
166
167 public List<Plot> getPlots() {
168 return plots;
169 }
170
171 public void setPlots(List<Plot> plots) {
172 this.plots = plots;
173 }
174
175 public int getPlotCount() {
176 return plots.size();
177 }
178
179 public Plot getPlot(int index) {
180 return plots.get(index);
181 }
182
183 public Rectangle2D getDragRectangle() {
184 return dragRectangle;
185 }
186
187 public void setDragRectangle(Rectangle2D dragRectangle) {
188 this.dragRectangle = dragRectangle;
189 repaint();
190 }
191
192 public void selectPoints(Rectangle2D dragRectangle, boolean addToSelection) {
193 for (Plot plot : plots) {
194 plot.selectPoints(dragRectangle, addToSelection);
195 }
196 repaint();
197 }
198
199 public void clearSelection() {
200 for (Plot plot : plots) {
201 plot.clearSelection();
202 }
203 repaint();
204 }
205
206 private void resetPlots() {
207 // xAxis.setRange(Double.POSITIVE_INFINITY,Double.NEGATIVE_INFINITY);
208 // yAxis.setRange(Double.POSITIVE_INFINITY,Double.NEGATIVE_INFINITY);
209 for (Plot p : plots) {
210 p.resetAxes();
211 }
212 }
213
214 /**
215 * Set origin style. Use a stroke of null to not draw origin
216 */
217 public void setOriginStyle(Stroke originStroke, Paint originPaint) {
218 this.originStroke = originStroke;
219 this.originPaint = originPaint;
220 }
221
222 /**
223 * Set axis style.
224 */
225 public void setAxisStyle(Stroke axisStroke, Paint axisPaint) {
226 this.axisStroke = axisStroke;
227 this.axisPaint = axisPaint;
228 }
229
230 /**
231 * Get axis stroke.
232 */
233 public Stroke getAxisStroke() {
234 return axisStroke;
235 }
236
237 /**
238 * Get axis paint.
239 */
240 public Paint getAxisPaint() {
241 return axisPaint;
242 }
243
244 /**
245 * Set frame style. Use a stroke of null to not draw frame
246 */
247 public void setFrameStyle(Stroke frameStroke, Paint framePaint) {
248 this.frameStroke = frameStroke;
249 this.framePaint = framePaint;
250 }
251
252 /**
253 * Set label style.
254 */
255 public void setLabelStyle(Font labelFont, Paint labelPaint) {
256 this.labelFont = labelFont;
257 this.labelPaint = labelPaint;
258 }
259
260 /**
261 * Get label font.
262 */
263 public Font getLabelFont() {
264 return labelFont;
265 }
266
267 /**
268 * Get label paint.
269 */
270 public Paint getLabelPaint() {
271 return labelPaint;
272 }
273
274 /**
275 * Set legend on/off.
276 */
277 public void setShowLegend(boolean showLegend) {
278 this.showLegend = showLegend;
279 repaint();
280 }
281
282 /**
283 * Set legend alignment (use SwingConstants.NORTH_EAST etc.).
284 */
285 public void setLegendAlignment(int alignment) {
286 this.legendAlignment = alignment;
287 repaint();
288 }
289
290 public Dimension getMinimumSize() {
291 return new Dimension(128, 128);
292 }
293
294 public Rectangle2D getPlotBounds() {
295 return plotBounds;
296 }
297
298 public double getMajorTickSize() {
299 return majorTickSize;
300 }
301
302 public double getMinorTickSize() {
303 return minorTickSize;
304 }
305
306 public double getXTickLabelOffset() {
307 return xTickLabelOffset;
308 }
309
310 public double getYTickLabelOffset() {
311 return yTickLabelOffset;
312 }
313
314 private boolean calibrated = true;
315 public void recalibrate() { calibrated = false; }
316 protected void calibrate(Graphics2D g2, Dimension size) {
317 resetPlots();
318 }
319 protected boolean hasContents() {
320 return plots.size() > 0;
321 }
322
323 public void paintComponent(Graphics g) {
324
325 if (!hasContents()) return;
326
327 Graphics2D g2 = (Graphics2D)g;
328 Dimension size = getSize();
329
330 // g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
331 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
332
333 try {
334
335 if (!calibrated) {
336 calibrate(g2, size);
337 calibrated = true;
338 }
339
340 g2.setFont(labelFont);
341
342 double tickLabelHeight = g2.getFontMetrics().getHeight();
343
344 xTickLabelOffset = g2.getFontMetrics().getAscent();
345 yTickLabelOffset = g2.getFontMetrics().getAscent() / 2;
346
347 double maxXTickLabelWidth = getMaxTickLabelWidth(g2, xAxis);
348 double maxYTickLabelWidth = getMaxTickLabelWidth(g2, yAxis);
349
350 double w = size.width - (majorTickSize * 1.25) - maxYTickLabelWidth - (maxXTickLabelWidth / 2);
351 double h = size.height - yTickLabelOffset - (majorTickSize * 1.25) - tickLabelHeight;
352
353 //store current transformation in case of a translate transform
354 AffineTransform orig = g2.getTransform();
355 if (useAspectRatio) {
356 double newH = w / aspectRatio;
357 if (newH > h) {
358 w = h * aspectRatio;
359 } else {
360 h = newH;
361 }
362 if (size.width > size.height) {
363 g2.translate((size.width - size.height)/2.0, 0.0);
364 }
365 }
366
367 plotBounds = new Rectangle2D.Double((majorTickSize * 1.25) + maxYTickLabelWidth, yTickLabelOffset, w, h);
368
369 xOffset = plotBounds.getX();
370 yOffset = plotBounds.getMaxY();
371 xScale = w / (xAxis.transform(xAxis.getMaxAxis()) - xAxis.transform(xAxis.getMinAxis()));
372 yScale = -h / (yAxis.transform(yAxis.getMaxAxis()) - yAxis.transform(yAxis.getMinAxis()));
373
374 g2.setPaint(plotBackgroundPaint);
375 g2.fill(plotBounds);
376 g2.setClip(plotBounds);
377
378 Stroke oldStroke = g2.getStroke();
379
380 if (originStroke != null && originPaint != null) {
381 double minX = xAxis.getMinAxis();
382 double maxX = xAxis.getMaxAxis();
383 double minY = yAxis.getMinAxis();
384 double maxY = yAxis.getMaxAxis();
385
386 g2.setPaint(originPaint);
387 g2.setStroke(originStroke);
388
389 if (minX<0.0 && maxX>0.0) {
390 Line2D line = new Line2D.Double(transformX(0.0), transformY(minY),
391 transformX(0.0), transformY(maxY));
392 g2.draw(line);
393 }
394
395 if (minY<0.0 && maxY>0.0) {
396 Line2D line = new Line2D.Double(transformX(minX), transformY(0.0),
397 transformX(maxX), transformY(0.0));
398 g2.draw(line);
399 }
400 }
401 g2.setStroke(oldStroke);
402
403 paintContents(g2);
404
405 if (showLegend) {
406 paintLegend(g2);
407 }
408
409 if (dragRectangle != null) {
410 g2.setPaint(new Color(128, 128, 128, 128));
411 g2.fill(dragRectangle);
412 }
413
414 g2.setClip(null);
415
416 paintFrame(g2);
417
418 paintAxis(g2, xAxis, true);
419 paintAxis(g2, yAxis, false);
420
421 //restore transformation in any case
422 g2.setTransform(orig);
423
424 } catch (ChartRuntimeException cre) {
425 if (DEBUG) {
426 System.err.println(cre.getStackTrace());
427 }
428 // ignore (just won't paint chart)
429 }
430
431 }
432
433 protected void paintContents(Graphics2D g2) {
434 int plotNumber = 0;
435 for (Plot plot : plots) {
436 plot.paintPlot(g2, xScale, yScale, xOffset, yOffset, plotNumber, plots.size());
437 plotNumber += 1;
438 }
439 }
440
441 protected void paintFrame(Graphics2D g2) {
442 g2.setPaint(framePaint);
443 g2.setStroke(frameStroke);
444 g2.draw(plotBounds);
445 }
446
447
448 /**
449 * Transform a chart co-ordinates into a drawing co-ordinates
450 */
451 protected double transformX(double value) {
452 return ((xAxis.transform(value) - xAxis.transform(xAxis.getMinAxis())) * xScale) + xOffset;
453 }
454
455 /**
456 * Transform a chart co-ordinates into a drawing co-ordinates
457 */
458 protected double transformY(double value) {
459 return ((yAxis.transform(value) - yAxis.transform(yAxis.getMinAxis())) * yScale) + yOffset;
460 }
461
462 /*
463 * Transform a drawing co-ordinate into a chart co-ordinate
464 * /
465 private double untransformX(double value) {
466
467 return xAxis.untransform(
468 xAxis.transform(xAxis.getMinAxis()) + ((value - xOffset) / xScale));
469 }*/
470
471 /*
472 * Transform a drawing co-ordinate into a chart co-ordinate
473 * /
474 private double untransformY(double value) {
475
476 return yAxis.untransform(
477 yAxis.transform(yAxis.getMinAxis()) + ((value - yOffset) / yScale));
478 }*/
479
480 protected void paintLegend(Graphics2D g2)
481 {
482 float width = 0;
483 int itemCount = 0;
484
485 for (int i = 0; i < getPlotCount(); i++) {
486 String name = getPlot(i).getName();
487 if (name != null) {
488 float w = (float)g2.getFontMetrics().stringWidth(name);
489 if (width < w) {
490 width = w;
491 }
492 itemCount++;
493 }
494 }
495
496 if (width == 0) return; // no plots have names so just return
497
498 width += 32;
499 float height = (float)(g2.getFontMetrics().getAscent() + 8) * itemCount;
500
501 float x, y;
502
503 if (legendAlignment == SwingConstants.NORTH_WEST ||
504 legendAlignment == SwingConstants.WEST ||
505 legendAlignment == SwingConstants.SOUTH_WEST) {
506 x = (float)(plotBounds.getX() + 8);
507 } else if (legendAlignment == SwingConstants.NORTH_EAST ||
508 legendAlignment == SwingConstants.EAST ||
509 legendAlignment == SwingConstants.SOUTH_EAST) {
510 x = (float)(plotBounds.getX() + plotBounds.getWidth() - width - 8);
511 } else { // centered
512 x = (float)(plotBounds.getX() + ((plotBounds.getWidth() - width) / 2));
513 }
514
515 if (legendAlignment == SwingConstants.NORTH_WEST ||
516 legendAlignment == SwingConstants.NORTH ||
517 legendAlignment == SwingConstants.NORTH_EAST) {
518 y = (float)(plotBounds.getY() + 8);
519 } else if (legendAlignment == SwingConstants.SOUTH_EAST ||
520 legendAlignment == SwingConstants.SOUTH ||
521 legendAlignment == SwingConstants.SOUTH_WEST) {
522 y = (float)(plotBounds.getY() + plotBounds.getHeight() - height - 8);
523 } else { // centered
524 y = (float)(plotBounds.getY() + ((plotBounds.getHeight() - height) / 2));
525 }
526
527 Rectangle2D legendBounds = new Rectangle2D.Float(x, y, width, height);
528 g2.setPaint(framePaint);
529 g2.setStroke(frameStroke);
530 g2.draw(legendBounds);
531
532 x += 8;
533
534 float iy = 8 + g2.getFontMetrics().getAscent();
535 y += g2.getFontMetrics().getAscent() + 4;
536 for (int i = 0; i < getPlotCount(); i++) {
537 Plot plot = getPlot(i);
538 String name = plot.getName();
539 if (name != null) {
540
541 g2.setPaint(plot.getLineColor());
542 g2.fill(new Rectangle2D.Float(x, y - 8, 8, 8));
543
544 g2.setPaint(framePaint);
545 g2.drawString(name, x + 16, y);
546
547 y += iy;
548 }
549 }
550
551 }
552
553 /**
554 * Get the maximum width of the labels of an axis
555 */
556 protected double getMaxTickLabelWidth(Graphics2D g2, Axis axis)
557 {
558 String label;
559 double width;
560 double maxWidth = 0;
561
562 if (axis.getLabelFirst()) { // Draw first minor tick as a major one (with a label)
563 label = axis.format(axis.getMinorTickValue(0, -1));
564 width = g2.getFontMetrics().stringWidth(label);
565 if (maxWidth < width)
566 maxWidth = width;
567 }
568 int n = axis.getMajorTickCount();
569 for (int i = 0; i < n; i++) {
570 double value = axis.getMajorTickValue(i);
571 label = axis.format(value);
572 width = g2.getFontMetrics().stringWidth(label);
573 if (maxWidth < width)
574 maxWidth = width;
575 }
576 if (axis.getLabelLast()) { // Draw first minor tick as a major one (with a label)
577 label = axis.format(axis.getMinorTickValue(0, n - 1));
578 width = g2.getFontMetrics().stringWidth(label);
579 if (maxWidth < width)
580 maxWidth = width;
581 }
582
583 return maxWidth;
584 }
585
586 protected void paintAxis(Graphics2D g2, Axis axis, boolean horizontalAxis) {
587 if (axis.getIsDiscrete()) {
588 int n1 = axis.getMajorTickCount();
589 int n2, i, j;
590
591 n2 = axis.getMinorTickCount(-1);
592
593 for (i = 0; i < n1; i++) {
594 paintMajorTick(g2, axis.getMajorTickValue(i), axis.getMajorTickLabel(i), horizontalAxis);
595 n2 = axis.getMinorTickCount(i);
596
597 if (i == (n1 - 1) && axis.getLabelLast()) { // Draw last minor tick as a major one
598
599 paintMajorTick(g2, axis.getMinorTickValue(0, i), axis.format((int) axis.getMinorTickValue(0, i)), horizontalAxis);
600
601 for (j = 1; j < n2; j++) {
602 paintMinorTick(g2, axis.getMinorTickValue(j, i), horizontalAxis);
603 }
604 } else {
605
606 for (j = 0; j < n2; j++) {
607 paintMinorTick(g2, axis.getMinorTickValue(j, i), horizontalAxis);
608 }
609 }
610 }
611 } else {
612 int n1 = axis.getMajorTickCount();
613 int n2, i, j;
614
615 n2 = axis.getMinorTickCount(-1);
616 if (axis.getLabelFirst()) { // Draw first minor tick as a major one (with a label)
617
618 paintMajorTick(g2, axis.getMinorTickValue(0, -1), horizontalAxis);
619
620 for (j = 1; j < n2; j++) {
621 paintMinorTick(g2, axis.getMinorTickValue(j, -1), horizontalAxis);
622 }
623 } else {
624
625 for (j = 0; j < n2; j++) {
626 paintMinorTick(g2, axis.getMinorTickValue(j, -1), horizontalAxis);
627 }
628 }
629
630 for (i = 0; i < n1; i++) {
631
632 paintMajorTick(g2, axis.getMajorTickValue(i), horizontalAxis);
633 n2 = axis.getMinorTickCount(i);
634
635 if (i == (n1 - 1) && axis.getLabelLast()) { // Draw last minor tick as a major one
636
637 paintMajorTick(g2, axis.getMinorTickValue(0, i), horizontalAxis);
638
639 for (j = 1; j < n2; j++) {
640 paintMinorTick(g2, axis.getMinorTickValue(j, i), horizontalAxis);
641 }
642 } else {
643
644 for (j = 0; j < n2; j++) {
645 paintMinorTick(g2, axis.getMinorTickValue(j, i), horizontalAxis);
646 }
647 }
648 }
649 }
650 }
651
652 protected String getXAxisLabel(double value) {
653 return xAxis.format(value);
654 }
655
656 protected String getYAxisLabel(double value) {
657 return yAxis.format(value);
658 }
659
660 // protected void paintMajorTick(Graphics2D g2, double value, String label, boolean horizontalAxis) {
661 // g2.setPaint(getAxisPaint());
662 // g2.setStroke(getAxisStroke());
663 //
664 // if (label == null) {
665 // label = " ";
666 // }
667 //
668 // if (horizontalAxis) {
669 // double pos = transformX(value);
670 //
671 // Line2D line = new Line2D.Double(pos, getPlotBounds().getMaxY(), pos, getPlotBounds().getMaxY() + getMajorTickSize());
672 // g2.draw(line);
673 //
674 // g2.setPaint(getLabelPaint());
675 // double width = g2.getFontMetrics().stringWidth(label);
676 //
677 // if (label == null) {
678 // label = getXAxis().format(value);
679 // }
680 // g2.drawString(label, (float) (pos - (width / 2)), (float) (getPlotBounds().getMaxY() + (getMajorTickSize() * 1.25) + getXTickLabelOffset()));
681 //
682 // } else {
683 // double pos = transformY(value);
684 //
685 // Line2D line = new Line2D.Double(getPlotBounds().getMinX(), pos, getPlotBounds().getMinX() - getMajorTickSize(), pos);
686 // g2.draw(line);
687 //
688 // g2.setPaint(getLabelPaint());
689 // double width = g2.getFontMetrics().stringWidth(label);
690 //
691 // if (label == null) {
692 // label = getYAxis().format(value);
693 // }
694 // g2.drawString(label, (float)(getPlotBounds().getMinX() - width - (getMajorTickSize() * 1.25)), (float)(pos + getYTickLabelOffset()));
695 // }
696 // }
697
698 protected void paintMajorTick(Graphics2D g2, double value, boolean horizontalAxis) {
699 paintMajorTick(g2, value, null, horizontalAxis);
700 }
701
702 protected void paintMajorTick(Graphics2D g2, double value, String label, boolean horizontalAxis)
703 {
704 g2.setPaint(axisPaint);
705 g2.setStroke(axisStroke);
706
707
708 if (horizontalAxis) {
709 if (label == null) {
710 label = getXAxisLabel(value);
711 }
712
713 if (label != null) {
714 double pos = transformX(value);
715
716 Line2D line = new Line2D.Double(pos, plotBounds.getMaxY(), pos, plotBounds.getMaxY() + majorTickSize);
717 g2.draw(line);
718
719 g2.setPaint(labelPaint);
720 double width = g2.getFontMetrics().stringWidth(label);
721 /*if (rotateHorizontal) {
722 AffineTransform orig = g2.getTransform();
723 g2.rotate(Math.toRadians(90), (float) (pos - width / 2), (float) (plotBounds.getMaxY() + (majorTickSize * 1.25) + xTickLabelOffset));
724 g2.drawString(label, (float) (pos - (width / 2)), (float) (plotBounds.getMaxY() + (majorTickSize * 1.25) + xTickLabelOffset - width / 2));
725 g2.setTransform(orig);
726 } else {
727 g2.drawString(label, (float) (pos - (width / 2)), (float) (plotBounds.getMaxY() + (majorTickSize * 1.25) + xTickLabelOffset));
728 }*/
729 g2.drawString(label, (float) (pos - (width / 2)), (float) (plotBounds.getMaxY() + (majorTickSize * 1.25) + xTickLabelOffset));
730 }
731
732 } else {
733 if (label == null) {
734 label = getYAxisLabel(value);
735 }
736
737 if (label != null) {
738 double pos = transformY(value);
739
740 Line2D line = new Line2D.Double(plotBounds.getMinX(), pos, plotBounds.getMinX() - majorTickSize, pos);
741 g2.draw(line);
742
743 g2.setPaint(labelPaint);
744 double width = g2.getFontMetrics().stringWidth(label);
745 g2.drawString(label, (float) (plotBounds.getMinX() - width - (majorTickSize * 1.25)), (float) (pos + yTickLabelOffset));
746 }
747 }
748 }
749
750 protected void paintMinorTick(Graphics2D g2, double value, boolean horizontalAxis)
751 {
752
753 g2.setPaint(axisPaint);
754 g2.setStroke(axisStroke);
755 if (horizontalAxis) {
756 double pos = transformX(value);
757
758 Line2D line = new Line2D.Double(pos, plotBounds.getMaxY(), pos, plotBounds.getMaxY() + minorTickSize);
759 g2.draw(line);
760 } else {
761 double pos = transformY(value);
762
763 Line2D line = new Line2D.Double(plotBounds.getMinX(), pos, plotBounds.getMinX() - minorTickSize, pos);
764 g2.draw(line);
765 }
766 }
767
768 // private Point2D currentPoint = null;
769
770 public class MMListener extends MouseMotionAdapter {
771
772 public void mouseMoved(MouseEvent me) {
773 // currentPoint = me.getPoint();
774 }
775
776 public void mouseDragged(MouseEvent me) {
777
778 // selectionEnd = boundedPoint(me.getPoint(), getSize());
779 // currentPoint = realPoint(selectionEnd);
780
781 // repaint(200);
782 }
783 }
784
785 public class MListener extends MouseAdapter {
786
787 Point2D start, finish;
788
789 public void mouseExited(MouseEvent me) {
790 // currentPoint = null;
791 }
792
793 public void mousePressed(MouseEvent me) {
794 }
795
796
797 public void mouseReleased(MouseEvent me) {
798 }
799
800 public void mouseClicked(MouseEvent me) {
801
802 if (plotBounds != null && plotBounds.contains(me.getPoint())) {
803 for (Plot plot : plots) {
804 plot.pointClicked(me.getPoint(), me.isShiftDown());
805 }
806
807
808 }
809 }
810 }
811 }