01: /*
02: ** $Id: View.java,v 1.6 2000/10/26 08:34:15 mrw Exp $
03: **
04: ** Mike Wilson, July 2000, mrw@whisperingwind.co.uk
05: **
06: ** (C) Copyright 2000, Mike Wilson, Reading, Berkshire, UK
07: **
08: ** This program is free software; you can redistribute it and/or modify
09: ** it under the terms of the GNU General Public License as published by
10: ** the Free Software Foundation; either version 2 of the License, or
11: ** (at your option) any later version.
12: **
13: ** This program is distributed in the hope that it will be useful,
14: ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: ** GNU General Public License for more details.
17: **
18: ** You should have received a copy of the GNU Library General
19: ** Public License along with this library; if not, write to the
20: ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21: ** Boston, MA 02111-1307 USA.
22: */
23:
24: package uk.co.whisperingwind.framework;
25:
26: import java.awt.Component;
27: import java.util.Observable;
28: import java.util.Observer;
29:
30: /**
31: ** Base class for views. As views extend this, view with (for example)
32: ** a JDialog will contain the dialog rather than extend it.
33: */
34:
35: public abstract class View extends Observable implements Observer {
36: /**
37: ** Fire a view event.
38: ** @see #fireEvent (String arg1, Object arg2)
39: */
40:
41: protected void fireEvent(String arg1) {
42: fireEvent(arg1, null);
43: }
44:
45: /**
46: ** Fire a view event. It is assumed that view event are always
47: ** fired from the event dispatch thread. This method makes no
48: ** check for this. Things may go horribly wrong if this is called
49: ** from a different thread.
50: **
51: ** @arg1 the first argument to the event.
52: ** @arg2 the second argument to the event.
53: */
54:
55: protected void fireEvent(String arg1, Object arg2) {
56: setChanged();
57: notifyObservers(new ViewEvent(this , arg1, arg2));
58: }
59:
60: /**
61: ** Callback for the Observer interface. Dispatches the event into
62: ** a ModelEvent.
63: */
64:
65: public void update(Observable observable, Object arg) {
66: if (arg instanceof ModelEvent)
67: modelEvent((ModelEvent) arg);
68: }
69:
70: protected abstract void modelEvent(ModelEvent event);
71:
72: protected abstract void cleanUp();
73: }
|