001: /*
002: * $RCSfile: VAIBuilderModel.java,v $
003: * @modification $Date: 2001/09/28 19:27:49 $
004: * @version $Id: VAIBuilderModel.java,v 1.1 2001/09/28 19:27:49 hfalk Exp $
005: *
006: */
007:
008: package com.memoire.vainstall.builder;
009:
010: import com.memoire.vainstall.builder.event.*;
011: import com.memoire.vainstall.builder.util.*;
012:
013: import java.util.Hashtable;
014: import java.util.LinkedList;
015:
016: import javax.swing.event.EventListenerList;
017:
018: /**
019: * This is the VAIBuilder data model
020: *
021: * @see javax.swing.event.EventListenerList
022: *
023: * @author Henrik Falk
024: * @version $Id: VAIBuilderModel.java,v 1.1 2001/09/28 19:27:49 hfalk Exp $
025: */
026: public class VAIBuilderModel {
027:
028: /**
029: * The list of listenere that are interested in changes in
030: * the data model
031: */
032: EventListenerList listenerList = new EventListenerList();
033:
034: /**
035: * The persistance class for this model
036: */
037: BuilderPersisterInterface builderPersister;
038:
039: /**
040: * list of windows and bounds in the format <name, Rectangle>
041: */
042: Hashtable windowList = new Hashtable();
043:
044: /**
045: * list of previous opened projects
046: */
047: LinkedList lastOpenedProjectList = new LinkedList();
048:
049: /**
050: * list of properties in the format <name,String value>
051: */
052: Hashtable propertyList = new Hashtable();
053:
054: /**
055: * Default constructor
056: */
057: public VAIBuilderModel() {
058: super ();
059:
060: try {
061: if (System.getProperty("java.version").indexOf("1.4.") != -1) {
062: builderPersister = (BuilderPersisterInterface) Class
063: .forName(
064: "com.memoire.vainstall.builder.util.JavaBuilderPersister")
065: .newInstance();
066: } else {
067: builderPersister = (BuilderPersisterInterface) Class
068: .forName(
069: "com.memoire.vainstall.builder.util.NanoBuilderPersister")
070: .newInstance();
071: }
072:
073: builderPersister.initialize(this );
074:
075: // add proper exception handling
076: } catch (InstantiationException exc) {
077: } catch (ClassNotFoundException exc) {
078: } catch (IllegalAccessException exc) {
079: }
080:
081: }
082:
083: /**
084: * @param e VAIBuilderEvent
085: */
086: public void fireVAIBuilderEvent(VAIBuilderEvent e) {
087:
088: // guaranteed to return a non-null array
089: Object[] listeners = listenerList.getListenerList();
090:
091: // process the listeners last to first, notifying
092: // those that are interested in this event
093: for (int i = listeners.length - 2; i >= 0; i -= 2) {
094: if (listeners[i] == com.memoire.vainstall.builder.event.VAIBuilderListener.class) {
095: ((com.memoire.vainstall.builder.event.VAIBuilderListener) listeners[i + 1])
096: .builderChanged(e);
097: }
098: }
099: }
100:
101: /**
102: * @param l com.memoire.vainstall.builder.event.VAIBuilderListener
103: */
104: public void addVAIBuilderListener(
105: com.memoire.vainstall.builder.event.VAIBuilderListener l) {
106: listenerList
107: .add(
108: com.memoire.vainstall.builder.event.VAIBuilderListener.class,
109: l);
110: }
111:
112: /**
113: * @param l com.memoire.vainstall.builder.event.VAIBuilderListener
114: */
115: public void removeVAIBuilderListener(
116: com.memoire.vainstall.builder.event.VAIBuilderListener l) {
117: listenerList
118: .remove(
119: com.memoire.vainstall.builder.event.VAIBuilderListener.class,
120: l);
121: }
122:
123: /**
124: * load data from datastore
125: */
126: public void load() {
127:
128: builderPersister.load(); // add exception handling
129:
130: fireVAIBuilderEvent(new VAIBuilderEvent(this ,
131: VAIBuilderEvent.PREFERENCES_LOADED));
132: }
133:
134: /**
135: * save data to datastore
136: */
137: public void save() {
138:
139: builderPersister.save(); // add exception handling
140:
141: fireVAIBuilderEvent(new VAIBuilderEvent(this ,
142: VAIBuilderEvent.PREFERENCES_SAVED));
143: }
144:
145: /**
146: * Returns the list of windows who has registrered bounds
147: * @return The list of window bounds
148: */
149: public Hashtable getWindowList() {
150: return windowList;
151: }
152:
153: /**
154: * Returns the list of last opened projects
155: * @return a linked list of strings
156: */
157: public LinkedList getLastOpenedProjectList() {
158: return lastOpenedProjectList;
159: }
160:
161: /**
162: * Add a filename to the list of last opened projects
163: * @param filename the fully qualified name of the project file
164: */
165: public void addLastOpenedProject(String filename) {
166:
167: // if found in list
168: int pos = lastOpenedProjectList.indexOf(filename);
169: if (pos != -1) {
170: lastOpenedProjectList.remove(pos);
171: lastOpenedProjectList.addFirst(filename);
172: } else {
173:
174: if (lastOpenedProjectList.size() < 5) {
175: lastOpenedProjectList.addFirst(filename);
176: } else {
177: lastOpenedProjectList.removeLast();
178: lastOpenedProjectList.addFirst(filename);
179: }
180: }
181: fireVAIBuilderEvent(new VAIBuilderEvent(this ,
182: VAIBuilderEvent.LASTFILELIST_CHANGED));
183: }
184:
185: /**
186: * Convenience method to access properties directly
187: * @return a list of builder properties
188: */
189: public Hashtable getPropertyList() {
190: return propertyList;
191: }
192:
193: }
|