1:
141:
142: package ;
143:
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: import ;
165: import ;
166: import ;
167: import ;
168: import ;
169: import ;
170:
171: import ;
172: import ;
173: import ;
174: import ;
175: import ;
176: import ;
177: import ;
178: import ;
179: import ;
180:
181: import ;
182: import ;
183: import ;
184: import ;
185: import ;
186: import ;
187: import ;
188: import ;
189: import ;
190: import ;
191: import ;
192: import ;
193: import ;
194:
195:
202: public class ChartPanel extends JPanel implements ChartChangeListener,
203: ChartProgressListener, ActionListener, MouseListener,
204: MouseMotionListener, Printable, Serializable {
205:
206:
207: private static final long serialVersionUID = 6046366297214274674L;
208:
209:
210: public static final boolean DEFAULT_BUFFER_USED = false;
211:
212:
213: public static final int DEFAULT_WIDTH = 680;
214:
215:
216: public static final int DEFAULT_HEIGHT = 420;
217:
218:
219: public static final int DEFAULT_MINIMUM_DRAW_WIDTH = 300;
220:
221:
222: public static final int DEFAULT_MINIMUM_DRAW_HEIGHT = 200;
223:
224:
225: public static final int DEFAULT_MAXIMUM_DRAW_WIDTH = 800;
226:
227:
228: public static final int DEFAULT_MAXIMUM_DRAW_HEIGHT = 600;
229:
230:
231: public static final int DEFAULT_ZOOM_TRIGGER_DISTANCE = 10;
232:
233:
234: public static final String PROPERTIES_COMMAND = "PROPERTIES";
235:
236:
237: public static final String SAVE_COMMAND = "SAVE";
238:
239:
240: public static final String PRINT_COMMAND = "PRINT";
241:
242:
243: public static final String ZOOM_IN_BOTH_COMMAND = "ZOOM_IN_BOTH";
244:
245:
246: public static final String ZOOM_IN_DOMAIN_COMMAND = "ZOOM_IN_DOMAIN";
247:
248:
249: public static final String ZOOM_IN_RANGE_COMMAND = "ZOOM_IN_RANGE";
250:
251:
252: public static final String ZOOM_OUT_BOTH_COMMAND = "ZOOM_OUT_BOTH";
253:
254:
255: public static final String ZOOM_OUT_DOMAIN_COMMAND = "ZOOM_DOMAIN_BOTH";
256:
257:
258: public static final String ZOOM_OUT_RANGE_COMMAND = "ZOOM_RANGE_BOTH";
259:
260:
261: public static final String ZOOM_RESET_BOTH_COMMAND = "ZOOM_RESET_BOTH";
262:
263:
264: public static final String ZOOM_RESET_DOMAIN_COMMAND = "ZOOM_RESET_DOMAIN";
265:
266:
267: public static final String ZOOM_RESET_RANGE_COMMAND = "ZOOM_RESET_RANGE";
268:
269:
270: private JFreeChart chart;
271:
272:
273: private EventListenerList chartMouseListeners;
274:
275:
276: private boolean useBuffer;
277:
278:
279: private boolean refreshBuffer;
280:
281:
282: private Image chartBuffer;
283:
284:
285: private int chartBufferHeight;
286:
287:
288: private int chartBufferWidth;
289:
290:
293: private int minimumDrawWidth;
294:
295:
299: private int minimumDrawHeight;
300:
301:
305: private int maximumDrawWidth;
306:
307:
311: private int maximumDrawHeight;
312:
313:
314: private JPopupMenu popup;
315:
316:
317: private ChartRenderingInfo info;
318:
319:
320: private Point2D anchor;
321:
322:
323: private double scaleX;
324:
325:
326: private double scaleY;
327:
328:
329: private PlotOrientation orientation = PlotOrientation.VERTICAL;
330:
331:
332: private boolean domainZoomable = false;
333:
334:
335: private boolean rangeZoomable = false;
336:
337:
342: private Point zoomPoint = null;
343:
344:
345: private transient Rectangle2D zoomRectangle = null;
346:
347:
348: private boolean fillZoomRectangle = false;
349:
350:
351: private int zoomTriggerDistance;
352:
353:
354: private boolean horizontalAxisTrace = false;
355:
356:
357: private boolean verticalAxisTrace = false;
358:
359:
360: private transient Line2D verticalTraceLine;
361:
362:
363: private transient Line2D horizontalTraceLine;
364:
365:
366: private JMenuItem zoomInBothMenuItem;
367:
368:
369: private JMenuItem zoomInDomainMenuItem;
370:
371:
372: private JMenuItem zoomInRangeMenuItem;
373:
374:
375: private JMenuItem zoomOutBothMenuItem;
376:
377:
378: private JMenuItem zoomOutDomainMenuItem;
379:
380:
381: private JMenuItem zoomOutRangeMenuItem;
382:
383:
384: private JMenuItem zoomResetBothMenuItem;
385:
386:
387: private JMenuItem zoomResetDomainMenuItem;
388:
389:
390: private JMenuItem zoomResetRangeMenuItem;
391:
392:
397: private File defaultDirectoryForSaveAs;
398:
399:
400: private boolean enforceFileExtensions;
401:
402:
403: private boolean ownToolTipDelaysActive;
404:
405:
406: private int originalToolTipInitialDelay;
407:
408:
409: private int originalToolTipReshowDelay;
410:
411:
412: private int originalToolTipDismissDelay;
413:
414:
415: private int ownToolTipInitialDelay;
416:
417:
418: private int ownToolTipReshowDelay;
419:
420:
421: private int ownToolTipDismissDelay;
422:
423:
424: private double zoomInFactor = 0.5;
425:
426:
427: private double zoomOutFactor = 2.0;
428:
429:
435: private boolean zoomAroundAnchor;
436:
437:
438: protected static ResourceBundle localizationResources
439: = ResourceBundle.getBundle("org.jfree.chart.LocalizationBundle");
440:
441:
446: public ChartPanel(JFreeChart chart) {
447:
448: this(
449: chart,
450: DEFAULT_WIDTH,
451: DEFAULT_HEIGHT,
452: DEFAULT_MINIMUM_DRAW_WIDTH,
453: DEFAULT_MINIMUM_DRAW_HEIGHT,
454: DEFAULT_MAXIMUM_DRAW_WIDTH,
455: DEFAULT_MAXIMUM_DRAW_HEIGHT,
456: DEFAULT_BUFFER_USED,
457: true,
458: true,
459: true,
460: true,
461: true
462: );
463:
464: }
465:
466:
473: public ChartPanel(JFreeChart chart, boolean useBuffer) {
474:
475: this(chart,
476: DEFAULT_WIDTH,
477: DEFAULT_HEIGHT,
478: DEFAULT_MINIMUM_DRAW_WIDTH,
479: DEFAULT_MINIMUM_DRAW_HEIGHT,
480: DEFAULT_MAXIMUM_DRAW_WIDTH,
481: DEFAULT_MAXIMUM_DRAW_HEIGHT,
482: useBuffer,
483: true,
484: true,
485: true,
486: true,
487: true
488: );
489:
490: }
491:
492:
507: public ChartPanel(JFreeChart chart,
508: boolean properties,
509: boolean save,
510: boolean print,
511: boolean zoom,
512: boolean tooltips) {
513:
514: this(chart,
515: DEFAULT_WIDTH,
516: DEFAULT_HEIGHT,
517: DEFAULT_MINIMUM_DRAW_WIDTH,
518: DEFAULT_MINIMUM_DRAW_HEIGHT,
519: DEFAULT_MAXIMUM_DRAW_WIDTH,
520: DEFAULT_MAXIMUM_DRAW_HEIGHT,
521: DEFAULT_BUFFER_USED,
522: properties,
523: save,
524: print,
525: zoom,
526: tooltips
527: );
528:
529: }
530:
531:
555: public ChartPanel(JFreeChart chart,
556: int width,
557: int height,
558: int minimumDrawWidth,
559: int minimumDrawHeight,
560: int maximumDrawWidth,
561: int maximumDrawHeight,
562: boolean useBuffer,
563: boolean properties,
564: boolean save,
565: boolean print,
566: boolean zoom,
567: boolean tooltips) {
568:
569: this.setChart(chart);
570: this.chartMouseListeners = new EventListenerList();
571: this.info = new ChartRenderingInfo();
572: setPreferredSize(new Dimension(width, height));
573: this.useBuffer = useBuffer;
574: this.refreshBuffer = false;
575: this.minimumDrawWidth = minimumDrawWidth;
576: this.minimumDrawHeight = minimumDrawHeight;
577: this.maximumDrawWidth = maximumDrawWidth;
578: this.maximumDrawHeight = maximumDrawHeight;
579: this.zoomTriggerDistance = DEFAULT_ZOOM_TRIGGER_DISTANCE;
580:
581:
582: this.popup = null;
583: if (properties || save || print || zoom) {
584: this.popup = createPopupMenu(properties, save, print, zoom);
585: }
586:
587: enableEvents(AWTEvent.MOUSE_EVENT_MASK);
588: enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK);
589: setDisplayToolTips(tooltips);
590: addMouseListener(this);
591: addMouseMotionListener(this);
592:
593: this.defaultDirectoryForSaveAs = null;
594: this.enforceFileExtensions = true;
595:
596:
597:
598: ToolTipManager ttm = ToolTipManager.sharedInstance();
599: this.ownToolTipInitialDelay = ttm.getInitialDelay();
600: this.ownToolTipDismissDelay = ttm.getDismissDelay();
601: this.ownToolTipReshowDelay = ttm.getReshowDelay();
602:
603: this.zoomAroundAnchor = false;
604: }
605:
606:
611: public JFreeChart getChart() {
612: return this.chart;
613: }
614:
615:
620: public void setChart(JFreeChart chart) {
621:
622:
623: if (this.chart != null) {
624: this.chart.removeChangeListener(this);
625: this.chart.removeProgressListener(this);
626: }
627:
628:
629: this.chart = chart;
630: if (chart != null) {
631: this.chart.addChangeListener(this);
632: this.chart.addProgressListener(this);
633: Plot plot = chart.getPlot();
634: this.domainZoomable = false;
635: this.rangeZoomable = false;
636: if (plot instanceof Zoomable) {
637: Zoomable z = (Zoomable) plot;
638: this.domainZoomable = z.isDomainZoomable();
639: this.rangeZoomable = z.isRangeZoomable();
640: this.orientation = z.getOrientation();
641: }
642: }
643: else {
644: this.domainZoomable = false;
645: this.rangeZoomable = false;
646: }
647: if (this.useBuffer) {
648: this.refreshBuffer = true;
649: }
650: repaint();
651:
652: }
653:
654:
662: public int getMinimumDrawWidth() {
663: return this.minimumDrawWidth;
664: }
665:
666:
675: public void setMinimumDrawWidth(int width) {
676: this.minimumDrawWidth = width;
677: }
678:
679:
687: public int getMaximumDrawWidth() {
688: return this.maximumDrawWidth;
689: }
690:
691:
700: public void setMaximumDrawWidth(int width) {
701: this.maximumDrawWidth = width;
702: }
703:
704:
712: public int getMinimumDrawHeight() {
713: return this.minimumDrawHeight;
714: }
715:
716:
725: public void setMinimumDrawHeight(int height) {
726: this.minimumDrawHeight = height;
727: }
728:
729:
737: public int getMaximumDrawHeight() {
738: return this.maximumDrawHeight;
739: }
740:
741:
750: public void setMaximumDrawHeight(int height) {
751: this.maximumDrawHeight = height;
752: }
753:
754:
760: public double getScaleX() {
761: return this.scaleX;
762: }
763:
764:
770: public double getScaleY() {
771: return this.scaleY;
772: }
773:
774:
779: public Point2D getAnchor() {
780: return this.anchor;
781: }
782:
783:
789: protected void setAnchor(Point2D anchor) {
790: this.anchor = anchor;
791: }
792:
793:
798: public JPopupMenu getPopupMenu() {
799: return this.popup;
800: }
801:
802:
807: public void setPopupMenu(JPopupMenu popup) {
808: this.popup = popup;
809: }
810:
811:
816: public ChartRenderingInfo getChartRenderingInfo() {
817: return this.info;
818: }
819:
820:
826: public void setMouseZoomable(boolean flag) {
827: setMouseZoomable(flag, true);
828: }
829:
830:
837: public void setMouseZoomable(boolean flag, boolean fillRectangle) {
838: setDomainZoomable(flag);
839: setRangeZoomable(flag);
840: setFillZoomRectangle(fillRectangle);
841: }
842:
843:
849: public boolean isDomainZoomable() {
850: return this.domainZoomable;
851: }
852:
853:
860: public void setDomainZoomable(boolean flag) {
861: if (flag) {
862: Plot plot = this.chart.getPlot();
863: if (plot instanceof Zoomable) {
864: Zoomable z = (Zoomable) plot;
865: this.domainZoomable = flag && (z.isDomainZoomable());
866: }
867: }
868: else {
869: this.domainZoomable = false;
870: }
871: }
872:
873:
879: public boolean isRangeZoomable() {
880: return this.rangeZoomable;
881: }
882:
883:
888: public void setRangeZoomable(boolean flag) {
889: if (flag) {
890: Plot plot = this.chart.getPlot();
891: if (plot instanceof Zoomable) {
892: Zoomable z = (Zoomable) plot;
893: this.rangeZoomable = flag && (z.isRangeZoomable());
894: }
895: }
896: else {
897: this.rangeZoomable = false;
898: }
899: }
900:
901:
907: public boolean getFillZoomRectangle() {
908: return this.fillZoomRectangle;
909: }
910:
911:
917: public void setFillZoomRectangle(boolean flag) {
918: this.fillZoomRectangle = flag;
919: }
920:
921:
927: public int getZoomTriggerDistance() {
928: return this.zoomTriggerDistance;
929: }
930:
931:
937: public void setZoomTriggerDistance(int distance) {
938: this.zoomTriggerDistance = distance;
939: }
940:
941:
947: public boolean getHorizontalAxisTrace() {
948: return this.horizontalAxisTrace;
949: }
950:
951:
957: public void setHorizontalAxisTrace(boolean flag) {
958: this.horizontalAxisTrace = flag;
959: }
960:
961:
966: protected Line2D getHorizontalTraceLine() {
967: return this.horizontalTraceLine;
968: }
969:
970:
975: protected void setHorizontalTraceLine(Line2D line) {
976: this.horizontalTraceLine = line;
977: }
978:
979:
985: public boolean getVerticalAxisTrace() {
986: return this.verticalAxisTrace;
987: }
988:
989:
995: public void setVerticalAxisTrace(boolean flag) {
996: this.verticalAxisTrace = flag;
997: }
998:
999:
1004: protected Line2D getVerticalTraceLine() {
1005: return this.verticalTraceLine;
1006: }
1007:
1008:
1013: protected void setVerticalTraceLine(Line2D line) {
1014: this.verticalTraceLine = line;
1015: }
1016:
1017:
1024: public File getDefaultDirectoryForSaveAs() {
1025: return this.defaultDirectoryForSaveAs;
1026: }
1027:
1028:
1036: public void setDefaultDirectoryForSaveAs(File directory) {
1037: if (directory != null) {
1038: if (!directory.isDirectory()) {
1039: throw new IllegalArgumentException(
1040: "The 'directory' argument is not a directory.");
1041: }
1042: }
1043: this.defaultDirectoryForSaveAs = directory;
1044: }
1045:
1046:
1054: public boolean isEnforceFileExtensions() {
1055: return this.enforceFileExtensions;
1056: }
1057:
1058:
1065: public void setEnforceFileExtensions(boolean enforce) {
1066: this.enforceFileExtensions = enforce;
1067: }
1068:
1069:
1079: public boolean getZoomAroundAnchor() {
1080: return this.zoomAroundAnchor;
1081: }
1082:
1083:
1093: public void setZoomAroundAnchor(boolean zoomAroundAnchor) {
1094: this.zoomAroundAnchor = zoomAroundAnchor;
1095: }
1096:
1097:
1105: public void setDisplayToolTips(boolean flag) {
1106: if (flag) {
1107: ToolTipManager.sharedInstance().registerComponent(this);
1108: }
1109: else {
1110: ToolTipManager.sharedInstance().unregisterComponent(this);
1111: }
1112: }
1113:
1114:
1121: public String getToolTipText(MouseEvent e) {
1122:
1123: String result = null;
1124: if (this.info != null) {
1125: EntityCollection entities = this.info.getEntityCollection();
1126: if (entities != null) {
1127: Insets insets = getInsets();
1128: ChartEntity entity = entities.getEntity(
1129: (int) ((e.getX() - insets.left) / this.scaleX),
1130: (int) ((e.getY() - insets.top) / this.scaleY));
1131: if (entity != null) {
1132: result = entity.getToolTipText();
1133: }
1134: }
1135: }
1136: return result;
1137:
1138: }
1139:
1140:
1147: public Point translateJava2DToScreen(Point2D java2DPoint) {
1148: Insets insets = getInsets();
1149: int x = (int) (java2DPoint.getX() * this.scaleX + insets.left);
1150: int y = (int) (java2DPoint.getY() * this.scaleY + insets.top);
1151: return new Point(x, y);
1152: }
1153:
1154:
1162: public Point2D translateScreenToJava2D(Point screenPoint) {
1163: Insets insets = getInsets();
1164: double x = (screenPoint.getX() - insets.left) / this.scaleX;
1165: double y = (screenPoint.getY() - insets.top) / this.scaleY;
1166: return new Point2D.Double(x, y);
1167: }
1168:
1169:
1177: public Rectangle2D scale(Rectangle2D rect) {
1178: Insets insets = getInsets();
1179: double x = rect.getX() * getScaleX() + insets.left;
1180: double y = rect.getY() * this.getScaleY() + insets.top;
1181: double w = rect.getWidth() * this.getScaleX();
1182: double h = rect.getHeight() * this.getScaleY();
1183: return new Rectangle2D.Double(x, y, w, h);
1184: }
1185:
1186:
1197: public ChartEntity getEntityForPoint(int viewX, int viewY) {
1198:
1199: ChartEntity result = null;
1200: if (this.info != null) {
1201: Insets insets = getInsets();
1202: double x = (viewX - insets.left) / this.scaleX;
1203: double y = (viewY - insets.top) / this.scaleY;
1204: EntityCollection entities = this.info.getEntityCollection();
1205: result = entities != null ? entities.getEntity(x, y) : null;
1206: }
1207: return result;
1208:
1209: }
1210:
1211:
1217: public boolean getRefreshBuffer() {
1218: return this.refreshBuffer;
1219: }
1220:
1221:
1228: public void setRefreshBuffer(boolean flag) {
1229: this.refreshBuffer = flag;
1230: }
1231:
1232:
1240: public void paintComponent(Graphics g) {
1241: super.paintComponent(g);
1242: if (this.chart == null) {
1243: return;
1244: }
1245: Graphics2D g2 = (Graphics2D) g.create();
1246:
1247:
1248: Dimension size = getSize();
1249: Insets insets = getInsets();
1250: Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top,
1251: size.getWidth() - insets.left - insets.right,
1252: size.getHeight() - insets.top - insets.bottom);
1253:
1254:
1255: boolean scale = false;
1256: double drawWidth = available.getWidth();
1257: double drawHeight = available.getHeight();
1258: this.scaleX = 1.0;
1259: this.scaleY = 1.0;
1260:
1261: if (drawWidth < this.minimumDrawWidth) {
1262: this.scaleX = drawWidth / this.minimumDrawWidth;
1263: drawWidth = this.minimumDrawWidth;
1264: scale = true;
1265: }
1266: else if (drawWidth > this.maximumDrawWidth) {
1267: this.scaleX = drawWidth / this.maximumDrawWidth;
1268: drawWidth = this.maximumDrawWidth;
1269: scale = true;
1270: }
1271:
1272: if (drawHeight < this.minimumDrawHeight) {
1273: this.scaleY = drawHeight / this.minimumDrawHeight;
1274: drawHeight = this.minimumDrawHeight;
1275: scale = true;
1276: }
1277: else if (drawHeight > this.maximumDrawHeight) {
1278: this.scaleY = drawHeight / this.maximumDrawHeight;
1279: drawHeight = this.maximumDrawHeight;
1280: scale = true;
1281: }
1282:
1283: Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth,
1284: drawHeight);
1285:
1286:
1287: if (this.useBuffer) {
1288:
1289:
1290:
1291: boolean clearBuffer = true;
1292:
1293:
1294: if ((this.chartBuffer == null)
1295: || (this.chartBufferWidth != available.getWidth())
1296: || (this.chartBufferHeight != available.getHeight())) {
1297: this.chartBufferWidth = (int) available.getWidth();
1298: this.chartBufferHeight = (int) available.getHeight();
1299: this.chartBuffer = createImage(this.chartBufferWidth,
1300: this.chartBufferHeight);
1301:
1302:
1303:
1304:
1305: this.refreshBuffer = true;
1306: clearBuffer = false;
1307: }
1308:
1309:
1310: if (this.refreshBuffer) {
1311:
1312: this.refreshBuffer = false;
1313:
1314: Rectangle2D bufferArea = new Rectangle2D.Double(
1315: 0, 0, this.chartBufferWidth, this.chartBufferHeight);
1316:
1317: Graphics2D bufferG2 = (Graphics2D)
1318: this.chartBuffer.getGraphics();
1319: if (clearBuffer) {
1320: bufferG2.clearRect(0, 0, this.chartBufferWidth,
1321: this.chartBufferHeight);
1322: }
1323: if (scale) {
1324: AffineTransform saved = bufferG2.getTransform();
1325: AffineTransform st = AffineTransform.getScaleInstance(
1326: this.scaleX, this.scaleY);
1327: bufferG2.transform(st);
1328: this.chart.draw(bufferG2, chartArea, this.anchor,
1329: this.info);
1330: bufferG2.setTransform(saved);
1331: }
1332: else {
1333: this.chart.draw(bufferG2, bufferArea, this.anchor,
1334: this.info);
1335: }
1336:
1337: }
1338:
1339:
1340: g2.drawImage(this.chartBuffer, insets.left, insets.top, this);
1341:
1342: }
1343:
1344:
1345: else {
1346:
1347: AffineTransform saved = g2.getTransform();
1348: g2.translate(insets.left, insets.top);
1349: if (scale) {
1350: AffineTransform st = AffineTransform.getScaleInstance(
1351: this.scaleX, this.scaleY);
1352: g2.transform(st);
1353: }
1354: this.chart.draw(g2, chartArea, this.anchor, this.info);
1355: g2.setTransform(saved);
1356:
1357: }
1358:
1359:
1360: drawZoomRectangle(g2);
1361:
1362: g2.dispose();
1363:
1364: this.anchor = null;
1365: this.verticalTraceLine = null;
1366: this.horizontalTraceLine = null;
1367:
1368: }
1369:
1370:
1375: public void chartChanged(ChartChangeEvent event) {
1376: this.refreshBuffer = true;
1377: Plot plot = this.chart.getPlot();
1378: if (plot instanceof Zoomable) {
1379: Zoomable z = (Zoomable) plot;
1380: this.orientation = z.getOrientation();
1381: }
1382: repaint();
1383: }
1384:
1385:
1390: public void chartProgress(ChartProgressEvent event) {
1391:
1392: }
1393:
1394:
1399: public void actionPerformed(ActionEvent event) {
1400:
1401: String command = event.getActionCommand();
1402:
1403:
1404:
1405:
1406: double screenX = -1.0;
1407: double screenY = -1.0;
1408: if (this.zoomPoint != null) {
1409: screenX = this.zoomPoint.getX();
1410: screenY = this.zoomPoint.getY();
1411: }
1412:
1413: if (command.equals(PROPERTIES_COMMAND)) {
1414: doEditChartProperties();
1415: }
1416: else if (command.equals(SAVE_COMMAND)) {
1417: try {
1418: doSaveAs();
1419: }
1420: catch (IOException e) {
1421: e.printStackTrace();
1422: }
1423: }
1424: else if (command.equals(PRINT_COMMAND)) {
1425: createChartPrintJob();
1426: }
1427: else if (command.equals(ZOOM_IN_BOTH_COMMAND)) {
1428: zoomInBoth(screenX, screenY);
1429: }
1430: else if (command.equals(ZOOM_IN_DOMAIN_COMMAND)) {
1431: zoomInDomain(screenX, screenY);
1432: }
1433: else if (command.equals(ZOOM_IN_RANGE_COMMAND)) {
1434: zoomInRange(screenX, screenY);
1435: }
1436: else if (command.equals(ZOOM_OUT_BOTH_COMMAND)) {
1437: zoomOutBoth(screenX, screenY);
1438: }
1439: else if (command.equals(ZOOM_OUT_DOMAIN_COMMAND)) {
1440: zoomOutDomain(screenX, screenY);
1441: }
1442: else if (command.equals(ZOOM_OUT_RANGE_COMMAND)) {
1443: zoomOutRange(screenX, screenY);
1444: }
1445: else if (command.equals(ZOOM_RESET_BOTH_COMMAND)) {
1446: restoreAutoBounds();
1447: }
1448: else if (command.equals(ZOOM_RESET_DOMAIN_COMMAND)) {
1449: restoreAutoDomainBounds();
1450: }
1451: else if (command.equals(ZOOM_RESET_RANGE_COMMAND)) {
1452: restoreAutoRangeBounds();
1453: }
1454:
1455: }
1456:
1457:
1464: public void mouseEntered(MouseEvent e) {
1465: if (!this.ownToolTipDelaysActive) {
1466: ToolTipManager ttm = ToolTipManager.sharedInstance();
1467:
1468: this.originalToolTipInitialDelay = ttm.getInitialDelay();
1469: ttm.setInitialDelay(this.ownToolTipInitialDelay);
1470:
1471: this.originalToolTipReshowDelay = ttm.getReshowDelay();
1472: ttm.setReshowDelay(this.ownToolTipReshowDelay);
1473:
1474: this.originalToolTipDismissDelay = ttm.getDismissDelay();
1475: ttm.setDismissDelay(this.ownToolTipDismissDelay);
1476:
1477: this.ownToolTipDelaysActive = true;
1478: }
1479: }
1480:
1481:
1488: public void mouseExited(MouseEvent e) {
1489: if (this.ownToolTipDelaysActive) {
1490:
1491: ToolTipManager ttm = ToolTipManager.sharedInstance();
1492: ttm.setInitialDelay(this.originalToolTipInitialDelay);
1493: ttm.setReshowDelay(this.originalToolTipReshowDelay);
1494: ttm.setDismissDelay(this.originalToolTipDismissDelay);
1495: this.ownToolTipDelaysActive = false;
1496: }
1497: }
1498:
1499:
1507: public void mousePressed(MouseEvent e) {
1508: if (this.zoomRectangle == null) {
1509: Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY());
1510: if (screenDataArea != null) {
1511: this.zoomPoint = getPointInRectangle(e.getX(), e.getY(),
1512: screenDataArea);
1513: }
1514: else {
1515: this.zoomPoint = null;
1516: }
1517: if (e.isPopupTrigger()) {
1518: if (this.popup != null) {
1519: displayPopupMenu(e.getX(), e.getY());
1520: }
1521: }
1522: }
1523: }
1524:
1525:
1535: private Point getPointInRectangle(int x, int y, Rectangle2D area) {
1536: x = (int) Math.max(Math.ceil(area.getMinX()), Math.min(x,
1537: Math.floor(area.getMaxX())));
1538: y = (int) Math.max(Math.ceil(area.getMinY()), Math.min(y,
1539: Math.floor(area.getMaxY())));
1540: return new Point(x, y);
1541: }
1542:
1543:
1548: public void mouseDragged(MouseEvent e) {
1549:
1550:
1551: if (this.popup != null && this.popup.isShowing()) {
1552: return;
1553: }
1554:
1555: if (this.zoomPoint == null) {
1556: return;
1557: }
1558: Graphics2D g2 = (Graphics2D) getGraphics();
1559:
1560:
1561: drawZoomRectangle(g2);
1562:
1563: boolean hZoom = false;
1564: boolean vZoom = false;
1565: if (this.orientation == PlotOrientation.HORIZONTAL) {
1566: hZoom = this.rangeZoomable;
1567: vZoom = this.domainZoomable;
1568: }
1569: else {
1570: hZoom = this.domainZoomable;
1571: vZoom = this.rangeZoomable;
1572: }
1573: Rectangle2D scaledDataArea = getScreenDataArea(
1574: (int) this.zoomPoint.getX(), (int) this.zoomPoint.getY());
1575: if (hZoom && vZoom) {
1576:
1577: double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
1578: double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
1579: this.zoomRectangle = new Rectangle2D.Double(
1580: this.zoomPoint.getX(), this.zoomPoint.getY(),
1581: xmax - this.zoomPoint.getX(), ymax - this.zoomPoint.getY());
1582: }
1583: else if (hZoom) {
1584: double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
1585: this.zoomRectangle = new Rectangle2D.Double(
1586: this.zoomPoint.getX(), scaledDataArea.getMinY(),
1587: xmax - this.zoomPoint.getX(), scaledDataArea.getHeight());
1588: }
1589: else if (vZoom) {
1590: double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
1591: this.zoomRectangle = new Rectangle2D.Double(
1592: scaledDataArea.getMinX(), this.zoomPoint.getY(),
1593: scaledDataArea.getWidth(), ymax - this.zoomPoint.getY());
1594: }
1595:
1596:
1597: drawZoomRectangle(g2);
1598:
1599: g2.dispose();
1600:
1601: }
1602:
1603:
1610: public void mouseReleased(MouseEvent e) {
1611:
1612: if (this.zoomRectangle != null) {
1613: boolean hZoom = false;
1614: boolean vZoom = false;
1615: if (this.orientation == PlotOrientation.HORIZONTAL) {
1616: hZoom = this.rangeZoomable;
1617: vZoom = this.domainZoomable;
1618: }
1619: else {
1620: hZoom = this.domainZoomable;
1621: vZoom = this.rangeZoomable;
1622: }
1623:
1624: boolean zoomTrigger1 = hZoom && Math.abs(e.getX()
1625: - this.zoomPoint.getX()) >= this.zoomTriggerDistance;
1626: boolean zoomTrigger2 = vZoom && Math.abs(e.getY()
1627: - this.zoomPoint.getY()) >= this.zoomTriggerDistance;
1628: if (zoomTrigger1 || zoomTrigger2) {
1629: if ((hZoom && (e.getX() < this.zoomPoint.getX()))
1630: || (vZoom && (e.getY() < this.zoomPoint.getY()))) {
1631: restoreAutoBounds();
1632: }
1633: else {
1634: double x, y, w, h;
1635: Rectangle2D screenDataArea = getScreenDataArea(
1636: (int) this.zoomPoint.getX(),
1637: (int) this.zoomPoint.getY());
1638:
1639:
1640:
1641: if (!vZoom) {
1642: x = this.zoomPoint.getX();
1643: y = screenDataArea.getMinY();
1644: w = Math.min(this.zoomRectangle.getWidth(),
1645: screenDataArea.getMaxX()
1646: - this.zoomPoint.getX());
1647: h = screenDataArea.getHeight();
1648: }
1649: else if (!hZoom) {
1650: x = screenDataArea.getMinX();
1651: y = this.zoomPoint.getY();
1652: w = screenDataArea.getWidth();
1653: h = Math.min(this.zoomRectangle.getHeight(),
1654: screenDataArea.getMaxY()
1655: - this.zoomPoint.getY());
1656: }
1657: else {
1658: x = this.zoomPoint.getX();
1659: y = this.zoomPoint.getY();
1660: w = Math.min(this.zoomRectangle.getWidth(),
1661: screenDataArea.getMaxX()
1662: - this.zoomPoint.getX());
1663: h = Math.min(this.zoomRectangle.getHeight(),
1664: screenDataArea.getMaxY()
1665: - this.zoomPoint.getY());
1666: }
1667: Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
1668: zoom(zoomArea);
1669: }
1670: this.zoomPoint = null;
1671: this.zoomRectangle = null;
1672: }
1673: else {
1674:
1675: Graphics2D g2 = (Graphics2D) getGraphics();
1676: drawZoomRectangle(g2);
1677: g2.dispose();
1678: this.zoomPoint = null;
1679: this.zoomRectangle = null;
1680: }
1681:
1682: }
1683:
1684: else if (e.isPopupTrigger()) {
1685: if (this.popup != null) {
1686: displayPopupMenu(e.getX(), e.getY());
1687: }
1688: }
1689:
1690: }
1691:
1692:
1698: public void mouseClicked(MouseEvent event) {
1699:
1700: Insets insets = getInsets();
1701: int x = (int) ((event.getX() - insets.left) / this.scaleX);
1702: int y = (int) ((event.getY() - insets.top) / this.scaleY);
1703:
1704: this.anchor = new Point2D.Double(x, y);
1705: if (this.chart == null) {
1706: return;
1707: }
1708: this.chart.setNotify(true);
1709:
1710: Object[] listeners = this.chartMouseListeners.getListeners(
1711: ChartMouseListener.class);
1712: if (listeners.length == 0) {
1713: return;
1714: }
1715:
1716: ChartEntity entity = null;
1717: if (this.info != null) {
1718: EntityCollection entities = this.info.getEntityCollection();
1719: if (entities != null) {
1720: entity = entities.getEntity(x, y);
1721: }
1722: }
1723: ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), event,
1724: entity);
1725: for (int i = listeners.length - 1; i >= 0; i -= 1) {
1726: ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent);
1727: }
1728:
1729: }
1730:
1731:
1736: public void mouseMoved(MouseEvent e) {
1737: Graphics2D g2 = (Graphics2D) getGraphics();
1738: if (this.horizontalAxisTrace) {
1739: drawHorizontalAxisTrace(g2, e.getX());
1740: }
1741: if (this.verticalAxisTrace) {
1742: drawVerticalAxisTrace(g2, e.getY());
1743: }
1744: g2.dispose();
1745:
1746: Object[] listeners = this.chartMouseListeners.getListeners(
1747: ChartMouseListener.class);
1748: if (listeners.length == 0) {
1749: return;
1750: }
1751: Insets insets = getInsets();
1752: int x = (int) ((e.getX() - insets.left) / this.scaleX);
1753: int y = (int) ((e.getY() - insets.top) / this.scaleY);
1754:
1755: ChartEntity entity = null;
1756: if (this.info != null) {
1757: EntityCollection entities = this.info.getEntityCollection();
1758: if (entities != null) {
1759: entity = entities.getEntity(x, y);
1760: }
1761: }
1762:
1763:
1764:
1765: if (this.chart != null) {
1766: ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity);
1767: for (int i = listeners.length - 1; i >= 0; i -= 1) {
1768: ((ChartMouseListener) listeners[i]).chartMouseMoved(event);
1769: }
1770: }
1771:
1772: }
1773:
1774:
1780: public void zoomInBoth(double x, double y) {
1781: zoomInDomain(x, y);
1782: zoomInRange(x, y);
1783: }
1784:
1785:
1793: public void zoomInDomain(double x, double y) {
1794: Plot p = this.chart.getPlot();
1795: if (p instanceof Zoomable) {
1796: Zoomable plot = (Zoomable) p;
1797: plot.zoomDomainAxes(this.zoomInFactor, this.info.getPlotInfo(),
1798: translateScreenToJava2D(new Point((int) x, (int) y)),
1799: this.zoomAroundAnchor);
1800: }
1801: }
1802:
1803:
1811: public void zoomInRange(double x, double y) {
1812: Plot p = this.chart.getPlot();
1813: if (p instanceof Zoomable) {
1814: Zoomable z = (Zoomable) p;
1815: z.zoomRangeAxes(this.zoomInFactor, this.info.getPlotInfo(),
1816: translateScreenToJava2D(new Point((int) x, (int) y)),
1817: this.zoomAroundAnchor);
1818: }
1819: }
1820:
1821:
1827: public void zoomOutBoth(double x, double y) {
1828: zoomOutDomain(x, y);
1829: zoomOutRange(x, y);
1830: }
1831:
1832:
1840: public void zoomOutDomain(double x, double y) {
1841: Plot p = this.chart.getPlot();
1842: if (p instanceof Zoomable) {
1843: Zoomable z = (Zoomable) p;
1844: z.zoomDomainAxes(this.zoomOutFactor, this.info.getPlotInfo(),
1845: translateScreenToJava2D(new Point((int) x, (int) y)),
1846: this.zoomAroundAnchor);
1847: }
1848: }
1849:
1850:
1858: public void zoomOutRange(double x, double y) {
1859: Plot p = this.chart.getPlot();
1860: if (p instanceof Zoomable) {
1861: Zoomable z = (Zoomable) p;
1862: z.zoomRangeAxes(this.zoomOutFactor, this.info.getPlotInfo(),
1863: translateScreenToJava2D(new Point((int) x, (int) y)),
1864: this.zoomAroundAnchor);
1865: }
1866: }
1867:
1868:
1873: public void zoom(Rectangle2D selection) {
1874:
1875:
1876:
1877: Point2D selectOrigin = translateScreenToJava2D(new Point(
1878: (int) Math.ceil(selection.getX()),
1879: (int) Math.ceil(selection.getY())));
1880: PlotRenderingInfo plotInfo = this.info.getPlotInfo();
1881: Rectangle2D scaledDataArea = getScreenDataArea(
1882: (int) selection.getCenterX(), (int) selection.getCenterY());
1883: if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) {
1884:
1885: double hLower = (selection.getMinX() - scaledDataArea.getMinX())
1886: / scaledDataArea.getWidth();
1887: double hUpper = (selection.getMaxX() - scaledDataArea.getMinX())
1888: / scaledDataArea.getWidth();
1889: double vLower = (scaledDataArea.getMaxY() - selection.getMaxY())
1890: / scaledDataArea.getHeight();
1891: double vUpper = (scaledDataArea.getMaxY() - selection.getMinY())
1892: / scaledDataArea.getHeight();
1893:
1894: Plot p = this.chart.getPlot();
1895: if (p instanceof Zoomable) {
1896: Zoomable z = (Zoomable) p;
1897: if (z.getOrientation() == PlotOrientation.HORIZONTAL) {
1898: z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin);
1899: z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin);
1900: }
1901: else {
1902: z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin);
1903: z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin);
1904: }
1905: }
1906:
1907: }
1908:
1909: }
1910:
1911:
1914: public void restoreAutoBounds() {
1915: restoreAutoDomainBounds();
1916: restoreAutoRangeBounds();
1917: }
1918:
1919:
1922: public void restoreAutoDomainBounds() {
1923: Plot p = this.chart.getPlot();
1924: if (p instanceof Zoomable) {
1925: Zoomable z = (Zoomable) p;
1926:
1927: Point zp = (this.zoomPoint != null ? this.zoomPoint : new Point());
1928: z.zoomDomainAxes(0.0, this.info.getPlotInfo(), zp);
1929: }
1930: }
1931:
1932:
1935: public void restoreAutoRangeBounds() {
1936: Plot p = this.chart.getPlot();
1937: if (p instanceof Zoomable) {
1938: Zoomable z = (Zoomable) p;
1939:
1940: Point zp = (this.zoomPoint != null ? this.zoomPoint : new Point());
1941: z.zoomRangeAxes(0.0, this.info.getPlotInfo(), zp);
1942: }
1943: }
1944:
1945:
1951: public Rectangle2D getScreenDataArea() {
1952: Rectangle2D dataArea = this.info.getPlotInfo().getDataArea();
1953: Insets insets = getInsets();
1954: double x = dataArea.getX() * this.scaleX + insets.left;
1955: double y = dataArea.getY() * this.scaleY + insets.top;
1956: double w = dataArea.getWidth() * this.scaleX;
1957: double h = dataArea.getHeight() * this.scaleY;
1958: return new Rectangle2D.Double(x, y, w, h);
1959: }
1960:
1961:
1970: public Rectangle2D getScreenDataArea(int x, int y) {
1971: PlotRenderingInfo plotInfo = this.info.getPlotInfo();
1972: Rectangle2D result;
1973: if (plotInfo.getSubplotCount() == 0) {
1974: result = getScreenDataArea();
1975: }
1976: else {
1977:
1978:
1979: Point2D selectOrigin = translateScreenToJava2D(new Point(x, y));
1980: int subplotIndex = plotInfo.getSubplotIndex(selectOrigin);
1981: if (subplotIndex == -1) {
1982: return null;
1983: }
1984: result = scale(plotInfo.getSubplotInfo(subplotIndex).getDataArea());
1985: }
1986: return result;
1987: }
1988:
1989:
1996: public int getInitialDelay() {
1997: return this.ownToolTipInitialDelay;
1998: }
1999:
2000:
2007: public int getReshowDelay() {
2008: return this.ownToolTipReshowDelay;
2009: }
2010:
2011:
2019: public int getDismissDelay() {
2020: return this.ownToolTipDismissDelay;
2021: }
2022:
2023:
2031: public void setInitialDelay(int delay) {
2032: this.ownToolTipInitialDelay = delay;
2033: }
2034:
2035:
2043: public void setReshowDelay(int delay) {
2044: this.ownToolTipReshowDelay = delay;
2045: }
2046:
2047:
2055: public void setDismissDelay(int delay) {
2056: this.ownToolTipDismissDelay = delay;
2057: }
2058:
2059:
2066: public double getZoomInFactor() {
2067: return this.zoomInFactor;
2068: }
2069:
2070:
2077: public void setZoomInFactor(double factor) {
2078: this.zoomInFactor = factor;
2079: }
2080:
2081:
2088: public double getZoomOutFactor() {
2089: return this.zoomOutFactor;
2090: }
2091:
2092:
2099: public void setZoomOutFactor(double factor) {
2100: this.zoomOutFactor = factor;
2101: }
2102:
2103:
2112: private void drawZoomRectangle(Graphics2D g2) {
2113:
2114: g2.setXORMode(Color.gray);
2115: if (this.zoomRectangle != null) {
2116: if (this.fillZoomRectangle) {
2117: g2.fill(this.zoomRectangle);
2118: }
2119: else {
2120: g2.draw(this.zoomRectangle);
2121: }
2122: }
2123:
2124: g2.setPaintMode();
2125: }
2126:
2127:
2134: private void drawHorizontalAxisTrace(Graphics2D g2, int x) {
2135:
2136: Rectangle2D dataArea = getScreenDataArea();
2137:
2138: g2.setXORMode(Color.orange);
2139: if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) {
2140:
2141: if (this.verticalTraceLine != null) {
2142: g2.draw(this.verticalTraceLine);
2143: this.verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x,
2144: (int) dataArea.getMaxY());
2145: }
2146: else {
2147: this.verticalTraceLine = new Line2D.Float(x,
2148: (int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
2149: }
2150: g2.draw(this.verticalTraceLine);
2151: }
2152:
2153:
2154: g2.setPaintMode();
2155: }
2156:
2157:
2164: private void drawVerticalAxisTrace(Graphics2D g2, int y) {
2165:
2166: Rectangle2D dataArea = getScreenDataArea();
2167:
2168: g2.setXORMode(Color.orange);
2169: if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) {
2170:
2171: if (this.horizontalTraceLine != null) {
2172: g2.draw(this.horizontalTraceLine);
2173: this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y,
2174: (int) dataArea.getMaxX(), y);
2175: }
2176: else {
2177: this.horizontalTraceLine = new Line2D.Float(
2178: (int) dataArea.getMinX(), y, (int) dataArea.getMaxX(),
2179: y);
2180: }
2181: g2.draw(this.horizontalTraceLine);
2182: }
2183:
2184:
2185: g2.setPaintMode();
2186: }
2187:
2188:
2194: public void doEditChartProperties() {
2195:
2196: ChartEditor editor = ChartEditorManager.getChartEditor(this.chart);
2197: int result = JOptionPane.showConfirmDialog(this, editor,
2198: localizationResources.getString("Chart_Properties"),
2199: JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
2200: if (result == JOptionPane.OK_OPTION) {
2201: editor.updateChart(this.chart);
2202: }
2203:
2204: }
2205:
2206:
2212: public void doSaveAs() throws IOException {
2213:
2214: JFileChooser fileChooser = new JFileChooser();
2215: fileChooser.setCurrentDirectory(this.defaultDirectoryForSaveAs);
2216: ExtensionFileFilter filter = new ExtensionFileFilter(
2217: localizationResources.getString("PNG_Image_Files"), ".png");
2218: fileChooser.addChoosableFileFilter(filter);
2219:
2220: int option = fileChooser.showSaveDialog(this);
2221: if (option == JFileChooser.APPROVE_OPTION) {
2222: String filename = fileChooser.getSelectedFile().getPath();
2223: if (isEnforceFileExtensions()) {
2224: if (!filename.endsWith(".png")) {
2225: filename = filename + ".png";
2226: }
2227: }
2228: ChartUtilities.saveChartAsPNG(new File(filename), this.chart,
2229: getWidth(), getHeight());
2230: }
2231:
2232: }
2233:
2234:
2237: public void createChartPrintJob() {
2238:
2239: PrinterJob job = PrinterJob.getPrinterJob();
2240: PageFormat pf = job.defaultPage();
2241: PageFormat pf2 = job.pageDialog(pf);
2242: if (pf2 != pf) {
2243: job.setPrintable(this, pf2);
2244: if (job.printDialog()) {
2245: try {
2246: job.print();
2247: }
2248: catch (PrinterException e) {
2249: JOptionPane.showMessageDialog(this, e);
2250: }
2251: }
2252: }
2253:
2254: }
2255:
2256:
2266: public int print(Graphics g, PageFormat pf, int pageIndex) {
2267:
2268: if (pageIndex != 0) {
2269: return NO_SUCH_PAGE;
2270: }
2271: Graphics2D g2 = (Graphics2D) g;
2272: double x = pf.getImageableX();
2273: double y = pf.getImageableY();
2274: double w = pf.getImageableWidth();
2275: double h = pf.getImageableHeight();
2276: this.chart.draw(g2, new Rectangle2D.Double(x, y, w, h), this.anchor,
2277: null);
2278: return PAGE_EXISTS;
2279:
2280: }
2281:
2282:
2287: public void addChartMouseListener(ChartMouseListener listener) {
2288: if (listener == null) {
2289: throw new IllegalArgumentException("Null 'listener' argument.");
2290: }
2291: this.chartMouseListeners.add(ChartMouseListener.class, listener);
2292: }
2293:
2294:
2300: public void removeChartMouseListener(ChartMouseListener listener) {
2301: this.chartMouseListeners.remove(ChartMouseListener.class, listener);
2302: }
2303:
2304:
2312: public EventListener[] getListeners(Class listenerType) {
2313: if (listenerType == ChartMouseListener.class) {
2314:
2315: return this.chartMouseListeners.getListeners(listenerType);
2316: }
2317: else {
2318: return super.getListeners(listenerType);
2319: }
2320: }
2321:
2322:
2332: protected JPopupMenu createPopupMenu(boolean properties,
2333: boolean save,
2334: boolean print,
2335: boolean zoom) {
2336:
2337: JPopupMenu result = new JPopupMenu("Chart:");
2338: boolean separator = false;
2339:
2340: if (properties) {
2341: JMenuItem propertiesItem = new JMenuItem(
2342: localizationResources.getString("Properties..."));
2343: propertiesItem.setActionCommand(PROPERTIES_COMMAND);
2344: propertiesItem.addActionListener(this);
2345: result.add(propertiesItem);
2346: separator = true;
2347: }
2348:
2349: if (save) {
2350: if (separator) {
2351: result.addSeparator();
2352: separator = false;
2353: }
2354: JMenuItem saveItem = new JMenuItem(
2355: localizationResources.getString("Save_as..."));
2356: saveItem.setActionCommand(SAVE_COMMAND);
2357: saveItem.addActionListener(this);
2358: result.add(saveItem);
2359: separator = true;
2360: }
2361:
2362: if (print) {
2363: if (separator) {
2364: result.addSeparator();
2365: separator = false;
2366: }
2367: JMenuItem printItem = new JMenuItem(
2368: localizationResources.getString("Print..."));
2369: printItem.setActionCommand(PRINT_COMMAND);
2370: printItem.addActionListener(this);
2371: result.add(printItem);
2372: separator = true;
2373: }
2374:
2375: if (zoom) {
2376: if (separator) {
2377: result.addSeparator();
2378: separator = false;
2379: }
2380:
2381: JMenu zoomInMenu = new JMenu(
2382: localizationResources.getString("Zoom_In"));
2383:
2384: this.zoomInBothMenuItem = new JMenuItem(
2385: localizationResources.getString("All_Axes"));
2386: this.zoomInBothMenuItem.setActionCommand(ZOOM_IN_BOTH_COMMAND);
2387: this.zoomInBothMenuItem.addActionListener(this);
2388: zoomInMenu.add(this.zoomInBothMenuItem);
2389:
2390: zoomInMenu.addSeparator();
2391:
2392: this.zoomInDomainMenuItem = new JMenuItem(
2393: localizationResources.getString("Domain_Axis"));
2394: this.zoomInDomainMenuItem.setActionCommand(ZOOM_IN_DOMAIN_COMMAND);
2395: this.zoomInDomainMenuItem.addActionListener(this);
2396: zoomInMenu.add(this.zoomInDomainMenuItem);
2397:
2398: this.zoomInRangeMenuItem = new JMenuItem(
2399: localizationResources.getString("Range_Axis"));
2400: this.zoomInRangeMenuItem.setActionCommand(ZOOM_IN_RANGE_COMMAND);
2401: this.zoomInRangeMenuItem.addActionListener(this);
2402: zoomInMenu.add(this.zoomInRangeMenuItem);
2403:
2404: result.add(zoomInMenu);
2405:
2406: JMenu zoomOutMenu = new JMenu(
2407: localizationResources.getString("Zoom_Out"));
2408:
2409: this.zoomOutBothMenuItem = new JMenuItem(
2410: localizationResources.getString("All_Axes"));
2411: this.zoomOutBothMenuItem.setActionCommand(ZOOM_OUT_BOTH_COMMAND);
2412: this.zoomOutBothMenuItem.addActionListener(this);
2413: zoomOutMenu.add(this.zoomOutBothMenuItem);
2414:
2415: zoomOutMenu.addSeparator();
2416:
2417: this.zoomOutDomainMenuItem = new JMenuItem(
2418: localizationResources.getString("Domain_Axis"));
2419: this.zoomOutDomainMenuItem.setActionCommand(
2420: ZOOM_OUT_DOMAIN_COMMAND);
2421: this.zoomOutDomainMenuItem.addActionListener(this);
2422: zoomOutMenu.add(this.zoomOutDomainMenuItem);
2423:
2424: this.zoomOutRangeMenuItem = new JMenuItem(
2425: localizationResources.getString("Range_Axis"));
2426: this.zoomOutRangeMenuItem.setActionCommand(ZOOM_OUT_RANGE_COMMAND);
2427: this.zoomOutRangeMenuItem.addActionListener(this);
2428: zoomOutMenu.add(this.zoomOutRangeMenuItem);
2429:
2430: result.add(zoomOutMenu);
2431:
2432: JMenu autoRangeMenu = new JMenu(
2433: localizationResources.getString("Auto_Range"));
2434:
2435: this.zoomResetBothMenuItem = new JMenuItem(
2436: localizationResources.getString("All_Axes"));
2437: this.zoomResetBothMenuItem.setActionCommand(
2438: ZOOM_RESET_BOTH_COMMAND);
2439: this.zoomResetBothMenuItem.addActionListener(this);
2440: autoRangeMenu.add(this.zoomResetBothMenuItem);
2441:
2442: autoRangeMenu.addSeparator();
2443: this.zoomResetDomainMenuItem = new JMenuItem(
2444: localizationResources.getString("Domain_Axis"));
2445: this.zoomResetDomainMenuItem.setActionCommand(
2446: ZOOM_RESET_DOMAIN_COMMAND);
2447: this.zoomResetDomainMenuItem.addActionListener(this);
2448: autoRangeMenu.add(this.zoomResetDomainMenuItem);
2449:
2450: this.zoomResetRangeMenuItem = new JMenuItem(
2451: localizationResources.getString("Range_Axis"));
2452: this.zoomResetRangeMenuItem.setActionCommand(
2453: ZOOM_RESET_RANGE_COMMAND);
2454: this.zoomResetRangeMenuItem.addActionListener(this);
2455: autoRangeMenu.add(this.zoomResetRangeMenuItem);
2456:
2457: result.addSeparator();
2458: result.add(autoRangeMenu);
2459:
2460: }
2461:
2462: return result;
2463:
2464: }
2465:
2466:
2473: protected void displayPopupMenu(int x, int y) {
2474:
2475: if (this.popup != null) {
2476:
2477:
2478:
2479: Plot plot = this.chart.getPlot();
2480: boolean isDomainZoomable = false;
2481: boolean isRangeZoomable = false;
2482: if (plot instanceof Zoomable) {
2483: Zoomable z = (Zoomable) plot;
2484: isDomainZoomable = z.isDomainZoomable();
2485: isRangeZoomable = z.isRangeZoomable();
2486: }
2487:
2488: if (this.zoomInDomainMenuItem != null) {
2489: this.zoomInDomainMenuItem.setEnabled(isDomainZoomable);
2490: }
2491: if (this.zoomOutDomainMenuItem != null) {
2492: this.zoomOutDomainMenuItem.setEnabled(isDomainZoomable);
2493: }
2494: if (this.zoomResetDomainMenuItem != null) {
2495: this.zoomResetDomainMenuItem.setEnabled(isDomainZoomable);
2496: }
2497:
2498: if (this.zoomInRangeMenuItem != null) {
2499: this.zoomInRangeMenuItem.setEnabled(isRangeZoomable);
2500: }
2501: if (this.zoomOutRangeMenuItem != null) {
2502: this.zoomOutRangeMenuItem.setEnabled(isRangeZoomable);
2503: }
2504:
2505: if (this.zoomResetRangeMenuItem != null) {
2506: this.zoomResetRangeMenuItem.setEnabled(isRangeZoomable);
2507: }
2508:
2509: if (this.zoomInBothMenuItem != null) {
2510: this.zoomInBothMenuItem.setEnabled(isDomainZoomable
2511: && isRangeZoomable);
2512: }
2513: if (this.zoomOutBothMenuItem != null) {
2514: this.zoomOutBothMenuItem.setEnabled(isDomainZoomable
2515: && isRangeZoomable);
2516: }
2517: if (this.zoomResetBothMenuItem != null) {
2518: this.zoomResetBothMenuItem.setEnabled(isDomainZoomable
2519: && isRangeZoomable);
2520: }
2521:
2522: this.popup.show(this, x, y);
2523: }
2524:
2525: }
2526:
2527:
2530: public void updateUI() {
2531:
2532:
2533: if (this.popup != null) {
2534: SwingUtilities.updateComponentTreeUI(this.popup);
2535: }
2536: super.updateUI();
2537: }
2538:
2539: }