summaryrefslogtreecommitdiff
path: root/java/apps/NexusII/classes/awtCommand/CPanel.java
blob: 1c8d39f853702dfe069f637142fd5804ce1dcf4b (plain)
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
375
376
377
378
379
380
381
/*
 * Copyright 1996 Jan Newmarch, University of Canberra.
 * Permission to use, copy, modify, and distribute this
 * software and its documentation for any purpose and without
 * fee is hereby granted, provided that the above copyright
 * notice appear in all copies.  The author
 * makes no representations about the suitability of this
 * software for any purpose.  It is provided "as is" without
 * express or implied warranty.
 */

package awtCommand;

import java.awt.*;

public class CPanel extends Panel {

    protected Command gotFocusCommand = null,
		      lostFocusCommand = null;
    protected Command mouseDownCommand = null,
		      mouseDragCommand = null,
		      mouseEnterCommand = null,
		      mouseExitCommand = null,
		      mouseMoveCommand = null,
		      mouseUpCommand = null;
    protected Command keyUpCommand = null,
		      keyDownCommand = null;
    protected Command actionCommand = null;
    protected Command scrollAbsoluteCommand = null,
	      	      lineDownCommand = null,
	      	      lineUpCommand = null,
	      	      pageDownCommand = null,
	      	      pageUpCommand = null;
    protected Command selectCommand 	= null,
		      deselectCommand 	= null;

    /**
     * Constructs a new CPanel.
     */
    public CPanel() {
	super();
    }


    /**
     * Handles the event.
     * Calls methods for variousL events and passes
     * others to its superclass method.
     */
    public boolean handleEvent(Event evt) {
	switch (evt.id) {
	    case Event.SCROLL_ABSOLUTE:
		return scrollAbsolute(evt, evt.arg);
	    case Event.SCROLL_LINE_DOWN:
		return lineDown(evt, evt.arg);
	    case Event.SCROLL_LINE_UP:
		return lineUp(evt, evt.arg);
	    case Event.SCROLL_PAGE_DOWN:
		return pageDown(evt, evt.arg);
	    case Event.SCROLL_PAGE_UP:
		return pageUp(evt, evt.arg);
	    case Event.LIST_SELECT:
		return select(evt, evt.arg);
	    case Event.LIST_DESELECT:
		return deselect(evt, evt.arg);
	    default:
		return super.handleEvent(evt);
	}
    }

    /*
     * event handling methods
     */

    /**
     * Called if the window gains focus. This results in a call to
     * the gotFocusCommand object with <code>what</code> set to null.
     */
    public boolean gotFocus(Event evt, Object what) {
	if (gotFocusCommand != null)
	    gotFocusCommand.execute(this, evt, what);
	return false;
    }

    /**
     * Called if the window loses focus. This results in a call to
     * the lostFocusCommand object with <code>what</code> set to null.
     */
     public boolean lostFocus(Event evt, Object what) {
	if (lostFocusCommand != null)
	    lostFocusCommand.execute(this, evt, what);
	return false;
    }

    /**
     * Called if the mouse is down.
     * This results in a call to the mouseDownCommand object with 
     * <code>what</code> set to Point(x, y)
     */
    public boolean mouseDown(Event evt, int x, int y) {
	if (mouseDownCommand != null)
	    mouseDownCommand.execute(this, evt, new Point(x, y));
	return false;
    }

    /**
     * Called if the mouse is dragged.
     * This results in a call to the mouseDragCommand object with 
     * <code>what</code> set to Point(x, y)
     */
    public boolean mouseDrag(Event evt, int x, int y) {
	if (mouseDragCommand != null)
	    mouseDragCommand.execute(this, evt, new Point(x, y));
	return false;
    }

    /**
     * Called if the mouse enters the window.
     * This results in a call to the mouseEnterCommand object with 
     * <code>what</code> set to Point(x, y)
     */
     public boolean mouseEnter(Event evt, int x, int y) {
	if (mouseEnterCommand != null)
	    mouseEnterCommand.execute(this, evt, new Point(x, y));
	return false;
    }

    /**
     * Called if the mouse moves inside the window.
     * This results in a call to the mouseMoveCommand object with 
     * <code>what</code> set to Point(x, y)
     */
    public boolean mouseMove(Event evt, int x, int y) {
	if (mouseExitCommand != null)
	    mouseExitCommand.execute(this, evt, new Point(x, y));
	return false;
    }

    /**
     * Called if the mouse is up.
     * This results in a call to the mouseUpCommand object with 
     * <code>what</code> set to Point(x, y)
     */
    public boolean mouseUp(Event evt, int x, int y) {
	if (mouseUpCommand != null)
	    mouseUpCommand.execute(this, evt, new Point(x, y));
	return false;
    }

    /**
     * Called if a character is pressed.
     * This results in a call to the keyDownCommand object with 
     * <code>what</code> set to Integer(key).
     */
    public boolean keyDown(Event evt, int key) {
	if (keyDownCommand != null)
	    keyDownCommand.execute(this, evt, new Integer(key));
	return false;
    }

