1:
135:
136: package ;
137:
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: import ;
157: import ;
158: import ;
159: import ;
160: import ;
161: import ;
162: import ;
163: import ;
164:
165: import ;
166: import ;
167: import ;
168: import ;
169: import ;
170: import ;
171: import ;
172: import ;
173:
174: import ;
175: import ;
176: import ;
177: import ;
178: import ;
179: import ;
180: import ;
181: import ;
182: import ;
183: import ;
184: import ;
185: import ;
186: import ;
187:
188:
195: public class ChartPanel extends JPanel
196: implements ChartChangeListener,
197: ChartProgressListener,
198: ActionListener,
199: MouseListener,
200: MouseMotionListener,
201: Printable,
202: Serializable {
203:
204:
205: private static final long serialVersionUID = 6046366297214274674L;
206:
207:
208: public static final boolean DEFAULT_BUFFER_USED = false;
209:
210:
211: public static final int DEFAULT_WIDTH = 680;
212:
213:
214: public static final int DEFAULT_HEIGHT = 420;
215:
216:
217: public static final int DEFAULT_MINIMUM_DRAW_WIDTH = 300;
218:
219:
220: public static final int DEFAULT_MINIMUM_DRAW_HEIGHT = 200;
221:
222:
223: public static final int DEFAULT_MAXIMUM_DRAW_WIDTH = 800;
224:
225:
226: public static final int DEFAULT_MAXIMUM_DRAW_HEIGHT = 600;
227:
228:
229: public static final int DEFAULT_ZOOM_TRIGGER_DISTANCE = 10;
230:
231:
232: public static final String PROPERTIES_COMMAND = "PROPERTIES";
233:
234:
235: public static final String SAVE_COMMAND = "SAVE";
236:
237:
238: public static final String PRINT_COMMAND = "PRINT";
239:
240:
241: public static final String ZOOM_IN_BOTH_COMMAND = "ZOOM_IN_BOTH";
242:
243:
244: public static final String ZOOM_IN_DOMAIN_COMMAND = "ZOOM_IN_DOMAIN";
245:
246:
247: public static final String ZOOM_IN_RANGE_COMMAND = "ZOOM_IN_RANGE";
248:
249:
250: public static final String ZOOM_OUT_BOTH_COMMAND = "ZOOM_OUT_BOTH";
251:
252:
253: public static final String ZOOM_OUT_DOMAIN_COMMAND = "ZOOM_DOMAIN_BOTH";
254:
255:
256: public static final String ZOOM_OUT_RANGE_COMMAND = "ZOOM_RANGE_BOTH";
257:
258:
259: public static final String ZOOM_RESET_BOTH_COMMAND = "ZOOM_RESET_BOTH";
260:
261:
262: public static final String ZOOM_RESET_DOMAIN_COMMAND = "ZOOM_RESET_DOMAIN";
263:
264:
265: public static final String ZOOM_RESET_RANGE_COMMAND = "ZOOM_RESET_RANGE";
266:
267:
268: private JFreeChart chart;
269:
270:
271: private EventListenerList chartMouseListeners;
272:
273:
274: private boolean useBuffer;
275:
276:
277: private boolean refreshBuffer;
278:
279:
280: private Image chartBuffer;
281:
282:
283: private int chartBufferHeight;
284:
285:
286: private int chartBufferWidth;
287:
288:
291: private int minimumDrawWidth;
292:
293:
297: private int minimumDrawHeight;
298:
299:
303: private int maximumDrawWidth;
304:
305:
309: private int maximumDrawHeight;
310:
311:
312: private JPopupMenu popup;
313:
314:
315: private ChartRenderingInfo info;
316:
317:
318: private Point2D anchor;
319:
320:
321: private double scaleX;
322:
323:
324: private double scaleY;
325:
326:
327: private PlotOrientation orientation = PlotOrientation.VERTICAL;
328:
329:
330: private boolean domainZoomable = false;
331:
332:
333: private boolean rangeZoomable = false;
334:
335:
340: private Point zoomPoint = null;
341:
342:
343: private transient Rectangle2D zoomRectangle = null;
344:
345:
346: private boolean fillZoomRectangle = false;
347:
348:
349: private int zoomTriggerDistance;
350:
351:
352: private boolean horizontalAxisTrace = false;
353:
354:
355: private boolean verticalAxisTrace = false;
356:
357:
358: private transient Line2D verticalTraceLine;
359:
360:
361: private transient Line2D horizontalTraceLine;
362:
363:
364: private JMenuItem zoomInBothMenuItem;
365:
366:
367: private JMenuItem zoomInDomainMenuItem;
368:
369:
370: private JMenuItem zoomInRangeMenuItem;
371:
372:
373: private JMenuItem zoomOutBothMenuItem;
374:
375:
376: private JMenuItem zoomOutDomainMenuItem;
377:
378:
379: private JMenuItem zoomOutRangeMenuItem;
380:
381:
382: private JMenuItem zoomResetBothMenuItem;
383:
384:
385: private JMenuItem zoomResetDomainMenuItem;
386:
387:
388: private JMenuItem zoomResetRangeMenuItem;
389:
390:
391: private boolean enforceFileExtensions;
392:
393:
394: private boolean ownToolTipDelaysActive;
395:
396:
397: private int originalToolTipInitialDelay;
398:
399:
400: private int originalToolTipReshowDelay;
401:
402:
403: private int originalToolTipDismissDelay;
404:
405:
406: private int ownToolTipInitialDelay;
407:
408:
409: private int ownToolTipReshowDelay;
410:
411:
412: private int ownToolTipDismissDelay;
413:
414:
415: private double zoomInFactor = 0.5;
416:
417:
418: private double zoomOutFactor = 2.0;
419:
420:
421: protected static ResourceBundle localizationResources
422: = ResourceBundle.getBundle("org.jfree.chart.LocalizationBundle");
423:
424:
429: public ChartPanel(JFreeChart chart) {
430:
431: this(
432: chart,
433: DEFAULT_WIDTH,
434: DEFAULT_HEIGHT,
435: DEFAULT_MINIMUM_DRAW_WIDTH,
436: DEFAULT_MINIMUM_DRAW_HEIGHT,
437: DEFAULT_MAXIMUM_DRAW_WIDTH,
438: DEFAULT_MAXIMUM_DRAW_HEIGHT,
439: DEFAULT_BUFFER_USED,
440: true,
441: true,
442: true,
443: true,
444: true
445: );
446:
447: }
448:
449:
456: public ChartPanel(JFreeChart chart, boolean useBuffer) {
457:
458: this(chart,
459: DEFAULT_WIDTH,
460: DEFAULT_HEIGHT,
461: DEFAULT_MINIMUM_DRAW_WIDTH,
462: DEFAULT_MINIMUM_DRAW_HEIGHT,
463: DEFAULT_MAXIMUM_DRAW_WIDTH,
464: DEFAULT_MAXIMUM_DRAW_HEIGHT,
465: useBuffer,
466: true,
467: true,
468: true,
469: true,
470: true
471: );
472:
473: }
474:
475:
490: public ChartPanel(JFreeChart chart,
491: boolean properties,
492: boolean save,
493: boolean print,
494: boolean zoom,
495: boolean tooltips) {
496:
497: this(chart,
498: DEFAULT_WIDTH,
499: DEFAULT_HEIGHT,
500: DEFAULT_MINIMUM_DRAW_WIDTH,
501: DEFAULT_MINIMUM_DRAW_HEIGHT,
502: DEFAULT_MAXIMUM_DRAW_WIDTH,
503: DEFAULT_MAXIMUM_DRAW_HEIGHT,
504: DEFAULT_BUFFER_USED,
505: properties,
506: save,
507: print,
508: zoom,
509: tooltips
510: );
511:
512: }
513:
514:
538: public ChartPanel(JFreeChart chart,
539: int width,
540: int height,
541: int minimumDrawWidth,
542: int minimumDrawHeight,
543: int maximumDrawWidth,
544: int maximumDrawHeight,
545: boolean useBuffer,
546: boolean properties,
547: boolean save,
548: boolean print,
549: boolean zoom,
550: boolean tooltips) {
551:
552: this.setChart(chart);
553: this.chartMouseListeners = new EventListenerList();
554: this.info = new ChartRenderingInfo();
555: setPreferredSize(new Dimension(width, height));
556: this.useBuffer = useBuffer;
557: this.refreshBuffer = false;
558: this.minimumDrawWidth = minimumDrawWidth;
559: this.minimumDrawHeight = minimumDrawHeight;
560: this.maximumDrawWidth = maximumDrawWidth;
561: this.maximumDrawHeight = maximumDrawHeight;
562: this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE;
563:
564:
565: this.popup = null;
566: if (properties || save || print || zoom) {
567: this.popup = createPopupMenu(properties, save, print, zoom);
568: }
569:
570: enableEvents(AWTEvent.MOUSE_EVENT_MASK);
571: enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
572: setDisplayToolTips(tooltips);
573: addMouseListener(this);
574: addMouseMotionListener(this);
575:
576: this.enforceFileExtensions = true;
577:
578:
579:
580: ToolTipManager ttm = ToolTipManager.sharedInstance();
581: this.ownToolTipInitialDelay = ttm.getInitialDelay();
582: this.ownToolTipDismissDelay = ttm.getDismissDelay();
583: this.ownToolTipReshowDelay = ttm.getReshowDelay();
584:
585: }
586:
587:
592: public JFreeChart getChart() {
593: return this.chart;
594: }
595:
596:
601: public void setChart(JFreeChart chart) {
602:
603:
604: if (this.chart != null) {
605: this.chart.removeChangeListener(this);
606: this.chart.removeProgressListener(this);
607: }
608:
609:
610: this.chart = chart;
611: if (chart != null) {
612: this.chart.addChangeListener(this);
613: this.chart.addProgressListener(this);
614: Plot plot = chart.getPlot();
615: this.domainZoomable = false;
616: this.rangeZoomable = false;
617: if (plot instanceof Zoomable) {
618: Zoomable z = (Zoomable) plot;
619: this.domainZoomable = z.isDomainZoomable();
620: this.rangeZoomable = z.isRangeZoomable();
621: this.orientation = z.getOrientation();
622: }
623: }
624: else {
625: this.domainZoomable = false;
626: this.rangeZoomable = false;
627: }
628: if (this.useBuffer) {
629: this.refreshBuffer = true;
630: }
631: repaint();
632:
633: }
634:
635:
643: public int getMinimumDrawWidth() {
644: return this.minimumDrawWidth;
645: }
646:
647:
656: public void setMinimumDrawWidth(int width) {
657: this.minimumDrawWidth = width;
658: }
659:
660:
668: public int getMaximumDrawWidth() {
669: return this.maximumDrawWidth;
670: }
671:
672:
681: public void setMaximumDrawWidth(int width) {
682: this.maximumDrawWidth = width;
683: }
684:
685:
693: public int getMinimumDrawHeight() {
694: return this.minimumDrawHeight;
695: }
696:
697:
706: public void setMinimumDrawHeight(int height) {
707: this.minimumDrawHeight = height;
708: }
709:
710:
718: public int getMaximumDrawHeight() {
719: return this.maximumDrawHeight;
720: }
721:
722:
731: public void setMaximumDrawHeight(int height) {
732: this.maximumDrawHeight = height;
733: }
734:
735:
741: public double getScaleX() {
742: return this.scaleX;
743: }
744:
745:
751: public double getScaleY() {
752: return this.scaleY;
753: }
754:
755:
760: public Point2D getAnchor() {
761: return this.anchor;
762: }
763:
764:
770: protected void setAnchor(Point2D anchor) {
771: this.anchor = anchor;
772: }
773:
774:
779: public JPopupMenu getPopupMenu() {
780: return this.popup;
781: }
782:
783:
788: public void setPopupMenu(JPopupMenu popup) {
789: this.popup = popup;
790: }
791:
792:
797: public ChartRenderingInfo getChartRenderingInfo() {
798: return this.info;
799: }
800:
801:
807: public void setMouseZoomable(boolean flag) {
808: setMouseZoomable(flag, true);
809: }
810:
811:
818: public void setMouseZoomable(boolean flag, boolean fillRectangle) {
819: setDomainZoomable(flag);
820: setRangeZoomable(flag);
821: setFillZoomRectangle(fillRectangle);
822: }
823:
824:
830: public boolean isDomainZoomable() {
831: return this.domainZoomable;
832: }
833:
834:
841: public void setDomainZoomable(boolean flag) {
842: if (flag) {
843: Plot plot = this.chart.getPlot();
844: if (plot instanceof Zoomable) {
845: Zoomable z = (Zoomable) plot;
846: this.domainZoomable = flag && (z.isDomainZoomable());
847: }
848: }
849: else {
850: this.domainZoomable = false;
851: }
852: }
853:
854:
860: public boolean isRangeZoomable() {
861: return this.rangeZoomable;
862: }
863:
864:
869: public void setRangeZoomable(boolean flag) {
870: if (flag) {
871: Plot plot = this.chart.getPlot();
872: if (plot instanceof Zoomable) {
873: Zoomable z = (Zoomable) plot;
874: this.rangeZoomable = flag && (z.isRangeZoomable());
875: }
876: }
877: else {
878: this.rangeZoomable = false;
879: }
880: }
881:
882:
888: public boolean getFillZoomRectangle() {
889: return this.fillZoomRectangle;
890: }
891:
892:
898: public void setFillZoomRectangle(boolean flag) {
899: this.fillZoomRectangle = flag;
900: }
901:
902:
908: public int getZoomTriggerDistance() {
909: return this.zoomTriggerDistance;
910: }
911:
912:
918: public void setZoomTriggerDistance(int distance) {
919: this.zoomTriggerDistance = distance;
920: }
921:
922:
928: public boolean getHorizontalAxisTrace() {
929: return this.horizontalAxisTrace;
930: }
931:
932:
938: public void setHorizontalAxisTrace(boolean flag) {
939: this.horizontalAxisTrace = flag;
940: }
941:
942:
947: protected Line2D getHorizontalTraceLine() {
948: return this.horizontalTraceLine;
949: }
950:
951:
956: protected void setHorizontalTraceLine(Line2D line) {
957: this.horizontalTraceLine = line;
958: }
959:
960:
966: public boolean getVerticalAxisTrace() {
967: return this.verticalAxisTrace;
968: }
969:
970:
976: public void setVerticalAxisTrace(boolean flag) {
977: this.verticalAxisTrace = flag;
978: }
979:
980:
985: protected Line2D getVerticalTraceLine() {
986: return this.verticalTraceLine;
987: }
988:
989:
994: protected void setVerticalTraceLine(Line2D line) {
995: this.verticalTraceLine = line;
996: }
997:
998:
1004: public boolean isEnforceFileExtensions() {
1005: return this.enforceFileExtensions;
1006: }
1007:
1008:
1013: public void setEnforceFileExtensions(boolean enforce) {
1014: this.enforceFileExtensions = enforce;
1015: }
1016:
1017:
1025: public void setDisplayToolTips(boolean flag) {
1026: if (flag) {
1027: ToolTipManager.sharedInstance().registerComponent(this);
1028: }
1029: else {
1030: ToolTipManager.sharedInstance().unregisterComponent(this);
1031: }
1032: }
1033:
1034:
1041: public String getToolTipText(MouseEvent e) {
1042:
1043: String result = null;
1044: if (this.info != null) {
1045: EntityCollection entities = this.info.getEntityCollection();
1046: if (entities != null) {
1047: Insets insets = getInsets();
1048: ChartEntity entity = entities.getEntity(
1049: (int) ((e.getX() - insets.left) / this.scaleX),
1050: (int) ((e.getY() - insets.top) / this.scaleY));
1051: if (entity != null) {
1052: result = entity.getToolTipText();
1053: }
1054: }
1055: }
1056: return result;
1057:
1058: }
1059:
1060:
1067: public Point translateJava2DToScreen(Point2D java2DPoint) {
1068: Insets insets = getInsets();
1069: int x = (int) (java2DPoint.getX() * this.scaleX + insets.left);
1070: int y = (int) (java2DPoint.getY() * this.scaleY + insets.top);
1071: return new Point(x, y);
1072: }
1073:
1074:
1081: public Point2D translateScreenToJava2D(Point screenPoint) {
1082: Insets insets = getInsets();
1083: double x = (screenPoint.getX() - insets.left) / this.scaleX;
1084: double y = (screenPoint.getY() - insets.top) / this.scaleY;
1085: return new Point2D.Double(x, y);
1086: }
1087:
1088:
1096: public Rectangle2D scale(Rectangle2D rect) {
1097: Insets insets = getInsets();
1098: double x = rect.getX() * getScaleX() + insets.left;
1099: double y = rect.getY() * this.getScaleY() + insets.top;
1100: double w = rect.getWidth() * this.getScaleX();
1101: double h = rect.getHeight() * this.getScaleY();
1102: return new Rectangle2D.Double(x, y, w, h);
1103: }
1104:
1105:
1116: public ChartEntity getEntityForPoint(int viewX, int viewY) {
1117:
1118: ChartEntity result = null;
1119: if (this.info != null) {
1120: Insets insets = getInsets();
1121: double x = (viewX - insets.left) / this.scaleX;
1122: double y = (viewY - insets.top) / this.scaleY;
1123: EntityCollection entities = this.info.getEntityCollection();
1124: result = entities != null ? entities.getEntity(x, y) : null;
1125: }
1126: return result;
1127:
1128: }
1129:
1130:
1136: public boolean getRefreshBuffer() {
1137: return this.refreshBuffer;
1138: }
1139:
1140:
1147: public void setRefreshBuffer(boolean flag) {
1148: this.refreshBuffer = flag;
1149: }
1150:
1151:
1159: public void paintComponent(Graphics g) {
1160: super.paintComponent(g);
1161: if (this.chart == null) {
1162: return;
1163: }
1164: Graphics2D g2 = (Graphics2D) g.create();
1165:
1166:
1167: Dimension size = getSize();
1168: Insets insets = getInsets();
1169: Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top,
1170: size.getWidth() - insets.left - insets.right,
1171: size.getHeight() - insets.top - insets.bottom);
1172:
1173:
1174: boolean scale = false;
1175: double drawWidth = available.getWidth();
1176: double drawHeight = available.getHeight();
1177: this.scaleX = 1.0;
1178: this.scaleY = 1.0;
1179:
1180: if (drawWidth < this.minimumDrawWidth) {
1181: this.scaleX = drawWidth / this.minimumDrawWidth;
1182: drawWidth = this.minimumDrawWidth;
1183: scale = true;
1184: }
1185: else if (drawWidth > this.maximumDrawWidth) {
1186: this.scaleX = drawWidth / this.maximumDrawWidth;
1187: drawWidth = this.maximumDrawWidth;
1188: scale = true;
1189: }
1190:
1191: if (drawHeight < this.minimumDrawHeight) {
1192: this.scaleY = drawHeight / this.minimumDrawHeight;
1193: drawHeight = this.minimumDrawHeight;
1194: scale = true;
1195: }
1196: else if (drawHeight > this.maximumDrawHeight) {
1197: this.scaleY = drawHeight / this.maximumDrawHeight;
1198: drawHeight = this.maximumDrawHeight;
1199: scale = true;
1200: }
1201:
1202: Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth,
1203: drawHeight);
1204:
1205:
1206: if (this.useBuffer) {
1207:
1208:
1209: if ((this.chartBuffer == null)
1210: || (this.chartBufferWidth != available.getWidth())
1211: || (this.chartBufferHeight != available.getHeight())
1212: ) {
1213: this.chartBufferWidth = (int) available.getWidth();
1214: this.chartBufferHeight = (int) available.getHeight();
1215: this.chartBuffer = createImage(
1216: this.chartBufferWidth, this.chartBufferHeight);
1217:
1218:
1219:
1220:
1221: this.refreshBuffer = true;
1222: }
1223:
1224:
1225: if (this.refreshBuffer) {
1226:
1227: Rectangle2D bufferArea = new Rectangle2D.Double(
1228: 0, 0, this.chartBufferWidth, this.chartBufferHeight);
1229:
1230: Graphics2D bufferG2
1231: = (Graphics2D) this.chartBuffer.getGraphics();
1232: if (scale) {
1233: AffineTransform saved = bufferG2.getTransform();
1234: AffineTransform st = AffineTransform.getScaleInstance(
1235: this.scaleX, this.scaleY);
1236: bufferG2.transform(st);
1237: this.chart.draw(bufferG2, chartArea, this.anchor,
1238: this.info);
1239: bufferG2.setTransform(saved);
1240: }
1241: else {
1242: this.chart.draw(bufferG2, bufferArea, this.anchor,
1243: this.info);
1244: }
1245:
1246: this.refreshBuffer = false;
1247:
1248: }
1249:
1250:
1251: g2.drawImage(this.chartBuffer, insets.left, insets.right, this);
1252:
1253: }
1254:
1255:
1256: else {
1257:
1258: AffineTransform saved = g2.getTransform();
1259: g2.translate(insets.left, insets.top);
1260: if (scale) {
1261: AffineTransform st = AffineTransform.getScaleInstance(
1262: this.scaleX, this.scaleY);
1263: g2.transform(st);
1264: }
1265: this.chart.draw(g2, chartArea, this.anchor, this.info);
1266: g2.setTransform(saved);
1267:
1268: }
1269:
1270:
1271: drawZoomRectangle(g2);
1272:
1273: g2.dispose();
1274:
1275: this.anchor = null;
1276: this.verticalTraceLine = null;
1277: this.horizontalTraceLine = null;
1278:
1279: }
1280:
1281:
1286: public void chartChanged(ChartChangeEvent event) {
1287: this.refreshBuffer = true;
1288: Plot plot = this.chart.getPlot();
1289: if (plot instanceof Zoomable) {
1290: Zoomable z = (Zoomable) plot;
1291: this.orientation = z.getOrientation();
1292: }
1293: repaint();
1294: }
1295:
1296:
1301: public void chartProgress(ChartProgressEvent event) {
1302:
1303: }
1304:
1305:
1310: public void actionPerformed(ActionEvent event) {
1311:
1312: String command = event.getActionCommand();
1313:
1314: if (command.equals(PROPERTIES_COMMAND)) {
1315: doEditChartProperties();
1316: }
1317: else if (command.equals(SAVE_COMMAND)) {
1318: try {
1319: doSaveAs();
1320: }
1321: catch (IOException e) {
1322: e.printStackTrace();
1323: }
1324: }
1325: else if (command.equals(PRINT_COMMAND)) {
1326: createChartPrintJob();
1327: }
1328: else if (command.equals(ZOOM_IN_BOTH_COMMAND)) {
1329: zoomInBoth(this.zoomPoint.getX(), this.zoomPoint.getY());
1330: }
1331: else if (command.equals(ZOOM_IN_DOMAIN_COMMAND)) {
1332: zoomInDomain(this.zoomPoint.getX(), this.zoomPoint.getY());
1333: }
1334: else if (command.equals(ZOOM_IN_RANGE_COMMAND)) {
1335: zoomInRange(this.zoomPoint.getX(), this.zoomPoint.getY());
1336: }
1337: else if (command.equals(ZOOM_OUT_BOTH_COMMAND)) {
1338: zoomOutBoth(this.zoomPoint.getX(), this.zoomPoint.getY());
1339: }
1340: else if (command.equals(ZOOM_OUT_DOMAIN_COMMAND)) {
1341: zoomOutDomain(this.zoomPoint.getX(), this.zoomPoint.getY());
1342: }
1343: else if (command.equals(ZOOM_OUT_RANGE_COMMAND)) {
1344: zoomOutRange(this.zoomPoint.getX(), this.zoomPoint.getY());
1345: }
1346: else if (command.equals(ZOOM_RESET_BOTH_COMMAND)) {
1347: restoreAutoBounds();
1348: }
1349: else if (command.equals(ZOOM_RESET_DOMAIN_COMMAND)) {
1350: restoreAutoDomainBounds();
1351: }
1352: else if (command.equals(ZOOM_RESET_RANGE_COMMAND)) {
1353: restoreAutoRangeBounds();
1354: }
1355:
1356: }
1357:
1358:
1365: public void mouseEntered(MouseEvent e) {
1366: if (!this.ownToolTipDelaysActive) {
1367: ToolTipManager ttm = ToolTipManager.sharedInstance();
1368:
1369: this.originalToolTipInitialDelay = ttm.getInitialDelay();
1370: ttm.setInitialDelay(this.ownToolTipInitialDelay);
1371:
1372: this.originalToolTipReshowDelay = ttm.getReshowDelay();
1373: ttm.setReshowDelay(this.ownToolTipReshowDelay);
1374:
1375: this.originalToolTipDismissDelay = ttm.getDismissDelay();
1376: ttm.setDismissDelay(this.ownToolTipDismissDelay);
1377:
1378: this.ownToolTipDelaysActive = true;
1379: }
1380: }
1381:
1382:
1389: public void mouseExited(MouseEvent e) {
1390: if (this.ownToolTipDelaysActive) {
1391:
1392: ToolTipManager ttm = ToolTipManager.sharedInstance();
1393: ttm.setInitialDelay(this.originalToolTipInitialDelay);
1394: ttm.setReshowDelay(this.originalToolTipReshowDelay);
1395: ttm.setDismissDelay(this.originalToolTipDismissDelay);
1396: this.ownToolTipDelaysActive = false;
1397: }
1398: }
1399:
1400:
1408: public void mousePressed(MouseEvent e) {
1409: if (this.zoomRectangle == null) {
1410: Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY());
1411: if (screenDataArea != null) {
1412: this.zoomPoint = getPointInRectangle(e.getX(), e.getY(),
1413: screenDataArea);
1414: }
1415: else {
1416: this.zoomPoint = null;
1417: }
1418: if (e.isPopupTrigger()) {
1419: if (this.popup != null) {
1420: displayPopupMenu(e.getX(), e.getY());
1421: }
1422: }
1423: }
1424: }
1425:
1426:
1436: private Point getPointInRectangle(int x, int y, Rectangle2D area) {
1437: x = (int) Math.max(Math.ceil(area.getMinX()), Math.min(x,
1438: Math.floor(area.getMaxX())));
1439: y = (int) Math.max(Math.ceil(area.getMinY()), Math.min(y,
1440: Math.floor(area.getMaxY())));
1441: return new Point(x, y);
1442: }
1443:
1444:
1449: public void mouseDragged(MouseEvent e) {
1450:
1451:
1452: if (this.popup != null && this.popup.isShowing()) {
1453: return;
1454: }
1455:
1456: if (this.zoomPoint == null) {
1457: return;
1458: }
1459: Graphics2D g2 = (Graphics2D) getGraphics();
1460:
1461:
1462: drawZoomRectangle(g2);
1463:
1464: boolean hZoom = false;
1465: boolean vZoom = false;
1466: if (this.orientation == PlotOrientation.HORIZONTAL) {
1467: hZoom = this.rangeZoomable;
1468: vZoom = this.domainZoomable;
1469: }
1470: else {
1471: hZoom = this.domainZoomable;
1472: vZoom = this.rangeZoomable;
1473: }
1474: Rectangle2D scaledDataArea = getScreenDataArea(
1475: (int) this.zoomPoint.getX(), (int) this.zoomPoint.getY());
1476: if (hZoom && vZoom) {
1477:
1478: double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
1479: double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
1480: this.zoomRectangle = new Rectangle2D.Double(
1481: this.zoomPoint.getX(), this.zoomPoint.getY(),
1482: xmax - this.zoomPoint.getX(), ymax - this.zoomPoint.getY());
1483: }
1484: else if (hZoom) {
1485: double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
1486: this.zoomRectangle = new Rectangle2D.Double(
1487: this.zoomPoint.getX(), scaledDataArea.getMinY(),
1488: xmax - this.zoomPoint.getX(), scaledDataArea.getHeight());
1489: }
1490: else if (vZoom) {
1491: double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
1492: this.zoomRectangle = new Rectangle2D.Double(
1493: scaledDataArea.getMinX(), this.zoomPoint.getY(),
1494: scaledDataArea.getWidth(), ymax - this.zoomPoint.getY());
1495: }
1496:
1497:
1498: drawZoomRectangle(g2);
1499:
1500: g2.dispose();
1501:
1502: }
1503:
1504:
1511: public void mouseReleased(MouseEvent e) {
1512:
1513: if (this.zoomRectangle != null) {
1514: boolean hZoom = false;
1515: boolean vZoom = false;
1516: if (this.orientation == PlotOrientation.HORIZONTAL) {
1517: hZoom = this.rangeZoomable;
1518: vZoom = this.domainZoomable;
1519: }
1520: else {
1521: hZoom = this.domainZoomable;
1522: vZoom = this.rangeZoomable;
1523: }
1524:
1525: boolean zoomTrigger1 = hZoom && Math.abs(e.getX()
1526: - this.zoomPoint.getX()) >= this.zoomTriggerDistance;
1527: boolean zoomTrigger2 = vZoom && Math.abs(e.getY()
1528: - this.zoomPoint.getY()) >= this.zoomTriggerDistance;
1529: if (zoomTrigger1 || zoomTrigger2) {
1530: if ((hZoom && (e.getX() < this.zoomPoint.getX()))
1531: || (vZoom && (e.getY() < this.zoomPoint.getY()))) {
1532: restoreAutoBounds();
1533: }
1534: else {
1535: double x, y, w, h;
1536: Rectangle2D screenDataArea = getScreenDataArea(
1537: (int) this.zoomPoint.getX(),
1538: (int) this.zoomPoint.getY());
1539:
1540:
1541:
1542: if (!vZoom) {
1543: x = this.zoomPoint.getX();
1544: y = screenDataArea.getMinY();
1545: w = Math.min(this.zoomRectangle.getWidth(),
1546: screenDataArea.getMaxX()
1547: - this.zoomPoint.getX());
1548: h = screenDataArea.getHeight();
1549: }
1550: else if (!hZoom) {
1551: x = screenDataArea.getMinX();
1552: y = this.zoomPoint.getY();
1553: w = screenDataArea.getWidth();
1554: h = Math.min(this.zoomRectangle.getHeight(),
1555: screenDataArea.getMaxY()
1556: - this.zoomPoint.getY());
1557: }
1558: else {
1559: x = this.zoomPoint.getX();
1560: y = this.zoomPoint.getY();
1561: w = Math.min(this.zoomRectangle.getWidth(),
1562: screenDataArea.getMaxX()
1563: - this.zoomPoint.getX());
1564: h = Math.min(this.zoomRectangle.getHeight(),
1565: screenDataArea.getMaxY()
1566: - this.zoomPoint.getY());
1567: }
1568: Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
1569: zoom(zoomArea);
1570: }
1571: this.zoomPoint = null;
1572: this.zoomRectangle = null;
1573: }
1574: else {
1575:
1576: Graphics2D g2 = (Graphics2D) getGraphics();
1577: drawZoomRectangle(g2);
1578: g2.dispose();
1579: this.zoomPoint = null;
1580: this.zoomRectangle = null;
1581: }
1582:
1583: }
1584:
1585: else if (e.isPopupTrigger()) {
1586: if (this.popup != null) {
1587: displayPopupMenu(e.getX(), e.getY());
1588: }
1589: }
1590:
1591: }
1592:
1593:
1599: public void mouseClicked(MouseEvent event) {
1600:
1601: Insets insets = getInsets();
1602: int x = (int) ((event.getX() - insets.left) / this.scaleX);
1603: int y = (int) ((event.getY() - insets.top) / this.scaleY);
1604:
1605: this.anchor = new Point2D.Double(x, y);
1606: if (this.chart == null) {
1607: return;
1608: }
1609: this.chart.setNotify(true);
1610:
1611: Object[] listeners = this.chartMouseListeners.getListeners(
1612: ChartMouseListener.class);
1613: if (listeners.length == 0) {
1614: return;
1615: }
1616:
1617: ChartEntity entity = null;
1618: if (this.info != null) {
1619: EntityCollection entities = this.info.getEntityCollection();
1620: if (entities != null) {
1621: entity = entities.getEntity(x, y);
1622: }
1623: }
1624: ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), event,
1625: entity);
1626: for (int i = listeners.length - 1; i >= 0; i -= 1) {
1627: ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent);
1628: }
1629:
1630: }
1631:
1632:
1637: public void mouseMoved(MouseEvent e) {
1638: Graphics2D g2 = (Graphics2D) getGraphics();
1639: if (this.horizontalAxisTrace) {
1640: drawHorizontalAxisTrace(g2, e.getX());
1641: }
1642: if (this.verticalAxisTrace) {
1643: drawVerticalAxisTrace(g2, e.getY());
1644: }
1645: g2.dispose();
1646:
1647: Object[] listeners = this.chartMouseListeners.getListeners(
1648: ChartMouseListener.class);
1649: if (listeners.length == 0) {
1650: return;
1651: }
1652: Insets insets = getInsets();
1653: int x = (int) ((e.getX() - insets.left) / this.scaleX);
1654: int y = (int) ((e.getY() - insets.top) / this.scaleY);
1655:
1656: ChartEntity entity = null;
1657: if (this.info != null) {
1658: EntityCollection entities = this.info.getEntityCollection();
1659: if (entities != null) {
1660: entity = entities.getEntity(x, y);
1661: }
1662: }
1663:
1664:
1665:
1666: if (this.chart != null) {
1667: ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity);
1668: for (int i = listeners.length - 1; i >= 0; i -= 1) {
1669: ((ChartMouseListener) listeners[i]).chartMouseMoved(event);
1670: }
1671: }
1672:
1673: }
1674:
1675:
1681: public void zoomInBoth(double x, double y) {
1682: zoomInDomain(x, y);
1683: zoomInRange(x, y);
1684: }
1685:
1686:
1694: public void zoomInDomain(double x, double y) {
1695: Plot p = this.chart.getPlot();
1696: if (p instanceof Zoomable) {
1697: Zoomable plot = (Zoomable) p;
1698: plot.zoomDomainAxes(this.zoomInFactor, this.info.getPlotInfo(),
1699: translateScreenToJava2D(new Point((int) x, (int) y)));
1700: }
1701: }
1702:
1703:
1711: public void zoomInRange(double x, double y) {
1712: Plot p = this.chart.getPlot();
1713: if (p instanceof Zoomable) {
1714: Zoomable z = (Zoomable) p;
1715: z.zoomRangeAxes(this.zoomInFactor, this.info.getPlotInfo(),
1716: translateScreenToJava2D(new Point((int) x, (int) y)));
1717: }
1718: }
1719:
1720:
1726: public void zoomOutBoth(double x, double y) {
1727: zoomOutDomain(x, y);
1728: zoomOutRange(x, y);
1729: }
1730:
1731:
1739: public void zoomOutDomain(double x, double y) {
1740: Plot p = this.chart.getPlot();
1741: if (p instanceof Zoomable) {
1742: Zoomable z = (Zoomable) p;
1743: z.zoomDomainAxes(this.zoomOutFactor, this.info.getPlotInfo(),
1744: translateScreenToJava2D(new Point((int) x, (int) y)));
1745: }
1746: }
1747:
1748:
1756: public void zoomOutRange(double x, double y) {
1757: Plot p = this.chart.getPlot();
1758: if (p instanceof Zoomable) {
1759: Zoomable z = (Zoomable) p;
1760: z.zoomRangeAxes(this.zoomOutFactor, this.info.getPlotInfo(),
1761: translateScreenToJava2D(new Point((int) x, (int) y)));
1762: }
1763: }
1764:
1765:
1770: public void zoom(Rectangle2D selection) {
1771:
1772:
1773:
1774: Point2D selectOrigin = translateScreenToJava2D(new Point(
1775: (int) Math.ceil(selection.getX()),
1776: (int) Math.ceil(selection.getY())));
1777: PlotRenderingInfo plotInfo = this.info.getPlotInfo();
1778: Rectangle2D scaledDataArea = getScreenDataArea(
1779: (int) selection.getCenterX(), (int) selection.getCenterY());
1780: if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) {
1781:
1782: double hLower = (selection.getMinX() - scaledDataArea.getMinX())
1783: / scaledDataArea.getWidth();
1784: double hUpper = (selection.getMaxX() - scaledDataArea.getMinX())
1785: / scaledDataArea.getWidth();
1786: double vLower = (scaledDataArea.getMaxY() - selection.getMaxY())
1787: / scaledDataArea.getHeight();
1788: double vUpper = (scaledDataArea.getMaxY() - selection.getMinY())
1789: / scaledDataArea.getHeight();
1790:
1791: Plot p = this.chart.getPlot();
1792: if (p instanceof Zoomable) {
1793: Zoomable z = (Zoomable) p;
1794: if (z.getOrientation() == PlotOrientation.HORIZONTAL) {
1795: z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin);
1796: z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin);
1797: }
1798: else {
1799: z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin);
1800: z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin);
1801: }
1802: }
1803:
1804: }
1805:
1806: }
1807:
1808:
1811: public void restoreAutoBounds() {
1812: restoreAutoDomainBounds();
1813: restoreAutoRangeBounds();
1814: }
1815:
1816:
1819: public void restoreAutoDomainBounds() {
1820: Plot p = this.chart.getPlot();
1821: if (p instanceof Zoomable) {
1822: Zoomable z = (Zoomable) p;
1823: z.zoomDomainAxes(0.0, this.info.getPlotInfo(), this.zoomPoint);
1824: }
1825: }
1826:
1827:
1830: public void restoreAutoRangeBounds() {
1831: Plot p = this.chart.getPlot();
1832: if (p instanceof Zoomable) {
1833: Zoomable z = (Zoomable) p;
1834: z.zoomRangeAxes(0.0, this.info.getPlotInfo(), this.zoomPoint);
1835: }
1836: }
1837:
1838:
1844: public Rectangle2D getScreenDataArea() {
1845: Rectangle2D dataArea = this.info.getPlotInfo().getDataArea();
1846: Insets insets = getInsets();
1847: double x = dataArea.getX() * this.scaleX + insets.left;
1848: double y = dataArea.getY() * this.scaleY + insets.top;
1849: double w = dataArea.getWidth() * this.scaleX;
1850: double h = dataArea.getHeight() * this.scaleY;
1851: return new Rectangle2D.Double(x, y, w, h);
1852: }
1853:
1854:
1863: public Rectangle2D getScreenDataArea(int x, int y) {
1864: PlotRenderingInfo plotInfo = this.info.getPlotInfo();
1865: Rectangle2D result;
1866: if (plotInfo.getSubplotCount() == 0) {
1867: result = getScreenDataArea();
1868: }
1869: else {
1870:
1871:
1872: Point2D selectOrigin = translateScreenToJava2D(new Point(x, y));
1873: int subplotIndex = plotInfo.getSubplotIndex(selectOrigin);
1874: if (subplotIndex == -1) {
1875: return null;
1876: }
1877: result = scale(plotInfo.getSubplotInfo(subplotIndex).getDataArea());
1878: }
1879: return result;
1880: }
1881:
1882:
1889: public int getInitialDelay() {
1890: return this.ownToolTipInitialDelay;
1891: }
1892:
1893:
1900: public int getReshowDelay() {
1901: return this.ownToolTipReshowDelay;
1902: }
1903:
1904:
1912: public int getDismissDelay() {
1913: return this.ownToolTipDismissDelay;
1914: }
1915:
1916:
1924: public void setInitialDelay(int delay) {
1925: this.ownToolTipInitialDelay = delay;
1926: }
1927:
1928:
1936: public void setReshowDelay(int delay) {
1937: this.ownToolTipReshowDelay = delay;
1938: }
1939:
1940:
1948: public void setDismissDelay(int delay) {
1949: this.ownToolTipDismissDelay = delay;
1950: }
1951:
1952:
1959: public double getZoomInFactor() {
1960: return this.zoomInFactor;
1961: }
1962:
1963:
1970: public void setZoomInFactor(double factor) {
1971: this.zoomInFactor = factor;
1972: }
1973:
1974:
1981: public double getZoomOutFactor() {
1982: return this.zoomOutFactor;
1983: }
1984:
1985:
1992: public void setZoomOutFactor(double factor) {
1993: this.zoomOutFactor = factor;
1994: }
1995:
1996:
2005: private void drawZoomRectangle(Graphics2D g2) {
2006:
2007: g2.setXORMode(Color.gray);
2008: if (this.zoomRectangle != null) {
2009: if (this.fillZoomRectangle) {
2010: g2.fill(this.zoomRectangle);
2011: }
2012: else {
2013: g2.draw(this.zoomRectangle);
2014: }
2015: }
2016:
2017: g2.setPaintMode();
2018: }
2019:
2020:
2027: private void drawHorizontalAxisTrace(Graphics2D g2, int x) {
2028:
2029: Rectangle2D dataArea = getScreenDataArea();
2030:
2031: g2.setXORMode(Color.orange);
2032: if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) {
2033:
2034: if (this.verticalTraceLine != null) {
2035: g2.draw(this.verticalTraceLine);
2036: this.verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x,
2037: (int) dataArea.getMaxY());
2038: }
2039: else {
2040: this.verticalTraceLine = new Line2D.Float(x,
2041: (int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
2042: }
2043: g2.draw(this.verticalTraceLine);
2044: }
2045:
2046:
2047: g2.setPaintMode();
2048: }
2049:
2050:
2057: private void drawVerticalAxisTrace(Graphics2D g2, int y) {
2058:
2059: Rectangle2D dataArea = getScreenDataArea();
2060:
2061: g2.setXORMode(Color.orange);
2062: if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) {
2063:
2064: if (this.horizontalTraceLine != null) {
2065: g2.draw(this.horizontalTraceLine);
2066: this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y,
2067: (int) dataArea.getMaxX(), y);
2068: }
2069: else {
2070: this.horizontalTraceLine = new Line2D.Float(
2071: (int) dataArea.getMinX(), y, (int) dataArea.getMaxX(),
2072: y);
2073: }
2074: g2.draw(this.horizontalTraceLine);
2075: }
2076:
2077:
2078: g2.setPaintMode();
2079: }
2080:
2081:
2087: public void doEditChartProperties() {
2088:
2089: ChartEditor editor = ChartEditorManager.getChartEditor(this.chart);
2090: int result = JOptionPane.showConfirmDialog(this, editor,
2091: localizationResources.getString("Chart_Properties"),
2092: JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
2093: if (result == JOptionPane.OK_OPTION) {
2094: editor.updateChart(this.chart);
2095: }
2096:
2097: }
2098:
2099:
2105: public void doSaveAs() throws IOException {
2106:
2107: JFileChooser fileChooser = new JFileChooser();
2108: ExtensionFileFilter filter = new ExtensionFileFilter(
2109: localizationResources.getString("PNG_Image_Files"), ".png");
2110: fileChooser.addChoosableFileFilter(filter);
2111:
2112: int option = fileChooser.showSaveDialog(this);
2113: if (option == JFileChooser.APPROVE_OPTION) {
2114: String filename = fileChooser.getSelectedFile().getPath();
2115: if (isEnforceFileExtensions()) {
2116: if (!filename.endsWith(".png")) {
2117: filename = filename + ".png";
2118: }
2119: }
2120: ChartUtilities.saveChartAsPNG(new File(filename), this.chart,
2121: getWidth(), getHeight());
2122: }
2123:
2124: }
2125:
2126:
2129: public void createChartPrintJob() {
2130:
2131: PrinterJob job = PrinterJob.getPrinterJob();
2132: PageFormat pf = job.defaultPage();
2133: PageFormat pf2 = job.pageDialog(pf);
2134: if (pf2 != pf) {
2135: job.setPrintable(this, pf2);
2136: if (job.printDialog()) {
2137: try {
2138: job.print();
2139: }
2140: catch (PrinterException e) {
2141: JOptionPane.showMessageDialog(this, e);
2142: }
2143: }
2144: }
2145:
2146: }
2147:
2148:
2158: public int print(Graphics g, PageFormat pf, int pageIndex) {
2159:
2160: if (pageIndex != 0) {
2161: return NO_SUCH_PAGE;
2162: }
2163: Graphics2D g2 = (Graphics2D) g;
2164: double x = pf.getImageableX();
2165: double y = pf.getImageableY();
2166: double w = pf.getImageableWidth();
2167: double h = pf.getImageableHeight();
2168: this.chart.draw(g2, new Rectangle2D.Double(x, y, w, h), this.anchor,
2169: null);
2170: return PAGE_EXISTS;
2171:
2172: }
2173:
2174:
2179: public void addChartMouseListener(ChartMouseListener listener) {
2180: if (listener == null) {
2181: throw new IllegalArgumentException("Null 'listener' argument.");
2182: }
2183: this.chartMouseListeners.add(ChartMouseListener.class, listener);
2184: }
2185:
2186:
2192: public void removeChartMouseListener(ChartMouseListener listener) {
2193: this.chartMouseListeners.remove(ChartMouseListener.class, listener);
2194: }
2195:
2196:
2204: public EventListener[] getListeners(Class listenerType) {
2205: if (listenerType == ChartMouseListener.class) {
2206:
2207: return this.chartMouseListeners.getListeners(listenerType);
2208: }
2209: else {
2210: return super.getListeners(listenerType);
2211: }
2212: }
2213:
2214:
2224: protected JPopupMenu createPopupMenu(boolean properties,
2225: boolean save,
2226: boolean print,
2227: boolean zoom) {
2228:
2229: JPopupMenu result = new JPopupMenu("Chart:");
2230: boolean separator = false;
2231:
2232: if (properties) {
2233: JMenuItem propertiesItem = new JMenuItem(
2234: localizationResources.getString("Properties..."));
2235: propertiesItem.setActionCommand(PROPERTIES_COMMAND);
2236: propertiesItem.addActionListener(this);
2237: result.add(propertiesItem);
2238: separator = true;
2239: }
2240:
2241: if (save) {
2242: if (separator) {
2243: result.addSeparator();
2244: separator = false;
2245: }
2246: JMenuItem saveItem = new JMenuItem(
2247: localizationResources.getString("Save_as..."));
2248: saveItem.setActionCommand(SAVE_COMMAND);
2249: saveItem.addActionListener(this);
2250: result.add(saveItem);
2251: separator = true;
2252: }
2253:
2254: if (print) {
2255: if (separator) {
2256: result.addSeparator();
2257: separator = false;
2258: }
2259: JMenuItem printItem = new JMenuItem(
2260: localizationResources.getString("Print..."));
2261: printItem.setActionCommand(PRINT_COMMAND);
2262: printItem.addActionListener(this);
2263: result.add(printItem);
2264: separator = true;
2265: }
2266:
2267: if (zoom) {
2268: if (separator) {
2269: result.addSeparator();
2270: separator = false;
2271: }
2272:
2273: JMenu zoomInMenu = new JMenu(
2274: localizationResources.getString("Zoom_In"));
2275:
2276: this.zoomInBothMenuItem = new JMenuItem(
2277: localizationResources.getString("All_Axes"));
2278: this.zoomInBothMenuItem.setActionCommand(ZOOM_IN_BOTH_COMMAND);
2279: this.zoomInBothMenuItem.addActionListener(this);
2280: zoomInMenu.add(this.zoomInBothMenuItem);
2281:
2282: zoomInMenu.addSeparator();
2283:
2284: this.zoomInDomainMenuItem = new JMenuItem(
2285: localizationResources.getString("Domain_Axis"));
2286: this.zoomInDomainMenuItem.setActionCommand(ZOOM_IN_DOMAIN_COMMAND);
2287: this.zoomInDomainMenuItem.addActionListener(this);
2288: zoomInMenu.add(this.zoomInDomainMenuItem);
2289:
2290: this.zoomInRangeMenuItem = new JMenuItem(
2291: localizationResources.getString("Range_Axis"));
2292: this.zoomInRangeMenuItem.setActionCommand(ZOOM_IN_RANGE_COMMAND);
2293: this.zoomInRangeMenuItem.addActionListener(this);
2294: zoomInMenu.add(this.zoomInRangeMenuItem);
2295:
2296: result.add(zoomInMenu);
2297:
2298: JMenu zoomOutMenu = new JMenu(
2299: localizationResources.getString("Zoom_Out"));
2300:
2301: this.zoomOutBothMenuItem = new JMenuItem(
2302: localizationResources.getString("All_Axes"));
2303: this.zoomOutBothMenuItem.setActionCommand(ZOOM_OUT_BOTH_COMMAND);
2304: this.zoomOutBothMenuItem.addActionListener(this);
2305: zoomOutMenu.add(this.zoomOutBothMenuItem);
2306:
2307: zoomOutMenu.addSeparator();
2308:
2309: this.zoomOutDomainMenuItem = new JMenuItem(
2310: localizationResources.getString("Domain_Axis"));
2311: this.zoomOutDomainMenuItem.setActionCommand(
2312: ZOOM_OUT_DOMAIN_COMMAND);
2313: this.zoomOutDomainMenuItem.addActionListener(this);
2314: zoomOutMenu.add(this.zoomOutDomainMenuItem);
2315:
2316: this.zoomOutRangeMenuItem = new JMenuItem(
2317: localizationResources.getString("Range_Axis"));
2318: this.zoomOutRangeMenuItem.setActionCommand(ZOOM_OUT_RANGE_COMMAND);
2319: this.zoomOutRangeMenuItem.addActionListener(this);
2320: zoomOutMenu.add(this.zoomOutRangeMenuItem);
2321:
2322: result.add(zoomOutMenu);
2323:
2324: JMenu autoRangeMenu = new JMenu(
2325: localizationResources.getString("Auto_Range"));
2326:
2327: this.zoomResetBothMenuItem = new JMenuItem(
2328: localizationResources.getString("All_Axes"));
2329: this.zoomResetBothMenuItem.setActionCommand(
2330: ZOOM_RESET_BOTH_COMMAND);
2331: this.zoomResetBothMenuItem.addActionListener(this);
2332: autoRangeMenu.add(this.zoomResetBothMenuItem);
2333:
2334: autoRangeMenu.addSeparator();
2335: this.zoomResetDomainMenuItem = new JMenuItem(
2336: localizationResources.getString("Domain_Axis"));
2337: this.zoomResetDomainMenuItem.setActionCommand(
2338: ZOOM_RESET_DOMAIN_COMMAND);
2339: this.zoomResetDomainMenuItem.addActionListener(this);
2340: autoRangeMenu.add(this.zoomResetDomainMenuItem);
2341:
2342: this.zoomResetRangeMenuItem = new JMenuItem(
2343: localizationResources.getString("Range_Axis"));
2344: this.zoomResetRangeMenuItem.setActionCommand(
2345: ZOOM_RESET_RANGE_COMMAND);
2346: this.zoomResetRangeMenuItem.addActionListener(this);
2347: autoRangeMenu.add(this.zoomResetRangeMenuItem);
2348:
2349: result.addSeparator();
2350: result.add(autoRangeMenu);
2351:
2352: }
2353:
2354: return result;
2355:
2356: }
2357:
2358:
2365: protected void displayPopupMenu(int x, int y) {
2366:
2367: if (this.popup != null) {
2368:
2369:
2370:
2371: Plot plot = this.chart.getPlot();
2372: boolean isDomainZoomable = false;
2373: boolean isRangeZoomable = false;
2374: if (plot instanceof Zoomable) {
2375: Zoomable z = (Zoomable) plot;
2376: isDomainZoomable = z.isDomainZoomable();
2377: isRangeZoomable = z.isRangeZoomable();
2378: }
2379:
2380: if (this.zoomInDomainMenuItem != null) {
2381: this.zoomInDomainMenuItem.setEnabled(isDomainZoomable);
2382: }
2383: if (this.zoomOutDomainMenuItem != null) {
2384: this.zoomOutDomainMenuItem.setEnabled(isDomainZoomable);
2385: }
2386: if (this.zoomResetDomainMenuItem != null) {
2387: this.zoomResetDomainMenuItem.setEnabled(isDomainZoomable);
2388: }
2389:
2390: if (this.zoomInRangeMenuItem != null) {
2391: this.zoomInRangeMenuItem.setEnabled(isRangeZoomable);
2392: }
2393: if (this.zoomOutRangeMenuItem != null) {
2394: this.zoomOutRangeMenuItem.setEnabled(isRangeZoomable);
2395: }
2396:
2397: if (this.zoomResetRangeMenuItem != null) {
2398: this.zoomResetRangeMenuItem.setEnabled(isRangeZoomable);
2399: }
2400:
2401: if (this.zoomInBothMenuItem != null) {
2402: this.zoomInBothMenuItem.setEnabled(isDomainZoomable
2403: && isRangeZoomable);
2404: }
2405: if (this.zoomOutBothMenuItem != null) {
2406: this.zoomOutBothMenuItem.setEnabled(isDomainZoomable
2407: && isRangeZoomable);
2408: }
2409: if (this.zoomResetBothMenuItem != null) {
2410: this.zoomResetBothMenuItem.setEnabled(isDomainZoomable
2411: && isRangeZoomable);
2412: }
2413:
2414: this.popup.show(this, x, y);
2415: }
2416:
2417: }
2418:
2419: }