comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ZoomboxControl.java @ 779:f1a559d13eef

#185 Repaired zooming for IE8 and Chrome. flys-client/trunk@2268 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 29 Jun 2011 12:33:58 +0000
parents feaf6a8881ee
children
comparison
equal deleted inserted replaced
778:e14dc5fed6bb 779:f1a559d13eef
51 public ZoomboxControl(ChartOutputTab chartTab, String imageUrl) { 51 public ZoomboxControl(ChartOutputTab chartTab, String imageUrl) {
52 super(); 52 super();
53 53
54 this.handlers = new ArrayList<ZoomHandler>(); 54 this.handlers = new ArrayList<ZoomHandler>();
55 this.chartTab = chartTab; 55 this.chartTab = chartTab;
56 this.start = new int[2]; 56 this.start = new int[] { -1, -1 };
57 this.end = new int[2]; 57 this.end = new int[2];
58 this.zoombox = new Canvas(); 58 this.zoombox = new Canvas();
59 59
60 initZoombox(); 60 initZoombox();
61 61
64 setActionType(SelectionType.CHECKBOX); 64 setActionType(SelectionType.CHECKBOX);
65 setSize(20); 65 setSize(20);
66 setShowRollOver(false); 66 setShowRollOver(false);
67 setSelected(false); 67 setSelected(false);
68 68
69 chartTab.getChartPanel().addMouseDownHandler(this); 69 Canvas chart = chartTab.getChartPanel();
70 chartTab.getChartPanel().addMouseOutHandler(this); 70 chart.addMouseDownHandler(this);
71 chartTab.getChartPanel().addMouseMoveHandler(this); 71 chart.addMouseOutHandler(this);
72 chartTab.getChartPanel().addMouseUpHandler(this); 72 chart.addMouseMoveHandler(this);
73 chart.addMouseUpHandler(this);
73 } 74 }
74 75
75 76
76 /** 77 /**
77 * Initializes the zoombox that is displayed over the observed area. The 78 * Initializes the zoombox that is displayed over the observed area. The
78 * zoombox has an opaque background. Its height/width and x/y values are 79 * zoombox has an opaque background. Its height/width and x/y values are
79 * determined by the start point (mouse down) and the current mouse 80 * determined by the start point (mouse down) and the current mouse
80 * position. 81 * position.
81 */ 82 */
82 protected void initZoombox() { 83 protected void initZoombox() {
84 Canvas chart = chartTab.getChartPanel();
85 chart.addChild(zoombox);
86
83 zoombox.setPosition(Positioning.ABSOLUTE); 87 zoombox.setPosition(Positioning.ABSOLUTE);
84 zoombox.setBorder("2px solid black"); 88 zoombox.setBorder("2px solid black");
85 zoombox.setOpacity(50); 89 zoombox.setOpacity(50);
86 zoombox.setWidth(0); 90 zoombox.setWidth(1);
87 zoombox.setHeight(0); 91 zoombox.setHeight(1);
92 zoombox.setLeft(-10000);
93 zoombox.setTop(-10000);
88 } 94 }
89 95
90 96
91 /** 97 /**
92 * Registers a new ZoomHandler that wants to listen to ZoomEvents. 98 * Registers a new ZoomHandler that wants to listen to ZoomEvents.
110 public void onMouseDown(MouseDownEvent event) { 116 public void onMouseDown(MouseDownEvent event) {
111 if (!isSelected()) { 117 if (!isSelected()) {
112 return; 118 return;
113 } 119 }
114 120
115 start[0] = getRelativeX(event.getX()); 121 start[0] = getRelativeX(event.getX()) - 1;
116 start[1] = getRelativeY(event.getY()); 122 start[1] = getRelativeY(event.getY()) + 1;
117 123
118 end[0] = start[0]; 124 end[0] = start[0];
119 end[1] = start[1]; 125 end[1] = start[1];
120
121 Canvas c = getChartPanel();
122 c.addChild(zoombox);
123
124 positionZoombox();
125 } 126 }
126 127
127 128
128 /** 129 /**
129 * A mouse move event on the specified area will set the end point for the 130 * A mouse move event on the specified area will set the end point for the
132 * 133 *
133 * @param event The mouse move event which contains the xy coordinates of 134 * @param event The mouse move event which contains the xy coordinates of
134 * the observed area. 135 * the observed area.
135 */ 136 */
136 public void onMouseMove(MouseMoveEvent event) { 137 public void onMouseMove(MouseMoveEvent event) {
137 if (!isSelected()) { 138 if (!isSelected() || !isZooming()) {
138 return; 139 return;
139 } 140 }
140 141
141 end[0] = getRelativeX(event.getX()); 142 int x = getRelativeX(event.getX());
142 end[1] = getRelativeY(event.getY()); 143 int y = getRelativeY(event.getY());
144
145 end[0] = x > start[0] ? x-1 : x+1;
146 end[1] = y > start[1] ? y-1 : y+1;
143 147
144 positionZoombox(); 148 positionZoombox();
145 } 149 }
146 150
147 151
160 end[0] = getRelativeX(event.getX()); 164 end[0] = getRelativeX(event.getX());
161 end[1] = getRelativeY(event.getY()); 165 end[1] = getRelativeY(event.getY());
162 166
163 fireZoomEvent(); 167 fireZoomEvent();
164 168
165 clearZoombox(); 169 reset();
166 } 170 }
167 171
168 172
169 /** 173 /**
170 * The mouse out event is used to cancel an active zoom operation. 174 * The mouse out event is used to cancel an active zoom operation.
174 public void onMouseOut(MouseOutEvent event) { 178 public void onMouseOut(MouseOutEvent event) {
175 if (!isSelected() || !isMouseOut(event.getX(), event.getY())) { 179 if (!isSelected() || !isMouseOut(event.getX(), event.getY())) {
176 return; 180 return;
177 } 181 }
178 182
179 start[0] = 0; 183 reset();
180 start[1] = 0;
181 end[0] = 0;
182 end[1] = 0;
183
184 clearZoombox();
185 } 184 }
186 185
187 186
188 /** 187 /**
189 * Returns the chart panel. 188 * Returns the chart panel.
222 return false; 221 return false;
223 } 222 }
224 223
225 224
226 /** 225 /**
226 * Returns true, if a zoom action is in process.
227 *
228 * @return true, if a zoom action is in process.
229 */
230 public boolean isZooming() {
231 return start[0] > 0 && start[1] > 0;
232 }
233
234
235 /**
227 * Returns the X coordinate relative to the left border. 236 * Returns the X coordinate relative to the left border.
228 * 237 *
229 * @param x The X coordinate relative to the window. 238 * @param x The X coordinate relative to the window.
230 * 239 *
231 * @return the X coordinate relative to the left border. 240 * @return the X coordinate relative to the left border.
279 288
280 /** 289 /**
281 * Clears the zoombox (set position and size to null). 290 * Clears the zoombox (set position and size to null).
282 */ 291 */
283 protected void clearZoombox() { 292 protected void clearZoombox() {
284 zoombox.setLeft(0); 293 zoombox.setLeft(-10000);
285 zoombox.setTop(0); 294 zoombox.setTop(-10000);
286 zoombox.setWidth(0); 295 zoombox.setWidth(1);
287 zoombox.setHeight(0); 296 zoombox.setHeight(1);
288 297 }
289 Canvas c = getChartPanel(); 298
290 c.removeChild(zoombox); 299
300 /**
301 * Resets the zoom control (start point and zoombox).
302 */
303 protected void reset() {
304 start[0] = -1;
305 start[1] = -1;
306
307 clearZoombox();
291 } 308 }
292 309
293 310
294 /** 311 /**
295 * Fires a ZoomEvent to all registered listeners. 312 * Fires a ZoomEvent to all registered listeners.

http://dive4elements.wald.intevation.org