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.config.Config;
16 import tim.prune.config.ConfigException;
17 import tim.prune.gui.DetailsDisplay;
18 import tim.prune.gui.IconManager;
19 import tim.prune.gui.MenuManager;
20 import tim.prune.gui.ProfileChart;
21 import tim.prune.gui.SelectorDisplay;
22 import tim.prune.gui.StatusBar;
23 import tim.prune.gui.Viewport;
24 import tim.prune.gui.map.MapCanvas;
27 * Prune is a tool to visualize, edit, convert and prune GPS data
28 * Please see the included readme.txt or http://activityworkshop.net
29 * This software is copyright activityworkshop.net 2006-2010 and made available through the Gnu GPL version 2.
30 * For license details please see the included license.txt.
31 * GpsPruner is the main entry point to the application, including initialisation and launch
33 public class GpsPruner
35 /** Version number of application, used in about screen and for version check */
36 public static final String VERSION_NUMBER = "9";
37 /** Build number, just used for about screen */
38 public static final String BUILD_NUMBER = "176";
39 /** Static reference to App object */
40 private static App APP = null;
45 * @param args command line arguments
47 public static void main(String[] args)
50 String localeCode = null;
51 String langFilename = null;
52 String configFilename = null;
53 ArrayList<File> dataFiles = new ArrayList<File>();
54 boolean showUsage = false;
55 for (int i=0; i<args.length; i++)
58 if (arg.startsWith("--locale="))
60 localeCode = arg.substring(9);
61 locale = getLanguage(localeCode);
63 else if (arg.startsWith("--lang="))
65 localeCode = arg.substring(7);
66 locale = getLanguage(localeCode);
68 else if (arg.startsWith("--langfile="))
70 langFilename = arg.substring(11);
72 else if (arg.startsWith("--configfile="))
74 configFilename = arg.substring(13);
76 else if (arg.startsWith("--help")) {
81 // Check if a data file has been given
82 File f = new File(arg);
83 if (f.exists() && f.canRead()) {
87 System.out.println("Unknown parameter '" + arg + "'.");
93 System.out.println("Possible parameters:"
94 + "\n --configfile=<file> used to specify a configuration file"
95 + "\n --lang=<code> or --locale=<code> used to specify language"
96 + "\n --langfile=<file> used to specify an alternative language file\n");
98 // Initialise configuration if selected
101 if (configFilename != null) {
102 Config.loadFile(new File(configFilename));
105 Config.loadDefaultFile();
108 catch (ConfigException ce) {
109 System.err.println("Failed to load config file: " + configFilename);
111 boolean overrideLang = (locale != null);
113 // Make sure Config holds chosen language
114 Config.setConfigString(Config.KEY_LANGUAGE_CODE, localeCode);
117 // Set locale according to Config's language property
118 String configLang = Config.getConfigString(Config.KEY_LANGUAGE_CODE);
119 if (configLang != null) {
120 Locale configLocale = getLanguage(configLang);
121 if (configLocale != null) {locale = configLocale;}
124 I18nManager.init(locale);
125 // Load the external language file, either from config file or from command line params
126 if (langFilename == null && !overrideLang) {
127 // If langfilename is blank on command line parameters then don't use setting from config
128 langFilename = Config.getConfigString(Config.KEY_LANGUAGE_FILE);
130 if (langFilename != null && !langFilename.equals("")) {
132 I18nManager.addLanguageFile(langFilename);
133 Config.setConfigString(Config.KEY_LANGUAGE_FILE, langFilename);
135 catch (FileNotFoundException fnfe) {
136 System.err.println("Failed to load language file: " + langFilename);
139 // Set up the window and go
145 * Choose a locale based on the given code
146 * @param inString code for locale
147 * @return Locale object if available, otherwise null
149 private static Locale getLanguage(String inString)
151 if (inString.length() == 2)
153 return new Locale(inString);
155 else if (inString.length() == 5)
157 return new Locale(inString.substring(0, 2), inString.substring(3));
159 System.out.println("Unrecognised locale '" + inString
160 + "' - value should be eg 'DE' or 'DE_ch'");
166 * Launch the main application
167 * @param inDataFiles list of data files to load on startup
169 private static void launch(ArrayList<File> inDataFiles)
171 JFrame frame = new JFrame("Prune");
172 APP = new App(frame);
175 MenuManager menuManager = new MenuManager(APP, APP.getTrackInfo());
176 frame.setJMenuBar(menuManager.createMenuBar());
177 APP.setMenuManager(menuManager);
178 UpdateMessageBroker.addSubscriber(menuManager);
179 // Make toolbar for buttons
180 JToolBar toolbar = menuManager.createToolBar();
182 // Make main GUI components and add as listeners
183 SelectorDisplay leftPanel = new SelectorDisplay(APP.getTrackInfo());
184 UpdateMessageBroker.addSubscriber(leftPanel);
185 DetailsDisplay rightPanel = new DetailsDisplay(APP.getTrackInfo());
186 UpdateMessageBroker.addSubscriber(rightPanel);
187 MapCanvas mapDisp = new MapCanvas(APP, APP.getTrackInfo());
188 UpdateMessageBroker.addSubscriber(mapDisp);
189 Viewport viewport = new Viewport(mapDisp);
190 APP.setViewport(viewport);
191 ProfileChart profileDisp = new ProfileChart(APP.getTrackInfo());
192 UpdateMessageBroker.addSubscriber(profileDisp);
193 StatusBar statusBar = new StatusBar();
194 UpdateMessageBroker.addSubscriber(statusBar);
195 UpdateMessageBroker.informSubscribers("Prune v" + VERSION_NUMBER);
197 // Arrange in the frame using split panes
198 JSplitPane midPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mapDisp, profileDisp);
199 midPane.setResizeWeight(1.0); // allocate as much space as poss to map
200 JSplitPane triplePane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, midPane, rightPanel);
201 triplePane.setResizeWeight(1.0); // allocate as much space as poss to map
203 frame.getContentPane().setLayout(new BorderLayout());
204 frame.getContentPane().add(toolbar, BorderLayout.NORTH);
205 frame.getContentPane().add(new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel,
206 triplePane), BorderLayout.CENTER);
207 frame.getContentPane().add(statusBar, BorderLayout.SOUTH);
209 // add closing listener
210 frame.addWindowListener(new WindowAdapter() {
211 public void windowClosing(WindowEvent e) {
215 // Avoid automatically shutting down if window closed
216 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
220 frame.setIconImage(IconManager.getImageIcon(IconManager.WINDOW_ICON).getImage());
222 catch (Exception e) {} // ignore
224 // finish off and display frame
226 frame.setSize(650, 450);
227 frame.setVisible(true);
228 // Set position of map/profile splitter
229 midPane.setDividerLocation(0.75);
231 // Finally, give the files to load to the App
232 APP.loadDataFiles(inDataFiles);