1 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 ; 14 import java.util.LinkedList ; 15 16 import javax.swing.event.EventListenerList ; 17 18 26 public class VAIBuilderModel { 27 28 32 EventListenerList listenerList = new EventListenerList (); 33 34 37 BuilderPersisterInterface builderPersister; 38 39 42 Hashtable windowList = new Hashtable (); 43 44 47 LinkedList lastOpenedProjectList = new LinkedList (); 48 49 52 Hashtable propertyList = new Hashtable (); 53 54 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 } catch (InstantiationException exc) { 71 } catch (ClassNotFoundException exc) { 72 } catch (IllegalAccessException exc) { 73 } 74 75 } 76 77 80 public void fireVAIBuilderEvent(VAIBuilderEvent e) { 81 82 Object [] listeners = listenerList.getListenerList(); 84 85 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 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 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 111 public void load() { 112 113 builderPersister.load(); 115 fireVAIBuilderEvent(new VAIBuilderEvent(this,VAIBuilderEvent.PREFERENCES_LOADED)); 116 } 117 118 121 public void save() { 122 123 builderPersister.save(); 125 fireVAIBuilderEvent(new VAIBuilderEvent(this,VAIBuilderEvent.PREFERENCES_SAVED)); 126 } 127 128 132 public Hashtable getWindowList() { 133 return windowList; 134 } 135 136 140 public LinkedList getLastOpenedProjectList() { 141 return lastOpenedProjectList; 142 } 143 144 148 public void addLastOpenedProject(String filename) { 149 150 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 171 public Hashtable getPropertyList() { 172 return propertyList; 173 } 174 175 } 176 | Popular Tags |