3 import java.awt.event.WindowAdapter;
4 import java.awt.BorderLayout;
5 import java.awt.event.WindowEvent;
7 import java.io.FileNotFoundException;
8 import java.util.Locale;
9 import java.util.ArrayList;
10 import javax.swing.JFrame;
11 import javax.swing.JSplitPane;
12 import javax.swing.JToolBar;
13 import javax.swing.WindowConstants;
15 import tim.prune.gui.DetailsDisplay;
16 import tim.prune.gui.IconManager;
17 import tim.prune.gui.MenuManager;
18 import tim.prune.gui.ProfileChart;
19 import tim.prune.gui.SelectorDisplay;
20 import tim.prune.gui.StatusBar;
21 import tim.prune.gui.Viewport;
22 import tim.prune.gui.map.MapCanvas;
25 * Tool to visualize, edit, convert and prune GPS data
26 * Please see the included readme.txt or http://activityworkshop.net
27 * This software is copyright activityworkshop.net and made available through the Gnu GPL
29 public class GpsPruner
31 /** Version number of application, used in about screen and for version check */
32 public static final String VERSION_NUMBER = "8";
33 /** Build number, just used for about screen */
34 public static final String BUILD_NUMBER = "155";
35 /** Static reference to App object */
36 private static App APP = null;
41 * @param args command line arguments
43 public static void main(String[] args)
46 String localeCode = null;
47 String langFilename = null;
48 String configFilename = null;
49 ArrayList<File> dataFiles = new ArrayList<File>();
50 boolean showUsage = false;
51 for (int i=0; i<args.length; i++)
54 if (arg.startsWith("--locale="))
56 localeCode = arg.substring(9);
57 locale = getLanguage(localeCode);
59 else if (arg.startsWith("--lang="))
61 localeCode = arg.substring(7);
62 locale = getLanguage(localeCode);
64 else if (arg.startsWith("--langfile="))
66 langFilename = arg.substring(11);
68 else if (arg.startsWith("--configfile="))
70 configFilename = arg.substring(13);
72 else if (arg.startsWith("--help")) {
77 // Check if a data file has been given
78 File f = new File(arg);
79 if (f.exists() && f.canRead()) {
83 System.out.println("Unknown parameter '" + arg + "'.");
89 System.out.println("Possible parameters:"
90 + "\n --configfile=<file> used to specify a configuration file"
91 + "\n --lang=<code> or --locale=<code> used to specify language"
92 + "\n --langfile=<file> used to specify an alternative language file\n");
94 // Initialise configuration if selected
97 if (configFilename != null) {
98 Config.loadFile(new File(configFilename));
101 Config.loadDefaultFile();
104 catch (ConfigException ce) {
105 System.err.println("Failed to load config file: " + configFilename);
107 if (locale != null) {
108 // Make sure Config holds chosen language
109 Config.setConfigString(Config.KEY_LANGUAGE_CODE, localeCode);
112 // Set locale according to Config's language property
113 String configLang = Config.getConfigString(Config.KEY_LANGUAGE_CODE);
114 if (configLang != null) {
115 Locale configLocale = getLanguage(configLang);
116 if (configLocale != null) {locale = configLocale;}
119 I18nManager.init(locale);
120 if (langFilename != null) {
122 I18nManager.addLanguageFile(langFilename);
124 catch (FileNotFoundException fnfe) {
125 System.err.println("Failed to load language file: " + langFilename);
128 // Set up the window and go
134 * Choose a locale based on the given code
135 * @param inString code for locale
136 * @return Locale object if available, otherwise null
138 private static Locale getLanguage(String inString)
140 if (inString.length() == 2)
142 return new Locale(inString);
144 else if (inString.length() == 5)
146 return new Locale(inString.substring(0, 2), inString.substring(3));
148 System.out.println("Unrecognised locale '" + inString
149 + "' - value should be eg 'DE' or 'DE_ch'");
155 * Launch the main application
156 * @param inDataFiles list of data files to load on startup
158 private static void launch(ArrayList<File> inDataFiles)
160 JFrame frame = new JFrame("Prune");
161 APP = new App(frame);
164 MenuManager menuManager = new MenuManager(APP, APP.getTrackInfo());
165 frame.setJMenuBar(menuManager.createMenuBar());
166 APP.setMenuManager(menuManager);
167 UpdateMessageBroker.addSubscriber(menuManager);
168 // Make toolbar for buttons
169 JToolBar toolbar = menuManager.createToolBar();
171 // Make main GUI components and add as listeners
172 SelectorDisplay leftPanel = new SelectorDisplay(APP.getTrackInfo());
173 UpdateMessageBroker.addSubscriber(leftPanel);
174 DetailsDisplay rightPanel = new DetailsDisplay(APP.getTrackInfo());
175 UpdateMessageBroker.addSubscriber(rightPanel);
176 MapCanvas mapDisp = new MapCanvas(APP, APP.getTrackInfo());
177 UpdateMessageBroker.addSubscriber(mapDisp);
178 Viewport viewport = new Viewport(mapDisp);
179 APP.setViewport(viewport);
180 ProfileChart profileDisp = new ProfileChart(APP.getTrackInfo());
181 UpdateMessageBroker.addSubscriber(profileDisp);
182 StatusBar statusBar = new StatusBar();
183 UpdateMessageBroker.addSubscriber(statusBar);
184 UpdateMessageBroker.informSubscribers("Prune v" + VERSION_NUMBER);
186 // Arrange in the frame using split panes
187 JSplitPane midPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mapDisp, profileDisp);
188 midPane.setResizeWeight(1.0); // allocate as much space as poss to map
189 JSplitPane triplePane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, midPane, rightPanel);
190 triplePane.setResizeWeight(1.0); // allocate as much space as poss to map
192 frame.getContentPane().setLayout(new BorderLayout());
193 frame.getContentPane().add(toolbar, BorderLayout.NORTH);
194 frame.getContentPane().add(new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel,
195 triplePane), BorderLayout.CENTER);
196 frame.getContentPane().add(statusBar, BorderLayout.SOUTH);
198 // add closing listener
199 frame.addWindowListener(new WindowAdapter() {
200 public void windowClosing(WindowEvent e) {
204 // Avoid automatically shutting down if window closed
205 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
209 frame.setIconImage(IconManager.getImageIcon(IconManager.WINDOW_ICON).getImage());
211 catch (Exception e) {} // ignore
213 // finish off and display frame
215 frame.setSize(650, 450);
216 frame.setVisible(true);
217 // Set position of map/profile splitter
218 midPane.setDividerLocation(0.75);
220 // Finally, give the files to load to the App
221 APP.loadDataFiles(inDataFiles);