annotate flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ZoomboxControl.java @ 546:feaf6a8881ee

Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area. flys-client/trunk@2055 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 06 Jun 2011 08:21:08 +0000
parents 9c2cf4811a7d
children f1a559d13eef
rev   line source
540
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.client.client.ui.chart;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import java.util.ArrayList;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4 import java.util.List;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5
543
9c2cf4811a7d Added a control to reset the zoom of a chart. In addition, the zoom buttons are displayed as ImgButtons now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 541
diff changeset
6 import com.google.gwt.core.client.GWT;
9c2cf4811a7d Added a control to reset the zoom of a chart. In addition, the zoom buttons are displayed as ImgButtons now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 541
diff changeset
7
540
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8 import com.smartgwt.client.types.Positioning;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import com.smartgwt.client.types.SelectionType;
543
9c2cf4811a7d Added a control to reset the zoom of a chart. In addition, the zoom buttons are displayed as ImgButtons now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 541
diff changeset
10 import com.smartgwt.client.widgets.ImgButton;
540
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import com.smartgwt.client.widgets.Canvas;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import com.smartgwt.client.widgets.events.MouseDownEvent;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import com.smartgwt.client.widgets.events.MouseDownHandler;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import com.smartgwt.client.widgets.events.MouseMoveEvent;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import com.smartgwt.client.widgets.events.MouseMoveHandler;
546
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
16 import com.smartgwt.client.widgets.events.MouseOutEvent;
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
17 import com.smartgwt.client.widgets.events.MouseOutHandler;
540
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 import com.smartgwt.client.widgets.events.MouseUpEvent;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 import com.smartgwt.client.widgets.events.MouseUpHandler;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 import de.intevation.flys.client.client.event.HasZoomHandlers;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 import de.intevation.flys.client.client.event.ZoomEvent;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 import de.intevation.flys.client.client.event.ZoomHandler;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 /**
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 * This control observes that panel retrieved by ChartOutputTab.getChartPanel().
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 * If activated, a zoombox is drawn. One of the two edges is the position of the
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 * mouse down event on the observed panel. The other edge is specified by the
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 * current mouse position. If the mouse up event occurs, start and end point
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 * relative to the left and upper border of the observed panel is determined and
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 * a ZoomEvent is fired.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 *
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 */
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 public class ZoomboxControl
543
9c2cf4811a7d Added a control to reset the zoom of a chart. In addition, the zoom buttons are displayed as ImgButtons now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 541
diff changeset
37 extends ImgButton
546
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
38 implements MouseDownHandler, MouseUpHandler, MouseMoveHandler, HasZoomHandlers,
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
39 MouseOutHandler
540
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 {
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 protected List<ZoomHandler> handlers;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 protected ChartOutputTab chartTab;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 protected Canvas zoombox;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 protected int[] start;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 protected int[] end;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50
543
9c2cf4811a7d Added a control to reset the zoom of a chart. In addition, the zoom buttons are displayed as ImgButtons now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 541
diff changeset
51 public ZoomboxControl(ChartOutputTab chartTab, String imageUrl) {
9c2cf4811a7d Added a control to reset the zoom of a chart. In addition, the zoom buttons are displayed as ImgButtons now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 541
diff changeset
52 super();
540
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 this.handlers = new ArrayList<ZoomHandler>();
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 this.chartTab = chartTab;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 this.start = new int[2];
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 this.end = new int[2];
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 this.zoombox = new Canvas();
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 initZoombox();
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61
543
9c2cf4811a7d Added a control to reset the zoom of a chart. In addition, the zoom buttons are displayed as ImgButtons now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 541
diff changeset
62 String baseUrl = GWT.getHostPageBaseURL();
9c2cf4811a7d Added a control to reset the zoom of a chart. In addition, the zoom buttons are displayed as ImgButtons now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 541
diff changeset
63 setSrc(baseUrl + imageUrl);
540
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 setActionType(SelectionType.CHECKBOX);
543
9c2cf4811a7d Added a control to reset the zoom of a chart. In addition, the zoom buttons are displayed as ImgButtons now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 541
diff changeset
65 setSize(20);
9c2cf4811a7d Added a control to reset the zoom of a chart. In addition, the zoom buttons are displayed as ImgButtons now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 541
diff changeset
66 setShowRollOver(false);
540
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 setSelected(false);
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 chartTab.getChartPanel().addMouseDownHandler(this);
546
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
70 chartTab.getChartPanel().addMouseOutHandler(this);
540
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 chartTab.getChartPanel().addMouseMoveHandler(this);
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 chartTab.getChartPanel().addMouseUpHandler(this);
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 /**
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 * Initializes the zoombox that is displayed over the observed area. The
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 * zoombox has an opaque background. Its height/width and x/y values are
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 * determined by the start point (mouse down) and the current mouse
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 * position.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 */
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 protected void initZoombox() {
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 zoombox.setPosition(Positioning.ABSOLUTE);
541
ed29599e06e5 Added the ChartOutputTab as ZoomHandler for the ZoomboxControl - no zooming is done yet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 540
diff changeset
84 zoombox.setBorder("2px solid black");
540
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 zoombox.setOpacity(50);
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 zoombox.setWidth(0);
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 zoombox.setHeight(0);
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 /**
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 * Registers a new ZoomHandler that wants to listen to ZoomEvents.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 *
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 * @param handler A new ZoomHandler.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 */
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 public void addZoomHandler(ZoomHandler handler) {
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 if (handler != null) {
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 handlers.add(handler);
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 /**
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 * A mouse down event on the specified area will set the start point for the
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 * zoombox.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 *
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 * @param event The mouse down event which contains the xy coordinates of
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 * the observed area.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 */
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 public void onMouseDown(MouseDownEvent event) {
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 if (!isSelected()) {
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 return;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 start[0] = getRelativeX(event.getX());
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 start[1] = getRelativeY(event.getY());
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 end[0] = start[0];
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 end[1] = start[1];
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120
546
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
121 Canvas c = getChartPanel();
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
122 c.addChild(zoombox);
540
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124 positionZoombox();
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 /**
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129 * A mouse move event on the specified area will set the end point for the
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130 * zoombox. If the end point differs from the start point, an opaque box is
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131 * displayed.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
132 *
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133 * @param event The mouse move event which contains the xy coordinates of
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134 * the observed area.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135 */
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 public void onMouseMove(MouseMoveEvent event) {
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
137 if (!isSelected()) {
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 return;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
139 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
141 end[0] = getRelativeX(event.getX());
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 end[1] = getRelativeY(event.getY());
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144 positionZoombox();
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
148 /**
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 * The mouse up event finalizes the zoom operation. It sets the end point
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150 * for this operation, clears the zoombox and fires a ZoomEvent.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151 *
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
152 * @param event The mouse up event which contains the xy coordinates of the
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 * observed area.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154 */
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 public void onMouseUp(MouseUpEvent event) {
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156 if (!isSelected()) {
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
157 return;
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160 end[0] = getRelativeX(event.getX());
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 end[1] = getRelativeY(event.getY());
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
162
541
ed29599e06e5 Added the ChartOutputTab as ZoomHandler for the ZoomboxControl - no zooming is done yet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 540
diff changeset
163 fireZoomEvent();
ed29599e06e5 Added the ChartOutputTab as ZoomHandler for the ZoomboxControl - no zooming is done yet.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 540
diff changeset
164
540
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165 clearZoombox();
546
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
166 }
540
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
167
546
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
168
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
169 /**
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
170 * The mouse out event is used to cancel an active zoom operation.
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
171 *
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
172 * @param event The mouse out event.
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
173 */
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
174 public void onMouseOut(MouseOutEvent event) {
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
175 if (!isSelected() || !isMouseOut(event.getX(), event.getY())) {
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
176 return;
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
177 }
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
178
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
179 start[0] = 0;
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
180 start[1] = 0;
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
181 end[0] = 0;
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
182 end[1] = 0;
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
183
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
184 clearZoombox();
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
185 }
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
186
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
187
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
188 /**
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
189 * Returns the chart panel.
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
190 *
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
191 * @return the chart panel.
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
192 */
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
193 protected Canvas getChartPanel() {
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
194 return chartTab.getChartPanel();
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
195 }
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
196
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
197
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
198 /**
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
199 * This method is required to check manually if the mouse pointer really
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
200 * moves out the chart area. The MouseOutEvent is also fired if the mouse
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
201 * goes down which doesn't seem to be correct. So, we gonna check this
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
202 * manually.
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
203 *
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
204 * @param x The x coordinate.
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
205 * @param y The y coordinate.
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
206 *
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
207 * @return true, if the mouse is really out of the chart area, otherwise
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
208 * false.
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
209 */
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
210 protected boolean isMouseOut(int x, int y) {
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
211 Canvas chart = getChartPanel();
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
212
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
213 int left = chart.getPageLeft();
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
214 int right = chart.getPageRight();
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
215 int top = chart.getPageTop();
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
216 int bottom = chart.getPageBottom();
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
217
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
218 if (x <= left || x >= right || y <= top || y >= bottom) {
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
219 return true;
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
220 }
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
221
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
222 return false;
540
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
223 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
224
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
225
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
226 /**
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
227 * Returns the X coordinate relative to the left border.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
228 *
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
229 * @param x The X coordinate relative to the window.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
230 *
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
231 * @return the X coordinate relative to the left border.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
232 */
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
233 protected int getRelativeX(int x) {
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
234 return x - chartTab.getChartPanel().getPageLeft();
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
235 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
236
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
237
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
238 /**
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
239 * Returns the Y coordinate relative to the top border.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
240 *
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
241 * @param y The Y coordinate relative to the window.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
242 *
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
243 * @return the Y coordinate relative to the top border.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
244 */
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
245 protected int getRelativeY(int y) {
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
246 return y - chartTab.getChartPanel().getPageTop();
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
247 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
248
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
249
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
250 /**
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
251 * Returns min and max x/y values based on the stored values in <i>start</i>
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
252 * and <i>end</i>.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
253 *
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
254 * @return an int[] as follows: [xmin, ymin, xmax, ymax].
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
255 */
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
256 protected int[] orderPositions() {
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
257 int xmin = start[0] < end[0] ? start[0] : end[0];
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
258 int ymin = start[1] < end[1] ? start[1] : end[1];
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
259
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
260 int xmax = start[0] >= end[0] ? start[0] : end[0];
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
261 int ymax = start[1] >= end[1] ? start[1] : end[1];
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
262
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
263 return new int[] { xmin, ymin, xmax, ymax };
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
264 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
265
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
266
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
267 /**
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
268 * Sets the width, height, x and y values of the zoombox.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
269 */
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
270 protected void positionZoombox() {
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
271 int[] values = orderPositions();
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
272
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
273 zoombox.setLeft(values[0]);
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
274 zoombox.setTop(values[1]);
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
275 zoombox.setWidth(values[2] - values[0]);
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
276 zoombox.setHeight(values[3] - values[1]);
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
277 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
278
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
279
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
280 /**
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
281 * Clears the zoombox (set position and size to null).
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
282 */
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
283 protected void clearZoombox() {
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
284 zoombox.setLeft(0);
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
285 zoombox.setTop(0);
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
286 zoombox.setWidth(0);
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
287 zoombox.setHeight(0);
546
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
288
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
289 Canvas c = getChartPanel();
feaf6a8881ee Improved the zoombox control: cancel the zoom operation if the mouse pointer leaves the chart area.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 543
diff changeset
290 c.removeChild(zoombox);
540
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
291 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
292
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
293
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
294 /**
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
295 * Fires a ZoomEvent to all registered listeners.
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
296 */
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
297 protected void fireZoomEvent() {
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
298 int[] pos = orderPositions();
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
299
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
300 ZoomEvent event = new ZoomEvent(pos[0], pos[1], pos[2], pos[3]);
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
301
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
302 for (ZoomHandler handler: handlers) {
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
303 handler.onZoom(event);
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
304 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
305 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
306 }
a866cdf1ca40 Implemented a zoombox control and added it to the chart toolbar.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
307 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org