3 import java.awt.event.WindowAdapter;
4 import java.awt.BorderLayout;
5 import java.awt.event.WindowEvent;
7 import java.util.Locale;
8 import javax.swing.JFrame;
9 import javax.swing.JSplitPane;
10 import javax.swing.JToolBar;
11 import javax.swing.WindowConstants;
13 import tim.prune.gui.DetailsDisplay;
14 import tim.prune.gui.IconManager;
15 import tim.prune.gui.MenuManager;
16 import tim.prune.gui.ProfileChart;
17 import tim.prune.gui.SelectorDisplay;
18 import tim.prune.gui.StatusBar;
19 import tim.prune.gui.map.MapCanvas;
22 * Tool to visualize, edit, convert and prune GPS data
23 * Please see the included readme.txt or http://activityworkshop.net
24 * This software is copyright activityworkshop.net and made available through the Gnu GPL
26 public class GpsPruner
28 /** Version number of application, used in about screen and for version check */
29 public static final String VERSION_NUMBER = "7";
30 /** Build number, just used for about screen */
31 public static final String BUILD_NUMBER = "136";
32 /** Static reference to App object */
33 private static App APP = null;
38 * @param args command line arguments
40 public static void main(String[] args)
43 String langFilename = null;
44 String configFilename = null;
45 boolean showUsage = false;
46 for (int i=0; i<args.length; i++)
49 if (arg.startsWith("--locale="))
51 locale = getLanguage(arg.substring(9));
53 else if (arg.startsWith("--lang="))
55 locale = getLanguage(arg.substring(7));
57 else if (arg.startsWith("--langfile="))
59 langFilename = arg.substring(11);
61 else if (arg.startsWith("--configfile="))
63 configFilename = arg.substring(13);
67 if (!arg.startsWith("--help")) {
68 System.out.println("Unknown parameter '" + arg + "'.");
74 System.out.println("Possible parameters:"
75 + "\n --configfile=<file> used to specify a configuration file"
76 + "\n --lang=<code> or --locale=<code> used to specify language"
77 + "\n --langfile=<file> used to specify an alternative language file\n");
79 // Initialise configuration if selected
82 if (configFilename != null) {
83 Config.loadFile(new File(configFilename));
86 Config.loadDefaultFile();
89 catch (ConfigException ce) {
90 System.err.println("Failed to load config file: " + configFilename);
92 // Set locale according to Config's language property
93 String langCode = Config.getLanguageCode();
94 if (locale == null && langCode != null) {
95 Locale configLocale = getLanguage(langCode);
96 if (configLocale != null) {locale = configLocale;}
98 I18nManager.init(locale);
99 if (langFilename != null) {
100 I18nManager.addLanguageFile(langFilename);
102 // Set up the window and go
108 * Choose a locale based on the given code
109 * @param inString code for locale
110 * @return Locale object if available, otherwise null
112 private static Locale getLanguage(String inString)
114 if (inString.length() == 2)
116 return new Locale(inString);
118 else if (inString.length() == 5)
120 return new Locale(inString.substring(0, 2), inString.substring(3));
122 System.out.println("Unrecognised locale '" + inString
123 + "' - value should be eg 'DE' or 'DE_ch'");
129 * Launch the main application
131 private static void launch()
133 JFrame frame = new JFrame("Prune");
134 APP = new App(frame);
137 MenuManager menuManager = new MenuManager(APP, APP.getTrackInfo());
138 frame.setJMenuBar(menuManager.createMenuBar());
139 APP.setMenuManager(menuManager);
140 UpdateMessageBroker.addSubscriber(menuManager);
141 // Make toolbar for buttons
142 JToolBar toolbar = menuManager.createToolBar();
144 // Make main GUI components and add as listeners
145 SelectorDisplay leftPanel = new SelectorDisplay(APP.getTrackInfo());
146 UpdateMessageBroker.addSubscriber(leftPanel);
147 DetailsDisplay rightPanel = new DetailsDisplay(APP.getTrackInfo());
148 UpdateMessageBroker.addSubscriber(rightPanel);
149 MapCanvas mapDisp = new MapCanvas(APP, APP.getTrackInfo());
150 UpdateMessageBroker.addSubscriber(mapDisp);
151 ProfileChart profileDisp = new ProfileChart(APP.getTrackInfo());
152 UpdateMessageBroker.addSubscriber(profileDisp);
153 StatusBar statusBar = new StatusBar();
154 UpdateMessageBroker.addSubscriber(statusBar);
155 UpdateMessageBroker.informSubscribers("Prune v" + VERSION_NUMBER);
157 // Arrange in the frame using split panes
158 JSplitPane midPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mapDisp, profileDisp);
159 midPane.setResizeWeight(1.0); // allocate as much space as poss to map
160 JSplitPane triplePane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, midPane, rightPanel);
161 triplePane.setResizeWeight(1.0); // allocate as much space as poss to map
163 frame.getContentPane().setLayout(new BorderLayout());
164 frame.getContentPane().add(toolbar, BorderLayout.NORTH);
165 frame.getContentPane().add(new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel,
166 triplePane), BorderLayout.CENTER);
167 frame.getContentPane().add(statusBar, BorderLayout.SOUTH);
169 // add closing listener
170 frame.addWindowListener(new WindowAdapter() {
171 public void windowClosing(WindowEvent e) {
175 // Avoid automatically shutting down if window closed
176 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
180 frame.setIconImage(IconManager.getImageIcon(IconManager.WINDOW_ICON).getImage());
182 catch (Exception e) {} // ignore
184 // finish off and display frame
186 frame.setSize(650, 450);
187 frame.setVisible(true);
188 // Set position of map/profile splitter
189 midPane.setDividerLocation(0.75);