KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > memoire > vainstall > builder > VAIBuilderModel


1 /*
2  * $RCSfile: VAIBuilderModel.java,v $
3  * @modification $Date: 2001/09/28 19:27:49 $
4  * @version $Id: VAIBuilderModel.java,v 1.1 2001/09/28 19:27:49 hfalk Exp $
5  *
6  */

7
8 package com.memoire.vainstall.builder;
9
10 import com.memoire.vainstall.builder.event.*;
11 import com.memoire.vainstall.builder.util.*;
12
13 import java.util.Hashtable JavaDoc;
14 import java.util.LinkedList JavaDoc;
15
16 import javax.swing.event.EventListenerList JavaDoc;
17
18 /**
19  * This is the VAIBuilder data model
20  *
21  * @see javax.swing.event.EventListenerList
22  *
23  * @author Henrik Falk
24  * @version $Id: VAIBuilderModel.java,v 1.1 2001/09/28 19:27:49 hfalk Exp $
25  */

26 public class VAIBuilderModel {
27
28     /**
29      * The list of listenere that are interested in changes in
30      * the data model
31      */

32     EventListenerList JavaDoc listenerList = new EventListenerList JavaDoc();
33
34     /**
35      * The persistance class for this model
36      */

37     BuilderPersisterInterface builderPersister;
38
39     /**
40      * list of windows and bounds in the format <name, Rectangle>
41      */

42     Hashtable JavaDoc windowList = new Hashtable JavaDoc();
43
44     /**
45      * list of previous opened projects
46      */

47     LinkedList JavaDoc lastOpenedProjectList = new LinkedList JavaDoc();
48
49     /**
50      * list of properties in the format <name,String value>
51      */

52     Hashtable JavaDoc propertyList = new Hashtable JavaDoc();
53
54     /**
55      * Default constructor
56      */

57     public VAIBuilderModel() {
58         super();
59
60         try {
61             if( System.getProperty("java.version").indexOf("1.4.") != -1 ) {
62                 builderPersister = (BuilderPersisterInterface)Class.forName("com.memoire.vainstall.builder.util.JavaBuilderPersister").newInstance();
63             } else {
64                 builderPersister = (BuilderPersisterInterface)Class.forName("com.memoire.vainstall.builder.util.NanoBuilderPersister").newInstance();
65             }
66
67             builderPersister.initialize(this);
68
69         // add proper exception handling
70
} catch (InstantiationException JavaDoc exc) {
71         } catch (ClassNotFoundException JavaDoc exc) {
72         } catch (IllegalAccessException JavaDoc exc) {
73         }
74
75     }
76
77     /**
78      * @param e VAIBuilderEvent
79      */

80     public void fireVAIBuilderEvent(VAIBuilderEvent e) {
81
82         // guaranteed to return a non-null array
83
Object JavaDoc[] listeners = listenerList.getListenerList();
84
85         // process the listeners last to first, notifying
86
// those that are interested in this event
87
for (int i = listeners.length - 2; i >= 0; i -= 2) {
88             if (listeners[i] == com.memoire.vainstall.builder.event.VAIBuilderListener.class) {
89                  ((com.memoire.vainstall.builder.event.VAIBuilderListener)listeners[i+1]).builderChanged(e);
90             }
91         }
92     }
93
94     /**
95      * @param l com.memoire.vainstall.builder.event.VAIBuilderListener
96      */

97     public void addVAIBuilderListener(com.memoire.vainstall.builder.event.VAIBuilderListener l) {
98         listenerList.add(com.memoire.vainstall.builder.event.VAIBuilderListener.class,l);
99     }
100
101     /**
102      * @param l com.memoire.vainstall.builder.event.VAIBuilderListener
103      */

104     public void removeVAIBuilderListener(com.memoire.vainstall.builder.event.VAIBuilderListener l) {
105         listenerList.remove(com.memoire.vainstall.builder.event.VAIBuilderListener.class,l);
106     }
107
108     /**
109      * load data from datastore
110      */

111     public void load() {
112
113         builderPersister.load(); // add exception handling
114

115         fireVAIBuilderEvent(new VAIBuilderEvent(this,VAIBuilderEvent.PREFERENCES_LOADED));
116     }
117
118     /**
119      * save data to datastore
120      */

121     public void save() {
122
123         builderPersister.save(); // add exception handling
124

125         fireVAIBuilderEvent(new VAIBuilderEvent(this,VAIBuilderEvent.PREFERENCES_SAVED));
126     }
127
128     /**
129      * Returns the list of windows who has registrered bounds
130      * @return The list of window bounds
131      */

132     public Hashtable JavaDoc getWindowList() {
133         return windowList;
134     }
135
136     /**
137      * Returns the list of last opened projects
138      * @return a linked list of strings
139      */

140     public LinkedList JavaDoc getLastOpenedProjectList() {
141         return lastOpenedProjectList;
142     }
143
144     /**
145      * Add a filename to the list of last opened projects
146      * @param filename the fully qualified name of the project file
147      */

148     public void addLastOpenedProject(String JavaDoc filename) {
149
150         // if found in list
151
int pos = lastOpenedProjectList.indexOf(filename);
152         if (pos != -1) {
153             lastOpenedProjectList.remove(pos);
154             lastOpenedProjectList.addFirst(filename);
155         } else {
156
157             if (lastOpenedProjectList.size() < 5) {
158                 lastOpenedProjectList.addFirst(filename);
159             } else {
160                 lastOpenedProjectList.removeLast();
161                 lastOpenedProjectList.addFirst(filename);
162             }
163         }
164         fireVAIBuilderEvent(new VAIBuilderEvent(this,VAIBuilderEvent.LASTFILELIST_CHANGED));
165     }
166
167     /**
168      * Convenience method to access properties directly
169      * @return a list of builder properties
170      */

171     public Hashtable JavaDoc getPropertyList() {
172         return propertyList;
173     }
174
175 }
176
Popular Tags