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