Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * ChartSelector.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 java.awt.*;
29 import java.awt.event.*;
30 import java.awt.geom.Point2D;
31 import java.awt.geom.Rectangle2D;
32
33 /**
34 * @author Andrew Rambaut
35 * @version $Id: TreePaneSelector.java 822 2007-10-26 13:50:26Z rambaut $
36 */
37 public class ChartSelector implements MouseListener, MouseMotionListener {
38
39 public ChartSelector(JChart chart) {
40 this.chart = chart;
41 chart.addMouseListener(this);
42 chart.addMouseMotionListener(this);
43
44 }
45
46 public boolean isCrossHairCursor() {
47 return crossHairCursor;
48 }
49
50 public void setCrossHairCursor(boolean crossHairCursor) {
51 this.crossHairCursor = crossHairCursor;
52 }
53
54 private void setupCursor() {
55 if (crossHairCursor) {
56 chart.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
57 } else {
58 chart.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
59 }
60
61 chart.repaint();
62 }
63
64 public void mouseClicked(MouseEvent mouseEvent) {
65 // Node selectedNode = treePane.getNodeAt((Graphics2D) treePane.getGraphics(), mouseEvent.getPoint());
66 // if (!mouseEvent.isShiftDown()) {
67 // treePane.clearSelection();
68 // }
69 //
70 // SelectionMode mode = selectionMode;
71 // if (mouseEvent.isAltDown()) {
72 // if (mode == SelectionMode.NODE) {
73 // mode = SelectionMode.CLADE;
74 // } else if (mode == SelectionMode.CLADE) {
75 // mode = SelectionMode.NODE;
76 // }
77 // }
78 //
79 // treePane.addSelectedNode(selectedNode);
80
81 }
82
83 public void mousePressed(MouseEvent mouseEvent) {
84 // This is used for dragging in combination with mouseDragged
85 // in the MouseMotionListener, below.
86 dragPoint = new Point2D.Double(mouseEvent.getPoint().getX(), mouseEvent.getPoint().getY());
87 if (!mouseEvent.isShiftDown()) {
88 chart.clearSelection();
89 }
90
91 }
92
93 public void mouseReleased(MouseEvent mouseEvent) {
94 if (chart == null) {
95 return;
96 }
97
98 double x1 = Math.min(dragPoint.getX(), mouseEvent.getPoint().getX());
99 double y1 = Math.min(dragPoint.getY(), mouseEvent.getPoint().getY());
100 double x2 = Math.max(dragPoint.getX(), mouseEvent.getPoint().getX());
101 double y2 = Math.max(dragPoint.getY(), mouseEvent.getPoint().getY());
102 chart.selectPoints(new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1), mouseEvent.isShiftDown());
103
104 chart.setDragRectangle(null);
105 }
106
107 public void mouseEntered(MouseEvent mouseEvent) {
108 }
109
110 public void mouseExited(MouseEvent mouseEvent) {
111 }
112
113 public void mouseMoved(MouseEvent mouseEvent) {
114 }
115
116 public void mouseDragged(MouseEvent mouseEvent) {
117
118 if (dragPoint == null) {
119 return;
120 }
121
122 double x1 = Math.min(dragPoint.getX(), mouseEvent.getPoint().getX());
123 double y1 = Math.min(dragPoint.getY(), mouseEvent.getPoint().getY());
124 double x2 = Math.max(dragPoint.getX(), mouseEvent.getPoint().getX());
125 double y2 = Math.max(dragPoint.getY(), mouseEvent.getPoint().getY());
126 chart.setDragRectangle(new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1));
127 // chart.scrollPointToVisible(mouseEvent.getPoint());
128 }
129
130 private JChart chart;
131 private Point2D dragPoint = null;
132
133 private boolean crossHairCursor = false;
134 }