    /**
     * Called if a character is released.
     * This results in a call to the keyUpCommand object with 
     * <code>what</code> set to Integer(key).
     */
    public boolean keyUp(Event evt, int key) {
	if (keyUpCommand != null)
	    keyUpCommand.execute(this, evt, new Integer(key));
	return false;
    }


    /**
     * Called when an ACTION_EVENT is generated.
     * This results in a call to the actionCommand object 
     * with <code>what</code> set to the event's arg.
     */
    public boolean action(Event evt, Object what) {
	if (actionCommand != null)
	    actionCommand.execute(this, evt, what);
	return false;
    }

    /**
     * Called when a scrollbar is dragged.
     * This results in a call to the scrollAbsoluteCommand object
     * with <code>what</code> set to the slider location value.
     */
    public boolean scrollAbsolute(Event evt, Object what) {
        if (scrollAbsoluteCommand != null)
            scrollAbsoluteCommand.execute(this, evt, what);
	return false;
    }

    /**
     * Called when a scrollbar is incremented down.
     * This results in a call to the lineDownCommand object
     * with <code>what</code> set to the slider location value.
     */
    public boolean lineDown(Event evt, Object what) {
        if (lineDownCommand != null)
            lineDownCommand.execute(this, evt, what);
	return false;
    }

    /**
     * Called when a scrollbar is incremented up.
     * This results in a call to the lineUpCommand object
     * with <code>what</code> set to the slider location value.
     */
    public boolean lineUp(Event evt, Object what) {
        if (lineUpCommand != null)
            lineUpCommand.execute(this, evt, what);
	return false;
    }

    /**
     * Called when a scrollbar pages up.
     * This results in a call to the pageUpCommand object
     * with <code>what</code> set to the slider location value.
     */
    public boolean pageUp(Event evt, Object what) {
        if (pageUpCommand != null)
            pageUpCommand.execute(this, evt, what);
	return false;
    }

    /**
     * Called when a scrollbar pages down.
     * This results in a call to the pageDownCommand object
     * with <code>what</code> set to the slider location value.
     */
    public boolean pageDown(Event evt, Object what) {
        if (pageDownCommand != null)
            pageDownCommand.execute(this, evt, what);
	return false;
    }

    /** 
     * Called if the mouse selects an item in a List. 
     * This results in a call to the selectCommand object 
     * with <code>what</code> set to the selected index.
     */
    public boolean select(Event evt, Object what) {
        if (selectCommand != null)
            selectCommand.execute(this, evt, what);
	return false;
    }


    /** 
     * Called if the mouse deselects an item in a List. 
     * This results in a call to the deselectCommand object 
     * with <code>what</code> set to the deselected index.
     */
    public boolean deselect(Event evt, Object what) {
        if (deselectCommand != null)
            deselectCommand.execute(this, evt, what);
	return false;
    }

    /*
     * set...Command methods
     */ 


 
    /**
     * Sets the mouseDownCommand object.
     */
    public void setMouseDownCommand(Command c) {
	mouseDownCommand = c;
    }

    /**
     * Sets the moueDragCommand object.
     */
    public void setMouseDragCommand(Command c) {
	mouseDragCommand = c;
    }

    /**
     * Sets the mouseEnterCommand object.
     */
    public void setMouseEnterCommand(Command c) {
	mouseEnterCommand = c;
    }

    /**
     * Sets the mouseExitCommand object.
     */
    public void setMouseExitCommand(Command c) {
	mouseExitCommand = c;
    }

    /**
     * Sets the mouseMoveCommand object.
     */
    public void setMouseMoveCommand(Command c) {
	mouseMoveCommand = c;
    }

    /**
     * Sets the mouseUpCommand object.
     */
    public void setMouseUpCommand(Command c) {
	mouseUpCommand = c;
    }

    /**
     * Sets the keyDownCommand object.
     */
    public void setKeyDownCommand(Command c) {
	keyDownCommand = c;
    }

    /**
     * Sets the keyUpCommand object.
     */
    public void setKeyUpCommand(Command c) {
	keyUpCommand = c;
    }


   /**
    * Sets the actionCommand object.
    */
    public void setActionCommand(Command action) {
	actionCommand = action;
    }

    /**
     * Sets the scrollAbsoluteCommand.
     */
    public void setScrollAbsoluteCommand(Command c) {
	scrollAbsoluteCommand = c;
    }

    /**
     * Sets the lineUpCommand.
     */
    public void setLineUpCommand(Command c) {
	lineUpCommand = c;
    }

    /**
     * Sets the lineDownCommand.
     */
    public void setLineDownCommand(Command c) {
	lineDownCommand = c;
    }

    /**
     * Sets the pageUpCommand.
     */
    public void setPageUpCommand(Command c) {
	pageUpCommand = c;
    }

    /**
     * Sets the pageDownCommand.
     */
    public void setPageDownCommand(Command c) {
	pageDownCommand = c;
    }

    /**
     * Sets the selectCommand.
     */
    public void setSelectCommand(Command select) {
	selectCommand = select;
    }

    /**
     * Sets the deselectCommand.
     */
    public void setDeselectCommand(Command deselect) {
	deselectCommand = deselect;
    }

}