15 |
15 |
import java.awt.event.MouseListener;
|
16 |
16 |
import java.awt.event.MouseMotionListener;
|
17 |
17 |
import java.awt.geom.AffineTransform;
|
18 |
|
import java.awt.geom.Line2D;
|
19 |
18 |
import java.awt.geom.Point2D;
|
20 |
19 |
import java.awt.geom.Rectangle2D;
|
21 |
20 |
import java.awt.print.PageFormat;
|
... | ... | |
25 |
24 |
import java.io.File;
|
26 |
25 |
import java.io.IOException;
|
27 |
26 |
import java.io.Serializable;
|
28 |
|
import java.util.EventListener;
|
29 |
27 |
import java.util.Iterator;
|
30 |
28 |
import java.util.ResourceBundle;
|
31 |
29 |
|
32 |
30 |
import javax.swing.JFileChooser;
|
33 |
|
import javax.swing.JMenu;
|
34 |
31 |
import javax.swing.JMenuItem;
|
35 |
32 |
import javax.swing.JOptionPane;
|
36 |
33 |
import javax.swing.JPanel;
|
... | ... | |
40 |
37 |
import javax.swing.event.EventListenerList;
|
41 |
38 |
|
42 |
39 |
import org.gvsig.remotesensing.scatterplot.gui.ManagerROIChartPanel;
|
43 |
|
import org.jfree.chart.ChartMouseEvent;
|
44 |
40 |
import org.jfree.chart.ChartMouseListener;
|
45 |
41 |
import org.jfree.chart.ChartRenderingInfo;
|
46 |
42 |
import org.jfree.chart.ChartUtilities;
|
47 |
43 |
import org.jfree.chart.JFreeChart;
|
48 |
|
import org.jfree.chart.entity.ChartEntity;
|
49 |
|
import org.jfree.chart.entity.EntityCollection;
|
50 |
44 |
import org.jfree.chart.event.ChartChangeEvent;
|
51 |
45 |
import org.jfree.chart.event.ChartChangeListener;
|
52 |
|
import org.jfree.chart.event.ChartProgressEvent;
|
53 |
|
import org.jfree.chart.event.ChartProgressListener;
|
54 |
46 |
import org.jfree.chart.plot.Plot;
|
55 |
47 |
import org.jfree.chart.plot.PlotOrientation;
|
56 |
48 |
import org.jfree.chart.plot.PlotRenderingInfo;
|
... | ... | |
62 |
54 |
|
63 |
55 |
/**
|
64 |
56 |
*
|
65 |
|
* Reescritura de la clase ChartPanel. Se a?den los elementos necesarios para poder dibujar
|
66 |
|
* rectangulos sobre el chart.
|
|
57 |
* Reescritura de la clase ChartPanel. Se reescribe para personalizar el grafico con
|
|
58 |
* opciones de dibujado de rectangulos sobre el area del gr?fico.
|
|
59 |
*
|
|
60 |
* @see CharPanel JfreeChart
|
|
61 |
*
|
67 |
62 |
*
|
68 |
63 |
* */
|
69 |
64 |
public class ScatterPlotDiagram extends JPanel implements ChartChangeListener,
|
70 |
|
ChartProgressListener, ActionListener, MouseListener,
|
|
65 |
ActionListener, MouseListener,
|
71 |
66 |
MouseMotionListener, Printable, Serializable {
|
72 |
67 |
|
73 |
|
/** For serialization. */
|
74 |
|
private static final long serialVersionUID = 6046366297214274674L;
|
75 |
|
|
76 |
|
/** Default setting for buffer usage. */
|
77 |
|
public static final boolean DEFAULT_BUFFER_USED = false;
|
78 |
68 |
|
79 |
|
/** The default panel width. */
|
|
69 |
private static final long serialVersionUID = 1L;
|
|
70 |
public static final boolean DEFAULT_BUFFER_USED = false;
|
80 |
71 |
public static final int DEFAULT_WIDTH = 680;
|
81 |
|
|
82 |
|
/** The default panel height. */
|
83 |
72 |
public static final int DEFAULT_HEIGHT = 420;
|
84 |
|
|
85 |
|
/** The default limit below which chart scaling kicks in. */
|
86 |
73 |
public static final int DEFAULT_MINIMUM_DRAW_WIDTH = 300;
|
87 |
|
|
88 |
|
/** The default limit below which chart scaling kicks in. */
|
89 |
74 |
public static final int DEFAULT_MINIMUM_DRAW_HEIGHT = 200;
|
90 |
|
|
91 |
|
/** The default limit below which chart scaling kicks in. */
|
92 |
75 |
public static final int DEFAULT_MAXIMUM_DRAW_WIDTH = 800;
|
93 |
|
|
94 |
|
/** The default limit below which chart scaling kicks in. */
|
95 |
76 |
public static final int DEFAULT_MAXIMUM_DRAW_HEIGHT = 600;
|
96 |
|
|
97 |
|
/** The minimum size required to perform a zoom on a rectangle */
|
98 |
|
public static final int DEFAULT_ZOOM_TRIGGER_DISTANCE = 10;
|
99 |
|
|
100 |
|
/** Properties action command. */
|
|
77 |
public static final int DEFAULT_ZOOM_TRIGGER_DISTANCE = 1;
|
101 |
78 |
public static final String PROPERTIES_COMMAND = "PROPERTIES";
|
102 |
|
|
103 |
|
/** Save action command. */
|
104 |
79 |
public static final String SAVE_COMMAND = "SAVE";
|
105 |
|
|
106 |
|
/** Print action command. */
|
107 |
80 |
public static final String PRINT_COMMAND = "PRINT";
|
108 |
|
|
109 |
|
/** Zoom in (both axes) action command. */
|
110 |
|
public static final String ZOOM_IN_BOTH_COMMAND = "ZOOM_IN_BOTH";
|
111 |
|
|
112 |
|
/** Zoom in (domain axis only) action command. */
|
113 |
|
public static final String ZOOM_IN_DOMAIN_COMMAND = "ZOOM_IN_DOMAIN";
|
114 |
|
|
115 |
|
/** Zoom in (range axis only) action command. */
|
116 |
|
public static final String ZOOM_IN_RANGE_COMMAND = "ZOOM_IN_RANGE";
|
117 |
|
|
118 |
|
/** Zoom out (both axes) action command. */
|
119 |
|
public static final String ZOOM_OUT_BOTH_COMMAND = "ZOOM_OUT_BOTH";
|
120 |
|
|
121 |
|
/** Zoom out (domain axis only) action command. */
|
122 |
|
public static final String ZOOM_OUT_DOMAIN_COMMAND = "ZOOM_DOMAIN_BOTH";
|
123 |
|
|
124 |
|
/** Zoom out (range axis only) action command. */
|
125 |
|
public static final String ZOOM_OUT_RANGE_COMMAND = "ZOOM_RANGE_BOTH";
|
126 |
|
|
127 |
|
/** Zoom reset (both axes) action command. */
|
128 |
|
public static final String ZOOM_RESET_BOTH_COMMAND = "ZOOM_RESET_BOTH";
|
129 |
|
|
130 |
|
/** Zoom reset (domain axis only) action command. */
|
131 |
|
public static final String ZOOM_RESET_DOMAIN_COMMAND = "ZOOM_RESET_DOMAIN";
|
132 |
|
|
133 |
|
/** Zoom reset (range axis only) action command. */
|
134 |
|
public static final String ZOOM_RESET_RANGE_COMMAND = "ZOOM_RESET_RANGE";
|
135 |
|
|
136 |
|
|
137 |
|
/** Definicion de nueva Roi **/
|
138 |
81 |
public static final String NEW_CLASS_COMMAND ="NEW_CLASS";
|
139 |
82 |
|
|
83 |
|
140 |
84 |
|
141 |
|
/** Borrado de las Rois sobre el grafico **/
|
142 |
|
public static final String CLEAR_CHART ="CLEAR_CHART";
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
/**Contador de Rois definidas para el diagrama*/
|
147 |
|
int contador= 0;
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
/** The chart that is displayed in the panel. */
|
152 |
85 |
private JFreeChart chart;
|
153 |
|
|
154 |
|
/** Storage for registered (chart) mouse listeners. */
|
155 |
86 |
private EventListenerList chartMouseListeners;
|
156 |
|
|
157 |
|
/** A flag that controls whether or not the off-screen buffer is used. */
|
158 |
87 |
private boolean useBuffer;
|
159 |
|
|
160 |
|
/** A flag that indicates that the buffer should be refreshed. */
|
161 |
88 |
private boolean refreshBuffer;
|
162 |
|
|
163 |
|
/** A buffer for the rendered chart. */
|
164 |
89 |
private Image chartBuffer;
|
165 |
|
|
166 |
|
/** The height of the chart buffer. */
|
167 |
90 |
private int chartBufferHeight;
|
168 |
|
|
169 |
|
/** The width of the chart buffer. */
|
170 |
91 |
private int chartBufferWidth;
|
171 |
|
|
172 |
|
/**
|
173 |
|
* The minimum width for drawing a chart (uses scaling for smaller widths).
|
174 |
|
*/
|
175 |
92 |
private int minimumDrawWidth;
|
176 |
|
|
177 |
|
/**
|
178 |
|
* The minimum height for drawing a chart (uses scaling for smaller
|
179 |
|
* heights).
|
180 |
|
*/
|
181 |
93 |
private int minimumDrawHeight;
|
182 |
|
|
183 |
|
/**
|
184 |
|
* The maximum width for drawing a chart (uses scaling for bigger
|
185 |
|
* widths).
|
186 |
|
*/
|
187 |
94 |
private int maximumDrawWidth;
|
188 |
|
|
189 |
|
/**
|
190 |
|
* The maximum height for drawing a chart (uses scaling for bigger
|
191 |
|
* heights).
|
192 |
|
*/
|
193 |
95 |
private int maximumDrawHeight;
|
194 |
96 |
|
195 |
|
/** The popup menu for the frame. */
|
|
97 |
|
196 |
98 |
private JPopupMenu popup;
|
197 |
|
|
198 |
|
/** The drawing info collected the last time the chart was drawn. */
|
199 |
99 |
private ChartRenderingInfo info;
|
200 |
|
|
201 |
|
/** The chart anchor point. */
|
202 |
100 |
private Point2D anchor;
|
203 |
|
|
204 |
|
/** The scale factor used to draw the chart. */
|
205 |
101 |
private double scaleX;
|
206 |
|
|
207 |
|
/** The scale factor used to draw the chart. */
|
208 |
102 |
private double scaleY;
|
209 |
|
|
210 |
|
/** The plot orientation. */
|
211 |
103 |
private PlotOrientation orientation = PlotOrientation.VERTICAL;
|
212 |
|
|
213 |
|
/** A flag that controls whether or not domain zooming is enabled. */
|
214 |
104 |
private boolean domainZoomable = false;
|
215 |
|
|
216 |
|
/** A flag that controls whether or not range zooming is enabled. */
|
217 |
105 |
private boolean rangeZoomable = false;
|
218 |
|
|
219 |
|
/**
|
220 |
|
* The zoom rectangle starting point (selected by the user with a mouse
|
221 |
|
* click). This is a point on the screen, not the chart (which may have
|
222 |
|
* been scaled up or down to fit the panel).
|
223 |
|
*/
|
224 |
106 |
private Point zoomPoint = null;
|
225 |
107 |
|
226 |
|
/** The zoom rectangle (selected by the user with the mouse). */
|
|
108 |
|
227 |
109 |
private transient Rectangle2D zoomRectangle = null;
|
228 |
|
|
229 |
|
/** Controls if the zoom rectangle is drawn as an outline or filled. */
|
230 |
110 |
private boolean fillZoomRectangle = true;
|
231 |
|
|
232 |
|
/** The minimum distance required to drag the mouse to trigger a zoom. */
|
233 |
111 |
private int zoomTriggerDistance;
|
234 |
|
|
235 |
|
/** A flag that controls whether or not horizontal tracing is enabled. */
|
236 |
|
private boolean horizontalAxisTrace = false;
|
237 |
|
|
238 |
|
/** A flag that controls whether or not vertical tracing is enabled. */
|
239 |
|
private boolean verticalAxisTrace =false;
|
240 |
|
|
241 |
|
/** A vertical trace line. */
|
242 |
|
private transient Line2D verticalTraceLine;
|
243 |
|
|
244 |
|
/** A horizontal trace line. */
|
245 |
|
private transient Line2D horizontalTraceLine;
|
246 |
|
|
247 |
|
/** Menu item for zooming in on a chart (both axes). */
|
248 |
|
private JMenuItem zoomInBothMenuItem;
|
249 |
|
|
250 |
|
/** Menu item for zooming in on a chart (domain axis). */
|
251 |
|
private JMenuItem zoomInDomainMenuItem;
|
252 |
|
|
253 |
|
/** Menu item for zooming in on a chart (range axis). */
|
254 |
|
private JMenuItem zoomInRangeMenuItem;
|
255 |
|
|
256 |
|
/** Menu item for zooming out on a chart. */
|
257 |
|
private JMenuItem zoomOutBothMenuItem;
|
258 |
|
|
259 |
|
/** Menu item for zooming out on a chart (domain axis). */
|
260 |
|
private JMenuItem zoomOutDomainMenuItem;
|
261 |
|
|
262 |
|
/** Menu item for zooming out on a chart (range axis). */
|
263 |
|
private JMenuItem zoomOutRangeMenuItem;
|
264 |
|
|
265 |
|
/** Menu item for resetting the zoom (both axes). */
|
266 |
|
private JMenuItem zoomResetBothMenuItem;
|
267 |
|
|
268 |
|
/** Menu item for resetting the zoom (domain axis only). */
|
269 |
|
private JMenuItem zoomResetDomainMenuItem;
|
270 |
|
|
271 |
|
/** Menu item for resetting the zoom (range axis only). */
|
272 |
|
private JMenuItem zoomResetRangeMenuItem;
|
273 |
|
|
274 |
|
/**
|
275 |
|
* The default directory for saving charts to file.
|
276 |
|
*
|
277 |
|
* @since 1.0.7
|
278 |
|
*/
|
279 |
112 |
private File defaultDirectoryForSaveAs;
|
280 |
113 |
|
281 |
|
/** A flag that controls whether or not file extensions are enforced. */
|
|
114 |
|
282 |
115 |
private boolean enforceFileExtensions;
|
283 |
|
|
284 |
|
/** A flag that indicates if original tooltip delays are changed. */
|
285 |
|
private boolean ownToolTipDelaysActive;
|
286 |
|
|
287 |
|
/** Original initial tooltip delay of ToolTipManager.sharedInstance(). */
|
288 |
|
private int originalToolTipInitialDelay;
|
289 |
|
|
290 |
|
/** Original reshow tooltip delay of ToolTipManager.sharedInstance(). */
|
291 |
|
private int originalToolTipReshowDelay;
|
292 |
|
|
293 |
|
/** Original dismiss tooltip delay of ToolTipManager.sharedInstance(). */
|
294 |
|
private int originalToolTipDismissDelay;
|
295 |
|
|
296 |
|
/** Own initial tooltip delay to be used in this chart panel. */
|
297 |
|
private int ownToolTipInitialDelay;
|
298 |
|
|
299 |
|
/** Own reshow tooltip delay to be used in this chart panel. */
|
300 |
|
private int ownToolTipReshowDelay;
|
301 |
|
|
302 |
|
/** Own dismiss tooltip delay to be used in this chart panel. */
|
303 |
|
private int ownToolTipDismissDelay;
|
304 |
|
|
305 |
|
/** The factor used to zoom in on an axis range. */
|
306 |
|
private double zoomInFactor = 0.5;
|
307 |
|
|
308 |
|
/** The factor used to zoom out on an axis range. */
|
309 |
|
private double zoomOutFactor = 2.0;
|
310 |
|
|
311 |
|
/**
|
312 |
|
* A flag that controls whether zoom operations are centred on the
|
313 |
|
* current anchor point, or the centre point of the relevant axis.
|
314 |
|
*
|
315 |
|
* @since 1.0.7
|
316 |
|
*/
|
317 |
116 |
private boolean zoomAroundAnchor;
|
318 |
|
|
319 |
|
/** The resourceBundle for the localization. */
|
320 |
|
protected static ResourceBundle localizationResources
|
321 |
|
= ResourceBundle.getBundle("org.jfree.chart.LocalizationBundle");
|
|
117 |
protected static ResourceBundle localizationResources = ResourceBundle.getBundle("org.jfree.chart.LocalizationBundle");
|
322 |
118 |
|
323 |
119 |
|
324 |
120 |
|
... | ... | |
404 |
200 |
this.maximumDrawHeight = maximumDrawHeight;
|
405 |
201 |
this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE;
|
406 |
202 |
|
407 |
|
// set up popup menu...
|
408 |
203 |
this.popup = null;
|
409 |
204 |
if (properties || save || print || zoom) {
|
410 |
205 |
this.popup = createPopupMenu(properties, save, print, zoom);
|
... | ... | |
419 |
214 |
this.defaultDirectoryForSaveAs = null;
|
420 |
215 |
this.enforceFileExtensions = true;
|
421 |
216 |
|
422 |
|
// initialize ChartPanel-specific tool tip delays with
|
423 |
|
// values the from ToolTipManager.sharedInstance()
|
424 |
|
ToolTipManager ttm = ToolTipManager.sharedInstance();
|
425 |
|
this.ownToolTipInitialDelay = ttm.getInitialDelay();
|
426 |
|
this.ownToolTipDismissDelay = ttm.getDismissDelay();
|
427 |
|
this.ownToolTipReshowDelay = ttm.getReshowDelay();
|
428 |
|
|
429 |
|
this.zoomAroundAnchor = false;
|
430 |
217 |
}
|
431 |
218 |
|
432 |
219 |
/**
|
... | ... | |
444 |
231 |
* @param chart the chart (<code>null</code> permitted).
|
445 |
232 |
*/
|
446 |
233 |
public void setChart(JFreeChart chart) {
|
447 |
|
|
448 |
|
// stop listening for changes to the existing chart
|
449 |
234 |
if (this.chart != null) {
|
450 |
235 |
this.chart.removeChangeListener(this);
|
451 |
|
this.chart.removeProgressListener(this);
|
452 |
236 |
}
|
453 |
|
|
454 |
|
// add the new chart
|
|
237 |
|
455 |
238 |
this.chart = chart;
|
456 |
239 |
if (chart != null) {
|
457 |
240 |
this.chart.addChangeListener(this);
|
458 |
|
this.chart.addProgressListener(this);
|
459 |
241 |
Plot plot = chart.getPlot();
|
460 |
242 |
this.domainZoomable = false;
|
461 |
243 |
this.rangeZoomable = false;
|
... | ... | |
474 |
256 |
this.refreshBuffer = true;
|
475 |
257 |
}
|
476 |
258 |
repaint();
|
477 |
|
|
478 |
259 |
}
|
479 |
260 |
|
480 |
|
/**
|
481 |
|
* Returns the minimum drawing width for charts.
|
482 |
|
* <P>
|
483 |
|
* If the width available on the panel is less than this, then the chart is
|
484 |
|
* drawn at the minimum width then scaled down to fit.
|
485 |
|
*
|
486 |
|
* @return The minimum drawing width.
|
487 |
|
*/
|
488 |
|
public int getMinimumDrawWidth() {
|
489 |
|
return this.minimumDrawWidth;
|
490 |
|
}
|
491 |
261 |
|
492 |
262 |
/**
|
493 |
|
* Sets the minimum drawing width for the chart on this panel.
|
494 |
|
* <P>
|
495 |
|
* At the time the chart is drawn on the panel, if the available width is
|
496 |
|
* less than this amount, the chart will be drawn using the minimum width
|
497 |
|
* then scaled down to fit the available space.
|
498 |
|
*
|
499 |
|
* @param width The width.
|
500 |
|
*/
|
501 |
|
public void setMinimumDrawWidth(int width) {
|
502 |
|
this.minimumDrawWidth = width;
|
503 |
|
}
|
504 |
|
|
505 |
|
/**
|
506 |
|
* Returns the maximum drawing width for charts.
|
507 |
|
* <P>
|
508 |
|
* If the width available on the panel is greater than this, then the chart
|
509 |
|
* is drawn at the maximum width then scaled up to fit.
|
510 |
|
*
|
511 |
|
* @return The maximum drawing width.
|
512 |
|
*/
|
513 |
|
public int getMaximumDrawWidth() {
|
514 |
|
return this.maximumDrawWidth;
|
515 |
|
}
|
516 |
|
|
517 |
|
/**
|
518 |
|
* Sets the maximum drawing width for the chart on this panel.
|
519 |
|
* <P>
|
520 |
|
* At the time the chart is drawn on the panel, if the available width is
|
521 |
|
* greater than this amount, the chart will be drawn using the maximum
|
522 |
|
* width then scaled up to fit the available space.
|
523 |
|
*
|
524 |
|
* @param width The width.
|
525 |
|
*/
|
526 |
|
public void setMaximumDrawWidth(int width) {
|
527 |
|
this.maximumDrawWidth = width;
|
528 |
|
}
|
529 |
|
|
530 |
|
/**
|
531 |
|
* Returns the minimum drawing height for charts.
|
532 |
|
* <P>
|
533 |
|
* If the height available on the panel is less than this, then the chart
|
534 |
|
* is drawn at the minimum height then scaled down to fit.
|
535 |
|
*
|
536 |
|
* @return The minimum drawing height.
|
537 |
|
*/
|
538 |
|
public int getMinimumDrawHeight() {
|
539 |
|
return this.minimumDrawHeight;
|
540 |
|
}
|
541 |
|
|
542 |
|
/**
|
543 |
|
* Sets the minimum drawing height for the chart on this panel.
|
544 |
|
* <P>
|
545 |
|
* At the time the chart is drawn on the panel, if the available height is
|
546 |
|
* less than this amount, the chart will be drawn using the minimum height
|
547 |
|
* then scaled down to fit the available space.
|
548 |
|
*
|
549 |
|
* @param height The height.
|
550 |
|
*/
|
551 |
|
public void setMinimumDrawHeight(int height) {
|
552 |
|
this.minimumDrawHeight = height;
|
553 |
|
}
|
554 |
|
|
555 |
|
/**
|
556 |
|
* Returns the maximum drawing height for charts.
|
557 |
|
* <P>
|
558 |
|
* If the height available on the panel is greater than this, then the
|
559 |
|
* chart is drawn at the maximum height then scaled up to fit.
|
560 |
|
*
|
561 |
|
* @return The maximum drawing height.
|
562 |
|
*/
|
563 |
|
public int getMaximumDrawHeight() {
|
564 |
|
return this.maximumDrawHeight;
|
565 |
|
}
|
566 |
|
|
567 |
|
/**
|
568 |
|
* Sets the maximum drawing height for the chart on this panel.
|
569 |
|
* <P>
|
570 |
|
* At the time the chart is drawn on the panel, if the available height is
|
571 |
|
* greater than this amount, the chart will be drawn using the maximum
|
572 |
|
* height then scaled up to fit the available space.
|
573 |
|
*
|
574 |
|
* @param height The height.
|
575 |
|
*/
|
576 |
|
public void setMaximumDrawHeight(int height) {
|
577 |
|
this.maximumDrawHeight = height;
|
578 |
|
}
|
579 |
|
|
580 |
|
/**
|
581 |
263 |
* Returns the X scale factor for the chart. This will be 1.0 if no
|
582 |
264 |
* scaling has been used.
|
583 |
265 |
*
|
... | ... | |
642 |
324 |
public ChartRenderingInfo getChartRenderingInfo() {
|
643 |
325 |
return this.info;
|
644 |
326 |
}
|
645 |
|
|
646 |
|
/**
|
647 |
|
* A convenience method that switches on mouse-based zooming.
|
648 |
|
*
|
649 |
|
* @param flag <code>true</code> enables zooming and rectangle fill on
|
650 |
|
* zoom.
|
651 |
|
*/
|
652 |
|
public void setMouseZoomable(boolean flag) {
|
653 |
|
setMouseZoomable(flag, true);
|
654 |
|
}
|
655 |
|
|
656 |
|
/**
|
657 |
|
* A convenience method that switches on mouse-based zooming.
|
658 |
|
*
|
659 |
|
* @param flag <code>true</code> if zooming enabled
|
660 |
|
* @param fillRectangle <code>true</code> if zoom rectangle is filled,
|
661 |
|
* false if rectangle is shown as outline only.
|
662 |
|
*/
|
663 |
|
public void setMouseZoomable(boolean flag, boolean fillRectangle) {
|
664 |
|
setDomainZoomable(flag);
|
665 |
|
setRangeZoomable(flag);
|
666 |
|
setFillZoomRectangle(fillRectangle);
|
667 |
|
}
|
668 |
|
|
669 |
|
/**
|
670 |
|
* Returns the flag that determines whether or not zooming is enabled for
|
671 |
|
* the domain axis.
|
672 |
|
*
|
673 |
|
* @return A boolean.
|
674 |
|
*/
|
675 |
|
public boolean isDomainZoomable() {
|
676 |
|
return this.domainZoomable;
|
677 |
|
}
|
678 |
327 |
|
679 |
328 |
/**
|
680 |
|
* Sets the flag that controls whether or not zooming is enable for the
|
681 |
|
* domain axis. A check is made to ensure that the current plot supports
|
682 |
|
* zooming for the domain values.
|
683 |
|
*
|
684 |
|
* @param flag <code>true</code> enables zooming if possible.
|
685 |
|
*/
|
686 |
|
public void setDomainZoomable(boolean flag) {
|
687 |
|
if (flag) {
|
688 |
|
Plot plot = this.chart.getPlot();
|
689 |
|
if (plot instanceof Zoomable) {
|
690 |
|
Zoomable z = (Zoomable) plot;
|
691 |
|
this.domainZoomable = flag && (z.isDomainZoomable());
|
692 |
|
}
|
693 |
|
}
|
694 |
|
else {
|
695 |
|
this.domainZoomable = false;
|
696 |
|
}
|
697 |
|
}
|
698 |
|
|
699 |
|
/**
|
700 |
|
* Returns the flag that determines whether or not zooming is enabled for
|
701 |
|
* the range axis.
|
702 |
|
*
|
703 |
|
* @return A boolean.
|
704 |
|
*/
|
705 |
|
public boolean isRangeZoomable() {
|
706 |
|
return this.rangeZoomable;
|
707 |
|
}
|
708 |
|
|
709 |
|
/**
|
710 |
|
* A flag that controls mouse-based zooming on the vertical axis.
|
711 |
|
*
|
712 |
|
* @param flag <code>true</code> enables zooming.
|
713 |
|
*/
|
714 |
|
public void setRangeZoomable(boolean flag) {
|
715 |
|
if (flag) {
|
716 |
|
Plot plot = this.chart.getPlot();
|
717 |
|
if (plot instanceof Zoomable) {
|
718 |
|
Zoomable z = (Zoomable) plot;
|
719 |
|
this.rangeZoomable = flag && (z.isRangeZoomable());
|
720 |
|
}
|
721 |
|
}
|
722 |
|
else {
|
723 |
|
this.rangeZoomable = false;
|
724 |
|
}
|
725 |
|
}
|
726 |
|
|
727 |
|
/**
|
728 |
|
* Returns the flag that controls whether or not the zoom rectangle is
|
729 |
|
* filled when drawn.
|
730 |
|
*
|
731 |
|
* @return A boolean.
|
732 |
|
*/
|
733 |
|
public boolean getFillZoomRectangle() {
|
734 |
|
return this.fillZoomRectangle;
|
735 |
|
}
|
736 |
|
|
737 |
|
/**
|
738 |
|
* A flag that controls how the zoom rectangle is drawn.
|
739 |
|
*
|
740 |
|
* @param flag <code>true</code> instructs to fill the rectangle on
|
741 |
|
* zoom, otherwise it will be outlined.
|
742 |
|
*/
|
743 |
|
public void setFillZoomRectangle(boolean flag) {
|
744 |
|
this.fillZoomRectangle = flag;
|
745 |
|
}
|
746 |
|
|
747 |
|
/**
|
748 |
|
* Returns the zoom trigger distance. This controls how far the mouse must
|
749 |
|
* move before a zoom action is triggered.
|
750 |
|
*
|
751 |
|
* @return The distance (in Java2D units).
|
752 |
|
*/
|
753 |
|
public int getZoomTriggerDistance() {
|
754 |
|
return this.zoomTriggerDistance;
|
755 |
|
}
|
756 |
|
|
757 |
|
/**
|
758 |
|
* Sets the zoom trigger distance. This controls how far the mouse must
|
759 |
|
* move before a zoom action is triggered.
|
760 |
|
*
|
761 |
|
* @param distance the distance (in Java2D units).
|
762 |
|
*/
|
763 |
|
public void setZoomTriggerDistance(int distance) {
|
764 |
|
this.zoomTriggerDistance = distance;
|
765 |
|
}
|
766 |
|
|
767 |
|
/**
|
768 |
|
* Returns the flag that controls whether or not a horizontal axis trace
|
769 |
|
* line is drawn over the plot area at the current mouse location.
|
770 |
|
*
|
771 |
|
* @return A boolean.
|
772 |
|
*/
|
773 |
|
public boolean getHorizontalAxisTrace() {
|
774 |
|
return this.horizontalAxisTrace;
|
775 |
|
}
|
776 |
|
|
777 |
|
/**
|
778 |
|
* A flag that controls trace lines on the horizontal axis.
|
779 |
|
*
|
780 |
|
* @param flag <code>true</code> enables trace lines for the mouse
|
781 |
|
* pointer on the horizontal axis.
|
782 |
|
*/
|
783 |
|
public void setHorizontalAxisTrace(boolean flag) {
|
784 |
|
this.horizontalAxisTrace = flag;
|
785 |
|
}
|
786 |
|
|
787 |
|
/**
|
788 |
|
* Returns the horizontal trace line.
|
789 |
|
*
|
790 |
|
* @return The horizontal trace line (possibly <code>null</code>).
|
791 |
|
*/
|
792 |
|
protected Line2D getHorizontalTraceLine() {
|
793 |
|
return this.horizontalTraceLine;
|
794 |
|
}
|
795 |
|
|
796 |
|
/**
|
797 |
|
* Sets the horizontal trace line.
|
798 |
|
*
|
799 |
|
* @param line the line (<code>null</code> permitted).
|
800 |
|
*/
|
801 |
|
protected void setHorizontalTraceLine(Line2D line) {
|
802 |
|
this.horizontalTraceLine = line;
|
803 |
|
}
|
804 |
|
|
805 |
|
/**
|
806 |
|
* Returns the flag that controls whether or not a vertical axis trace
|
807 |
|
* line is drawn over the plot area at the current mouse location.
|
808 |
|
*
|
809 |
|
* @return A boolean.
|
810 |
|
*/
|
811 |
|
public boolean getVerticalAxisTrace() {
|
812 |
|
return this.verticalAxisTrace;
|
813 |
|
}
|
814 |
|
|
815 |
|
/**
|
816 |
|
* A flag that controls trace lines on the vertical axis.
|
817 |
|
*
|
818 |
|
* @param flag <code>true</code> enables trace lines for the mouse
|
819 |
|
* pointer on the vertical axis.
|
820 |
|
*/
|
821 |
|
public void setVerticalAxisTrace(boolean flag) {
|
822 |
|
this.verticalAxisTrace = flag;
|
823 |
|
}
|
824 |
|
|
825 |
|
/**
|
826 |
|
* Returns the vertical trace line.
|
827 |
|
*
|
828 |
|
* @return The vertical trace line (possibly <code>null</code>).
|
829 |
|
*/
|
830 |
|
protected Line2D getVerticalTraceLine() {
|
831 |
|
return this.verticalTraceLine;
|
832 |
|
}
|
833 |
|
|
834 |
|
/**
|
835 |
|
* Sets the vertical trace line.
|
836 |
|
*
|
837 |
|
* @param line the line (<code>null</code> permitted).
|
838 |
|
*/
|
839 |
|
protected void setVerticalTraceLine(Line2D line) {
|
840 |
|
this.verticalTraceLine = line;
|
841 |
|
}
|
842 |
|
|
843 |
|
/**
|
844 |
329 |
* Returns the default directory for the "save as" option.
|
845 |
330 |
*
|
846 |
331 |
* @return The default directory (possibly <code>null</code>).
|
... | ... | |
937 |
422 |
}
|
938 |
423 |
}
|
939 |
424 |
|
|
425 |
|
940 |
426 |
/**
|
941 |
|
* Returns a string for the tooltip.
|
942 |
|
*
|
943 |
|
* @param e the mouse event.
|
944 |
|
*
|
945 |
|
* @return A tool tip or <code>null</code> if no tooltip is available.
|
946 |
|
*/
|
947 |
|
public String getToolTipText(MouseEvent e) {
|
948 |
|
|
949 |
|
String result = null;
|
950 |
|
if (this.info != null) {
|
951 |
|
EntityCollection entities = this.info.getEntityCollection();
|
952 |
|
if (entities != null) {
|
953 |
|
Insets insets = getInsets();
|
954 |
|
ChartEntity entity = entities.getEntity(
|
955 |
|
(int) ((e.getX() - insets.left) / this.scaleX),
|
956 |
|
(int) ((e.getY() - insets.top) / this.scaleY));
|
957 |
|
if (entity != null) {
|
958 |
|
result = entity.getToolTipText();
|
959 |
|
}
|
960 |
|
}
|
961 |
|
}
|
962 |
|
return result;
|
963 |
|
|
964 |
|
}
|
965 |
|
|
966 |
|
/**
|
967 |
|
* Translates a Java2D point on the chart to a screen location.
|
968 |
|
*
|
969 |
|
* @param java2DPoint the Java2D point.
|
970 |
|
*
|
971 |
|
* @return The screen location.
|
972 |
|
*/
|
973 |
|
public Point translateJava2DToScreen(Point2D java2DPoint) {
|
974 |
|
Insets insets = getInsets();
|
975 |
|
int x = (int) (java2DPoint.getX() * this.scaleX + insets.left);
|
976 |
|
int y = (int) (java2DPoint.getY() * this.scaleY + insets.top);
|
977 |
|
return new Point(x, y);
|
978 |
|
}
|
979 |
|
|
980 |
|
/**
|
981 |
427 |
* Translates a panel (component) location to a Java2D point.
|
982 |
428 |
*
|
983 |
429 |
* @param screenPoint the screen location (<code>null</code> not
|
... | ... | |
1009 |
455 |
return new Rectangle2D.Double(x, y, w, h);
|
1010 |
456 |
}
|
1011 |
457 |
|
1012 |
|
/**
|
1013 |
|
* Returns the chart entity at a given point.
|
1014 |
|
* <P>
|
1015 |
|
* This method will return null if there is (a) no entity at the given
|
1016 |
|
* point, or (b) no entity collection has been generated.
|
1017 |
|
*
|
1018 |
|
* @param viewX the x-coordinate.
|
1019 |
|
* @param viewY the y-coordinate.
|
1020 |
|
*
|
1021 |
|
* @return The chart entity (possibly <code>null</code>).
|
1022 |
|
*/
|
1023 |
|
public ChartEntity getEntityForPoint(int viewX, int viewY) {
|
1024 |
458 |
|
1025 |
|
ChartEntity result = null;
|
1026 |
|
if (this.info != null) {
|
1027 |
|
Insets insets = getInsets();
|
1028 |
|
double x = (viewX - insets.left) / this.scaleX;
|
1029 |
|
double y = (viewY - insets.top) / this.scaleY;
|
1030 |
|
EntityCollection entities = this.info.getEntityCollection();
|
1031 |
|
result = entities != null ? entities.getEntity(x, y) : null;
|
1032 |
|
}
|
1033 |
|
return result;
|
1034 |
|
|
1035 |
|
}
|
1036 |
|
|
1037 |
459 |
/**
|
1038 |
|
* Returns the flag that controls whether or not the offscreen buffer
|
1039 |
|
* needs to be refreshed.
|
1040 |
|
*
|
1041 |
|
* @return A boolean.
|
1042 |
|
*/
|
1043 |
|
public boolean getRefreshBuffer() {
|
1044 |
|
return this.refreshBuffer;
|
1045 |
|
}
|
1046 |
|
|
1047 |
|
/**
|
1048 |
|
* Sets the refresh buffer flag. This flag is used to avoid unnecessary
|
1049 |
|
* redrawing of the chart when the offscreen image buffer is used.
|
1050 |
|
*
|
1051 |
|
* @param flag <code>true</code> indicates that the buffer should be
|
1052 |
|
* refreshed.
|
1053 |
|
*/
|
1054 |
|
public void setRefreshBuffer(boolean flag) {
|
1055 |
|
this.refreshBuffer = flag;
|
1056 |
|
}
|
1057 |
|
|
1058 |
|
/**
|
1059 |
460 |
* Paints the component by drawing the chart to fill the entire component,
|
1060 |
461 |
* but allowing for the insets (which will be non-zero if a border has been
|
1061 |
462 |
* set for this component). To increase performance (at the expense of
|
... | ... | |
1094 |
495 |
drawWidth = this.maximumDrawWidth;
|
1095 |
496 |
scale = true;
|
1096 |
497 |
}
|
1097 |
|
|
1098 |
498 |
if (drawHeight < this.minimumDrawHeight) {
|
1099 |
499 |
this.scaleY = drawHeight / this.minimumDrawHeight;
|
1100 |
500 |
drawHeight = this.minimumDrawHeight;
|
... | ... | |
1187 |
587 |
g2.setTransform(saved);
|
1188 |
588 |
|
1189 |
589 |
}
|
1190 |
|
|
1191 |
|
// Redraw the zoom rectangle (if present)
|
1192 |
|
// drawZoomRectangle(g2);
|
1193 |
|
|
1194 |
|
g2.dispose();
|
1195 |
590 |
|
1196 |
|
this.anchor = null;
|
1197 |
|
this.verticalTraceLine = null;
|
1198 |
|
this.horizontalTraceLine = null;
|
1199 |
|
|
|
591 |
g2.dispose();
|
|
592 |
this.anchor = null;
|
1200 |
593 |
}
|
1201 |
594 |
|
1202 |
595 |
|
... | ... | |
1220 |
613 |
*
|
1221 |
614 |
* @param event the event.
|
1222 |
615 |
*/
|
1223 |
|
public void chartProgress(ChartProgressEvent event) {
|
1224 |
|
// does nothing - override if necessary
|
1225 |
|
}
|
1226 |
616 |
|
|
617 |
|
1227 |
618 |
/**
|
1228 |
619 |
* Handles action events generated by the popup menu.
|
1229 |
620 |
*
|
... | ... | |
1233 |
624 |
|
1234 |
625 |
String command = event.getActionCommand();
|
1235 |
626 |
|
1236 |
|
// many of the zoom methods need a screen location - all we have is
|
1237 |
|
// the zoomPoint, but it might be null. Here we grab the x and y
|
1238 |
|
// coordinates, or use defaults...
|
1239 |
|
double screenX = -1.0;
|
1240 |
|
double screenY = -1.0;
|
1241 |
|
if (this.zoomPoint != null) {
|
1242 |
|
screenX = this.zoomPoint.getX();
|
1243 |
|
screenY = this.zoomPoint.getY();
|
1244 |
|
}
|
1245 |
|
|
1246 |
627 |
if (command.equals(SAVE_COMMAND)) {
|
1247 |
628 |
try {
|
1248 |
629 |
doSaveAs();
|
... | ... | |
1254 |
635 |
else if (command.equals(PRINT_COMMAND)) {
|
1255 |
636 |
createChartPrintJob();
|
1256 |
637 |
}
|
1257 |
|
else if (command.equals(ZOOM_IN_BOTH_COMMAND)) {
|
1258 |
|
zoomInBoth(screenX, screenY);
|
1259 |
|
}
|
1260 |
|
else if (command.equals(ZOOM_IN_DOMAIN_COMMAND)) {
|
1261 |
|
zoomInDomain(screenX, screenY);
|
1262 |
|
}
|
1263 |
|
else if (command.equals(ZOOM_IN_RANGE_COMMAND)) {
|
1264 |
|
zoomInRange(screenX, screenY);
|
1265 |
|
}
|
1266 |
|
else if (command.equals(ZOOM_OUT_BOTH_COMMAND)) {
|
1267 |
|
zoomOutBoth(screenX, screenY);
|
1268 |
|
}
|
1269 |
|
else if (command.equals(ZOOM_OUT_DOMAIN_COMMAND)) {
|
1270 |
|
zoomOutDomain(screenX, screenY);
|
1271 |
|
}
|
1272 |
|
else if (command.equals(ZOOM_OUT_RANGE_COMMAND)) {
|
1273 |
|
zoomOutRange(screenX, screenY);
|
1274 |
|
}
|
1275 |
|
else if (command.equals(ZOOM_RESET_BOTH_COMMAND)) {
|
1276 |
|
restoreAutoBounds();
|
1277 |
|
}
|
1278 |
|
else if (command.equals(ZOOM_RESET_DOMAIN_COMMAND)) {
|
1279 |
|
restoreAutoDomainBounds();
|
1280 |
|
}
|
1281 |
|
else if (command.equals(ZOOM_RESET_RANGE_COMMAND)) {
|
1282 |
|
restoreAutoRangeBounds();
|
1283 |
|
}
|
|
638 |
|
1284 |
639 |
else if (command.equals(NEW_CLASS_COMMAND)) {
|
1285 |
640 |
// Definicion de nueba clase
|
1286 |
641 |
newRoiChart();
|
... | ... | |
1290 |
645 |
updateList();
|
1291 |
646 |
|
1292 |
647 |
}
|
1293 |
|
|
1294 |
|
// Acciones para el borrado de la visualizacion de las rois
|
1295 |
|
else if (command.equals(CLEAR_CHART)) {
|
1296 |
|
// Definicion de nueba clase
|
1297 |
|
|
1298 |
|
}
|
1299 |
|
|
|
648 |
|
1300 |
649 |
}
|
1301 |
650 |
|
1302 |
651 |
|
... | ... | |
1308 |
657 |
}
|
1309 |
658 |
|
1310 |
659 |
|
1311 |
|
|
1312 |
|
/**
|
1313 |
|
* Handles a 'mouse entered' event. This method changes the tooltip delays
|
1314 |
|
* of ToolTipManager.sharedInstance() to the possibly different values set
|
1315 |
|
* for this chart panel.
|
1316 |
|
*
|
1317 |
|
* @param e the mouse event.
|
1318 |
|
*/
|
1319 |
660 |
public void mouseEntered(MouseEvent e) {
|
1320 |
|
if (!this.ownToolTipDelaysActive) {
|
1321 |
|
ToolTipManager ttm = ToolTipManager.sharedInstance();
|
1322 |
|
|
1323 |
|
this.originalToolTipInitialDelay = ttm.getInitialDelay();
|
1324 |
|
ttm.setInitialDelay(this.ownToolTipInitialDelay);
|
1325 |
661 |
|
1326 |
|
this.originalToolTipReshowDelay = ttm.getReshowDelay();
|
1327 |
|
ttm.setReshowDelay(this.ownToolTipReshowDelay);
|
1328 |
|
|
1329 |
|
this.originalToolTipDismissDelay = ttm.getDismissDelay();
|
1330 |
|
ttm.setDismissDelay(this.ownToolTipDismissDelay);
|
1331 |
|
|
1332 |
|
this.ownToolTipDelaysActive = true;
|
1333 |
|
}
|
1334 |
662 |
}
|
1335 |
663 |
|
1336 |
|
/**
|
1337 |
|
* Handles a 'mouse exited' event. This method resets the tooltip delays of
|
1338 |
|
* ToolTipManager.sharedInstance() to their
|
1339 |
|
* original values in effect before mouseEntered()
|
1340 |
|
*
|
1341 |
|
* @param e the mouse event.
|
1342 |
|
*/
|
|
664 |
|
1343 |
665 |
public void mouseExited(MouseEvent e) {
|
1344 |
|
if (this.ownToolTipDelaysActive) {
|
1345 |
|
// restore original tooltip dealys
|
1346 |
|
ToolTipManager ttm = ToolTipManager.sharedInstance();
|
1347 |
|
ttm.setInitialDelay(this.originalToolTipInitialDelay);
|
1348 |
|
ttm.setReshowDelay(this.originalToolTipReshowDelay);
|
1349 |
|
ttm.setDismissDelay(this.originalToolTipDismissDelay);
|
1350 |
|
this.ownToolTipDelaysActive = false;
|
1351 |
|
}
|
|
666 |
|
1352 |
667 |
}
|
1353 |
668 |
|
1354 |
669 |
/**
|
... | ... | |
1413 |
728 |
Graphics2D g2 = (Graphics2D) getGraphics();
|
1414 |
729 |
|
1415 |
730 |
// Erase the previous zoom rectangle (if any)...
|
1416 |
|
drawZoomRectangle(g2);
|
|
731 |
drawRectangle(g2);
|
1417 |
732 |
|
1418 |
733 |
boolean hZoom = false;
|
1419 |
734 |
boolean vZoom = false;
|
... | ... | |
1449 |
764 |
}
|
1450 |
765 |
|
1451 |
766 |
// Draw the new zoom rectangle...
|
1452 |
|
drawZoomRectangle(g2);
|
1453 |
|
|
|
767 |
drawRectangle(g2);
|
1454 |
768 |
g2.dispose();
|
1455 |
|
|
1456 |
769 |
}
|
1457 |
770 |
|
1458 |
771 |
/**
|
... | ... | |
1483 |
796 |
if (zoomTrigger1 || zoomTrigger2) {
|
1484 |
797 |
if ((hZoom && (e.getX() < this.zoomPoint.getX()))
|
1485 |
798 |
|| (vZoom && (e.getY() < this.zoomPoint.getY()))) {
|
1486 |
|
restoreAutoBounds();
|
|
799 |
// restoreAutoBounds();
|
1487 |
800 |
}
|
1488 |
801 |
else {
|
1489 |
802 |
double x, y, w, h;
|
... | ... | |
1524 |
837 |
Rectangle2D rectangleArea = new Rectangle2D.Double(x, y, w, h);
|
1525 |
838 |
g2 = (Graphics2D)getGraphics();
|
1526 |
839 |
g2.setPaint(activeROI.getColor());
|
1527 |
|
|
1528 |
840 |
g2.draw(rectangleArea);
|
1529 |
841 |
activeROI.add(rectangleArea, getRange(rectangleArea));
|
1530 |
|
|
1531 |
|
Range r[]=getRange(rectangleArea);
|
1532 |
|
System.out.print("\n"+r[0]);
|
1533 |
|
System.out.print("\n");
|
1534 |
|
System.out.print(r[1]);
|
1535 |
|
|
1536 |
|
|
1537 |
|
|
1538 |
842 |
if(gestorRois!= null){
|
1539 |
843 |
// Cargar la nueva ROI en el destor
|
1540 |
844 |
gestorRois.clearRoiGraphics();
|
1541 |
|
|
1542 |
|
|
1543 |
845 |
}
|
1544 |
846 |
}
|
1545 |
847 |
|
... | ... | |
1551 |
853 |
else {
|
1552 |
854 |
// Erase the zoom rectangle
|
1553 |
855 |
Graphics2D g2 = (Graphics2D) getGraphics();
|
1554 |
|
drawZoomRectangle(g2);
|
|
856 |
drawRectangle(g2);
|
1555 |
857 |
g2.dispose();
|
1556 |
858 |
this.zoomPoint = null;
|
1557 |
859 |
this.zoomRectangle = null;
|
... | ... | |
1564 |
866 |
displayPopupMenu(e.getX(), e.getY());
|
1565 |
867 |
}
|
1566 |
868 |
}
|
1567 |
|
|
1568 |
869 |
}
|
1569 |
870 |
|
1570 |
871 |
|
1571 |
|
|
|
872 |
|
1572 |
873 |
/**
|
1573 |
|
* Receives notification of mouse clicks on the panel. These are
|
1574 |
|
* translated and passed on to any registered chart mouse click listeners.
|
1575 |
|
*
|
1576 |
|
* @param event Information about the mouse event.
|
|
874 |
* @param selection .
|
|
875 |
* @return range[] rangos del rectangulo
|
1577 |
876 |
*/
|
1578 |
|
public void mouseClicked(MouseEvent event) {
|
1579 |
|
|
1580 |
|
Insets insets = getInsets();
|
1581 |
|
int x = (int) ((event.getX() - insets.left) / this.scaleX);
|
1582 |
|
int y = (int) ((event.getY() - insets.top) / this.scaleY);
|
1583 |
|
|
1584 |
|
this.anchor = new Point2D.Double(x, y);
|
1585 |
|
if (this.chart == null) {
|
1586 |
|
return;
|
1587 |
|
}
|
1588 |
|
this.chart.setNotify(true); // force a redraw
|
1589 |
|
// new entity code...
|
1590 |
|
Object[] listeners = this.chartMouseListeners.getListeners(
|
1591 |
|
ChartMouseListener.class);
|
1592 |
|
if (listeners.length == 0) {
|
1593 |
|
return;
|
1594 |
|
}
|
1595 |
|
|
1596 |
|
ChartEntity entity = null;
|
1597 |
|
if (this.info != null) {
|
1598 |
|
EntityCollection entities = this.info.getEntityCollection();
|
1599 |
|
if (entities != null) {
|
1600 |
|
entity = entities.getEntity(x, y);
|
1601 |
|
}
|
1602 |
|
}
|
1603 |
|
ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), event,
|
1604 |
|
entity);
|
1605 |
|
for (int i = listeners.length - 1; i >= 0; i -= 1) {
|
1606 |
|
((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent);
|
1607 |
|
}
|
1608 |
|
updateUI();
|
1609 |
|
|
1610 |
|
}
|
1611 |
|
|
1612 |
|
/**
|
1613 |
|
* Implementation of the MouseMotionListener's method.
|
1614 |
|
*
|
1615 |
|
* @param e the event.
|
1616 |
|
*/
|
1617 |
|
public void mouseMoved(MouseEvent e) {
|
1618 |
|
|
1619 |
|
/* g2 = (Graphics2D) getGraphics();
|
1620 |
|
if (this.horizontalAxisTrace) {
|
1621 |
|
drawHorizontalAxisTrace(g2, e.getX());
|
1622 |
|
}
|
1623 |
|
if (this.verticalAxisTrace) {
|
1624 |
|
drawVerticalAxisTrace(g2, e.getY());
|
1625 |
|
}
|
1626 |
|
g2.dispose();
|
1627 |
|
|
1628 |
|
Object[] listeners = this.chartMouseListeners.getListeners(
|
1629 |
|
ChartMouseListener.class);
|
1630 |
|
if (listeners.length == 0) {
|
1631 |
|
return;
|
1632 |
|
}
|
1633 |
|
Insets insets = getInsets();
|
1634 |
|
int x = (int) ((e.getX() - insets.left) / this.scaleX);
|
1635 |
|
int y = (int) ((e.getY() - insets.top) / this.scaleY);
|
1636 |
|
|
1637 |
|
ChartEntity entity = null;
|
1638 |
|
if (this.info != null) {
|
1639 |
|
EntityCollection entities = this.info.getEntityCollection();
|
1640 |
|
if (entities != null) {
|
1641 |
|
entity = entities.getEntity(x, y);
|
1642 |
|
}
|
1643 |
|
}
|
1644 |
|
|
1645 |
|
// we can only generate events if the panel's chart is not null
|
1646 |
|
// (see bug report 1556951)
|
1647 |
|
if (this.chart != null) {
|
1648 |
|
ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity);
|
1649 |
|
for (int i = listeners.length - 1; i >= 0; i -= 1) {
|
1650 |
|
((ChartMouseListener) listeners[i]).chartMouseMoved(event);
|
1651 |
|
}
|
1652 |
|
}*/
|
1653 |
|
|
1654 |
|
}
|
1655 |
|
|
1656 |
|
/**
|
1657 |
|
* Zooms in on an anchor point (specified in screen coordinate space).
|
1658 |
|
*
|
1659 |
|
* @param x the x value (in screen coordinates).
|
1660 |
|
* @param y the y value (in screen coordinates).
|
1661 |
|
*/
|
1662 |
|
public void zoomInBoth(double x, double y) {
|
1663 |
|
zoomInDomain(x, y);
|
1664 |
|
zoomInRange(x, y);
|
1665 |
|
}
|
1666 |
|
|
1667 |
|
/**
|
1668 |
|
* Decreases the length of the domain axis, centered about the given
|
1669 |
|
* coordinate on the screen. The length of the domain axis is reduced
|
1670 |
|
* by the value of {@link #getZoomInFactor()}.
|
1671 |
|
*
|
1672 |
|
* @param x the x coordinate (in screen coordinates).
|
1673 |
|
* @param y the y-coordinate (in screen coordinates).
|
1674 |
|
*/
|
1675 |
|
public void zoomInDomain(double x, double y) {
|
1676 |
|
|
1677 |
|
}
|
1678 |
|
|
1679 |
|
/**
|
1680 |
|
* Decreases the length of the range axis, centered about the given
|
1681 |
|
* coordinate on the screen. The length of the range axis is reduced by
|
1682 |
|
* the value of {@link #getZoomInFactor()}.
|
1683 |
|
*
|
1684 |
|
* @param x the x-coordinate (in screen coordinates).
|
1685 |
|
* @param y the y coordinate (in screen coordinates).
|
1686 |
|
*/
|
1687 |
|
public void zoomInRange(double x, double y) {
|
1688 |
|
|
1689 |
|
}
|
1690 |
|
|
1691 |
|
/**
|
1692 |
|
* Zooms out on an anchor point (specified in screen coordinate space).
|
1693 |
|
*
|
1694 |
|
* @param x the x value (in screen coordinates).
|
1695 |
|
* @param y the y value (in screen coordinates).
|
1696 |
|
*/
|
1697 |
|
public void zoomOutBoth(double x, double y) {
|
1698 |
|
zoomOutDomain(x, y);
|
1699 |
|
zoomOutRange(x, y);
|
1700 |
|
}
|
1701 |
|
|
1702 |
|
/**
|
1703 |
|
* Increases the length of the domain axis, centered about the given
|
1704 |
|
* coordinate on the screen. The length of the domain axis is increased
|
1705 |
|
* by the value of {@link #getZoomOutFactor()}.
|
1706 |
|
*
|
1707 |
|
* @param x the x coordinate (in screen coordinates).
|
1708 |
|
* @param y the y-coordinate (in screen coordinates).
|
1709 |
|
*/
|
1710 |
|
public void zoomOutDomain(double x, double y) {
|
1711 |
|
|
1712 |
|
}
|
1713 |
|
|
1714 |
|
/**
|
1715 |
|
* Increases the length the range axis, centered about the given
|
1716 |
|
* coordinate on the screen. The length of the range axis is increased
|
1717 |
|
* by the value of {@link #getZoomOutFactor()}.
|
1718 |
|
*
|
1719 |
|
* @param x the x coordinate (in screen coordinates).
|
1720 |
|
* @param y the y-coordinate (in screen coordinates).
|
1721 |
|
*/
|
1722 |
|
public void zoomOutRange(double x, double y) {
|
1723 |
|
|
1724 |
|
}
|
1725 |
|
|
1726 |
|
/**
|
1727 |
|
* Zooms in on a selected region.
|
1728 |
|
*
|
1729 |
|
* @param selection the selected region.
|
1730 |
|
*/
|
1731 |
877 |
public Range[] getRange(Rectangle2D selection) {
|
1732 |
878 |
|
1733 |
879 |
Range[] rangos= new Range[2];
|
... | ... | |
1770 |
916 |
return rangos;
|
1771 |
917 |
}
|
1772 |
918 |
|
1773 |
|
/**
|
1774 |
|
* Restores the auto-range calculation on both axes.
|
1775 |
|
*/
|
1776 |
|
public void restoreAutoBounds() {
|
1777 |
|
restoreAutoDomainBounds();
|
1778 |
|
restoreAutoRangeBounds();
|
1779 |
|
}
|
1780 |
919 |
|
1781 |
920 |
/**
|
1782 |
|
* Restores the auto-range calculation on the domain axis.
|
1783 |
|
*/
|
1784 |
|
public void restoreAutoDomainBounds() {
|
1785 |
|
Plot p = this.chart.getPlot();
|
1786 |
|
if (p instanceof Zoomable) {
|
1787 |
|
Zoomable z = (Zoomable) p;
|
1788 |
|
// we need to guard against this.zoomPoint being null
|
1789 |
|
Point zp = (this.zoomPoint != null ? this.zoomPoint : new Point());
|
1790 |
|
z.zoomDomainAxes(0.0, this.info.getPlotInfo(), zp);
|
1791 |
|
}
|
1792 |
|
}
|
1793 |
|
|
1794 |
|
/**
|
1795 |
|
* Restores the auto-range calculation on the range axis.
|
1796 |
|
*/
|
1797 |
|
public void restoreAutoRangeBounds() {
|
1798 |
|
Plot p = this.chart.getPlot();
|
1799 |
|
if (p instanceof Zoomable) {
|
1800 |
|
Zoomable z = (Zoomable) p;
|
1801 |
|
// we need to guard against this.zoomPoint being null
|
1802 |
|
Point zp = (this.zoomPoint != null ? this.zoomPoint : new Point());
|
1803 |
|
z.zoomRangeAxes(0.0, this.info.getPlotInfo(), zp);
|
1804 |
|
}
|
1805 |
|
}
|
1806 |
|
|
1807 |
|
/**
|
1808 |
921 |
* Returns the data area for the chart (the area inside the axes) with the
|
1809 |
922 |
* current scaling applied (that is, the area as it appears on screen).
|
1810 |
923 |
*
|
... | ... | |
1836 |
949 |
result = getScreenDataArea();
|
1837 |
950 |
}
|
1838 |
951 |
else {
|
1839 |
|
// get the origin of the zoom selection in the Java2D space used for
|
1840 |
|
// drawing the chart (that is, before any scaling to fit the panel)
|
1841 |
952 |
Point2D selectOrigin = translateScreenToJava2D(new Point(x, y));
|
1842 |
953 |
int subplotIndex = plotInfo.getSubplotIndex(selectOrigin);
|
1843 |
954 |
if (subplotIndex == -1) {
|
... | ... | |
1847 |
958 |
}
|
1848 |
959 |
return result;
|
1849 |
960 |
}
|
1850 |
|
|
1851 |
|
/**
|
1852 |
|
* Returns the initial tooltip delay value used inside this chart panel.
|
1853 |
|
*
|
1854 |
|
* @return An integer representing the initial delay value, in milliseconds.
|
1855 |
|
*
|
1856 |
|
* @see javax.swing.ToolTipManager#getInitialDelay()
|
1857 |
|
*/
|
1858 |
|
public int getInitialDelay() {
|
1859 |
|
return this.ownToolTipInitialDelay;
|
1860 |
|
}
|
1861 |
|
|
1862 |
|
/**
|
1863 |
|
* Returns the reshow tooltip delay value used inside this chart panel.
|
1864 |
|
*
|
1865 |
|
* @return An integer representing the reshow delay value, in milliseconds.
|
1866 |
|
*
|
1867 |
|
* @see javax.swing.ToolTipManager#getReshowDelay()
|
1868 |
|
*/
|
1869 |
|
public int getReshowDelay() {
|
1870 |
|
return this.ownToolTipReshowDelay;
|
1871 |
|
}
|
1872 |
961 |
|
1873 |
|
/**
|
1874 |
|
* Returns the dismissal tooltip delay value used inside this chart panel.
|
1875 |
|
*
|
1876 |
|
* @return An integer representing the dismissal delay value, in
|
1877 |
|
* milliseconds.
|
1878 |
|
*
|
1879 |
|
* @see javax.swing.ToolTipManager#getDismissDelay()
|
1880 |
|
*/
|
1881 |
|
public int getDismissDelay() {
|
1882 |
|
return this.ownToolTipDismissDelay;
|
1883 |
|
}
|
1884 |
962 |
|
1885 |
963 |
/**
|
1886 |
|
* Specifies the initial delay value for this chart panel.
|
1887 |
964 |
*
|
1888 |
|
* @param delay the number of milliseconds to delay (after the cursor has
|
1889 |
|
* paused) before displaying.
|
1890 |
|
*
|
1891 |
|
* @see javax.swing.ToolTipManager#setInitialDelay(int)
|
1892 |
|
*/
|
1893 |
|
public void setInitialDelay(int delay) {
|
1894 |
|
this.ownToolTipInitialDelay = delay;
|
1895 |
|
}
|
1896 |
|
|
1897 |
|
/**
|
1898 |
|
* Specifies the amount of time before the user has to wait initialDelay
|
1899 |
|
* milliseconds before a tooltip will be shown.
|
1900 |
|
*
|
1901 |
|
* @param delay time in milliseconds
|
1902 |
|
*
|
1903 |
|
* @see javax.swing.ToolTipManager#setReshowDelay(int)
|
1904 |
|
*/
|
1905 |
|
public void setReshowDelay(int delay) {
|
1906 |
|
this.ownToolTipReshowDelay = delay;
|
1907 |
|
}
|
1908 |
|
|
1909 |
|
/**
|
1910 |
|
* Specifies the dismissal delay value for this chart panel.
|
1911 |
|
*
|
1912 |
|
* @param delay the number of milliseconds to delay before taking away the
|
1913 |
|
* tooltip
|
1914 |
|
*
|
1915 |
|
* @see javax.swing.ToolTipManager#setDismissDelay(int)
|
1916 |
|
*/
|
1917 |
|
public void setDismissDelay(int delay) {
|
1918 |
|
this.ownToolTipDismissDelay = delay;
|
1919 |
|
}
|
1920 |
|
|
1921 |
|
/**
|
1922 |
|
* Returns the zoom in factor.
|
1923 |
|
*
|
1924 |
|
* @return The zoom in factor.
|
1925 |
|
*
|
1926 |
|
* @see #setZoomInFactor(double)
|
1927 |
|
*/
|
1928 |
|
public double getZoomInFactor() {
|
1929 |
|
return this.zoomInFactor;
|
1930 |
|
}
|
1931 |
|
|
1932 |
|
/**
|
1933 |
|
* Sets the zoom in factor.
|
1934 |
|
*
|
1935 |
|
* @param factor the factor.
|
1936 |
|
*
|
1937 |
|
* @see #getZoomInFactor()
|
1938 |
|
*/
|
1939 |
|
public void setZoomInFactor(double factor) {
|
1940 |
|
this.zoomInFactor = factor;
|
1941 |
|
}
|
1942 |
|
|
1943 |
|
/**
|
1944 |
|
* Returns the zoom out factor.
|
1945 |
|
*
|
1946 |
|
* @return The zoom out factor.
|
1947 |
|
*
|
1948 |
|
* @see #setZoomOutFactor(double)
|
1949 |
|
*/
|
1950 |
|
public double getZoomOutFactor() {
|
1951 |
|
return this.zoomOutFactor;
|
1952 |
|
}
|
1953 |
|
|
1954 |
|
/**
|
1955 |
|
* Sets the zoom out factor.
|
1956 |
|
*
|
1957 |
|
* @param factor the factor.
|
1958 |
|
*
|
1959 |
|
* @see #getZoomOutFactor()
|
1960 |
|
*/
|
1961 |
|
public void setZoomOutFactor(double factor) {
|
1962 |
|
this.zoomOutFactor = factor;
|
1963 |
|
}
|
1964 |
|
|
1965 |
|
/**
|
1966 |
|
* Draws zoom rectangle (if present).
|
1967 |
|
* The drawing is performed in XOR mode, therefore
|
1968 |
|
* when this method is called twice in a row,
|
1969 |
|
* the second call will completely restore the state
|
1970 |
|
* of the canvas.
|
1971 |
|
*
|
|
965 |
* Pinta el rectangulo sombreado mientras se realiza la selecci?n
|
1972 |
966 |
* @param g2 the graphics device.
|
1973 |
967 |
*/
|
1974 |
|
private void drawZoomRectangle(Graphics2D g2) {
|
|
968 |
private void drawRectangle(Graphics2D g2) {
|
1975 |
969 |
// Set XOR mode to draw the zoom rectangle
|
1976 |
970 |
g2.setXORMode(Color.gray);
|
1977 |
971 |
if (this.zoomRectangle != null) {
|
... | ... | |
1986 |
980 |
g2.setPaintMode();
|
1987 |
981 |
}
|
1988 |
982 |
|
|
983 |
|
1989 |
984 |
/**
|
1990 |
|
* Draws a vertical line used to trace the mouse position to the horizontal
|
1991 |
|
* axis.
|
1992 |
|
*
|
1993 |
|
* @param g2 the graphics device.
|
1994 |
|
* @param x the x-coordinate of the trace line.
|
1995 |
|
*/
|
1996 |
|
private void drawHorizontalAxisTrace(Graphics2D g2, int x) {
|
1997 |
|
|
1998 |
|
Rectangle2D dataArea = getScreenDataArea();
|
1999 |
|
|
2000 |
|
g2.setXORMode(Color.orange);
|
2001 |
|
if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) {
|
2002 |
|
|
2003 |
|
if (this.verticalTraceLine != null) {
|
2004 |
|
g2.draw(this.verticalTraceLine);
|
2005 |
|
this.verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x,
|
2006 |
|
(int) dataArea.getMaxY());
|
2007 |
|
}
|
2008 |
|
else {
|
2009 |
|
this.verticalTraceLine = new Line2D.Float(x,
|
2010 |
|
(int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
|
2011 |
|
}
|
2012 |
|
g2.draw(this.verticalTraceLine);
|
2013 |
|
}
|
2014 |
|
|
2015 |
|
// Reset to the default 'overwrite' mode
|
2016 |
|
g2.setPaintMode();
|
2017 |
|
}
|
2018 |
|
|
2019 |
|
/**
|
2020 |
|
* Draws a horizontal line used to trace the mouse position to the vertical
|
2021 |
|
* axis.
|
2022 |
|
*
|
2023 |
|
* @param g2 the graphics device.
|
2024 |
|
* @param y the y-coordinate of the trace line.
|
2025 |
|
*/
|
2026 |
|
private void drawVerticalAxisTrace(Graphics2D g2, int y) {
|
2027 |
|
|
2028 |
|
Rectangle2D dataArea = getScreenDataArea();
|
2029 |
|
|
2030 |
|
g2.setXORMode(Color.orange);
|
2031 |
|
if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) {
|
2032 |
|
|
2033 |
|
if (this.horizontalTraceLine != null) {
|
2034 |
|
g2.draw(this.horizontalTraceLine);
|
2035 |
|
this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y,
|
2036 |
|
(int) dataArea.getMaxX(), y);
|
2037 |
|
}
|
2038 |
|
else {
|
2039 |
|
this.horizontalTraceLine = new Line2D.Float(
|
2040 |
|
(int) dataArea.getMinX(), y, (int) dataArea.getMaxX(),
|
2041 |
|
y);
|
2042 |
|
}
|
2043 |
|
g2.draw(this.horizontalTraceLine);
|
2044 |
|
}
|
2045 |
|
|
2046 |
|
// Reset to the default 'overwrite' mode
|
2047 |
|
g2.setPaintMode();
|
2048 |
|
}
|
2049 |
|
|
2050 |
|
/**
|
2051 |
985 |
* Displays a dialog that allows the user to edit the properties for the
|
2052 |
986 |
* current chart.
|
2053 |
987 |
*
|
... | ... | |
2166 |
1100 |
this.chartMouseListeners.remove(ChartMouseListener.class, listener);
|
2167 |
1101 |
}
|
2168 |
1102 |
|
2169 |
|
/**
|
2170 |
|
* Returns an array of the listeners of the given type registered with the
|
2171 |
|
* panel.
|
2172 |
|
*
|
2173 |
|
* @param listenerType the listener type.
|
2174 |
|
*
|
2175 |
|
* @return An array of listeners.
|
2176 |
|
*/
|
2177 |
|
public EventListener[] getListeners(Class listenerType) {
|
2178 |
|
if (listenerType == ChartMouseListener.class) {
|
2179 |
|
// fetch listeners from local storage
|
2180 |
|
return this.chartMouseListeners.getListeners(listenerType);
|
2181 |
|
}
|
2182 |
|
else {
|
2183 |
|
return super.getListeners(listenerType);
|
2184 |
|
}
|
2185 |
|
}
|
2186 |
1103 |
|
2187 |
1104 |
/**
|
2188 |
1105 |
* Creates a popup menu for the panel.
|
... | ... | |
2207 |
1124 |
newClassItem.addActionListener(this);
|
2208 |
1125 |
result.add(newClassItem);
|
2209 |
1126 |
separator = true;
|
2210 |
|
|
2211 |
|
|
2212 |
|
JMenuItem newClassItem2 = new JMenuItem( PluginServices.getText(this,"clear_chart"));
|
2213 |
|
newClassItem2.setActionCommand(CLEAR_CHART);
|
2214 |
|
newClassItem2.addActionListener(this);
|
2215 |
|
result.add(newClassItem2);
|
2216 |
|
separator = true;
|
2217 |
|
|
2218 |
|
|
2219 |
|
if (properties) {
|
2220 |
1127 |
|
|
1128 |
if (properties) {
|
2221 |
1129 |
}
|
2222 |
1130 |
|
2223 |
1131 |
if (save) {
|
... | ... | |
2251 |
1159 |
result.addSeparator();
|
2252 |
1160 |
separator = false;
|
2253 |
1161 |
}
|
2254 |
|
|
2255 |
|
|
2256 |
|
|
2257 |
|
JMenu zoomInMenu = new JMenu(
|
2258 |
|
localizationResources.getString("Zoom_In"));
|
2259 |
|
|
2260 |
|
this.zoomInBothMenuItem = new JMenuItem(
|
2261 |
|
localizationResources.getString("All_Axes"));
|
2262 |
|
this.zoomInBothMenuItem.setActionCommand(ZOOM_IN_BOTH_COMMAND);
|
2263 |
|
this.zoomInBothMenuItem.addActionListener(this);
|
2264 |
|
zoomInMenu.add(this.zoomInBothMenuItem);
|