1:
128:
129: package ;
130:
131: import ;
132: import ;
133: import ;
134: import ;
135: import ;
136: import ;
137: import ;
138: import ;
139: import ;
140: import ;
141: import ;
142: import ;
143: import ;
144: import ;
145: import ;
146: import ;
147: import ;
148: import ;
149: import ;
150: import ;
151: import ;
152: import ;
153: import ;
154: import ;
155: import ;
156:
157: import ;
158: import ;
159: import ;
160: import ;
161: import ;
162: import ;
163: import ;
164: import ;
165:
166: import ;
167: import ;
168: import ;
169: import ;
170: import ;
171: import ;
172: import ;
173: import ;
174: import ;
175: import ;
176: import ;
177: import ;
178: import ;
179:
180:
187: public class ChartPanel extends JPanel
188: implements ChartChangeListener,
189: ChartProgressListener,
190: ActionListener,
191: MouseListener,
192: MouseMotionListener,
193: Printable,
194: Serializable {
195:
196:
197: private static final long serialVersionUID = 6046366297214274674L;
198:
199:
200: public static final boolean DEFAULT_BUFFER_USED = false;
201:
202:
203: public static final int DEFAULT_WIDTH = 680;
204:
205:
206: public static final int DEFAULT_HEIGHT = 420;
207:
208:
209: public static final int DEFAULT_MINIMUM_DRAW_WIDTH = 300;
210:
211:
212: public static final int DEFAULT_MINIMUM_DRAW_HEIGHT = 200;
213:
214:
215: public static final int DEFAULT_MAXIMUM_DRAW_WIDTH = 800;
216:
217:
218: public static final int DEFAULT_MAXIMUM_DRAW_HEIGHT = 600;
219:
220:
221: public static final int DEFAULT_ZOOM_TRIGGER_DISTANCE = 10;
222:
223:
224: public static final String PROPERTIES_COMMAND = "PROPERTIES";
225:
226:
227: public static final String SAVE_COMMAND = "SAVE";
228:
229:
230: public static final String PRINT_COMMAND = "PRINT";
231:
232:
233: public static final String ZOOM_IN_BOTH_COMMAND = "ZOOM_IN_BOTH";
234:
235:
236: public static final String ZOOM_IN_DOMAIN_COMMAND = "ZOOM_IN_DOMAIN";
237:
238:
239: public static final String ZOOM_IN_RANGE_COMMAND = "ZOOM_IN_RANGE";
240:
241:
242: public static final String ZOOM_OUT_BOTH_COMMAND = "ZOOM_OUT_BOTH";
243:
244:
245: public static final String ZOOM_OUT_DOMAIN_COMMAND = "ZOOM_DOMAIN_BOTH";
246:
247:
248: public static final String ZOOM_OUT_RANGE_COMMAND = "ZOOM_RANGE_BOTH";
249:
250:
251: public static final String ZOOM_RESET_BOTH_COMMAND = "ZOOM_RESET_BOTH";
252:
253:
254: public static final String ZOOM_RESET_DOMAIN_COMMAND = "ZOOM_RESET_DOMAIN";
255:
256:
257: public static final String ZOOM_RESET_RANGE_COMMAND = "ZOOM_RESET_RANGE";
258:
259:
260: private JFreeChart chart;
261:
262:
263: private EventListenerList chartMouseListeners;
264:
265:
266: private boolean useBuffer;
267:
268:
269: private boolean refreshBuffer;
270:
271:
272: private Image chartBuffer;
273:
274:
275: private int chartBufferHeight;
276:
277:
278: private int chartBufferWidth;
279:
280:
283: private int minimumDrawWidth;
284:
285:
289: private int minimumDrawHeight;
290:
291:
295: private int maximumDrawWidth;
296:
297:
301: private int maximumDrawHeight;
302:
303:
304: private JPopupMenu popup;
305:
306:
307: private ChartRenderingInfo info;
308:
309:
310: private Point2D anchor;
311:
312:
313: private double scaleX;
314:
315:
316: private double scaleY;
317:
318:
319: private PlotOrientation orientation = PlotOrientation.VERTICAL;
320:
321:
322: private boolean domainZoomable = false;
323:
324:
325: private boolean rangeZoomable = false;
326:
327:
332: private Point zoomPoint = null;
333:
334:
335: private transient Rectangle2D zoomRectangle = null;
336:
337:
338: private boolean fillZoomRectangle = false;
339:
340:
341: private int zoomTriggerDistance;
342:
343:
344: private boolean horizontalAxisTrace = false;
345:
346:
347: private boolean verticalAxisTrace = false;
348:
349:
350: private transient Line2D verticalTraceLine;
351:
352:
353: private transient Line2D horizontalTraceLine;
354:
355:
356: private JMenuItem zoomInBothMenuItem;
357:
358:
359: private JMenuItem zoomInDomainMenuItem;
360:
361:
362: private JMenuItem zoomInRangeMenuItem;
363:
364:
365: private JMenuItem zoomOutBothMenuItem;
366:
367:
368: private JMenuItem zoomOutDomainMenuItem;
369:
370:
371: private JMenuItem zoomOutRangeMenuItem;
372:
373:
374: private JMenuItem zoomResetBothMenuItem;
375:
376:
377: private JMenuItem zoomResetDomainMenuItem;
378:
379:
380: private JMenuItem zoomResetRangeMenuItem;
381:
382:
383: private boolean enforceFileExtensions;
384:
385:
386: private boolean ownToolTipDelaysActive;
387:
388:
389: private int originalToolTipInitialDelay;
390:
391:
392: private int originalToolTipReshowDelay;
393:
394:
395: private int originalToolTipDismissDelay;
396:
397:
398: private int ownToolTipInitialDelay;
399:
400:
401: private int ownToolTipReshowDelay;
402:
403:
404: private int ownToolTipDismissDelay;
405:
406:
407: private double zoomInFactor = 0.5;
408:
409:
410: private double zoomOutFactor = 2.0;
411:
412:
413: protected static ResourceBundle localizationResources
414: = ResourceBundle.getBundle("org.jfree.chart.LocalizationBundle");
415:
416:
421: public ChartPanel(JFreeChart chart) {
422:
423: this(
424: chart,
425: DEFAULT_WIDTH,
426: DEFAULT_HEIGHT,
427: DEFAULT_MINIMUM_DRAW_WIDTH,
428: DEFAULT_MINIMUM_DRAW_HEIGHT,
429: DEFAULT_MAXIMUM_DRAW_WIDTH,
430: DEFAULT_MAXIMUM_DRAW_HEIGHT,
431: DEFAULT_BUFFER_USED,
432: true,
433: true,
434: true,
435: true,
436: true
437: );
438:
439: }
440:
441:
448: public ChartPanel(JFreeChart chart, boolean useBuffer) {
449:
450: this(chart,
451: DEFAULT_WIDTH,
452: DEFAULT_HEIGHT,
453: DEFAULT_MINIMUM_DRAW_WIDTH,
454: DEFAULT_MINIMUM_DRAW_HEIGHT,
455: DEFAULT_MAXIMUM_DRAW_WIDTH,
456: DEFAULT_MAXIMUM_DRAW_HEIGHT,
457: useBuffer,
458: true,
459: true,
460: true,
461: true,
462: true
463: );
464:
465: }
466:
467:
482: public ChartPanel(JFreeChart chart,
483: boolean properties,
484: boolean save,
485: boolean print,
486: boolean zoom,
487: boolean tooltips) {
488:
489: this(chart,
490: DEFAULT_WIDTH,
491: DEFAULT_HEIGHT,
492: DEFAULT_MINIMUM_DRAW_WIDTH,
493: DEFAULT_MINIMUM_DRAW_HEIGHT,
494: DEFAULT_MAXIMUM_DRAW_WIDTH,
495: DEFAULT_MAXIMUM_DRAW_HEIGHT,
496: DEFAULT_BUFFER_USED,
497: properties,
498: save,
499: print,
500: zoom,
501: tooltips
502: );
503:
504: }
505:
506:
530: public ChartPanel(JFreeChart chart,
531: int width,
532: int height,
533: int minimumDrawWidth,
534: int minimumDrawHeight,
535: int maximumDrawWidth,
536: int maximumDrawHeight,
537: boolean useBuffer,
538: boolean properties,
539: boolean save,
540: boolean print,
541: boolean zoom,
542: boolean tooltips) {
543:
544: this.chart = chart;
545: this.chartMouseListeners = new EventListenerList();
546: if (chart != null) {
547: chart.addChangeListener(this);
548: Plot plot = chart.getPlot();
549: this.domainZoomable = false;
550: this.rangeZoomable = false;
551: if (plot instanceof Zoomable) {
552: Zoomable z = (Zoomable) plot;
553: this.domainZoomable = z.isDomainZoomable();
554: this.rangeZoomable = z.isRangeZoomable();
555: this.orientation = z.getOrientation();
556: }
557: }
558: this.info = new ChartRenderingInfo();
559: setPreferredSize(new Dimension(width, height));
560: this.useBuffer = useBuffer;
561: this.refreshBuffer = false;
562: this.minimumDrawWidth = minimumDrawWidth;
563: this.minimumDrawHeight = minimumDrawHeight;
564: this.maximumDrawWidth = maximumDrawWidth;
565: this.maximumDrawHeight = maximumDrawHeight;
566: this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE;
567:
568:
569: this.popup = null;
570: if (properties || save || print || zoom) {
571: this.popup = createPopupMenu(properties, save, print, zoom);
572: }
573:
574: enableEvents(AWTEvent.MOUSE_EVENT_MASK);
575: enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
576: setDisplayToolTips(tooltips);
577: addMouseListener(this);
578: addMouseMotionListener(this);
579:
580: this.enforceFileExtensions = true;
581:
582:
583:
584: ToolTipManager ttm = ToolTipManager.sharedInstance();
585: this.ownToolTipInitialDelay = ttm.getInitialDelay();
586: this.ownToolTipDismissDelay = ttm.getDismissDelay();
587: this.ownToolTipReshowDelay = ttm.getReshowDelay();
588:
589: }
590:
591:
596: public JFreeChart getChart() {
597: return this.chart;
598: }
599:
600:
605: public void setChart(JFreeChart chart) {
606:
607:
608: if (this.chart != null) {
609: this.chart.removeChangeListener(this);
610: this.chart.removeProgressListener(this);
611: }
612:
613:
614: this.chart = chart;
615: if (chart != null) {
616: this.chart.addChangeListener(this);
617: this.chart.addProgressListener(this);
618: Plot plot = chart.getPlot();
619: this.domainZoomable = false;
620: this.rangeZoomable = false;
621: if (plot instanceof Zoomable) {
622: Zoomable z = (Zoomable) plot;
623: this.domainZoomable = z.isDomainZoomable();
624: this.rangeZoomable = z.isRangeZoomable();
625: this.orientation = z.getOrientation();
626: }
627: }
628: else {
629: this.domainZoomable = false;
630: this.rangeZoomable = false;
631: }
632: if (this.useBuffer) {
633: this.refreshBuffer = true;
634: }
635: repaint();
636:
637: }
638:
639:
647: public int getMinimumDrawWidth() {
648: return this.minimumDrawWidth;
649: }
650:
651:
660: public void setMinimumDrawWidth(int width) {
661: this.minimumDrawWidth = width;
662: }
663:
664:
672: public int getMaximumDrawWidth() {
673: return this.maximumDrawWidth;
674: }
675:
676:
685: public void setMaximumDrawWidth(int width) {
686: this.maximumDrawWidth = width;
687: }
688:
689:
697: public int getMinimumDrawHeight() {
698: return this.minimumDrawHeight;
699: }
700:
701:
710: public void setMinimumDrawHeight(int height) {
711: this.minimumDrawHeight = height;
712: }
713:
714:
722: public int getMaximumDrawHeight() {
723: return this.maximumDrawHeight;
724: }
725:
726:
735: public void setMaximumDrawHeight(int height) {
736: this.maximumDrawHeight = height;
737: }
738:
739:
745: public double getScaleX() {
746: return this.scaleX;
747: }
748:
749:
755: public double getScaleY() {
756: return this.scaleY;
757: }
758:
759:
764: public Point2D getAnchor() {
765: return this.anchor;
766: }
767:
768:
774: protected void setAnchor(Point2D anchor) {
775: this.anchor = anchor;
776: }
777:
778:
783: public JPopupMenu getPopupMenu() {
784: return this.popup;
785: }
786:
787:
792: public void setPopupMenu(JPopupMenu popup) {
793: this.popup = popup;
794: }
795:
796:
801: public ChartRenderingInfo getChartRenderingInfo() {
802: return this.info;
803: }
804:
805:
811: public void setMouseZoomable(boolean flag) {
812: setMouseZoomable(flag, true);
813: }
814:
815:
822: public void setMouseZoomable(boolean flag, boolean fillRectangle) {
823: setDomainZoomable(flag);
824: setRangeZoomable(flag);
825: setFillZoomRectangle(fillRectangle);
826: }
827:
828:
834: public boolean isDomainZoomable() {
835: return this.domainZoomable;
836: }
837:
838:
845: public void setDomainZoomable(boolean flag) {
846: if (flag) {
847: Plot plot = this.chart.getPlot();
848: if (plot instanceof Zoomable) {
849: Zoomable z = (Zoomable) plot;
850: this.domainZoomable = flag && (z.isDomainZoomable());
851: }
852: }
853: else {
854: this.domainZoomable = false;
855: }
856: }
857:
858:
864: public boolean isRangeZoomable() {
865: return this.rangeZoomable;
866: }
867:
868:
873: public void setRangeZoomable(boolean flag) {
874: if (flag) {
875: Plot plot = this.chart.getPlot();
876: if (plot instanceof Zoomable) {
877: Zoomable z = (Zoomable) plot;
878: this.rangeZoomable = flag && (z.isRangeZoomable());
879: }
880: }
881: else {
882: this.rangeZoomable = false;
883: }
884: }
885:
886:
892: public boolean getFillZoomRectangle() {
893: return this.fillZoomRectangle;
894: }
895:
896:
902: public void setFillZoomRectangle(boolean flag) {
903: this.fillZoomRectangle = flag;
904: }
905:
906:
912: public int getZoomTriggerDistance() {
913: return this.zoomTriggerDistance;
914: }
915:
916:
922: public void setZoomTriggerDistance(int distance) {
923: this.zoomTriggerDistance = distance;
924: }
925:
926:
932: public boolean getHorizontalAxisTrace() {
933: return this.horizontalAxisTrace;
934: }
935:
936:
942: public void setHorizontalAxisTrace(boolean flag) {
943: this.horizontalAxisTrace = flag;
944: }
945:
946:
951: protected Line2D getHorizontalTraceLine() {
952: return this.horizontalTraceLine;
953: }
954:
955:
960: protected void setHorizontalTraceLine(Line2D line) {
961: this.horizontalTraceLine = line;
962: }
963:
964:
970: public boolean getVerticalAxisTrace() {
971: return this.verticalAxisTrace;
972: }
973:
974:
980: public void setVerticalAxisTrace(boolean flag) {
981: this.verticalAxisTrace = flag;
982: }
983:
984:
989: protected Line2D getVerticalTraceLine() {
990: return this.verticalTraceLine;
991: }
992:
993:
998: protected void setVerticalTraceLine(Line2D line) {
999: this.verticalTraceLine = line;
1000: }
1001:
1002:
1008: public boolean isEnforceFileExtensions() {
1009: return this.enforceFileExtensions;
1010: }
1011:
1012:
1017: public void setEnforceFileExtensions(boolean enforce) {
1018: this.enforceFileExtensions = enforce;
1019: }
1020:
1021:
1029: public void setDisplayToolTips(boolean flag) {
1030: if (flag) {
1031: ToolTipManager.sharedInstance().registerComponent(this);
1032: }
1033: else {
1034: ToolTipManager.sharedInstance().unregisterComponent(this);
1035: }
1036: }
1037:
1038:
1045: public String getToolTipText(MouseEvent e) {
1046:
1047: String result = null;
1048: if (this.info != null) {
1049: EntityCollection entities = this.info.getEntityCollection();
1050: if (entities != null) {
1051: Insets insets = getInsets();
1052: ChartEntity entity = entities.getEntity(
1053: (int) ((e.getX() - insets.left) / this.scaleX),
1054: (int) ((e.getY() - insets.top) / this.scaleY)
1055: );
1056: if (entity != null) {
1057: result = entity.getToolTipText();
1058: }
1059: }
1060: }
1061: return result;
1062:
1063: }
1064:
1065:
1072: public Point translateJava2DToScreen(Point2D java2DPoint) {
1073: Insets insets = getInsets();
1074: int x = (int) (java2DPoint.getX() * this.scaleX + insets.left);
1075: int y = (int) (java2DPoint.getY() * this.scaleY + insets.top);
1076: return new Point(x, y);
1077: }
1078:
1079:
1086: public Point2D translateScreenToJava2D(Point screenPoint) {
1087: Insets insets = getInsets();
1088: double x = (screenPoint.getX() - insets.left) / this.scaleX;
1089: double y = (screenPoint.getY() - insets.top) / this.scaleY;
1090: return new Point2D.Double(x, y);
1091: }
1092:
1093:
1101: public Rectangle2D scale(Rectangle2D rect) {
1102: Insets insets = getInsets();
1103: double x = rect.getX() * getScaleX() + insets.left;
1104: double y = rect.getY() * this.getScaleY() + insets.top;
1105: double w = rect.getWidth() * this.getScaleX();
1106: double h = rect.getHeight() * this.getScaleY();
1107: return new Rectangle2D.Double(x, y, w, h);
1108: }
1109:
1110:
1121: public ChartEntity getEntityForPoint(int viewX, int viewY) {
1122:
1123: ChartEntity result = null;
1124: if (this.info != null) {
1125: Insets insets = getInsets();
1126: double x = (viewX - insets.left) / this.scaleX;
1127: double y = (viewY - insets.top) / this.scaleY;
1128: EntityCollection entities = this.info.getEntityCollection();
1129: result = entities != null ? entities.getEntity(x, y) : null;
1130: }
1131: return result;
1132:
1133: }
1134:
1135:
1141: public boolean getRefreshBuffer() {
1142: return this.refreshBuffer;
1143: }
1144:
1145:
1152: public void setRefreshBuffer(boolean flag) {
1153: this.refreshBuffer = flag;
1154: }
1155:
1156:
1164: public void paintComponent(Graphics g) {
1165: super.paintComponent(g);
1166: if (this.chart == null) {
1167: return;
1168: }
1169: Graphics2D g2 = (Graphics2D) g.create();
1170:
1171:
1172: Dimension size = getSize();
1173: Insets insets = getInsets();
1174: Rectangle2D available = new Rectangle2D.Double(
1175: insets.left, insets.top,
1176: size.getWidth() - insets.left - insets.right,
1177: size.getHeight() - insets.top - insets.bottom
1178: );
1179:
1180:
1181: boolean scale = false;
1182: double drawWidth = available.getWidth();
1183: double drawHeight = available.getHeight();
1184: this.scaleX = 1.0;
1185: this.scaleY = 1.0;
1186:
1187: if (drawWidth < this.minimumDrawWidth) {
1188: this.scaleX = drawWidth / this.minimumDrawWidth;
1189: drawWidth = this.minimumDrawWidth;
1190: scale = true;
1191: }
1192: else if (drawWidth > this.maximumDrawWidth) {
1193: this.scaleX = drawWidth / this.maximumDrawWidth;
1194: drawWidth = this.maximumDrawWidth;
1195: scale = true;
1196: }
1197:
1198: if (drawHeight < this.minimumDrawHeight) {
1199: this.scaleY = drawHeight / this.minimumDrawHeight;
1200: drawHeight = this.minimumDrawHeight;
1201: scale = true;
1202: }
1203: else if (drawHeight > this.maximumDrawHeight) {
1204: this.scaleY = drawHeight / this.maximumDrawHeight;
1205: drawHeight = this.maximumDrawHeight;
1206: scale = true;
1207: }
1208:
1209: Rectangle2D chartArea = new Rectangle2D.Double(
1210: 0.0, 0.0, drawWidth, drawHeight
1211: );
1212:
1213:
1214: if (this.useBuffer) {
1215:
1216:
1217: if ((this.chartBuffer == null)
1218: || (this.chartBufferWidth != available.getWidth())
1219: || (this.chartBufferHeight != available.getHeight())
1220: ) {
1221: this.chartBufferWidth = (int) available.getWidth();
1222: this.chartBufferHeight = (int) available.getHeight();
1223: this.chartBuffer = createImage(
1224: this.chartBufferWidth, this.chartBufferHeight
1225: );
1226: this.refreshBuffer = true;
1227: }
1228:
1229:
1230: if (this.refreshBuffer) {
1231:
1232: Rectangle2D bufferArea = new Rectangle2D.Double(
1233: 0, 0, this.chartBufferWidth, this.chartBufferHeight
1234: );
1235:
1236: Graphics2D bufferG2
1237: = (Graphics2D) this.chartBuffer.getGraphics();
1238: if (scale) {
1239: AffineTransform saved = bufferG2.getTransform();
1240: AffineTransform st = AffineTransform.getScaleInstance(
1241: this.scaleX, this.scaleY
1242: );
1243: bufferG2.transform(st);
1244: this.chart.draw(
1245: bufferG2, chartArea, this.anchor, this.info
1246: );
1247: bufferG2.setTransform(saved);
1248: }
1249: else {
1250: this.chart.draw(
1251: bufferG2, bufferArea, this.anchor, this.info
1252: );
1253: }
1254:
1255: this.refreshBuffer = false;
1256:
1257: }
1258:
1259:
1260: g2.drawImage(this.chartBuffer, insets.left, insets.right, this);
1261:
1262: }
1263:
1264:
1265: else {
1266:
1267: AffineTransform saved = g2.getTransform();
1268: g2.translate(insets.left, insets.top);
1269: if (scale) {
1270: AffineTransform st = AffineTransform.getScaleInstance(
1271: this.scaleX, this.scaleY
1272: );
1273: g2.transform(st);
1274: }
1275: this.chart.draw(g2, chartArea, this.anchor, this.info);
1276: g2.setTransform(saved);
1277:
1278: }
1279:
1280: this.anchor = null;
1281: this.verticalTraceLine = null;
1282: this.horizontalTraceLine = null;
1283:
1284: }
1285:
1286:
1291: public void chartChanged(ChartChangeEvent event) {
1292: this.refreshBuffer = true;
1293: Plot plot = chart.getPlot();
1294: if (plot instanceof Zoomable) {
1295: Zoomable z = (Zoomable) plot;
1296: this.orientation = z.getOrientation();
1297: }
1298: repaint();
1299: }
1300:
1301:
1306: public void chartProgress(ChartProgressEvent event) {
1307:
1308: }
1309:
1310:
1315: public void actionPerformed(ActionEvent event) {
1316:
1317: String command = event.getActionCommand();
1318:
1319: if (command.equals(PROPERTIES_COMMAND)) {
1320: attemptEditChartProperties();
1321: }
1322: else if (command.equals(SAVE_COMMAND)) {
1323: try {
1324: doSaveAs();
1325: }
1326: catch (IOException e) {
1327: e.printStackTrace();
1328: }
1329: }
1330: else if (command.equals(PRINT_COMMAND)) {
1331: createChartPrintJob();
1332: }
1333: else if (command.equals(ZOOM_IN_BOTH_COMMAND)) {
1334: zoomInBoth(this.zoomPoint.getX(), this.zoomPoint.getY());
1335: }
1336: else if (command.equals(ZOOM_IN_DOMAIN_COMMAND)) {
1337: zoomInDomain(this.zoomPoint.getX(), this.zoomPoint.getY());
1338: }
1339: else if (command.equals(ZOOM_IN_RANGE_COMMAND)) {
1340: zoomInRange(this.zoomPoint.getX(), this.zoomPoint.getY());
1341: }
1342: else if (command.equals(ZOOM_OUT_BOTH_COMMAND)) {
1343: zoomOutBoth(this.zoomPoint.getX(), this.zoomPoint.getY());
1344: }
1345: else if (command.equals(ZOOM_OUT_DOMAIN_COMMAND)) {
1346: zoomOutDomain(this.zoomPoint.getX(), this.zoomPoint.getY());
1347: }
1348: else if (command.equals(ZOOM_OUT_RANGE_COMMAND)) {
1349: zoomOutRange(this.zoomPoint.getX(), this.zoomPoint.getY());
1350: }
1351: else if (command.equals(ZOOM_RESET_BOTH_COMMAND)) {
1352: restoreAutoBounds();
1353: }
1354: else if (command.equals(ZOOM_RESET_DOMAIN_COMMAND)) {
1355: restoreAutoDomainBounds();
1356: }
1357: else if (command.equals(ZOOM_RESET_RANGE_COMMAND)) {
1358: restoreAutoRangeBounds();
1359: }
1360:
1361: }
1362:
1363:
1370: public void mouseEntered(MouseEvent e) {
1371: if (!this.ownToolTipDelaysActive) {
1372: ToolTipManager ttm = ToolTipManager.sharedInstance();
1373:
1374: this.originalToolTipInitialDelay = ttm.getInitialDelay();
1375: ttm.setInitialDelay(this.ownToolTipInitialDelay);
1376:
1377: this.originalToolTipReshowDelay = ttm.getReshowDelay();
1378: ttm.setReshowDelay(this.ownToolTipReshowDelay);
1379:
1380: this.originalToolTipDismissDelay = ttm.getDismissDelay();
1381: ttm.setDismissDelay(this.ownToolTipDismissDelay);
1382:
1383: this.ownToolTipDelaysActive = true;
1384: }
1385: }
1386:
1387:
1394: public void mouseExited(MouseEvent e) {
1395: if (this.ownToolTipDelaysActive) {
1396:
1397: ToolTipManager ttm = ToolTipManager.sharedInstance();
1398: ttm.setInitialDelay(this.originalToolTipInitialDelay);
1399: ttm.setReshowDelay(this.originalToolTipReshowDelay);
1400: ttm.setDismissDelay(this.originalToolTipDismissDelay);
1401: this.ownToolTipDelaysActive = false;
1402: }
1403: }
1404:
1405:
1413: public void mousePressed(MouseEvent e) {
1414: if (this.zoomRectangle == null) {
1415: Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY());
1416: if (screenDataArea != null) {
1417: this.zoomPoint = getPointInRectangle(
1418: e.getX(), e.getY(), screenDataArea
1419: );
1420: }
1421: else {
1422: this.zoomPoint = null;
1423: }
1424: if (e.isPopupTrigger()) {
1425: if (this.popup != null) {
1426: displayPopupMenu(e.getX(), e.getY());
1427: }
1428: }
1429: }
1430: }
1431:
1432:
1442: private Point getPointInRectangle(int x, int y, Rectangle2D area) {
1443: x = (int) Math.max(
1444: Math.ceil(area.getMinX()), Math.min(x, Math.floor(area.getMaxX()))
1445: );
1446: y = (int) Math.max(
1447: Math.ceil(area.getMinY()), Math.min(y, Math.floor(area.getMaxY()))
1448: );
1449: return new Point(x, y);
1450: }
1451:
1452:
1457: public void mouseDragged(MouseEvent e) {
1458:
1459:
1460: if (this.popup != null && this.popup.isShowing()) {
1461: return;
1462: }
1463:
1464: if (this.zoomPoint == null) {
1465: return;
1466: }
1467: Graphics2D g2 = (Graphics2D) getGraphics();
1468:
1469:
1470: g2.setXORMode(java.awt.Color.gray);
1471: if (this.zoomRectangle != null) {
1472: if (this.fillZoomRectangle) {
1473: g2.fill(this.zoomRectangle);
1474: }
1475: else {
1476: g2.draw(this.zoomRectangle);
1477: }
1478: }
1479:
1480: boolean hZoom = false;
1481: boolean vZoom = false;
1482: if (this.orientation == PlotOrientation.HORIZONTAL) {
1483: hZoom = this.rangeZoomable;
1484: vZoom = this.domainZoomable;
1485: }
1486: else {
1487: hZoom = this.domainZoomable;
1488: vZoom = this.rangeZoomable;
1489: }
1490: Rectangle2D scaledDataArea = getScreenDataArea(
1491: (int) this.zoomPoint.getX(), (int) this.zoomPoint.getY()
1492: );
1493: if (hZoom && vZoom) {
1494:
1495: double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
1496: double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
1497: this.zoomRectangle = new Rectangle2D.Double(
1498: this.zoomPoint.getX(), this.zoomPoint.getY(),
1499: xmax - this.zoomPoint.getX(), ymax - this.zoomPoint.getY()
1500: );
1501: }
1502: else if (hZoom) {
1503: double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
1504: this.zoomRectangle = new Rectangle2D.Double(
1505: this.zoomPoint.getX(), scaledDataArea.getMinY(),
1506: xmax - this.zoomPoint.getX(), scaledDataArea.getHeight()
1507: );
1508: }
1509: else if (vZoom) {
1510: double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
1511: this.zoomRectangle = new Rectangle2D.Double(
1512: scaledDataArea.getMinX(), this.zoomPoint.getY(),
1513: scaledDataArea.getWidth(), ymax - this.zoomPoint.getY()
1514: );
1515: }
1516:
1517: if (this.zoomRectangle != null) {
1518:
1519: if (this.fillZoomRectangle) {
1520: g2.fill(this.zoomRectangle);
1521: }
1522: else {
1523: g2.draw(this.zoomRectangle);
1524: }
1525: }
1526: g2.dispose();
1527:
1528: }
1529:
1530:
1537: public void mouseReleased(MouseEvent e) {
1538:
1539: if (this.zoomRectangle != null) {
1540: boolean hZoom = false;
1541: boolean vZoom = false;
1542: if (this.orientation == PlotOrientation.HORIZONTAL) {
1543: hZoom = this.rangeZoomable;
1544: vZoom = this.domainZoomable;
1545: }
1546: else {
1547: hZoom = this.domainZoomable;
1548: vZoom = this.rangeZoomable;
1549: }
1550:
1551: boolean zoomTrigger1 = hZoom && Math.abs(e.getX()
1552: - this.zoomPoint.getX()) >= this.zoomTriggerDistance;
1553: boolean zoomTrigger2 = vZoom && Math.abs(e.getY()
1554: - this.zoomPoint.getY()) >= this.zoomTriggerDistance;
1555: if (zoomTrigger1 || zoomTrigger2) {
1556: if ((hZoom && (e.getX() < this.zoomPoint.getX()))
1557: || (vZoom && (e.getY() < this.zoomPoint.getY()))) {
1558: restoreAutoBounds();
1559: }
1560: else {
1561: double x, y, w, h;
1562: Rectangle2D screenDataArea = getScreenDataArea(
1563: (int) this.zoomPoint.getX(),
1564: (int) this.zoomPoint.getY()
1565: );
1566:
1567:
1568:
1569: if (!vZoom) {
1570: x = this.zoomPoint.getX();
1571: y = screenDataArea.getMinY();
1572: w = Math.min(
1573: this.zoomRectangle.getWidth(),
1574: screenDataArea.getMaxX() - this.zoomPoint.getX()
1575: );
1576: h = screenDataArea.getHeight();
1577: }
1578: else if (!hZoom) {
1579: x = screenDataArea.getMinX();
1580: y = this.zoomPoint.getY();
1581: w = screenDataArea.getWidth();
1582: h = Math.min(
1583: this.zoomRectangle.getHeight(),
1584: screenDataArea.getMaxY() - this.zoomPoint.getY()
1585: );
1586: }
1587: else {
1588: x = this.zoomPoint.getX();
1589: y = this.zoomPoint.getY();
1590: w = Math.min(
1591: this.zoomRectangle.getWidth(),
1592: screenDataArea.getMaxX() - this.zoomPoint.getX()
1593: );
1594: h = Math.min(
1595: this.zoomRectangle.getHeight(),
1596: screenDataArea.getMaxY() - this.zoomPoint.getY()
1597: );
1598: }
1599: Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
1600: zoom(zoomArea);
1601: }
1602: this.zoomPoint = null;
1603: this.zoomRectangle = null;
1604: }
1605: else {
1606: Graphics2D g2 = (Graphics2D) getGraphics();
1607: g2.setXORMode(java.awt.Color.gray);
1608: if (this.fillZoomRectangle) {
1609: g2.fill(this.zoomRectangle);
1610: }
1611: else {
1612: g2.draw(this.zoomRectangle);
1613: }
1614: g2.dispose();
1615: this.zoomPoint = null;
1616: this.zoomRectangle = null;
1617: }
1618:
1619: }
1620:
1621: else if (e.isPopupTrigger()) {
1622: if (this.popup != null) {
1623: displayPopupMenu(e.getX(), e.getY());
1624: }
1625: }
1626:
1627: }
1628:
1629:
1635: public void mouseClicked(MouseEvent event) {
1636:
1637: Insets insets = getInsets();
1638: int x = (int) ((event.getX() - insets.left) / this.scaleX);
1639: int y = (int) ((event.getY() - insets.top) / this.scaleY);
1640:
1641: this.anchor = new Point2D.Double(x, y);
1642: this.chart.setNotify(true);
1643:
1644: Object[] listeners = this.chartMouseListeners.getListeners(
1645: ChartMouseListener.class);
1646: if (listeners.length == 0) {
1647: return;
1648: }
1649:
1650: ChartEntity entity = null;
1651: if (this.info != null) {
1652: EntityCollection entities = this.info.getEntityCollection();
1653: if (entities != null) {
1654: entity = entities.getEntity(x, y);
1655: }
1656: }
1657: ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), event,
1658: entity);
1659: for (int i = listeners.length - 1; i >= 0; i -= 1) {
1660: ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent);
1661: }
1662:
1663: }
1664:
1665:
1670: public void mouseMoved(MouseEvent e) {
1671: if (this.horizontalAxisTrace) {
1672: drawHorizontalAxisTrace(e.getX());
1673: }
1674: if (this.verticalAxisTrace) {
1675: drawVerticalAxisTrace(e.getY());
1676: }
1677: Object[] listeners = this.chartMouseListeners.getListeners(
1678: ChartMouseListener.class);
1679: if (listeners.length == 0) {
1680: return;
1681: }
1682: Insets insets = getInsets();
1683: int x = (int) ((e.getX() - insets.left) / this.scaleX);
1684: int y = (int) ((e.getY() - insets.top) / this.scaleY);
1685:
1686: ChartEntity entity = null;
1687: if (this.info != null) {
1688: EntityCollection entities = this.info.getEntityCollection();
1689: if (entities != null) {
1690: entity = entities.getEntity(x, y);
1691: }
1692: }
1693: ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity);
1694: for (int i = listeners.length - 1; i >= 0; i -= 1) {
1695: ((ChartMouseListener) listeners[i]).chartMouseMoved(event);
1696: }
1697:
1698: }
1699:
1700:
1706: public void zoomInBoth(double x, double y) {
1707: zoomInDomain(x, y);
1708: zoomInRange(x, y);
1709: }
1710:
1711:
1719: public void zoomInDomain(double x, double y) {
1720: Plot p = this.chart.getPlot();
1721: if (p instanceof Zoomable) {
1722: Zoomable plot = (Zoomable) p;
1723: plot.zoomDomainAxes(
1724: this.zoomInFactor, this.info.getPlotInfo(),
1725: translateScreenToJava2D(new Point((int) x, (int) y))
1726: );
1727: }
1728: }
1729:
1730:
1738: public void zoomInRange(double x, double y) {
1739: Plot p = this.chart.getPlot();
1740: if (p instanceof Zoomable) {
1741: Zoomable z = (Zoomable) p;
1742: z.zoomRangeAxes(
1743: this.zoomInFactor, this.info.getPlotInfo(),
1744: translateScreenToJava2D(new Point((int) x, (int) y))
1745: );
1746: }
1747: }
1748:
1749:
1755: public void zoomOutBoth(double x, double y) {
1756: zoomOutDomain(x, y);
1757: zoomOutRange(x, y);
1758: }
1759:
1760:
1768: public void zoomOutDomain(double x, double y) {
1769: Plot p = this.chart.getPlot();
1770: if (p instanceof Zoomable) {
1771: Zoomable z = (Zoomable) p;
1772: z.zoomDomainAxes(
1773: this.zoomOutFactor, this.info.getPlotInfo(),
1774: translateScreenToJava2D(new Point((int) x, (int) y))
1775: );
1776: }
1777: }
1778:
1779:
1787: public void zoomOutRange(double x, double y) {
1788: Plot p = this.chart.getPlot();
1789: if (p instanceof Zoomable) {
1790: Zoomable z = (Zoomable) p;
1791: z.zoomRangeAxes(
1792: this.zoomOutFactor, this.info.getPlotInfo(),
1793: translateScreenToJava2D(new Point((int) x, (int) y))
1794: );
1795: }
1796: }
1797:
1798:
1803: public void zoom(Rectangle2D selection) {
1804:
1805:
1806:
1807: Point2D selectOrigin = translateScreenToJava2D(
1808: new Point(
1809: (int) Math.ceil(selection.getX()),
1810: (int) Math.ceil(selection.getY())
1811: )
1812: );
1813: PlotRenderingInfo plotInfo = this.info.getPlotInfo();
1814: Rectangle2D scaledDataArea = getScreenDataArea(
1815: (int) selection.getCenterX(), (int) selection.getCenterY()
1816: );
1817: if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) {
1818:
1819: double hLower = (selection.getMinX() - scaledDataArea.getMinX())
1820: / scaledDataArea.getWidth();
1821: double hUpper = (selection.getMaxX() - scaledDataArea.getMinX())
1822: / scaledDataArea.getWidth();
1823: double vLower = (scaledDataArea.getMaxY() - selection.getMaxY())
1824: / scaledDataArea.getHeight();
1825: double vUpper = (scaledDataArea.getMaxY() - selection.getMinY())
1826: / scaledDataArea.getHeight();
1827:
1828: Plot p = this.chart.getPlot();
1829: if (p instanceof Zoomable) {
1830: Zoomable z = (Zoomable) p;
1831: if (z.getOrientation() == PlotOrientation.HORIZONTAL) {
1832: z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin);
1833: z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin);
1834: }
1835: else {
1836: z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin);
1837: z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin);
1838: }
1839: }
1840:
1841: }
1842:
1843: }
1844:
1845:
1848: public void restoreAutoBounds() {
1849: restoreAutoDomainBounds();
1850: restoreAutoRangeBounds();
1851: }
1852:
1853:
1856: public void restoreAutoDomainBounds() {
1857: Plot p = this.chart.getPlot();
1858: if (p instanceof Zoomable) {
1859: Zoomable z = (Zoomable) p;
1860: z.zoomDomainAxes(0.0, this.info.getPlotInfo(), this.zoomPoint);
1861: }
1862: }
1863:
1864:
1867: public void restoreAutoRangeBounds() {
1868: Plot p = this.chart.getPlot();
1869: if (p instanceof Zoomable) {
1870: Zoomable z = (Zoomable) p;
1871: z.zoomRangeAxes(0.0, this.info.getPlotInfo(), this.zoomPoint);
1872: }
1873: }
1874:
1875:
1881: public Rectangle2D getScreenDataArea() {
1882: Rectangle2D dataArea = this.info.getPlotInfo().getDataArea();
1883: Insets insets = getInsets();
1884: double x = dataArea.getX() * this.scaleX + insets.left;
1885: double y = dataArea.getY() * this.scaleY + insets.top;
1886: double w = dataArea.getWidth() * this.scaleX;
1887: double h = dataArea.getHeight() * this.scaleY;
1888: return new Rectangle2D.Double(x, y, w, h);
1889: }
1890:
1891:
1900: public Rectangle2D getScreenDataArea(int x, int y) {
1901: PlotRenderingInfo plotInfo = this.info.getPlotInfo();
1902: Rectangle2D result;
1903: if (plotInfo.getSubplotCount() == 0) {
1904: result = getScreenDataArea();
1905: }
1906: else {
1907:
1908:
1909: Point2D selectOrigin = translateScreenToJava2D(new Point(x, y));
1910: int subplotIndex = plotInfo.getSubplotIndex(selectOrigin);
1911: if (subplotIndex == -1) {
1912: return null;
1913: }
1914: result = scale(plotInfo.getSubplotInfo(subplotIndex).getDataArea());
1915: }
1916: return result;
1917: }
1918:
1919:
1926: public int getInitialDelay() {
1927: return this.ownToolTipInitialDelay;
1928: }
1929:
1930:
1937: public int getReshowDelay() {
1938: return this.ownToolTipReshowDelay;
1939: }
1940:
1941:
1949: public int getDismissDelay() {
1950: return this.ownToolTipDismissDelay;
1951: }
1952:
1953:
1961: public void setInitialDelay(int delay) {
1962: this.ownToolTipInitialDelay = delay;
1963: }
1964:
1965:
1973: public void setReshowDelay(int delay) {
1974: this.ownToolTipReshowDelay = delay;
1975: }
1976:
1977:
1985: public void setDismissDelay(int delay) {
1986: this.ownToolTipDismissDelay = delay;
1987: }
1988:
1989:
1994: public double getZoomInFactor() {
1995: return this.zoomInFactor;
1996: }
1997:
1998:
2003: public void setZoomInFactor(double factor) {
2004: this.zoomInFactor = factor;
2005: }
2006:
2007:
2012: public double getZoomOutFactor() {
2013: return this.zoomOutFactor;
2014: }
2015:
2016:
2021: public void setZoomOutFactor(double factor) {
2022: this.zoomOutFactor = factor;
2023: }
2024:
2025:
2031: private void drawHorizontalAxisTrace(int x) {
2032:
2033: Graphics2D g2 = (Graphics2D) getGraphics();
2034: Rectangle2D dataArea = getScreenDataArea();
2035:
2036: g2.setXORMode(java.awt.Color.orange);
2037: if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) {
2038:
2039: if (this.verticalTraceLine != null) {
2040: g2.draw(this.verticalTraceLine);
2041: this.verticalTraceLine.setLine(
2042: x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()
2043: );
2044: }
2045: else {
2046: this.verticalTraceLine = new Line2D.Float(
2047: x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()
2048: );
2049: }
2050: g2.draw(this.verticalTraceLine);
2051: }
2052:
2053: }
2054:
2055:
2061: private void drawVerticalAxisTrace(int y) {
2062:
2063: Graphics2D g2 = (Graphics2D) getGraphics();
2064: Rectangle2D dataArea = getScreenDataArea();
2065:
2066: g2.setXORMode(java.awt.Color.orange);
2067: if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) {
2068:
2069: if (this.horizontalTraceLine != null) {
2070: g2.draw(this.horizontalTraceLine);
2071: this.horizontalTraceLine.setLine(
2072: (int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y
2073: );
2074: }
2075: else {
2076: this.horizontalTraceLine = new Line2D.Float(
2077: (int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y
2078: );
2079: }
2080: g2.draw(this.horizontalTraceLine);
2081: }
2082:
2083: }
2084:
2085:
2089: private void attemptEditChartProperties() {
2090:
2091: ChartEditor editor = ChartEditorManager.getChartEditor(this.chart);
2092: int result = JOptionPane.showConfirmDialog(this, editor,
2093: localizationResources.getString("Chart_Properties"),
2094: JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
2095: if (result == JOptionPane.OK_OPTION) {
2096: editor.updateChart(this.chart);
2097: }
2098:
2099: }
2100:
2101:
2107: public void doSaveAs() throws IOException {
2108:
2109: JFileChooser fileChooser = new JFileChooser();
2110: ExtensionFileFilter filter = new ExtensionFileFilter(
2111: localizationResources.getString("PNG_Image_Files"), ".png"
2112: );
2113: fileChooser.addChoosableFileFilter(filter);
2114:
2115: int option = fileChooser.showSaveDialog(this);
2116: if (option == JFileChooser.APPROVE_OPTION) {
2117: String filename = fileChooser.getSelectedFile().getPath();
2118: if (isEnforceFileExtensions()) {
2119: if (!filename.endsWith(".png")) {
2120: filename = filename + ".png";
2121: }
2122: }
2123: ChartUtilities.saveChartAsPNG(
2124: new File(filename), this.chart, getWidth(), getHeight()
2125: );
2126: }
2127:
2128: }
2129:
2130:
2133: public void createChartPrintJob() {
2134:
2135: PrinterJob job = PrinterJob.getPrinterJob();
2136: PageFormat pf = job.defaultPage();
2137: PageFormat pf2 = job.pageDialog(pf);
2138: if (pf2 != pf) {
2139: job.setPrintable(this, pf2);
2140: if (job.printDialog()) {
2141: try {
2142: job.print();
2143: }
2144: catch (PrinterException e) {
2145: JOptionPane.showMessageDialog(this, e);
2146: }
2147: }
2148: }
2149:
2150: }
2151:
2152:
2162: public int print(Graphics g, PageFormat pf, int pageIndex) {
2163:
2164: if (pageIndex != 0) {
2165: return NO_SUCH_PAGE;
2166: }
2167: Graphics2D g2 = (Graphics2D) g;
2168: double x = pf.getImageableX();
2169: double y = pf.getImageableY();
2170: double w = pf.getImageableWidth();
2171: double h = pf.getImageableHeight();
2172: this.chart.draw(
2173: g2, new Rectangle2D.Double(x, y, w, h), this.anchor, null
2174: );
2175: return PAGE_EXISTS;
2176:
2177: }
2178:
2179:
2184: public void addChartMouseListener(ChartMouseListener listener) {
2185: if (listener == null) {
2186: throw new IllegalArgumentException("Null 'listener' argument.");
2187: }
2188: this.chartMouseListeners.add(ChartMouseListener.class, listener);
2189: }
2190:
2191:
2197: public void removeChartMouseListener(ChartMouseListener listener) {
2198: this.chartMouseListeners.remove(ChartMouseListener.class, listener);
2199: }
2200:
2201:
2209: public EventListener[] getListeners(Class listenerType) {
2210: if (listenerType == ChartMouseListener.class) {
2211:
2212: return this.chartMouseListeners.getListeners(listenerType);
2213: }
2214: else {
2215: return super.getListeners(listenerType);
2216: }
2217: }
2218:
2219:
2229: protected JPopupMenu createPopupMenu(boolean properties,
2230: boolean save,
2231: boolean print,
2232: boolean zoom) {
2233:
2234: JPopupMenu result = new JPopupMenu("Chart:");
2235: boolean separator = false;
2236:
2237: if (properties) {
2238: JMenuItem propertiesItem = new JMenuItem(
2239: localizationResources.getString("Properties...")
2240: );
2241: propertiesItem.setActionCommand(PROPERTIES_COMMAND);
2242: propertiesItem.addActionListener(this);
2243: result.add(propertiesItem);
2244: separator = true;
2245: }
2246:
2247: if (save) {
2248: if (separator) {
2249: result.addSeparator();
2250: separator = false;
2251: }
2252: JMenuItem saveItem = new JMenuItem(
2253: localizationResources.getString("Save_as...")
2254: );
2255: saveItem.setActionCommand(SAVE_COMMAND);
2256: saveItem.addActionListener(this);
2257: result.add(saveItem);
2258: separator = true;
2259: }
2260:
2261: if (print) {
2262: if (separator) {
2263: result.addSeparator();
2264: separator = false;
2265: }
2266: JMenuItem printItem = new JMenuItem(
2267: localizationResources.getString("Print...")
2268: );
2269: printItem.setActionCommand(PRINT_COMMAND);
2270: printItem.addActionListener(this);
2271: result.add(printItem);
2272: separator = true;
2273: }
2274:
2275: if (zoom) {
2276: if (separator) {
2277: result.addSeparator();
2278: separator = false;
2279: }
2280:
2281: JMenu zoomInMenu = new JMenu(
2282: localizationResources.getString("Zoom_In")
2283: );
2284:
2285: this.zoomInBothMenuItem = new JMenuItem(
2286: localizationResources.getString("All_Axes")
2287: );
2288: this.zoomInBothMenuItem.setActionCommand(ZOOM_IN_BOTH_COMMAND);
2289: this.zoomInBothMenuItem.addActionListener(this);
2290: zoomInMenu.add(this.zoomInBothMenuItem);
2291:
2292: zoomInMenu.addSeparator();
2293:
2294: this.zoomInDomainMenuItem = new JMenuItem(
2295: localizationResources.getString("Domain_Axis")
2296: );
2297: this.zoomInDomainMenuItem.setActionCommand(ZOOM_IN_DOMAIN_COMMAND);
2298: this.zoomInDomainMenuItem.addActionListener(this);
2299: zoomInMenu.add(this.zoomInDomainMenuItem);
2300:
2301: this.zoomInRangeMenuItem = new JMenuItem(
2302: localizationResources.getString("Range_Axis")
2303: );
2304: this.zoomInRangeMenuItem.setActionCommand(ZOOM_IN_RANGE_COMMAND);
2305: this.zoomInRangeMenuItem.addActionListener(this);
2306: zoomInMenu.add(this.zoomInRangeMenuItem);
2307:
2308: result.add(zoomInMenu);
2309:
2310: JMenu zoomOutMenu = new JMenu(
2311: localizationResources.getString("Zoom_Out")
2312: );
2313:
2314: this.zoomOutBothMenuItem = new JMenuItem(
2315: localizationResources.getString("All_Axes")
2316: );
2317: this.zoomOutBothMenuItem.setActionCommand(ZOOM_OUT_BOTH_COMMAND);
2318: this.zoomOutBothMenuItem.addActionListener(this);
2319: zoomOutMenu.add(this.zoomOutBothMenuItem);
2320:
2321: zoomOutMenu.addSeparator();
2322:
2323: this.zoomOutDomainMenuItem = new JMenuItem(
2324: localizationResources.getString("Domain_Axis")
2325: );
2326: this.zoomOutDomainMenuItem.setActionCommand(
2327: ZOOM_OUT_DOMAIN_COMMAND
2328: );
2329: this.zoomOutDomainMenuItem.addActionListener(this);
2330: zoomOutMenu.add(this.zoomOutDomainMenuItem);
2331:
2332: this.zoomOutRangeMenuItem = new JMenuItem(
2333: localizationResources.getString("Range_Axis")
2334: );
2335: this.zoomOutRangeMenuItem.setActionCommand(ZOOM_OUT_RANGE_COMMAND);
2336: this.zoomOutRangeMenuItem.addActionListener(this);
2337: zoomOutMenu.add(this.zoomOutRangeMenuItem);
2338:
2339: result.add(zoomOutMenu);
2340:
2341: JMenu autoRangeMenu = new JMenu(
2342: localizationResources.getString("Auto_Range")
2343: );
2344:
2345: this.zoomResetBothMenuItem = new JMenuItem(
2346: localizationResources.getString("All_Axes")
2347: );
2348: this.zoomResetBothMenuItem.setActionCommand(
2349: ZOOM_RESET_BOTH_COMMAND
2350: );
2351: this.zoomResetBothMenuItem.addActionListener(this);
2352: autoRangeMenu.add(this.zoomResetBothMenuItem);
2353:
2354: autoRangeMenu.addSeparator();
2355: this.zoomResetDomainMenuItem = new JMenuItem(
2356: localizationResources.getString("Domain_Axis")
2357: );
2358: this.zoomResetDomainMenuItem.setActionCommand(
2359: ZOOM_RESET_DOMAIN_COMMAND
2360: );
2361: this.zoomResetDomainMenuItem.addActionListener(this);
2362: autoRangeMenu.add(this.zoomResetDomainMenuItem);
2363:
2364: this.zoomResetRangeMenuItem = new JMenuItem(
2365: localizationResources.getString("Range_Axis")
2366: );
2367: this.zoomResetRangeMenuItem.setActionCommand(
2368: ZOOM_RESET_RANGE_COMMAND
2369: );
2370: this.zoomResetRangeMenuItem.addActionListener(this);
2371: autoRangeMenu.add(this.zoomResetRangeMenuItem);
2372:
2373: result.addSeparator();
2374: result.add(autoRangeMenu);
2375:
2376: }
2377:
2378: return result;
2379:
2380: }
2381:
2382:
2389: protected void displayPopupMenu(int x, int y) {
2390:
2391: if (this.popup != null) {
2392:
2393:
2394:
2395: Plot plot = this.chart.getPlot();
2396: boolean isDomainZoomable = false;
2397: boolean isRangeZoomable = false;
2398: if (plot instanceof Zoomable) {
2399: Zoomable z = (Zoomable) plot;
2400: isDomainZoomable = z.isDomainZoomable();
2401: isRangeZoomable = z.isRangeZoomable();
2402: }
2403:
2404: if (this.zoomInDomainMenuItem != null) {
2405: this.zoomInDomainMenuItem.setEnabled(isDomainZoomable);
2406: }
2407: if (this.zoomOutDomainMenuItem != null) {
2408: this.zoomOutDomainMenuItem.setEnabled(isDomainZoomable);
2409: }
2410: if (this.zoomResetDomainMenuItem != null) {
2411: this.zoomResetDomainMenuItem.setEnabled(isDomainZoomable);
2412: }
2413:
2414: if (this.zoomInRangeMenuItem != null) {
2415: this.zoomInRangeMenuItem.setEnabled(isRangeZoomable);
2416: }
2417: if (this.zoomOutRangeMenuItem != null) {
2418: this.zoomOutRangeMenuItem.setEnabled(isRangeZoomable);
2419: }
2420:
2421: if (this.zoomResetRangeMenuItem != null) {
2422: this.zoomResetRangeMenuItem.setEnabled(isRangeZoomable);
2423: }
2424:
2425: if (this.zoomInBothMenuItem != null) {
2426: this.zoomInBothMenuItem.setEnabled(
2427: isDomainZoomable & isRangeZoomable
2428: );
2429: }
2430: if (this.zoomOutBothMenuItem != null) {
2431: this.zoomOutBothMenuItem.setEnabled(
2432: isDomainZoomable & isRangeZoomable
2433: );
2434: }
2435: if (this.zoomResetBothMenuItem != null) {
2436: this.zoomResetBothMenuItem.setEnabled(
2437: isDomainZoomable & isRangeZoomable
2438: );
2439: }
2440:
2441: this.popup.show(this, x, y);
2442: }
2443:
2444: }
2445:
2446: }