1:
144:
145: package ;
146:
147: import ;
148: import ;
149: import ;
150: import ;
151: import ;
152: import ;
153: import ;
154: import ;
155: import ;
156: import ;
157: import ;
158: import ;
159: import ;
160: import ;
161: import ;
162: import ;
163: import ;
164: import ;
165: import ;
166: import ;
167: import ;
168: import ;
169: import ;
170: import ;
171: import ;
172: import ;
173: import ;
174: import ;
175:
176: import ;
177: import ;
178: import ;
179: import ;
180: import ;
181: import ;
182: import ;
183: import ;
184: import ;
185:
186: import ;
187: import ;
188: import ;
189: import ;
190: import ;
191: import ;
192: import ;
193: import ;
194: import ;
195: import ;
196: import ;
197: import ;
198: import ;
199:
200:
207: public class ChartPanel extends JPanel implements ChartChangeListener,
208: ChartProgressListener, ActionListener, MouseListener,
209: MouseMotionListener, Printable, Serializable {
210:
211:
212: private static final long serialVersionUID = 6046366297214274674L;
213:
214:
215: public static final boolean DEFAULT_BUFFER_USED = false;
216:
217:
218: public static final int DEFAULT_WIDTH = 680;
219:
220:
221: public static final int DEFAULT_HEIGHT = 420;
222:
223:
224: public static final int DEFAULT_MINIMUM_DRAW_WIDTH = 300;
225:
226:
227: public static final int DEFAULT_MINIMUM_DRAW_HEIGHT = 200;
228:
229:
230: public static final int DEFAULT_MAXIMUM_DRAW_WIDTH = 800;
231:
232:
233: public static final int DEFAULT_MAXIMUM_DRAW_HEIGHT = 600;
234:
235:
236: public static final int DEFAULT_ZOOM_TRIGGER_DISTANCE = 10;
237:
238:
239: public static final String PROPERTIES_COMMAND = "PROPERTIES";
240:
241:
242: public static final String SAVE_COMMAND = "SAVE";
243:
244:
245: public static final String PRINT_COMMAND = "PRINT";
246:
247:
248: public static final String ZOOM_IN_BOTH_COMMAND = "ZOOM_IN_BOTH";
249:
250:
251: public static final String ZOOM_IN_DOMAIN_COMMAND = "ZOOM_IN_DOMAIN";
252:
253:
254: public static final String ZOOM_IN_RANGE_COMMAND = "ZOOM_IN_RANGE";
255:
256:
257: public static final String ZOOM_OUT_BOTH_COMMAND = "ZOOM_OUT_BOTH";
258:
259:
260: public static final String ZOOM_OUT_DOMAIN_COMMAND = "ZOOM_DOMAIN_BOTH";
261:
262:
263: public static final String ZOOM_OUT_RANGE_COMMAND = "ZOOM_RANGE_BOTH";
264:
265:
266: public static final String ZOOM_RESET_BOTH_COMMAND = "ZOOM_RESET_BOTH";
267:
268:
269: public static final String ZOOM_RESET_DOMAIN_COMMAND = "ZOOM_RESET_DOMAIN";
270:
271:
272: public static final String ZOOM_RESET_RANGE_COMMAND = "ZOOM_RESET_RANGE";
273:
274:
275: private JFreeChart chart;
276:
277:
278: private transient EventListenerList chartMouseListeners;
279:
280:
281: private boolean useBuffer;
282:
283:
284: private boolean refreshBuffer;
285:
286:
287: private transient Image chartBuffer;
288:
289:
290: private int chartBufferHeight;
291:
292:
293: private int chartBufferWidth;
294:
295:
298: private int minimumDrawWidth;
299:
300:
304: private int minimumDrawHeight;
305:
306:
310: private int maximumDrawWidth;
311:
312:
316: private int maximumDrawHeight;
317:
318:
319: private JPopupMenu popup;
320:
321:
322: private ChartRenderingInfo info;
323:
324:
325: private Point2D anchor;
326:
327:
328: private double scaleX;
329:
330:
331: private double scaleY;
332:
333:
334: private PlotOrientation orientation = PlotOrientation.VERTICAL;
335:
336:
337: private boolean domainZoomable = false;
338:
339:
340: private boolean rangeZoomable = false;
341:
342:
347: private Point2D zoomPoint = null;
348:
349:
350: private transient Rectangle2D zoomRectangle = null;
351:
352:
353: private boolean fillZoomRectangle = false;
354:
355:
356: private int zoomTriggerDistance;
357:
358:
359: private boolean horizontalAxisTrace = false;
360:
361:
362: private boolean verticalAxisTrace = false;
363:
364:
365: private transient Line2D verticalTraceLine;
366:
367:
368: private transient Line2D horizontalTraceLine;
369:
370:
371: private JMenuItem zoomInBothMenuItem;
372:
373:
374: private JMenuItem zoomInDomainMenuItem;
375:
376:
377: private JMenuItem zoomInRangeMenuItem;
378:
379:
380: private JMenuItem zoomOutBothMenuItem;
381:
382:
383: private JMenuItem zoomOutDomainMenuItem;
384:
385:
386: private JMenuItem zoomOutRangeMenuItem;
387:
388:
389: private JMenuItem zoomResetBothMenuItem;
390:
391:
392: private JMenuItem zoomResetDomainMenuItem;
393:
394:
395: private JMenuItem zoomResetRangeMenuItem;
396:
397:
402: private File defaultDirectoryForSaveAs;
403:
404:
405: private boolean enforceFileExtensions;
406:
407:
408: private boolean ownToolTipDelaysActive;
409:
410:
411: private int originalToolTipInitialDelay;
412:
413:
414: private int originalToolTipReshowDelay;
415:
416:
417: private int originalToolTipDismissDelay;
418:
419:
420: private int ownToolTipInitialDelay;
421:
422:
423: private int ownToolTipReshowDelay;
424:
425:
426: private int ownToolTipDismissDelay;
427:
428:
429: private double zoomInFactor = 0.5;
430:
431:
432: private double zoomOutFactor = 2.0;
433:
434:
440: private boolean zoomAroundAnchor;
441:
442:
443: protected static ResourceBundle localizationResources
444: = ResourceBundle.getBundle("org.jfree.chart.LocalizationBundle");
445:
446:
451: public ChartPanel(JFreeChart chart) {
452:
453: this(
454: chart,
455: DEFAULT_WIDTH,
456: DEFAULT_HEIGHT,
457: DEFAULT_MINIMUM_DRAW_WIDTH,
458: DEFAULT_MINIMUM_DRAW_HEIGHT,
459: DEFAULT_MAXIMUM_DRAW_WIDTH,
460: DEFAULT_MAXIMUM_DRAW_HEIGHT,
461: DEFAULT_BUFFER_USED,
462: true,
463: true,
464: true,
465: true,
466: true
467: );
468:
469: }
470:
471:
478: public ChartPanel(JFreeChart chart, boolean useBuffer) {
479:
480: this(chart,
481: DEFAULT_WIDTH,
482: DEFAULT_HEIGHT,
483: DEFAULT_MINIMUM_DRAW_WIDTH,
484: DEFAULT_MINIMUM_DRAW_HEIGHT,
485: DEFAULT_MAXIMUM_DRAW_WIDTH,
486: DEFAULT_MAXIMUM_DRAW_HEIGHT,
487: useBuffer,
488: true,
489: true,
490: true,
491: true,
492: true
493: );
494:
495: }
496:
497:
512: public ChartPanel(JFreeChart chart,
513: boolean properties,
514: boolean save,
515: boolean print,
516: boolean zoom,
517: boolean tooltips) {
518:
519: this(chart,
520: DEFAULT_WIDTH,
521: DEFAULT_HEIGHT,
522: DEFAULT_MINIMUM_DRAW_WIDTH,
523: DEFAULT_MINIMUM_DRAW_HEIGHT,
524: DEFAULT_MAXIMUM_DRAW_WIDTH,
525: DEFAULT_MAXIMUM_DRAW_HEIGHT,
526: DEFAULT_BUFFER_USED,
527: properties,
528: save,
529: print,
530: zoom,
531: tooltips
532: );
533:
534: }
535:
536:
560: public ChartPanel(JFreeChart chart,
561: int width,
562: int height,
563: int minimumDrawWidth,
564: int minimumDrawHeight,
565: int maximumDrawWidth,
566: int maximumDrawHeight,
567: boolean useBuffer,
568: boolean properties,
569: boolean save,
570: boolean print,
571: boolean zoom,
572: boolean tooltips) {
573:
574: this.setChart(chart);
575: this.chartMouseListeners = new EventListenerList();
576: this.info = new ChartRenderingInfo();
577: setPreferredSize(new Dimension(width, height));
578: this.useBuffer = useBuffer;
579: this.refreshBuffer = false;
580: this.minimumDrawWidth = minimumDrawWidth;
581: this.minimumDrawHeight = minimumDrawHeight;
582: this.maximumDrawWidth = maximumDrawWidth;
583: this.maximumDrawHeight = maximumDrawHeight;
584: this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE;
585:
586:
587: this.popup = null;
588: if (properties || save || print || zoom) {
589: this.popup = createPopupMenu(properties, save, print, zoom);
590: }
591:
592: enableEvents(AWTEvent.MOUSE_EVENT_MASK);
593: enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
594: setDisplayToolTips(tooltips);
595: addMouseListener(this);
596: addMouseMotionListener(this);
597:
598: this.defaultDirectoryForSaveAs = null;
599: this.enforceFileExtensions = true;
600:
601:
602:
603: ToolTipManager ttm = ToolTipManager.sharedInstance();
604: this.ownToolTipInitialDelay = ttm.getInitialDelay();
605: this.ownToolTipDismissDelay = ttm.getDismissDelay();
606: this.ownToolTipReshowDelay = ttm.getReshowDelay();
607:
608: this.zoomAroundAnchor = false;
609: }
610:
611:
616: public JFreeChart getChart() {
617: return this.chart;
618: }
619:
620:
625: public void setChart(JFreeChart chart) {
626:
627:
628: if (this.chart != null) {
629: this.chart.removeChangeListener(this);
630: this.chart.removeProgressListener(this);
631: }
632:
633:
634: this.chart = chart;
635: if (chart != null) {
636: this.chart.addChangeListener(this);
637: this.chart.addProgressListener(this);
638: Plot plot = chart.getPlot();
639: this.domainZoomable = false;
640: this.rangeZoomable = false;
641: if (plot instanceof Zoomable) {
642: Zoomable z = (Zoomable) plot;
643: this.domainZoomable = z.isDomainZoomable();
644: this.rangeZoomable = z.isRangeZoomable();
645: this.orientation = z.getOrientation();
646: }
647: }
648: else {
649: this.domainZoomable = false;
650: this.rangeZoomable = false;
651: }
652: if (this.useBuffer) {
653: this.refreshBuffer = true;
654: }
655: repaint();
656:
657: }
658:
659:
667: public int getMinimumDrawWidth() {
668: return this.minimumDrawWidth;
669: }
670:
671:
680: public void setMinimumDrawWidth(int width) {
681: this.minimumDrawWidth = width;
682: }
683:
684:
692: public int getMaximumDrawWidth() {
693: return this.maximumDrawWidth;
694: }
695:
696:
705: public void setMaximumDrawWidth(int width) {
706: this.maximumDrawWidth = width;
707: }
708:
709:
717: public int getMinimumDrawHeight() {
718: return this.minimumDrawHeight;
719: }
720:
721:
730: public void setMinimumDrawHeight(int height) {
731: this.minimumDrawHeight = height;
732: }
733:
734:
742: public int getMaximumDrawHeight() {
743: return this.maximumDrawHeight;
744: }
745:
746:
755: public void setMaximumDrawHeight(int height) {
756: this.maximumDrawHeight = height;
757: }
758:
759:
765: public double getScaleX() {
766: return this.scaleX;
767: }
768:
769:
775: public double getScaleY() {
776: return this.scaleY;
777: }
778:
779:
784: public Point2D getAnchor() {
785: return this.anchor;
786: }
787:
788:
794: protected void setAnchor(Point2D anchor) {
795: this.anchor = anchor;
796: }
797:
798:
803: public JPopupMenu getPopupMenu() {
804: return this.popup;
805: }
806:
807:
812: public void setPopupMenu(JPopupMenu popup) {
813: this.popup = popup;
814: }
815:
816:
821: public ChartRenderingInfo getChartRenderingInfo() {
822: return this.info;
823: }
824:
825:
831: public void setMouseZoomable(boolean flag) {
832: setMouseZoomable(flag, true);
833: }
834:
835:
842: public void setMouseZoomable(boolean flag, boolean fillRectangle) {
843: setDomainZoomable(flag);
844: setRangeZoomable(flag);
845: setFillZoomRectangle(fillRectangle);
846: }
847:
848:
854: public boolean isDomainZoomable() {
855: return this.domainZoomable;
856: }
857:
858:
865: public void setDomainZoomable(boolean flag) {
866: if (flag) {
867: Plot plot = this.chart.getPlot();
868: if (plot instanceof Zoomable) {
869: Zoomable z = (Zoomable) plot;
870: this.domainZoomable = flag && (z.isDomainZoomable());
871: }
872: }
873: else {
874: this.domainZoomable = false;
875: }
876: }
877:
878:
884: public boolean isRangeZoomable() {
885: return this.rangeZoomable;
886: }
887:
888:
893: public void setRangeZoomable(boolean flag) {
894: if (flag) {
895: Plot plot = this.chart.getPlot();
896: if (plot instanceof Zoomable) {
897: Zoomable z = (Zoomable) plot;
898: this.rangeZoomable = flag && (z.isRangeZoomable());
899: }
900: }
901: else {
902: this.rangeZoomable = false;
903: }
904: }
905:
906:
912: public boolean getFillZoomRectangle() {
913: return this.fillZoomRectangle;
914: }
915:
916:
922: public void setFillZoomRectangle(boolean flag) {
923: this.fillZoomRectangle = flag;
924: }
925:
926:
932: public int getZoomTriggerDistance() {
933: return this.zoomTriggerDistance;
934: }
935:
936:
942: public void setZoomTriggerDistance(int distance) {
943: this.zoomTriggerDistance = distance;
944: }
945:
946:
952: public boolean getHorizontalAxisTrace() {
953: return this.horizontalAxisTrace;
954: }
955:
956:
962: public void setHorizontalAxisTrace(boolean flag) {
963: this.horizontalAxisTrace = flag;
964: }
965:
966:
971: protected Line2D getHorizontalTraceLine() {
972: return this.horizontalTraceLine;
973: }
974:
975:
980: protected void setHorizontalTraceLine(Line2D line) {
981: this.horizontalTraceLine = line;
982: }
983:
984:
990: public boolean getVerticalAxisTrace() {
991: return this.verticalAxisTrace;
992: }
993:
994:
1000: public void setVerticalAxisTrace(boolean flag) {
1001: this.verticalAxisTrace = flag;
1002: }
1003:
1004:
1009: protected Line2D getVerticalTraceLine() {
1010: return this.verticalTraceLine;
1011: }
1012:
1013:
1018: protected void setVerticalTraceLine(Line2D line) {
1019: this.verticalTraceLine = line;
1020: }
1021:
1022:
1029: public File getDefaultDirectoryForSaveAs() {
1030: return this.defaultDirectoryForSaveAs;
1031: }
1032:
1033:
1041: public void setDefaultDirectoryForSaveAs(File directory) {
1042: if (directory != null) {
1043: if (!directory.isDirectory()) {
1044: throw new IllegalArgumentException(
1045: "The 'directory' argument is not a directory.");
1046: }
1047: }
1048: this.defaultDirectoryForSaveAs = directory;
1049: }
1050:
1051:
1059: public boolean isEnforceFileExtensions() {
1060: return this.enforceFileExtensions;
1061: }
1062:
1063:
1070: public void setEnforceFileExtensions(boolean enforce) {
1071: this.enforceFileExtensions = enforce;
1072: }
1073:
1074:
1084: public boolean getZoomAroundAnchor() {
1085: return this.zoomAroundAnchor;
1086: }
1087:
1088:
1098: public void setZoomAroundAnchor(boolean zoomAroundAnchor) {
1099: this.zoomAroundAnchor = zoomAroundAnchor;
1100: }
1101:
1102:
1110: public void setDisplayToolTips(boolean flag) {
1111: if (flag) {
1112: ToolTipManager.sharedInstance().registerComponent(this);
1113: }
1114: else {
1115: ToolTipManager.sharedInstance().unregisterComponent(this);
1116: }
1117: }
1118:
1119:
1126: public String getToolTipText(MouseEvent e) {
1127:
1128: String result = null;
1129: if (this.info != null) {
1130: EntityCollection entities = this.info.getEntityCollection();
1131: if (entities != null) {
1132: Insets insets = getInsets();
1133: ChartEntity entity = entities.getEntity(
1134: (int) ((e.getX() - insets.left) / this.scaleX),
1135: (int) ((e.getY() - insets.top) / this.scaleY));
1136: if (entity != null) {
1137: result = entity.getToolTipText();
1138: }
1139: }
1140: }
1141: return result;
1142:
1143: }
1144:
1145:
1152: public Point translateJava2DToScreen(Point2D java2DPoint) {
1153: Insets insets = getInsets();
1154: int x = (int) (java2DPoint.getX() * this.scaleX + insets.left);
1155: int y = (int) (java2DPoint.getY() * this.scaleY + insets.top);
1156: return new Point(x, y);
1157: }
1158:
1159:
1167: public Point2D translateScreenToJava2D(Point screenPoint) {
1168: Insets insets = getInsets();
1169: double x = (screenPoint.getX() - insets.left) / this.scaleX;
1170: double y = (screenPoint.getY() - insets.top) / this.scaleY;
1171: return new Point2D.Double(x, y);
1172: }
1173:
1174:
1182: public Rectangle2D scale(Rectangle2D rect) {
1183: Insets insets = getInsets();
1184: double x = rect.getX() * getScaleX() + insets.left;
1185: double y = rect.getY() * getScaleY() + insets.top;
1186: double w = rect.getWidth() * getScaleX();
1187: double h = rect.getHeight() * getScaleY();
1188: return new Rectangle2D.Double(x, y, w, h);
1189: }
1190:
1191:
1202: public ChartEntity getEntityForPoint(int viewX, int viewY) {
1203:
1204: ChartEntity result = null;
1205: if (this.info != null) {
1206: Insets insets = getInsets();
1207: double x = (viewX - insets.left) / this.scaleX;
1208: double y = (viewY - insets.top) / this.scaleY;
1209: EntityCollection entities = this.info.getEntityCollection();
1210: result = entities != null ? entities.getEntity(x, y) : null;
1211: }
1212: return result;
1213:
1214: }
1215:
1216:
1222: public boolean getRefreshBuffer() {
1223: return this.refreshBuffer;
1224: }
1225:
1226:
1233: public void setRefreshBuffer(boolean flag) {
1234: this.refreshBuffer = flag;
1235: }
1236:
1237:
1245: public void paintComponent(Graphics g) {
1246: super.paintComponent(g);
1247: if (this.chart == null) {
1248: return;
1249: }
1250: Graphics2D g2 = (Graphics2D) g.create();
1251:
1252:
1253: Dimension size = getSize();
1254: Insets insets = getInsets();
1255: Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top,
1256: size.getWidth() - insets.left - insets.right,
1257: size.getHeight() - insets.top - insets.bottom);
1258:
1259:
1260: boolean scale = false;
1261: double drawWidth = available.getWidth();
1262: double drawHeight = available.getHeight();
1263: this.scaleX = 1.0;
1264: this.scaleY = 1.0;
1265:
1266: if (drawWidth < this.minimumDrawWidth) {
1267: this.scaleX = drawWidth / this.minimumDrawWidth;
1268: drawWidth = this.minimumDrawWidth;
1269: scale = true;
1270: }
1271: else if (drawWidth > this.maximumDrawWidth) {
1272: this.scaleX = drawWidth / this.maximumDrawWidth;
1273: drawWidth = this.maximumDrawWidth;
1274: scale = true;
1275: }
1276:
1277: if (drawHeight < this.minimumDrawHeight) {
1278: this.scaleY = drawHeight / this.minimumDrawHeight;
1279: drawHeight = this.minimumDrawHeight;
1280: scale = true;
1281: }
1282: else if (drawHeight > this.maximumDrawHeight) {
1283: this.scaleY = drawHeight / this.maximumDrawHeight;
1284: drawHeight = this.maximumDrawHeight;
1285: scale = true;
1286: }
1287:
1288: Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth,
1289: drawHeight);
1290:
1291:
1292: if (this.useBuffer) {
1293:
1294:
1295:
1296: boolean clearBuffer = true;
1297:
1298:
1299: if ((this.chartBuffer == null)
1300: || (this.chartBufferWidth != available.getWidth())
1301: || (this.chartBufferHeight != available.getHeight())) {
1302: this.chartBufferWidth = (int) available.getWidth();
1303: this.chartBufferHeight = (int) available.getHeight();
1304: this.chartBuffer = createImage(this.chartBufferWidth,
1305: this.chartBufferHeight);
1306:
1307:
1308:
1309:
1310: this.refreshBuffer = true;
1311: clearBuffer = false;
1312: }
1313:
1314:
1315: if (this.refreshBuffer) {
1316:
1317: this.refreshBuffer = false;
1318:
1319: Rectangle2D bufferArea = new Rectangle2D.Double(
1320: 0, 0, this.chartBufferWidth, this.chartBufferHeight);
1321:
1322: Graphics2D bufferG2 = (Graphics2D)
1323: this.chartBuffer.getGraphics();
1324: if (clearBuffer) {
1325: bufferG2.clearRect(0, 0, this.chartBufferWidth,
1326: this.chartBufferHeight);
1327: }
1328: if (scale) {
1329: AffineTransform saved = bufferG2.getTransform();
1330: AffineTransform st = AffineTransform.getScaleInstance(
1331: this.scaleX, this.scaleY);
1332: bufferG2.transform(st);
1333: this.chart.draw(bufferG2, chartArea, this.anchor,
1334: this.info);
1335: bufferG2.setTransform(saved);
1336: }
1337: else {
1338: this.chart.draw(bufferG2, bufferArea, this.anchor,
1339: this.info);
1340: }
1341:
1342: }
1343:
1344:
1345: g2.drawImage(this.chartBuffer, insets.left, insets.top, this);
1346:
1347: }
1348:
1349:
1350: else {
1351:
1352: AffineTransform saved = g2.getTransform();
1353: g2.translate(insets.left, insets.top);
1354: if (scale) {
1355: AffineTransform st = AffineTransform.getScaleInstance(
1356: this.scaleX, this.scaleY);
1357: g2.transform(st);
1358: }
1359: this.chart.draw(g2, chartArea, this.anchor, this.info);
1360: g2.setTransform(saved);
1361:
1362: }
1363:
1364:
1365: drawZoomRectangle(g2);
1366:
1367: g2.dispose();
1368:
1369: this.anchor = null;
1370: this.verticalTraceLine = null;
1371: this.horizontalTraceLine = null;
1372:
1373: }
1374:
1375:
1380: public void chartChanged(ChartChangeEvent event) {
1381: this.refreshBuffer = true;
1382: Plot plot = this.chart.getPlot();
1383: if (plot instanceof Zoomable) {
1384: Zoomable z = (Zoomable) plot;
1385: this.orientation = z.getOrientation();
1386: }
1387: repaint();
1388: }
1389:
1390:
1395: public void chartProgress(ChartProgressEvent event) {
1396:
1397: }
1398:
1399:
1404: public void actionPerformed(ActionEvent event) {
1405:
1406: String command = event.getActionCommand();
1407:
1408:
1409:
1410:
1411: double screenX = -1.0;
1412: double screenY = -1.0;
1413: if (this.zoomPoint != null) {
1414: screenX = this.zoomPoint.getX();
1415: screenY = this.zoomPoint.getY();
1416: }
1417:
1418: if (command.equals(PROPERTIES_COMMAND)) {
1419: doEditChartProperties();
1420: }
1421: else if (command.equals(SAVE_COMMAND)) {
1422: try {
1423: doSaveAs();
1424: }
1425: catch (IOException e) {
1426: e.printStackTrace();
1427: }
1428: }
1429: else if (command.equals(PRINT_COMMAND)) {
1430: createChartPrintJob();
1431: }
1432: else if (command.equals(ZOOM_IN_BOTH_COMMAND)) {
1433: zoomInBoth(screenX, screenY);
1434: }
1435: else if (command.equals(ZOOM_IN_DOMAIN_COMMAND)) {
1436: zoomInDomain(screenX, screenY);
1437: }
1438: else if (command.equals(ZOOM_IN_RANGE_COMMAND)) {
1439: zoomInRange(screenX, screenY);
1440: }
1441: else if (command.equals(ZOOM_OUT_BOTH_COMMAND)) {
1442: zoomOutBoth(screenX, screenY);
1443: }
1444: else if (command.equals(ZOOM_OUT_DOMAIN_COMMAND)) {
1445: zoomOutDomain(screenX, screenY);
1446: }
1447: else if (command.equals(ZOOM_OUT_RANGE_COMMAND)) {
1448: zoomOutRange(screenX, screenY);
1449: }
1450: else if (command.equals(ZOOM_RESET_BOTH_COMMAND)) {
1451: restoreAutoBounds();
1452: }
1453: else if (command.equals(ZOOM_RESET_DOMAIN_COMMAND)) {
1454: restoreAutoDomainBounds();
1455: }
1456: else if (command.equals(ZOOM_RESET_RANGE_COMMAND)) {
1457: restoreAutoRangeBounds();
1458: }
1459:
1460: }
1461:
1462:
1469: public void mouseEntered(MouseEvent e) {
1470: if (!this.ownToolTipDelaysActive) {
1471: ToolTipManager ttm = ToolTipManager.sharedInstance();
1472:
1473: this.originalToolTipInitialDelay = ttm.getInitialDelay();
1474: ttm.setInitialDelay(this.ownToolTipInitialDelay);
1475:
1476: this.originalToolTipReshowDelay = ttm.getReshowDelay();
1477: ttm.setReshowDelay(this.ownToolTipReshowDelay);
1478:
1479: this.originalToolTipDismissDelay = ttm.getDismissDelay();
1480: ttm.setDismissDelay(this.ownToolTipDismissDelay);
1481:
1482: this.ownToolTipDelaysActive = true;
1483: }
1484: }
1485:
1486:
1493: public void mouseExited(MouseEvent e) {
1494: if (this.ownToolTipDelaysActive) {
1495:
1496: ToolTipManager ttm = ToolTipManager.sharedInstance();
1497: ttm.setInitialDelay(this.originalToolTipInitialDelay);
1498: ttm.setReshowDelay(this.originalToolTipReshowDelay);
1499: ttm.setDismissDelay(this.originalToolTipDismissDelay);
1500: this.ownToolTipDelaysActive = false;
1501: }
1502: }
1503:
1504:
1512: public void mousePressed(MouseEvent e) {
1513: if (this.zoomRectangle == null) {
1514: Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY());
1515: if (screenDataArea != null) {
1516: this.zoomPoint = getPointInRectangle(e.getX(), e.getY(),
1517: screenDataArea);
1518: }
1519: else {
1520: this.zoomPoint = null;
1521: }
1522: if (e.isPopupTrigger()) {
1523: if (this.popup != null) {
1524: displayPopupMenu(e.getX(), e.getY());
1525: }
1526: }
1527: }
1528: }
1529:
1530:
1540: private Point2D getPointInRectangle(int x, int y, Rectangle2D area) {
1541: double xx = Math.max(area.getMinX(), Math.min(x, area.getMaxX()));
1542: double yy = Math.max(area.getMinY(), Math.min(y, area.getMaxY()));
1543: return new Point2D.Double(xx, yy);
1544: }
1545:
1546:
1551: public void mouseDragged(MouseEvent e) {
1552:
1553:
1554: if (this.popup != null && this.popup.isShowing()) {
1555: return;
1556: }
1557:
1558: if (this.zoomPoint == null) {
1559: return;
1560: }
1561: Graphics2D g2 = (Graphics2D) getGraphics();
1562:
1563:
1564: drawZoomRectangle(g2);
1565:
1566: boolean hZoom = false;
1567: boolean vZoom = false;
1568: if (this.orientation == PlotOrientation.HORIZONTAL) {
1569: hZoom = this.rangeZoomable;
1570: vZoom = this.domainZoomable;
1571: }
1572: else {
1573: hZoom = this.domainZoomable;
1574: vZoom = this.rangeZoomable;
1575: }
1576: Rectangle2D scaledDataArea = getScreenDataArea(
1577: (int) this.zoomPoint.getX(), (int) this.zoomPoint.getY());
1578: if (hZoom && vZoom) {
1579:
1580: double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
1581: double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
1582: this.zoomRectangle = new Rectangle2D.Double(
1583: this.zoomPoint.getX(), this.zoomPoint.getY(),
1584: xmax - this.zoomPoint.getX(), ymax - this.zoomPoint.getY());
1585: }
1586: else if (hZoom) {
1587: double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
1588: this.zoomRectangle = new Rectangle2D.Double(
1589: this.zoomPoint.getX(), scaledDataArea.getMinY(),
1590: xmax - this.zoomPoint.getX(), scaledDataArea.getHeight());
1591: }
1592: else if (vZoom) {
1593: double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
1594: this.zoomRectangle = new Rectangle2D.Double(
1595: scaledDataArea.getMinX(), this.zoomPoint.getY(),
1596: scaledDataArea.getWidth(), ymax - this.zoomPoint.getY());
1597: }
1598:
1599:
1600: drawZoomRectangle(g2);
1601:
1602: g2.dispose();
1603:
1604: }
1605:
1606:
1613: public void mouseReleased(MouseEvent e) {
1614:
1615: if (this.zoomRectangle != null) {
1616: boolean hZoom = false;
1617: boolean vZoom = false;
1618: if (this.orientation == PlotOrientation.HORIZONTAL) {
1619: hZoom = this.rangeZoomable;
1620: vZoom = this.domainZoomable;
1621: }
1622: else {
1623: hZoom = this.domainZoomable;
1624: vZoom = this.rangeZoomable;
1625: }
1626:
1627: boolean zoomTrigger1 = hZoom && Math.abs(e.getX()
1628: - this.zoomPoint.getX()) >= this.zoomTriggerDistance;
1629: boolean zoomTrigger2 = vZoom && Math.abs(e.getY()
1630: - this.zoomPoint.getY()) >= this.zoomTriggerDistance;
1631: if (zoomTrigger1 || zoomTrigger2) {
1632: if ((hZoom && (e.getX() < this.zoomPoint.getX()))
1633: || (vZoom && (e.getY() < this.zoomPoint.getY()))) {
1634: restoreAutoBounds();
1635: }
1636: else {
1637: double x, y, w, h;
1638: Rectangle2D screenDataArea = getScreenDataArea(
1639: (int) this.zoomPoint.getX(),
1640: (int) this.zoomPoint.getY());
1641: double maxX = screenDataArea.getMaxX();
1642: double maxY = screenDataArea.getMaxY();
1643:
1644:
1645:
1646: if (!vZoom) {
1647: x = this.zoomPoint.getX();
1648: y = screenDataArea.getMinY();
1649: w = Math.min(this.zoomRectangle.getWidth(),
1650: maxX - this.zoomPoint.getX());
1651: h = screenDataArea.getHeight();
1652: }
1653: else if (!hZoom) {
1654: x = screenDataArea.getMinX();
1655: y = this.zoomPoint.getY();
1656: w = screenDataArea.getWidth();
1657: h = Math.min(this.zoomRectangle.getHeight(),
1658: maxY - this.zoomPoint.getY());
1659: }
1660: else {
1661: x = this.zoomPoint.getX();
1662: y = this.zoomPoint.getY();
1663: w = Math.min(this.zoomRectangle.getWidth(),
1664: maxX - this.zoomPoint.getX());
1665: h = Math.min(this.zoomRectangle.getHeight(),
1666: maxY - this.zoomPoint.getY());
1667: }
1668: Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
1669: zoom(zoomArea);
1670: }
1671: this.zoomPoint = null;
1672: this.zoomRectangle = null;
1673: }
1674: else {
1675:
1676: Graphics2D g2 = (Graphics2D) getGraphics();
1677: drawZoomRectangle(g2);
1678: g2.dispose();
1679: this.zoomPoint = null;
1680: this.zoomRectangle = null;
1681: }
1682:
1683: }
1684:
1685: else if (e.isPopupTrigger()) {
1686: if (this.popup != null) {
1687: displayPopupMenu(e.getX(), e.getY());
1688: }
1689: }
1690:
1691: }
1692:
1693:
1699: public void mouseClicked(MouseEvent event) {
1700:
1701: Insets insets = getInsets();
1702: int x = (int) ((event.getX() - insets.left) / this.scaleX);
1703: int y = (int) ((event.getY() - insets.top) / this.scaleY);
1704:
1705: this.anchor = new Point2D.Double(x, y);
1706: if (this.chart == null) {
1707: return;
1708: }
1709: this.chart.setNotify(true);
1710:
1711: Object[] listeners = this.chartMouseListeners.getListeners(
1712: ChartMouseListener.class);
1713: if (listeners.length == 0) {
1714: return;
1715: }
1716:
1717: ChartEntity entity = null;
1718: if (this.info != null) {
1719: EntityCollection entities = this.info.getEntityCollection();
1720: if (entities != null) {
1721: entity = entities.getEntity(x, y);
1722: }
1723: }
1724: ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), event,
1725: entity);
1726: for (int i = listeners.length - 1; i >= 0; i -= 1) {
1727: ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent);
1728: }
1729:
1730: }
1731:
1732:
1737: public void mouseMoved(MouseEvent e) {
1738: Graphics2D g2 = (Graphics2D) getGraphics();
1739: if (this.horizontalAxisTrace) {
1740: drawHorizontalAxisTrace(g2, e.getX());
1741: }
1742: if (this.verticalAxisTrace) {
1743: drawVerticalAxisTrace(g2, e.getY());
1744: }
1745: g2.dispose();
1746:
1747: Object[] listeners = this.chartMouseListeners.getListeners(
1748: ChartMouseListener.class);
1749: if (listeners.length == 0) {
1750: return;
1751: }
1752: Insets insets = getInsets();
1753: int x = (int) ((e.getX() - insets.left) / this.scaleX);
1754: int y = (int) ((e.getY() - insets.top) / this.scaleY);
1755:
1756: ChartEntity entity = null;
1757: if (this.info != null) {
1758: EntityCollection entities = this.info.getEntityCollection();
1759: if (entities != null) {
1760: entity = entities.getEntity(x, y);
1761: }
1762: }
1763:
1764:
1765:
1766: if (this.chart != null) {
1767: ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity);
1768: for (int i = listeners.length - 1; i >= 0; i -= 1) {
1769: ((ChartMouseListener) listeners[i]).chartMouseMoved(event);
1770: }
1771: }
1772:
1773: }
1774:
1775:
1781: public void zoomInBoth(double x, double y) {
1782: zoomInDomain(x, y);
1783: zoomInRange(x, y);
1784: }
1785:
1786:
1794: public void zoomInDomain(double x, double y) {
1795: Plot p = this.chart.getPlot();
1796: if (p instanceof Zoomable) {
1797: Zoomable plot = (Zoomable) p;
1798: plot.zoomDomainAxes(this.zoomInFactor, this.info.getPlotInfo(),
1799: translateScreenToJava2D(new Point((int) x, (int) y)),
1800: this.zoomAroundAnchor);
1801: }
1802: }
1803:
1804:
1812: public void zoomInRange(double x, double y) {
1813: Plot p = this.chart.getPlot();
1814: if (p instanceof Zoomable) {
1815: Zoomable z = (Zoomable) p;
1816: z.zoomRangeAxes(this.zoomInFactor, this.info.getPlotInfo(),
1817: translateScreenToJava2D(new Point((int) x, (int) y)),
1818: this.zoomAroundAnchor);
1819: }
1820: }
1821:
1822:
1828: public void zoomOutBoth(double x, double y) {
1829: zoomOutDomain(x, y);
1830: zoomOutRange(x, y);
1831: }
1832:
1833:
1841: public void zoomOutDomain(double x, double y) {
1842: Plot p = this.chart.getPlot();
1843: if (p instanceof Zoomable) {
1844: Zoomable z = (Zoomable) p;
1845: z.zoomDomainAxes(this.zoomOutFactor, this.info.getPlotInfo(),
1846: translateScreenToJava2D(new Point((int) x, (int) y)),
1847: this.zoomAroundAnchor);
1848: }
1849: }
1850:
1851:
1859: public void zoomOutRange(double x, double y) {
1860: Plot p = this.chart.getPlot();
1861: if (p instanceof Zoomable) {
1862: Zoomable z = (Zoomable) p;
1863: z.zoomRangeAxes(this.zoomOutFactor, this.info.getPlotInfo(),
1864: translateScreenToJava2D(new Point((int) x, (int) y)),
1865: this.zoomAroundAnchor);
1866: }
1867: }
1868:
1869:
1874: public void zoom(Rectangle2D selection) {
1875:
1876:
1877:
1878: Point2D selectOrigin = translateScreenToJava2D(new Point(
1879: (int) Math.ceil(selection.getX()),
1880: (int) Math.ceil(selection.getY())));
1881: PlotRenderingInfo plotInfo = this.info.getPlotInfo();
1882: Rectangle2D scaledDataArea = getScreenDataArea(
1883: (int) selection.getCenterX(), (int) selection.getCenterY());
1884: if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) {
1885:
1886: double hLower = (selection.getMinX() - scaledDataArea.getMinX())
1887: / scaledDataArea.getWidth();
1888: double hUpper = (selection.getMaxX() - scaledDataArea.getMinX())
1889: / scaledDataArea.getWidth();
1890: double vLower = (scaledDataArea.getMaxY() - selection.getMaxY())
1891: / scaledDataArea.getHeight();
1892: double vUpper = (scaledDataArea.getMaxY() - selection.getMinY())
1893: / scaledDataArea.getHeight();
1894:
1895: Plot p = this.chart.getPlot();
1896: if (p instanceof Zoomable) {
1897: Zoomable z = (Zoomable) p;
1898: if (z.getOrientation() == PlotOrientation.HORIZONTAL) {
1899: z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin);
1900: z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin);
1901: }
1902: else {
1903: z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin);
1904: z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin);
1905: }
1906: }
1907:
1908: }
1909:
1910: }
1911:
1912:
1915: public void restoreAutoBounds() {
1916: restoreAutoDomainBounds();
1917: restoreAutoRangeBounds();
1918: }
1919:
1920:
1923: public void restoreAutoDomainBounds() {
1924: Plot p = this.chart.getPlot();
1925: if (p instanceof Zoomable) {
1926: Zoomable z = (Zoomable) p;
1927:
1928: Point2D zp = (this.zoomPoint != null
1929: ? this.zoomPoint : new Point());
1930: z.zoomDomainAxes(0.0, this.info.getPlotInfo(), zp);
1931: }
1932: }
1933:
1934:
1937: public void restoreAutoRangeBounds() {
1938: Plot p = this.chart.getPlot();
1939: if (p instanceof Zoomable) {
1940: Zoomable z = (Zoomable) p;
1941:
1942: Point2D zp = (this.zoomPoint != null
1943: ? this.zoomPoint : new Point());
1944: z.zoomRangeAxes(0.0, this.info.getPlotInfo(), zp);
1945: }
1946: }
1947:
1948:
1954: public Rectangle2D getScreenDataArea() {
1955: Rectangle2D dataArea = this.info.getPlotInfo().getDataArea();
1956: Insets insets = getInsets();
1957: double x = dataArea.getX() * this.scaleX + insets.left;
1958: double y = dataArea.getY() * this.scaleY + insets.top;
1959: double w = dataArea.getWidth() * this.scaleX;
1960: double h = dataArea.getHeight() * this.scaleY;
1961: return new Rectangle2D.Double(x, y, w, h);
1962: }
1963:
1964:
1973: public Rectangle2D getScreenDataArea(int x, int y) {
1974: PlotRenderingInfo plotInfo = this.info.getPlotInfo();
1975: Rectangle2D result;
1976: if (plotInfo.getSubplotCount() == 0) {
1977: result = getScreenDataArea();
1978: }
1979: else {
1980:
1981:
1982: Point2D selectOrigin = translateScreenToJava2D(new Point(x, y));
1983: int subplotIndex = plotInfo.getSubplotIndex(selectOrigin);
1984: if (subplotIndex == -1) {
1985: return null;
1986: }
1987: result = scale(plotInfo.getSubplotInfo(subplotIndex).getDataArea());
1988: }
1989: return result;
1990: }
1991:
1992:
1999: public int getInitialDelay() {
2000: return this.ownToolTipInitialDelay;
2001: }
2002:
2003:
2010: public int getReshowDelay() {
2011: return this.ownToolTipReshowDelay;
2012: }
2013:
2014:
2022: public int getDismissDelay() {
2023: return this.ownToolTipDismissDelay;
2024: }
2025:
2026:
2034: public void setInitialDelay(int delay) {
2035: this.ownToolTipInitialDelay = delay;
2036: }
2037:
2038:
2046: public void setReshowDelay(int delay) {
2047: this.ownToolTipReshowDelay = delay;
2048: }
2049:
2050:
2058: public void setDismissDelay(int delay) {
2059: this.ownToolTipDismissDelay = delay;
2060: }
2061:
2062:
2069: public double getZoomInFactor() {
2070: return this.zoomInFactor;
2071: }
2072:
2073:
2080: public void setZoomInFactor(double factor) {
2081: this.zoomInFactor = factor;
2082: }
2083:
2084:
2091: public double getZoomOutFactor() {
2092: return this.zoomOutFactor;
2093: }
2094:
2095:
2102: public void setZoomOutFactor(double factor) {
2103: this.zoomOutFactor = factor;
2104: }
2105:
2106:
2115: private void drawZoomRectangle(Graphics2D g2) {
2116:
2117: g2.setXORMode(Color.gray);
2118: if (this.zoomRectangle != null) {
2119: if (this.fillZoomRectangle) {
2120: g2.fill(this.zoomRectangle);
2121: }
2122: else {
2123: g2.draw(this.zoomRectangle);
2124: }
2125: }
2126:
2127: g2.setPaintMode();
2128: }
2129:
2130:
2137: private void drawHorizontalAxisTrace(Graphics2D g2, int x) {
2138:
2139: Rectangle2D dataArea = getScreenDataArea();
2140:
2141: g2.setXORMode(Color.orange);
2142: if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) {
2143:
2144: if (this.verticalTraceLine != null) {
2145: g2.draw(this.verticalTraceLine);
2146: this.verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x,
2147: (int) dataArea.getMaxY());
2148: }
2149: else {
2150: this.verticalTraceLine = new Line2D.Float(x,
2151: (int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
2152: }
2153: g2.draw(this.verticalTraceLine);
2154: }
2155:
2156:
2157: g2.setPaintMode();
2158: }
2159:
2160:
2167: private void drawVerticalAxisTrace(Graphics2D g2, int y) {
2168:
2169: Rectangle2D dataArea = getScreenDataArea();
2170:
2171: g2.setXORMode(Color.orange);
2172: if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) {
2173:
2174: if (this.horizontalTraceLine != null) {
2175: g2.draw(this.horizontalTraceLine);
2176: this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y,
2177: (int) dataArea.getMaxX(), y);
2178: }
2179: else {
2180: this.horizontalTraceLine = new Line2D.Float(
2181: (int) dataArea.getMinX(), y, (int) dataArea.getMaxX(),
2182: y);
2183: }
2184: g2.draw(this.horizontalTraceLine);
2185: }
2186:
2187:
2188: g2.setPaintMode();
2189: }
2190:
2191:
2197: public void doEditChartProperties() {
2198:
2199: ChartEditor editor = ChartEditorManager.getChartEditor(this.chart);
2200: int result = JOptionPane.showConfirmDialog(this, editor,
2201: localizationResources.getString("Chart_Properties"),
2202: JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
2203: if (result == JOptionPane.OK_OPTION) {
2204: editor.updateChart(this.chart);
2205: }
2206:
2207: }
2208:
2209:
2215: public void doSaveAs() throws IOException {
2216:
2217: JFileChooser fileChooser = new JFileChooser();
2218: fileChooser.setCurrentDirectory(this.defaultDirectoryForSaveAs);
2219: ExtensionFileFilter filter = new ExtensionFileFilter(
2220: localizationResources.getString("PNG_Image_Files"), ".png");
2221: fileChooser.addChoosableFileFilter(filter);
2222:
2223: int option = fileChooser.showSaveDialog(this);
2224: if (option == JFileChooser.APPROVE_OPTION) {
2225: String filename = fileChooser.getSelectedFile().getPath();
2226: if (isEnforceFileExtensions()) {
2227: if (!filename.endsWith(".png")) {
2228: filename = filename + ".png";
2229: }
2230: }
2231: ChartUtilities.saveChartAsPNG(new File(filename), this.chart,
2232: getWidth(), getHeight());
2233: }
2234:
2235: }
2236:
2237:
2240: public void createChartPrintJob() {
2241:
2242: PrinterJob job = PrinterJob.getPrinterJob();
2243: PageFormat pf = job.defaultPage();
2244: PageFormat pf2 = job.pageDialog(pf);
2245: if (pf2 != pf) {
2246: job.setPrintable(this, pf2);
2247: if (job.printDialog()) {
2248: try {
2249: job.print();
2250: }
2251: catch (PrinterException e) {
2252: JOptionPane.showMessageDialog(this, e);
2253: }
2254: }
2255: }
2256:
2257: }
2258:
2259:
2269: public int print(Graphics g, PageFormat pf, int pageIndex) {
2270:
2271: if (pageIndex != 0) {
2272: return NO_SUCH_PAGE;
2273: }
2274: Graphics2D g2 = (Graphics2D) g;
2275: double x = pf.getImageableX();
2276: double y = pf.getImageableY();
2277: double w = pf.getImageableWidth();
2278: double h = pf.getImageableHeight();
2279: this.chart.draw(g2, new Rectangle2D.Double(x, y, w, h), this.anchor,
2280: null);
2281: return PAGE_EXISTS;
2282:
2283: }
2284:
2285:
2290: public void addChartMouseListener(ChartMouseListener listener) {
2291: if (listener == null) {
2292: throw new IllegalArgumentException("Null 'listener' argument.");
2293: }
2294: this.chartMouseListeners.add(ChartMouseListener.class, listener);
2295: }
2296:
2297:
2303: public void removeChartMouseListener(ChartMouseListener listener) {
2304: this.chartMouseListeners.remove(ChartMouseListener.class, listener);
2305: }
2306:
2307:
2315: public EventListener[] getListeners(Class listenerType) {
2316: if (listenerType == ChartMouseListener.class) {
2317:
2318: return this.chartMouseListeners.getListeners(listenerType);
2319: }
2320: else {
2321: return super.getListeners(listenerType);
2322: }
2323: }
2324:
2325:
2335: protected JPopupMenu createPopupMenu(boolean properties,
2336: boolean save,
2337: boolean print,
2338: boolean zoom) {
2339:
2340: JPopupMenu result = new JPopupMenu("Chart:");
2341: boolean separator = false;
2342:
2343: if (properties) {
2344: JMenuItem propertiesItem = new JMenuItem(
2345: localizationResources.getString("Properties..."));
2346: propertiesItem.setActionCommand(PROPERTIES_COMMAND);
2347: propertiesItem.addActionListener(this);
2348: result.add(propertiesItem);
2349: separator = true;
2350: }
2351:
2352: if (save) {
2353: if (separator) {
2354: result.addSeparator();
2355: separator = false;
2356: }
2357: JMenuItem saveItem = new JMenuItem(
2358: localizationResources.getString("Save_as..."));
2359: saveItem.setActionCommand(SAVE_COMMAND);
2360: saveItem.addActionListener(this);
2361: result.add(saveItem);
2362: separator = true;
2363: }
2364:
2365: if (print) {
2366: if (separator) {
2367: result.addSeparator();
2368: separator = false;
2369: }
2370: JMenuItem printItem = new JMenuItem(
2371: localizationResources.getString("Print..."));
2372: printItem.setActionCommand(PRINT_COMMAND);
2373: printItem.addActionListener(this);
2374: result.add(printItem);
2375: separator = true;
2376: }
2377:
2378: if (zoom) {
2379: if (separator) {
2380: result.addSeparator();
2381: separator = false;
2382: }
2383:
2384: JMenu zoomInMenu = new JMenu(
2385: localizationResources.getString("Zoom_In"));
2386:
2387: this.zoomInBothMenuItem = new JMenuItem(
2388: localizationResources.getString("All_Axes"));
2389: this.zoomInBothMenuItem.setActionCommand(ZOOM_IN_BOTH_COMMAND);
2390: this.zoomInBothMenuItem.addActionListener(this);
2391: zoomInMenu.add(this.zoomInBothMenuItem);
2392:
2393: zoomInMenu.addSeparator();
2394:
2395: this.zoomInDomainMenuItem = new JMenuItem(
2396: localizationResources.getString("Domain_Axis"));
2397: this.zoomInDomainMenuItem.setActionCommand(ZOOM_IN_DOMAIN_COMMAND);
2398: this.zoomInDomainMenuItem.addActionListener(this);
2399: zoomInMenu.add(this.zoomInDomainMenuItem);
2400:
2401: this.zoomInRangeMenuItem = new JMenuItem(
2402: localizationResources.getString("Range_Axis"));
2403: this.zoomInRangeMenuItem.setActionCommand(ZOOM_IN_RANGE_COMMAND);
2404: this.zoomInRangeMenuItem.addActionListener(this);
2405: zoomInMenu.add(this.zoomInRangeMenuItem);
2406:
2407: result.add(zoomInMenu);
2408:
2409: JMenu zoomOutMenu = new JMenu(
2410: localizationResources.getString("Zoom_Out"));
2411:
2412: this.zoomOutBothMenuItem = new JMenuItem(
2413: localizationResources.getString("All_Axes"));
2414: this.zoomOutBothMenuItem.setActionCommand(ZOOM_OUT_BOTH_COMMAND);
2415: this.zoomOutBothMenuItem.addActionListener(this);
2416: zoomOutMenu.add(this.zoomOutBothMenuItem);
2417:
2418: zoomOutMenu.addSeparator();
2419:
2420: this.zoomOutDomainMenuItem = new JMenuItem(
2421: localizationResources.getString("Domain_Axis"));
2422: this.zoomOutDomainMenuItem.setActionCommand(
2423: ZOOM_OUT_DOMAIN_COMMAND);
2424: this.zoomOutDomainMenuItem.addActionListener(this);
2425: zoomOutMenu.add(this.zoomOutDomainMenuItem);
2426:
2427: this.zoomOutRangeMenuItem = new JMenuItem(
2428: localizationResources.getString("Range_Axis"));
2429: this.zoomOutRangeMenuItem.setActionCommand(ZOOM_OUT_RANGE_COMMAND);
2430: this.zoomOutRangeMenuItem.addActionListener(this);
2431: zoomOutMenu.add(this.zoomOutRangeMenuItem);
2432:
2433: result.add(zoomOutMenu);
2434:
2435: JMenu autoRangeMenu = new JMenu(
2436: localizationResources.getString("Auto_Range"));
2437:
2438: this.zoomResetBothMenuItem = new JMenuItem(
2439: localizationResources.getString("All_Axes"));
2440: this.zoomResetBothMenuItem.setActionCommand(
2441: ZOOM_RESET_BOTH_COMMAND);
2442: this.zoomResetBothMenuItem.addActionListener(this);
2443: autoRangeMenu.add(this.zoomResetBothMenuItem);
2444:
2445: autoRangeMenu.addSeparator();
2446: this.zoomResetDomainMenuItem = new JMenuItem(
2447: localizationResources.getString("Domain_Axis"));
2448: this.zoomResetDomainMenuItem.setActionCommand(
2449: ZOOM_RESET_DOMAIN_COMMAND);
2450: this.zoomResetDomainMenuItem.addActionListener(this);
2451: autoRangeMenu.add(this.zoomResetDomainMenuItem);
2452:
2453: this.zoomResetRangeMenuItem = new JMenuItem(
2454: localizationResources.getString("Range_Axis"));
2455: this.zoomResetRangeMenuItem.setActionCommand(
2456: ZOOM_RESET_RANGE_COMMAND);
2457: this.zoomResetRangeMenuItem.addActionListener(this);
2458: autoRangeMenu.add(this.zoomResetRangeMenuItem);
2459:
2460: result.addSeparator();
2461: result.add(autoRangeMenu);
2462:
2463: }
2464:
2465: return result;
2466:
2467: }
2468:
2469:
2476: protected void displayPopupMenu(int x, int y) {
2477:
2478: if (this.popup != null) {
2479:
2480:
2481:
2482: Plot plot = this.chart.getPlot();
2483: boolean isDomainZoomable = false;
2484: boolean isRangeZoomable = false;
2485: if (plot instanceof Zoomable) {
2486: Zoomable z = (Zoomable) plot;
2487: isDomainZoomable = z.isDomainZoomable();
2488: isRangeZoomable = z.isRangeZoomable();
2489: }
2490:
2491: if (this.zoomInDomainMenuItem != null) {
2492: this.zoomInDomainMenuItem.setEnabled(isDomainZoomable);
2493: }
2494: if (this.zoomOutDomainMenuItem != null) {
2495: this.zoomOutDomainMenuItem.setEnabled(isDomainZoomable);
2496: }
2497: if (this.zoomResetDomainMenuItem != null) {
2498: this.zoomResetDomainMenuItem.setEnabled(isDomainZoomable);
2499: }
2500:
2501: if (this.zoomInRangeMenuItem != null) {
2502: this.zoomInRangeMenuItem.setEnabled(isRangeZoomable);
2503: }
2504: if (this.zoomOutRangeMenuItem != null) {
2505: this.zoomOutRangeMenuItem.setEnabled(isRangeZoomable);
2506: }
2507:
2508: if (this.zoomResetRangeMenuItem != null) {
2509: this.zoomResetRangeMenuItem.setEnabled(isRangeZoomable);
2510: }
2511:
2512: if (this.zoomInBothMenuItem != null) {
2513: this.zoomInBothMenuItem.setEnabled(isDomainZoomable
2514: && isRangeZoomable);
2515: }
2516: if (this.zoomOutBothMenuItem != null) {
2517: this.zoomOutBothMenuItem.setEnabled(isDomainZoomable
2518: && isRangeZoomable);
2519: }
2520: if (this.zoomResetBothMenuItem != null) {
2521: this.zoomResetBothMenuItem.setEnabled(isDomainZoomable
2522: && isRangeZoomable);
2523: }
2524:
2525: this.popup.show(this, x, y);
2526: }
2527:
2528: }
2529:
2530:
2533: public void updateUI() {
2534:
2535:
2536: if (this.popup != null) {
2537: SwingUtilities.updateComponentTreeUI(this.popup);
2538: }
2539: super.updateUI();
2540: }
2541:
2542:
2549: private void writeObject(ObjectOutputStream stream) throws IOException {
2550: stream.defaultWriteObject();
2551: }
2552:
2553:
2561: private void readObject(ObjectInputStream stream)
2562: throws IOException, ClassNotFoundException {
2563: stream.defaultReadObject();
2564:
2565:
2566: this.chartMouseListeners = new EventListenerList();
2567:
2568:
2569: if (this.chart != null) {
2570: this.chart.addChangeListener(this);
2571: }
2572:
2573: }
2574:
2575:
2576: }