1
2 package hep.wired.heprep.interaction;
3
4 import java.awt.*;
5 import java.awt.event.*;
6 import java.util.*;
7 import java.util.List;
8 import javax.swing.*;
9 import javax.swing.border.*;
10 import javax.swing.event.*;
11
12 import org.jdom.Element;
13
14 import org.freehep.application.Application;
15 import org.freehep.xml.io.XMLIOManager;
16
17 import hep.wired.services.GraphicsPanel;
18 import hep.wired.services.RecordPlot;
19 import hep.wired.services.InteractionHandler;
20 import hep.wired.services.DelegatingInteractionHandler;
21 import hep.wired.interaction.NullInteractionHandler;
22 import hep.wired.heprep.plugin.WiredPlugin;
23
24 /***
25 *
26 * @author Mark Donszelmann
27 * @version $Id: RoutingInteractionHandler.java 1936 2005-06-21 18:20:26Z duns $
28 */
29 public abstract class RoutingInteractionHandler implements DelegatingInteractionHandler {
30
31 private String name;
32
33 protected List
34 protected InteractionHandler interactionHandler;
35
36 /***
37 * Creates a DelegatingInteractionHandler.
38 */
39 public RoutingInteractionHandler(String name) {
40 this.name = name;
41 }
42
43 public void add(InteractionHandler h) {
44 add(h, handlers == null);
45 }
46
47 public void add(final InteractionHandler h, boolean selected) {
48 if (handlers == null) handlers = new ArrayList();
49 handlers.add(h);
50 if (selected) interactionHandler = h;
51 }
52
53 public void setInteractionHandler(InteractionHandler interactionHandler) {
54 if (interactionHandler == null) {
55 this.interactionHandler = NullInteractionHandler.getInstance();
56 } else {
57 this.interactionHandler = interactionHandler;
58 }
59 }
60
61
62
63
64 public InteractionHandler getInteractionHandler() {
65 return interactionHandler;
66 }
67
68
69
70
71 public Icon getIcon(int size) {
72 return interactionHandler.getIcon(size);
73 }
74
75 public boolean isSupportedBy(GraphicsPanel panel) {
76 if (interactionHandler == NullInteractionHandler.getInstance()) return true;
77
78 for (Iterator i=handlers.iterator(); i.hasNext(); ) {
79 InteractionHandler handler = (InteractionHandler)i.next();
80 if (handler.isSupportedBy(panel)) return true;
81 }
82 return false;
83 }
84
85 public void changeCursor(RecordPlot plot, InputEvent event) {
86 interactionHandler.changeCursor(plot, event);
87 }
88
89 public String getID() {
90 return interactionHandler.getName();
91 }
92
93 public void setRecord(RecordPlot plot, Object record) {
94 interactionHandler.setRecord(plot, record);
95 }
96
97 public void setSelected(RecordPlot plot, boolean selected) {
98
99
100 interactionHandler.setSelected(plot, selected);
101 }
102
103 public void setSize(RecordPlot plot, int width, int height) {
104 interactionHandler.setSize(plot, width, height);
105 }
106
107 public void reset(RecordPlot plot, InputEvent event) {
108 interactionHandler.reset(plot, event);
109 }
110
111 public void mouseButton1Clicked(RecordPlot plot, MouseEvent event) {
112 interactionHandler.mouseButton1Clicked(plot, event);
113 }
114
115 public void mouseButton1Pressed(RecordPlot plot, MouseEvent event) {
116 interactionHandler.mouseButton1Pressed(plot, event);
117 }
118
119 public void mouseButton1Released(RecordPlot plot, MouseEvent event) {
120 interactionHandler.mouseButton1Released(plot, event);
121 }
122
123 public void mouseButton1DragStarted(RecordPlot plot, MouseEvent event) {
124 interactionHandler.mouseButton1DragStarted(plot, event);
125 }
126
127 public void mouseButton1Dragged(RecordPlot plot, MouseEvent event) {
128 interactionHandler.mouseButton1Dragged(plot, event);
129 }
130
131 public void mouseButton1DragEnded(RecordPlot plot, MouseEvent event) {
132 interactionHandler.mouseButton1DragEnded(plot, event);
133 }
134
135 public void mouseMoved(RecordPlot plot, MouseEvent event) {
136 interactionHandler.mouseMoved(plot, event);
137 }
138
139 public void mouseEntered(RecordPlot plot, MouseEvent event) {
140 interactionHandler.mouseEntered(plot, event);
141 }
142
143 public void mouseExited(RecordPlot plot, MouseEvent event) {
144 interactionHandler.mouseExited(plot, event);
145 }
146
147 public void mouseWheelMoved(RecordPlot plot, MouseWheelEvent event) {
148 interactionHandler.mouseWheelMoved(plot, event);
149 }
150
151 public boolean escKeyPressed(RecordPlot plot, KeyEvent event) {
152 return interactionHandler.escKeyPressed(plot, event);
153 }
154
155 public boolean escKeyReleased(RecordPlot plot, KeyEvent event) {
156 return interactionHandler.escKeyReleased(plot, event);
157 }
158
159 public boolean altKeyPressed(RecordPlot plot, KeyEvent event) {
160 return interactionHandler.altKeyPressed(plot, event);
161 }
162
163 public boolean altKeyReleased(RecordPlot plot, KeyEvent event) {
164 return interactionHandler.altKeyReleased(plot, event);
165 }
166
167 public boolean ctrlKeyPressed(RecordPlot plot, KeyEvent event) {
168 return interactionHandler.ctrlKeyPressed(plot, event);
169 }
170
171 public boolean ctrlKeyReleased(RecordPlot plot, KeyEvent event) {
172 return interactionHandler.ctrlKeyReleased(plot, event);
173 }
174
175 public boolean shiftKeyPressed(RecordPlot plot, KeyEvent event) {
176 return interactionHandler.shiftKeyPressed(plot, event);
177 }
178
179 public boolean shiftKeyReleased(RecordPlot plot, KeyEvent event) {
180 return interactionHandler.shiftKeyReleased(plot, event);
181 }
182
183 public boolean otherKeyPressed(RecordPlot plot, KeyEvent event) {
184 return interactionHandler.otherKeyPressed(plot, event);
185 }
186
187 public boolean otherKeyReleased(RecordPlot plot, KeyEvent event) {
188 return interactionHandler.otherKeyReleased(plot, event);
189 }
190
191 public boolean keyTyped(RecordPlot plot, KeyEvent event) {
192 return interactionHandler.keyTyped(plot, event);
193 }
194
195 public int getWidth() {
196 return interactionHandler.getWidth();
197 }
198
199 public int getHeight() {
200 return interactionHandler.getHeight();
201 }
202
203 public Component getControl() {
204 return null;
205 }
206
207 public String getName() {
208 return name;
209 }
210
211
212
213
214 public void save(XMLIOManager xmlioManager,
215 org.jdom.Element nodeEl) {
216 nodeEl.setAttribute("name", name);
217 if (handlers != null) {
218 for (Iterator i=handlers.iterator(); i.hasNext(); ) {
219 InteractionHandler handler = (InteractionHandler)i.next();
220 nodeEl.addContent(xmlioManager.save(handler));
221 if (handler == interactionHandler) nodeEl.setAttribute("selected", handler.getName());
222 }
223 }
224 }
225
226 public void restore(XMLIOManager xmlioManager,
227 org.jdom.Element nodeEl) {
228 name = nodeEl.getAttributeValue("name");
229 String selected = nodeEl.getAttributeValue("selected");
230 for (Iterator i = nodeEl.getChildren().iterator(); i.hasNext(); ) {
231 InteractionHandler handler = (InteractionHandler)xmlioManager.restore((Element)i.next());
232 add(handler, handler.getName().equals(selected));
233 }
234 }
235 }