View Javadoc

1   /*
2    * @(#)$Id: Geco.java 689 2009-07-22 00:10:27Z bsigner $
3    *
4    * Author       :   Michele Croci, mcroci@mgail.com
5    *
6    * Purpose      :   Main class for the geco application.
7    *
8    * -----------------------------------------------------------------------
9    *
10   * Revision Information:
11   *
12   * Date             Who         Reason
13   *
14   * Nov 19, 2007     crocimi     Initial Release
15   * Jan 20, 2008     bsigner     Cleanup and new GuiBundle functionality
16   *
17   * -----------------------------------------------------------------------
18   *
19   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20   *
21   * This software is the proprietary information of ETH Zurich.
22   * Use is subject to license terms.
23   * 
24   */
25  
26  
27  package org.ximtec.igesture.geco;
28  
29  import java.io.File;
30  import java.util.logging.Level;
31  import java.util.logging.Logger;
32  
33  import javax.swing.ImageIcon;
34  
35  import org.sigtec.graphix.SplashScreen;
36  import org.sigtec.util.FileHandler;
37  import org.ximtec.igesture.algorithm.AlgorithmException;
38  import org.ximtec.igesture.geco.gui.MainModel;
39  import org.ximtec.igesture.geco.gui.MainView;
40  import org.ximtec.igesture.geco.gui.action.OpenProjectAction;
41  import org.ximtec.igesture.geco.util.Constant;
42  import org.ximtec.igesture.geco.util.SystemTray;
43  import org.ximtec.igesture.util.XMLTool;
44  
45  
46  /**
47   * Main class for the geco application.
48   * 
49   * @version 0.9, Nov 2007
50   * @author Michele Croci, mcroci@gmail.com
51   * @author Beat Signer, signer@inf.ethz.ch
52   */
53  public class Geco {
54  
55     private static final Logger LOGGER = Logger.getLogger(Geco.class.getName());
56  
57     public static final String GECO_CONFIGURATION = "config/geco.xml";
58  
59     private static final String DEFAULT_PROJECT = "mappings/defaultMappings.xml";
60  
61     private static final String GECO_LOGO = "images/gecoLogo.png";
62  
63     private static final String RUBINE_CONFIGURATION = "config/rubineconfiguration.xml";
64  
65     public static final String CONFIG = "config";
66  
67     private org.ximtec.igesture.configuration.Configuration configuration;
68  
69     private Configuration gecoConfiguration;
70  
71     private MainView view;
72  
73  
74     public Geco(String[] args) throws AlgorithmException {
75        ImageIcon logo = new ImageIcon(Geco.class.getClassLoader().getResource(
76              GECO_LOGO));
77        SplashScreen splashScreen = new SplashScreen(logo, false, 4000);
78        splashScreen.splash();
79        Logger.getAnonymousLogger().setLevel(Level.INFO);
80        LOGGER.info(Constant.INITIALISING);
81  
82        if (args.length > 0) {
83           gecoConfiguration = new Configuration(args[0]);
84        }
85        else {
86           gecoConfiguration = new Configuration(GECO_CONFIGURATION);
87        }
88  
89        configuration = XMLTool.importConfiguration(ClassLoader
90              .getSystemResourceAsStream(RUBINE_CONFIGURATION));
91        MainModel model = new MainModel(configuration, gecoConfiguration);
92        view = new MainView(model);
93        openMostRecentProject();
94        new SystemTray(view);
95        LOGGER.info(Constant.INITIALISED);
96     }
97  
98  
99     /**
100     * Main method
101     * 
102     * @param args
103     */
104    public static void main(String[] args) {
105       try {
106          new Geco(args);
107       }
108       catch (Exception e) {
109          e.printStackTrace();
110       }
111 
112    }
113 
114 
115    private void openMostRecentProject() {
116       File file = null;
117       String filename = view.getModel().getGestureConfiguration()
118             .getMostRecentProject();
119 
120       if ((filename == null) || (filename.equals(Constant.EMPTY_STRING))) {
121          file = FileHandler.getResource(DEFAULT_PROJECT);
122       }
123 
124       (new OpenProjectAction(view)).openProject(file);
125    } // openMostRecentProject
126 
127 }