Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1bef22f38ac691efe25af836b2c4bcee1ce925f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/*******************************************************************************
 * Copyright (c) 2004, 2005 Sybase, Inc. and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/

package org.eclipse.jst.jsf.facesconfig.ui.pageflow;

// import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.draw2d.ScalableFigure;
import org.eclipse.draw2d.Viewport;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.editparts.ZoomListener;
import org.eclipse.gef.editparts.ZoomManager;

/**
 * A delegating ZoomManager.
 * 
 */
public class DelegatingZoomManager extends ZoomManager implements ZoomListener {
	/** Default string or double value of zoom level */
	private static final String DEFAULT_ZOOM_LEVEL_STRING = "100%";

	private static final double DEFAULT_ZOOM_LEVEL = 1;

	/** the current ZoomManager all work is delegated to */
	private ZoomManager currentZoomManager = null;

	/** listeners of zoom */
	private ListenerList zoomListeners = new ListenerList(
			ListenerList.IDENTITY);

	/**
	 * Creates a new DelegatingZoomManager instance.
	 */
	public DelegatingZoomManager() {
		super((ScalableFigure) null, (Viewport) null);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomListener#zoomChanged(double)
	 */
	public void zoomChanged(double zoom) {
		Object[] listeners = zoomListeners.getListeners();
		for (int i = 0; i < listeners.length; ++i) {
			((ZoomListener) listeners[i]).zoomChanged(zoom);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#addZoomListener(ZoomListener)
	 */
	public void addZoomListener(ZoomListener listener) {
		zoomListeners.add(listener);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#removeZoomListener(oZoomListener)
	 */
	public void removeZoomListener(ZoomListener listener) {
		zoomListeners.remove(listener);
	}

	/**
	 * Sets the ZoomManager all work should be delegated to.
	 * 
	 * @param zoomManager
	 */
	public void setCurrentZoomManager(ZoomManager zoomManager) {
		if (null != currentZoomManager) {
			currentZoomManager.removeZoomListener(this);
		}

		currentZoomManager = zoomManager;
		if (null != currentZoomManager) {
			currentZoomManager.addZoomListener(this);
			zoomChanged(currentZoomManager.getZoom());
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#canZoomIn()
	 */
	public boolean canZoomIn() {
		if (null == currentZoomManager) {
			return false;
		}

		return currentZoomManager.canZoomIn();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#canZoomOut()
	 */
	public boolean canZoomOut() {
		if (null == currentZoomManager) {
			return false;
		}

		return currentZoomManager.canZoomOut();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#getMaxZoom()
	 */
	public double getMaxZoom() {
		if (null == currentZoomManager) {
			return DEFAULT_ZOOM_LEVEL;
		}

		return currentZoomManager.getMaxZoom();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#getMinZoom()
	 */
	public double getMinZoom() {
		if (null == currentZoomManager) {
			return DEFAULT_ZOOM_LEVEL;
		}

		return currentZoomManager.getMinZoom();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#getNextZoomLevel()
	 */
	public double getNextZoomLevel() {
		if (null == currentZoomManager) {
			return DEFAULT_ZOOM_LEVEL;
		}

		return currentZoomManager.getNextZoomLevel();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#getPreviousZoomLevel()
	 */
	public double getPreviousZoomLevel() {
		if (null == currentZoomManager) {
			return DEFAULT_ZOOM_LEVEL;
		}

		return currentZoomManager.getPreviousZoomLevel();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#getScalableFigure()
	 */
	public ScalableFigure getScalableFigure() {
		if (null == currentZoomManager) {
			return null;
		}

		return currentZoomManager.getScalableFigure();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#getUIMultiplier()
	 */
	public double getUIMultiplier() {
		if (null == currentZoomManager) {
			return DEFAULT_ZOOM_LEVEL;
		}

		return currentZoomManager.getUIMultiplier();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#getViewport()
	 */
	public Viewport getViewport() {
		if (null == currentZoomManager) {
			return null;
		}

		return currentZoomManager.getViewport();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#getZoom()
	 */
	public double getZoom() {
		if (null == currentZoomManager) {
			return DEFAULT_ZOOM_LEVEL;
		}

		return currentZoomManager.getZoom();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#getZoomAsText()
	 */
	public String getZoomAsText() {
		if (null == currentZoomManager) {
			return DEFAULT_ZOOM_LEVEL_STRING;
		}

		return currentZoomManager.getZoomAsText();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#getZoomLevels()
	 */
	public double[] getZoomLevels() {
		if (null == currentZoomManager) {
			return new double[] { DEFAULT_ZOOM_LEVEL };
		}

		return currentZoomManager.getZoomLevels();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#getZoomLevelsAsText()
	 */
	public String[] getZoomLevelsAsText() {
		if (null == currentZoomManager) {
			return new String[] { DEFAULT_ZOOM_LEVEL_STRING };
		}

		return currentZoomManager.getZoomLevelsAsText();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#setUIMultiplier(double)
	 */
	public void setUIMultiplier(double multiplier) {
		if (null == currentZoomManager) {
			return;
		}

		currentZoomManager.setUIMultiplier(multiplier);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#setViewLocation(Point)
	 */
	public void setViewLocation(Point p) {
		if (null == currentZoomManager) {
			return;
		}

		currentZoomManager.setViewLocation(p);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#setZoom(double)
	 */
	public void setZoom(double zoom) {
		if (null == currentZoomManager) {
			return;
		}
		currentZoomManager.setZoom(zoom);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#setZoomAnimationStyle(int)
	 */
	public void setZoomAnimationStyle(int style) {
		if (null == currentZoomManager) {
			return;
		}
		currentZoomManager.setZoomAnimationStyle(style);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#setZoomAsText(String)
	 */
	public void setZoomAsText(String zoomString) {
		if (null == currentZoomManager) {
			return;
		}
		currentZoomManager.setZoomAsText(zoomString);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#setZoomLevels(double[])
	 */
	public void setZoomLevels(double[] zoomLevels) {
		if (null == currentZoomManager) {
			return;
		}
		currentZoomManager.setZoomLevels(zoomLevels);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#zoomIn()
	 */
	public void zoomIn() {
		if (null == currentZoomManager) {
			return;
		}
		currentZoomManager.zoomIn();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#zoomOut()
	 */
	public void zoomOut() {
		if (null == currentZoomManager) {
			return;
		}
		currentZoomManager.zoomOut();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see ZoomManager#zoomTo(Rectangle)
	 */
	public void zoomTo(Rectangle rect) {
		if (null == currentZoomManager) {
			return;
		}
		currentZoomManager.zoomTo(rect);
	}

}

Back to the top