Source code: com/cybertivity/powerjournal/framework/View.java
1 /*
2 * Title: Similated Intelligence
3 * Copyright: Copyright (c) 2001 Cybertivity
4 * Company: <A HREF="http://www.cybertivity.com">Cybertivity</A>
5 * @author <A HREF="mailto:chris.arrowood@cybertivity.com">Chris Arrowood</A>
6 * @version $Id: View.java,v 1.1.1.1 2001/11/24 03:51:34 arrowood Exp $
7 */
8 package com.cybertivity.powerjournal.framework;
9
10 import java.awt.Component;
11 import java.util.Observable;
12 import java.util.Observer;
13
14 /**
15 * Description of the Class
16 *
17 * @author arrowood
18 * @created July 17, 2001
19 */
20 public abstract class View extends Observable implements Observer {
21
22 /**
23 * This method is called whenever the observed object is changed. An
24 * application calls an Observable object's notifyObservers method to have all
25 * the object's observers notified of the change.
26 *
27 * @param observable The object that changed.
28 * @param arg Description of Parameter
29 */
30
31 public void update(Observable observable, Object arg) {
32 if(arg instanceof ModelEvent) {
33 handleModelEvent((ModelEvent) arg);
34 }
35 }
36
37
38 /**
39 * Fire a view event.
40 *
41 * @param event The event that occured.
42 */
43
44 protected void fireEvent(String event) {
45 fireEvent(event, null);
46 }
47
48
49 /**
50 * Fire a view event. It is assumed that view events are always fired from the
51 * event dispatch thread. This method makes no check for this. Things may go
52 * horribly wrong if this is called from a different thread.
53 *
54 * @param field The field that has changed
55 * @param value The new value of the field
56 */
57
58 protected void fireEvent(String field, Object value) {
59 //System.out.println("View: Notifying Observers about event - " + field);
60 setChanged();
61 notifyObservers(new ViewEvent(this, field, value));
62 }
63
64
65 /**
66 * @param event The event that occured
67 */
68 protected abstract void handleModelEvent(ModelEvent event);
69
70
71 protected abstract void cleanUp();
72
73 }
74