01: package net.sourceforge.squirrel_sql.plugins.graph;
02:
03: import net.sourceforge.squirrel_sql.plugins.graph.xmlbeans.ZoomerXmlBean;
04:
05: import java.util.Vector;
06:
07: public class Zoomer {
08: private double _zoom = 1;
09: private double _oldZoom = 1;
10: Vector<ZoomerListener> _listeners = new Vector<ZoomerListener>();
11: private boolean _enabled;
12: private boolean _hideScrollBars;
13:
14: public Zoomer(ZoomerXmlBean xmlBean) {
15: if (null != xmlBean) {
16: _zoom = xmlBean.getZoom();
17: _oldZoom = xmlBean.getOldZoom();
18: _enabled = xmlBean.isEnabled();
19: _hideScrollBars = xmlBean.isHideScrollbars();
20: }
21: }
22:
23: public void setEnabled(boolean b) {
24: _enabled = b;
25:
26: if (_enabled) {
27: setZoom(_oldZoom, false);
28: } else {
29: setZoom(1, false);
30: }
31:
32: ZoomerListener[] listeners = _listeners
33: .toArray(new ZoomerListener[_listeners.size()]);
34: for (int i = 0; i < listeners.length; i++) {
35: listeners[i].zoomEnabled(b);
36: }
37: }
38:
39: public void setZoom(double zoom, boolean adjusting) {
40: _oldZoom = _zoom;
41: _zoom = zoom;
42:
43: ZoomerListener[] listeners = _listeners
44: .toArray(new ZoomerListener[_listeners.size()]);
45: for (int i = 0; i < listeners.length; i++) {
46: listeners[i].zoomChanged(_zoom, _oldZoom, adjusting);
47: }
48: }
49:
50: public double getZoom() {
51: return _zoom;
52: }
53:
54: public void addZoomListener(ZoomerListener l) {
55: _listeners.remove(l);
56: _listeners.add(l);
57: }
58:
59: public void removeZoomListener(ZoomerListener l) {
60: _listeners.remove(l);
61: }
62:
63: public boolean isEnabled() {
64: return _enabled;
65: }
66:
67: public void setHideScrollBars(boolean b) {
68: _hideScrollBars = b;
69: ZoomerListener[] listeners = _listeners
70: .toArray(new ZoomerListener[_listeners.size()]);
71: for (int i = 0; i < listeners.length; i++) {
72: listeners[i].setHideScrollBars(b);
73: }
74: }
75:
76: public ZoomerXmlBean getXmlBean() {
77: ZoomerXmlBean xmlBean = new ZoomerXmlBean();
78: xmlBean.setZoom(_zoom);
79: xmlBean.setOldZoom(_oldZoom);
80: xmlBean.setEnabled(_enabled);
81: xmlBean.setHideScrollbars(_hideScrollBars);
82: return xmlBean;
83: }
84:
85: public boolean isHideScrollbars() {
86: return _hideScrollBars;
87: }
88: }
|