1 | package org.honours;
|
---|
2 |
|
---|
3 | import java.awt.Point;
|
---|
4 | import java.io.File;
|
---|
5 | import java.util.HashSet;
|
---|
6 | import java.util.Set;
|
---|
7 | import java.util.concurrent.CopyOnWriteArrayList;
|
---|
8 |
|
---|
9 | import javax.swing.SwingUtilities;
|
---|
10 |
|
---|
11 | import org.expeditee.actions.Actions;
|
---|
12 | import org.expeditee.gui.*;
|
---|
13 | import org.expeditee.items.*;
|
---|
14 |
|
---|
15 | import org.honours.collection.*;
|
---|
16 | import org.honours.greenstone.ArchiveFileReader;
|
---|
17 | import org.honours.gui.*;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Main class for the cultural collections
|
---|
21 | * management system.
|
---|
22 | * @author Korii
|
---|
23 | */
|
---|
24 | public class Main {
|
---|
25 |
|
---|
26 | public static CopyOnWriteArrayList<Collection> _collections = new CopyOnWriteArrayList<Collection>();
|
---|
27 |
|
---|
28 | public static final String SYSTEM_FRAMESET_NAME = "Honours";
|
---|
29 |
|
---|
30 | public static final String GSDL_HOME = "greenstone3-svn\\web";
|
---|
31 |
|
---|
32 | //
|
---|
33 | public static final String GSDL_COLLECT_PATH = GSDL_HOME + File.separator + "sites" + File.separator + "localsite" +
|
---|
34 | File.separator + "collect" + File.separator;
|
---|
35 |
|
---|
36 | public static Frame _profile;
|
---|
37 |
|
---|
38 | //position of assocfilepath annotation on the frame
|
---|
39 | public static final int _assocfilePathXpos = 175;
|
---|
40 | public static final int _assocfilePathYpos = 101;
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Initialize settings and other things for the system.
|
---|
44 | */
|
---|
45 | public static void initialize(){
|
---|
46 |
|
---|
47 | SwingUtilities.invokeLater(new Runnable(){
|
---|
48 |
|
---|
49 | public void run(){
|
---|
50 | loadSettings();
|
---|
51 | }
|
---|
52 | });
|
---|
53 |
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Load settings required for the system.
|
---|
58 | */
|
---|
59 | private static void loadSettings(){
|
---|
60 |
|
---|
61 | MessageBay.displayMessage("Initializing System...");
|
---|
62 |
|
---|
63 | Frame profile = FrameIO.LoadProfile(SYSTEM_FRAMESET_NAME);
|
---|
64 |
|
---|
65 | if(profile == null){
|
---|
66 |
|
---|
67 | try{
|
---|
68 | profile = FrameIO.CreateNewProfile(SYSTEM_FRAMESET_NAME);
|
---|
69 | }catch(Exception e){
|
---|
70 | e.printStackTrace();
|
---|
71 | MessageBay.errorMessage("ERROR: Unable to load profile.");
|
---|
72 | return;
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | assert(profile != null);
|
---|
77 |
|
---|
78 | _profile = profile;
|
---|
79 |
|
---|
80 | if(DisplayIO.getCurrentFrame() != _profile)
|
---|
81 | DisplayIO.setCurrentFrame(_profile, true);
|
---|
82 |
|
---|
83 | //Set up main overlay display
|
---|
84 | Interfaces.setUpMainOverlay(_profile);
|
---|
85 |
|
---|
86 | UserSettings.UserName = "honours";
|
---|
87 |
|
---|
88 | initializeMainFramesets();
|
---|
89 |
|
---|
90 | addActionsAndAgents();
|
---|
91 | addCustomMouseActions();
|
---|
92 | addCustomKeyboardActions();
|
---|
93 |
|
---|
94 | try{
|
---|
95 | setUpCollectionObjects();
|
---|
96 | }catch(Exception e){
|
---|
97 | e.printStackTrace();
|
---|
98 |
|
---|
99 | MessageBay.errorMessage("ERROR: Unable to load collection objects.");
|
---|
100 | return;
|
---|
101 | }
|
---|
102 |
|
---|
103 | MessageBay.displayMessage("System initialized and is now ready for use.");
|
---|
104 | System.err.println("Collections available: " + _collections.size());
|
---|
105 |
|
---|
106 | if(_collections.size() > 0){
|
---|
107 | System.err.println("*** " + _collections.get(0).getItems().size());
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Set up collection objects which last for entire runtime.
|
---|
113 | * A "Collections" directory has been specially created where
|
---|
114 | * collection framesets from GSDL are kept. This method will only
|
---|
115 | * search this directory for collections (and not any other directories
|
---|
116 | * where framesets are kept).
|
---|
117 | * @throws Exception
|
---|
118 | */
|
---|
119 | private static void setUpCollectionObjects() throws Exception{
|
---|
120 |
|
---|
121 | //File collectionsDir = new File(HonoursFrameIO.COLLECTIONS_PATH);
|
---|
122 |
|
---|
123 | File collectionsDir = new File(FrameIO.FRAME_PATH);
|
---|
124 |
|
---|
125 | if(collectionsDir.isDirectory()){
|
---|
126 |
|
---|
127 | //return list of folders in collections directory
|
---|
128 | File[] folders = collectionsDir.listFiles();
|
---|
129 |
|
---|
130 | for(File f : folders){
|
---|
131 |
|
---|
132 | if(!f.isDirectory())
|
---|
133 | continue;
|
---|
134 |
|
---|
135 | String fName = f.getName();
|
---|
136 |
|
---|
137 | if(fName.equals("collectionsmain") || fName.equals("exhibitionsmain") || fName.equals("interface-overlays") || fName.equals("notesmain") || fName.equals("documentation")){
|
---|
138 | continue;
|
---|
139 | }
|
---|
140 |
|
---|
141 | Collection collect = obtainCollectionItems(fName);
|
---|
142 |
|
---|
143 | if(collect.getItems().size() == 0)
|
---|
144 | continue;
|
---|
145 |
|
---|
146 | _collections.add(collect);
|
---|
147 |
|
---|
148 | }
|
---|
149 |
|
---|
150 | for(Collection c : _collections){
|
---|
151 |
|
---|
152 | for(CollectionItem cItem : c.getItems()){
|
---|
153 | Interfaces.setUpToolbarOverlay(cItem);
|
---|
154 | Interfaces.setUpToggleToolbarOverlay(cItem);
|
---|
155 | Interfaces.setUpNotesOverlay(cItem);
|
---|
156 | //Interfaces.setUpBox(cItem);
|
---|
157 | }
|
---|
158 | }
|
---|
159 |
|
---|
160 | MessageBay.displayMessage("Interfaces for collection items initialized.");
|
---|
161 | }
|
---|
162 |
|
---|
163 | }
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * This method obtains all frames in a "collection" frameset
|
---|
167 | * and converts them to collection item objects. These items are
|
---|
168 | * then added to a collection object.
|
---|
169 | * @param collectName
|
---|
170 | * @return
|
---|
171 | */
|
---|
172 | public static Collection obtainCollectionItems(String collectName){
|
---|
173 |
|
---|
174 | Collection collect = new Collection(collectName);
|
---|
175 | CollectionInformation cInfo = new CollectionInformation();
|
---|
176 |
|
---|
177 | //Having an issue here when running ImportCollections agent.
|
---|
178 | //int last = FrameIO.LoadLast(collectName,HonoursFrameIO.COLLECTIONS_PATH).getNumber();
|
---|
179 | int last = FrameIO.getLastNumber(collectName);
|
---|
180 |
|
---|
181 | //TODO: Add content layering stuff back in once I get just normal
|
---|
182 | //loading of collection items working.
|
---|
183 | for(int i = 1; i <= last; i++){
|
---|
184 |
|
---|
185 | //Frame curr = FrameIO.LoadFrame(collectName + i, HonoursFrameIO.COLLECTIONS_PATH);
|
---|
186 | Frame curr = FrameIO.LoadFrame(collectName + i);
|
---|
187 |
|
---|
188 | if(curr == null)
|
---|
189 | continue;
|
---|
190 |
|
---|
191 | String assoc = getAssocFilePath(curr);
|
---|
192 |
|
---|
193 | if(assoc == null)
|
---|
194 | continue;
|
---|
195 |
|
---|
196 | CollectionItem cItem = new CollectionItem();
|
---|
197 | cItem.setFrame(curr);
|
---|
198 |
|
---|
199 | cInfo.addRow("I", curr.getName(), assoc);
|
---|
200 |
|
---|
201 | String docXML = GSDL_COLLECT_PATH + collectName + File.separator + "archives" + File.separator + assoc + File.separator + "doc.xml";
|
---|
202 |
|
---|
203 | cItem.setDocXML(docXML);
|
---|
204 |
|
---|
205 | ArchiveFileReader afr = new ArchiveFileReader(docXML);
|
---|
206 |
|
---|
207 | //System.err.println("*** assoc = " + assoc);
|
---|
208 | //System.err.println("*** docXML = " + docXML);
|
---|
209 |
|
---|
210 | String[] splitAssocFileName = afr.obtainElementText("gsdlassocfile").split(":");
|
---|
211 |
|
---|
212 | String assocFileName = GSDL_COLLECT_PATH + collectName + File.separator +
|
---|
213 | "index" + File.separator + "assoc" + File.separator + assoc + File.separator + splitAssocFileName[0];
|
---|
214 |
|
---|
215 | cItem.setAssocfilePath(assoc);
|
---|
216 | cItem.setAssociatedFile(assocFileName);
|
---|
217 | //setInExpeditee(docXML);
|
---|
218 |
|
---|
219 | collect.addItem(cItem);
|
---|
220 | }
|
---|
221 |
|
---|
222 | cInfo.sort();
|
---|
223 | collect.setCollectionInformation(cInfo);
|
---|
224 | return collect;
|
---|
225 | }
|
---|
226 |
|
---|
227 | /**
|
---|
228 | * This method extracts a text annotation on the passed frame
|
---|
229 | * which contains an assocfilepath metadata value
|
---|
230 | * (e.g. "@assocfilepath HASH0170.dir"). Each frame/collection item
|
---|
231 | * has its own unique assocfilepath value.
|
---|
232 | * TODO: There is a bug in GSDL that is affecting this code here... The
|
---|
233 | * assocfilepath metadata is being displayed as "HASH0170, HASH0170" for example
|
---|
234 | * when it should only be displayed as "HASH0170.
|
---|
235 | * @param curr - the frame to extract the assocfilepath text annotation from.
|
---|
236 | * @return - the assocfilepath value. If none is found, return null.
|
---|
237 | */
|
---|
238 | private static String getAssocFilePath(Frame curr){
|
---|
239 |
|
---|
240 | String splitString = null;
|
---|
241 |
|
---|
242 | for(Item item : curr.getItems()){
|
---|
243 | if(item instanceof Text){
|
---|
244 | Text text = (Text) item;
|
---|
245 |
|
---|
246 | if(text.getText().startsWith("@assocfilepath")){
|
---|
247 |
|
---|
248 | String[] split = text.getText().split(" ");
|
---|
249 |
|
---|
250 | if(splitString == null){
|
---|
251 | splitString = split[1];
|
---|
252 |
|
---|
253 | //remove a comma that may be at the end of the string.
|
---|
254 | if(splitString.endsWith(",")){
|
---|
255 | splitString = splitString.substring(0, splitString.length()-1);
|
---|
256 | }
|
---|
257 | }
|
---|
258 |
|
---|
259 | //do this so that no one can edit/delete
|
---|
260 | //assocfilepath annotation.
|
---|
261 | item.setPermission(UserAppliedPermission.none);
|
---|
262 |
|
---|
263 | //Shift item to position (3,129).
|
---|
264 | if(item.getX() != _assocfilePathXpos && item.getY() != _assocfilePathYpos)
|
---|
265 | item.setPosition(new Point(_assocfilePathXpos,_assocfilePathYpos));
|
---|
266 |
|
---|
267 | if(item.getSize() != 14)
|
---|
268 | item.setSize(14);
|
---|
269 |
|
---|
270 | curr.setSaved();
|
---|
271 | curr.setChanged(true);
|
---|
272 | }
|
---|
273 | }
|
---|
274 | }
|
---|
275 | return splitString;
|
---|
276 | }
|
---|
277 |
|
---|
278 | /**
|
---|
279 | * Initialize (currently three) main framesets:
|
---|
280 | * collections,exhibitions,notes.
|
---|
281 | */
|
---|
282 | private static void initializeMainFramesets(){
|
---|
283 |
|
---|
284 | //NOTE: CollectionsMain not to be confused with the collections
|
---|
285 | //directory where all collection framesets are stored.
|
---|
286 | String[] mainFramesetNames = new String[]{"CollectionsMain","ExhibitionsMain","NotesMain"};
|
---|
287 |
|
---|
288 | //TODO: might be better just to check frameset directory
|
---|
289 | //instead of trying to load frames...
|
---|
290 | for(String s : mainFramesetNames){
|
---|
291 | Frame frame = FrameIO.LoadFrame(s + "1");
|
---|
292 |
|
---|
293 | if(frame == null){
|
---|
294 | try{
|
---|
295 | FrameIO.CreateNewFrameset(s);
|
---|
296 | }catch(Exception e){
|
---|
297 | e.printStackTrace();
|
---|
298 | }
|
---|
299 | }
|
---|
300 | }
|
---|
301 |
|
---|
302 | MessageBay.displayMessage("Main framesets initialized.");
|
---|
303 | }
|
---|
304 |
|
---|
305 | /**
|
---|
306 | * Method to load and set up actions and agents for this system.
|
---|
307 | */
|
---|
308 | @SuppressWarnings("rawtypes")
|
---|
309 | private static void addActionsAndAgents(){
|
---|
310 |
|
---|
311 | Actions.Init();
|
---|
312 |
|
---|
313 | Set<String> agents = new HashSet<String>();
|
---|
314 | try{
|
---|
315 | for(Class c : Actions.getClasses("org.honours.agents.")){
|
---|
316 | if(c != null){
|
---|
317 | agents.add(c.getName());
|
---|
318 | }else{
|
---|
319 | throw new ClassNotFoundException("ERROR: No class found.");
|
---|
320 | }
|
---|
321 | }
|
---|
322 |
|
---|
323 | }catch(ClassNotFoundException e){
|
---|
324 | e.printStackTrace();
|
---|
325 | }
|
---|
326 |
|
---|
327 | Actions.addAgents(agents);
|
---|
328 |
|
---|
329 | try{
|
---|
330 | for(Class c : Actions.getClasses("org.honours.actions.")){
|
---|
331 |
|
---|
332 | if(c != null)
|
---|
333 | Actions.LoadMethods(c);
|
---|
334 | else
|
---|
335 | throw new ClassNotFoundException("ERROR: No class found.");
|
---|
336 | }
|
---|
337 | }catch(ClassNotFoundException e){
|
---|
338 | e.printStackTrace();
|
---|
339 | }
|
---|
340 |
|
---|
341 | MessageBay.displayMessage("Actions and agents initialized.");
|
---|
342 | }
|
---|
343 |
|
---|
344 | /**
|
---|
345 | * Method to add custom mouse actions for this system.
|
---|
346 | * These extend on Expedite's mouse actions.
|
---|
347 | */
|
---|
348 | private static void addCustomMouseActions(){
|
---|
349 |
|
---|
350 | MouseActions mouseActions = MouseActions.getInstance();
|
---|
351 |
|
---|
352 | Browser._theBrowser.getMouseEventRouter().removeExpediteeMouseListener(FrameMouseActions.getInstance());
|
---|
353 | Browser._theBrowser.getMouseEventRouter().addExpediteeMouseListener(mouseActions);
|
---|
354 | Browser._theBrowser.getMouseEventRouter().removeExpediteeMouseMotionListener(FrameMouseActions.getInstance());
|
---|
355 | Browser._theBrowser.getMouseEventRouter().addExpediteeMouseMotionListener(mouseActions);
|
---|
356 |
|
---|
357 | MessageBay.displayMessage("Mouse actions initialized");
|
---|
358 | }
|
---|
359 |
|
---|
360 | /**
|
---|
361 | * Method to add custom keyboard actions for this system.
|
---|
362 | * These extend on Expeditee's keyboard actions.
|
---|
363 | */
|
---|
364 | private static void addCustomKeyboardActions(){
|
---|
365 |
|
---|
366 | KeyboardActions keyboardActions = KeyboardActions.getInstance();
|
---|
367 | Browser._theBrowser.removeKeyListener(FrameKeyboardActions.getInstance());
|
---|
368 | Browser._theBrowser.addKeyListener(keyboardActions);
|
---|
369 |
|
---|
370 | Browser._theBrowser.getContentPane().removeKeyListener(FrameKeyboardActions.getInstance());
|
---|
371 | Browser._theBrowser.getContentPane().addKeyListener(keyboardActions);
|
---|
372 |
|
---|
373 | MessageBay.displayMessage("Keyboard actions initialized");
|
---|
374 | }
|
---|
375 |
|
---|
376 | /**
|
---|
377 | * Main entry point for this system.
|
---|
378 | * @param args - any arguments passed to this system will be passed to the Expeditee browser.
|
---|
379 | */
|
---|
380 | public static void main(final String[] args){
|
---|
381 |
|
---|
382 | Browser.main(args);
|
---|
383 |
|
---|
384 | SwingUtilities.invokeLater(new Runnable(){
|
---|
385 | public void run(){
|
---|
386 | initialize();
|
---|
387 | }
|
---|
388 | });
|
---|
389 | }
|
---|
390 |
|
---|
391 | } |
---|