1
2 package hep.wired.services;
3
4 import java.awt.event.*;
5 import javax.swing.*;
6
7 import org.freehep.application.Application;
8 import org.freehep.graphics2d.VectorGraphics;
9 import org.freehep.xml.io.XMLIO;
10
11 import hep.wired.util.WiredRegistry;
12
13 /***
14 * Handles user interaction (Mouse and Keyboard) and dispatches edits to the plot.
15 *
16 * This interface filters the mouse interactions to only call subclasses for button 1 mouse
17 * events. To keep cross platform compatibility it is wise to only use button 1 mouse
18 * events (The Macintosh only has one mouse button). Other buttons are mapped using
19 * special keys, but then again, keys can also be used to adjust mouse behaviour.
20 * Also the pop up trigger (press and release) is filtered and not acted on.
21 * The sequence of some mouse events is slightly modified to make it easier to
22 * distinguish different sequences without extra logic. The basic sequences are:
23 * <UL>
24 * <LI>press-release-click: mouseButton1Pressed(), mouseButton1Released(), mouseButton1Clicked();
25 * You would normally act in mouseButton1Clicked().
26 * <LI>press-drag-release: mouseButton1Pressed(), mouseButton1DragStarted(), mouseButton1Dragged(),
27 * mouseButton1DragEnded(), mouseButton1Released().
28 * You would normally act in mouseButton1DragStarted, Dragged and Ended.
29 * mouseButton1DragStarted gets the same event as mouseButton1Pressed, but is only
30 * called after the drag has started. It is immediately followed by a mouseButton1Dragged().
31 * mouseButton1DragEnded is called with the same event as mouseButton1Released(), and is
32 * immediately followed by a call to the latter.
33 * </UL>
34 * All other sequences are as usual.
35 * Keyboard events are caught and handled. The Esc key allows to abort when a mouse was already
36 * pressed, but not yet released. The above sequences may be shortened to: press and
37 * press-drag. The sublass' reset() method gets called for hitting the escape key.
38 * Key such as ctrl, alt and shift are handled, and their repeat behaviour is
39 * filtered. Use methods such as isAltKeyDown() to find out if the alt key is pressed.
40 *
41 * @author Mark Donszelmann
42 * @version $Id: InteractionHandler.java 682 2005-03-14 02:24:52Z duns $
43 */
44 public interface InteractionHandler extends WiredRegistry.ID, XMLIO {
45
46 /***
47 * Returns the name of the Interaction Handler.
48 */
49 public String getName();
50
51 /***
52 * Returns a one line description.
53 */
54 public String getDescription();
55
56 /***
57 * Returns true if this Interaction Handler is supported by this Graphics Panel.
58 */
59 public boolean isSupportedBy(GraphicsPanel panel);
60
61 /***
62 * Sets the Record which is displayed in the GraphicsPanel.
63 * To be used if the interaction handler is event dependent.
64 */
65 public void setRecord(RecordPlot plot, Object record);
66
67 /***
68 * Called when underlying plot is selected/unselected.
69 */
70 public void setSelected(RecordPlot plot, boolean selected);
71
72 /***
73 * Sets the size of the wired plot on the handler, to be
74 * able to move/resize objects drawn by the handler.
75 */
76 public void setSize(RecordPlot plot, int width, int height);
77
78 /***
79 * Returns the width of the interaction panel.
80 */
81 public int getWidth();
82
83 /***
84 * Returns the height of the interaction panel.
85 */
86 public int getHeight();
87
88 /***
89 * Returns associated icon
90 */
91 public Icon getIcon(int size);
92
93 /***
94 * Called to reset the interaction handler in its initial state.
95 */
96 public void reset(RecordPlot plot, InputEvent event);
97
98 /***
99 * Called to allow the InteractionHandler to change the cursor.
100 */
101 public void changeCursor(RecordPlot plot, InputEvent event);
102
103 /***
104 * Called when mouse button 1 is clicked
105 */
106 public void mouseButton1Clicked(RecordPlot plot, MouseEvent event);
107
108 /***
109 * Called when mouse button 1 is pressed
110 */
111 public void mouseButton1Pressed(RecordPlot plot, MouseEvent event);
112
113 /***
114 * Called when mouse button 1 is released
115 */
116 public void mouseButton1Released(RecordPlot plot, MouseEvent event);
117
118 /***
119 * Called when mouse button 1 is starting a drag
120 */
121 public void mouseButton1DragStarted(RecordPlot plot, MouseEvent event);
122
123 /***
124 * Called when mouse button 1 is dragged
125 */
126 public void mouseButton1Dragged(RecordPlot plot, MouseEvent event);
127
128 /***
129 * Called when mouse button 1 is ending a drag
130 */
131 public void mouseButton1DragEnded(RecordPlot plot, MouseEvent event);
132
133 /***
134 * Called when the mouse is moved
135 */
136 public void mouseMoved(RecordPlot plot, MouseEvent event);
137
138 /***
139 * Called when the mouse is entering the component
140 */
141 public void mouseEntered(RecordPlot plot, MouseEvent event);
142
143 /***
144 * Called when the mouse is exitting the component
145 */
146 public void mouseExited(RecordPlot plot, MouseEvent event);
147
148 /***
149 * Called when the mousewheel is moved
150 */
151 public void mouseWheelMoved(RecordPlot plot, MouseWheelEvent event);
152
153 /***
154 * Called when the esc key is pressed. Return true if the event is handled.
155 */
156 public boolean escKeyPressed(RecordPlot plot, KeyEvent event);
157
158 /***
159 * Called when the esc key is released. Return true if the event is handled.
160 */
161 public boolean escKeyReleased(RecordPlot plot, KeyEvent event);
162
163 /***
164 * Called when the alt key is pressed. Return true if the event is handled.
165 */
166 public boolean altKeyPressed(RecordPlot plot, KeyEvent event);
167
168 /***
169 * Called when the alt key is released. Return true if the event is handled.
170 */
171 public boolean altKeyReleased(RecordPlot plot, KeyEvent event);
172
173 /***
174 * Called when the ctrl key is pressed. Return true if the event is handled.
175 */
176 public boolean ctrlKeyPressed(RecordPlot plot, KeyEvent event);
177
178 /***
179 * Called when the ctrl key is released. Return true if the event is handled.
180 */
181 public boolean ctrlKeyReleased(RecordPlot plot, KeyEvent event);
182
183 /***
184 * Called when the shift key is pressed. Return true if the event is handled.
185 */
186 public boolean shiftKeyPressed(RecordPlot plot, KeyEvent event);
187
188 /***
189 * Called when the esc key is released. Return true if the event is handled.
190 */
191 public boolean shiftKeyReleased(RecordPlot plot, KeyEvent event);
192
193 /***
194 * Called when any other key is pressed. Return true if the event is handled.
195 */
196 public boolean otherKeyPressed(RecordPlot plot, KeyEvent event);
197
198 /***
199 * Called when any other key is released. Return true if the event is handled.
200 */
201 public boolean otherKeyReleased(RecordPlot plot, KeyEvent event);
202
203 /***
204 * Called when a key is typed.
205 */
206 public boolean keyTyped(RecordPlot plot, KeyEvent event);
207 }