View Javadoc

1   package ch.odi.justblog;
2   
3   import ch.odi.justblog.gui.Ui;
4   import ch.odi.justblog.gui.UiFactory;
5   
6   /***
7    * The application's main class.
8    *
9    * @author oglueck
10   */
11  public class JustBlog {
12      private static JustBlog app;
13      private Ui gui;
14      
15      public JustBlog(String uiName) {
16          int id = UiFactory.SWING;
17          if (uiName.equals("swing")) id = UiFactory.SWING; 
18          if (uiName.equals("test")) id = UiFactory.TEST;
19          if (uiName.equals("cli")) id = UiFactory.CLI;
20          gui = UiFactory.getUi(id);
21          if (gui == null) throw new IllegalArgumentException("No such GUI: "+ uiName);
22      }
23      
24      /***
25       * Gets the application's user interface.
26       * 
27       * @return
28       */
29      public Ui getUi() {
30          return gui;
31      }
32      
33      /***
34       * Provides everybody with the current applicatio instance.
35       * 
36       * @return
37       */
38      public static JustBlog app() {
39          return app;
40      }
41      
42      /***
43       * Starts the application
44       * TODO accept parameters to choose a GUI: swing, test, cli 
45       * @param args
46       */
47      public static void main(String[] args) {
48          String name;
49          if (args.length < 1) {
50              name = "swing";
51          } else {
52              name = args[0].toLowerCase();
53          }
54          app = new JustBlog(name);
55      }
56  
57  }