]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/GpsPruner.java
Version 4, January 2008
[GpsPrune.git] / tim / prune / GpsPruner.java
1 package tim.prune;
2
3 import java.awt.BorderLayout;
4 import java.awt.event.WindowAdapter;
5 import java.awt.event.WindowEvent;
6 import java.util.Locale;
7
8 import javax.swing.JFrame;
9 import javax.swing.JSplitPane;
10 import javax.swing.JToolBar;
11 import javax.swing.WindowConstants;
12
13 import tim.prune.gui.DetailsDisplay;
14 import tim.prune.gui.MapChart;
15 import tim.prune.gui.MenuManager;
16 import tim.prune.gui.ProfileChart;
17 import tim.prune.gui.SelectorDisplay;
18
19 /**
20  * Tool to visualize, edit and prune GPS data
21  * Please see the included readme.txt or http://activityworkshop.net
22  */
23 public class GpsPruner
24 {
25         // Final release of version 4
26         public static final String VERSION_NUMBER = "4";
27         public static final String BUILD_NUMBER = "089";
28         private static App APP = null;
29
30
31         /**
32          * Main method
33          * @param args command line arguments
34          */
35         public static void main(String[] args)
36         {
37                 Locale locale = null;
38                 if (args.length == 1)
39                 {
40                         if (args[0].startsWith("--locale="))
41                         {
42                                 locale = getLanguage(args[0].substring(9));
43                         }
44                         else if (args[0].startsWith("--lang="))
45                         {
46                                 locale = getLanguage(args[0].substring(7));
47                         }
48                         else
49                         {
50                                 System.out.println("Unknown parameter '" + args[0] +
51                                         "'. Possible parameters:\n   --locale= or --lang=  used for overriding language settings\n");
52                         }
53                 }
54                 I18nManager.init(locale);
55                 launch();
56         }
57
58
59         /**
60          * Choose a locale based on the given code
61          * @param inString code for locale
62          * @return Locale object if available, otherwise null
63          */
64         private static Locale getLanguage(String inString)
65         {
66                 if (inString.length() == 2)
67                 {
68                         return new Locale(inString);
69                 }
70                 else if (inString.length() == 5)
71                 {
72                         return new Locale(inString.substring(0, 2), inString.substring(3));
73                 }
74                 System.out.println("Unrecognised locale '" + inString
75                         + "' - value should be eg 'DE' or 'DE_ch'");
76                 return null;
77         }
78
79
80         /**
81          * Launch the main application
82          */
83         private static void launch()
84         {
85                 JFrame frame = new JFrame("Prune");
86                 UpdateMessageBroker broker = new UpdateMessageBroker();
87                 APP = new App(frame, broker);
88
89                 // make menu
90                 MenuManager menuManager = new MenuManager(frame, APP, APP.getTrackInfo());
91                 frame.setJMenuBar(menuManager.createMenuBar());
92                 APP.setMenuManager(menuManager);
93                 broker.addSubscriber(menuManager);
94                 // Make toolbar for buttons
95                 JToolBar toolbar = menuManager.createToolBar();
96
97                 // Make three GUI components and add as listeners
98                 SelectorDisplay leftPanel = new SelectorDisplay(APP.getTrackInfo());
99                 broker.addSubscriber(leftPanel);
100                 DetailsDisplay rightPanel = new DetailsDisplay(APP.getTrackInfo());
101                 broker.addSubscriber(rightPanel);
102                 MapChart mapDisp = new MapChart(APP, APP.getTrackInfo());
103                 broker.addSubscriber(mapDisp);
104                 ProfileChart profileDisp = new ProfileChart(APP.getTrackInfo());
105                 broker.addSubscriber(profileDisp);
106
107                 JSplitPane midPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mapDisp, profileDisp);
108                 midPane.setResizeWeight(1.0); // allocate as much space as poss to map
109                 JSplitPane triplePane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, midPane, rightPanel);
110                 triplePane.setResizeWeight(1.0); // allocate as much space as poss to map
111
112                 frame.getContentPane().setLayout(new BorderLayout());
113                 frame.getContentPane().add(toolbar, BorderLayout.NORTH);
114                 frame.getContentPane().add(new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel,
115                         triplePane), BorderLayout.CENTER);
116                 // add closing listener
117                 frame.addWindowListener(new WindowAdapter() {
118                         public void windowClosing(WindowEvent e) {
119                                 APP.exit();
120                         }
121                 });
122                 // Avoid automatically shutting down if window closed
123                 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
124
125                 // finish off and display frame
126                 frame.pack();
127                 frame.setSize(650, 450);
128                 frame.show();
129         }
130 }