X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2FGpsPruner.java;h=7a172a4a64ceeb0a2576de987a4240b3018cc423;hb=1ee49ae3c8ef3aa2e63eadd458531e5f8bd4f92c;hp=7208eb7e83815b2de02341954cb9df3cdfa5441d;hpb=ca9bdb3916f9c39adbbf95d06ac95c21dafbb4e6;p=GpsPrune.git diff --git a/tim/prune/GpsPruner.java b/tim/prune/GpsPruner.java index 7208eb7..7a172a4 100644 --- a/tim/prune/GpsPruner.java +++ b/tim/prune/GpsPruner.java @@ -3,30 +3,40 @@ package tim.prune; import java.awt.event.WindowAdapter; import java.awt.BorderLayout; import java.awt.event.WindowEvent; +import java.io.File; +import java.io.FileNotFoundException; import java.util.Locale; - -import javax.swing.ImageIcon; +import java.util.ArrayList; import javax.swing.JFrame; import javax.swing.JSplitPane; import javax.swing.JToolBar; import javax.swing.WindowConstants; +import tim.prune.config.Config; +import tim.prune.config.ConfigException; import tim.prune.gui.DetailsDisplay; -import tim.prune.gui.MapChart; +import tim.prune.gui.IconManager; import tim.prune.gui.MenuManager; import tim.prune.gui.ProfileChart; import tim.prune.gui.SelectorDisplay; import tim.prune.gui.StatusBar; +import tim.prune.gui.Viewport; +import tim.prune.gui.map.MapCanvas; /** - * Tool to visualize, edit and prune GPS data + * Prune is a tool to visualize, edit, convert and prune GPS data * Please see the included readme.txt or http://activityworkshop.net + * This software is copyright activityworkshop.net 2006-2010 and made available through the Gnu GPL version 2. + * For license details please see the included license.txt. + * GpsPruner is the main entry point to the application, including initialisation and launch */ public class GpsPruner { - // Final build of version 5 - public static final String VERSION_NUMBER = "5"; - public static final String BUILD_NUMBER = "100"; + /** Version number of application, used in about screen and for version check */ + public static final String VERSION_NUMBER = "9"; + /** Build number, just used for about screen */ + public static final String BUILD_NUMBER = "176"; + /** Static reference to App object */ private static App APP = null; @@ -37,24 +47,97 @@ public class GpsPruner public static void main(String[] args) { Locale locale = null; - if (args.length == 1) + String localeCode = null; + String langFilename = null; + String configFilename = null; + ArrayList dataFiles = new ArrayList(); + boolean showUsage = false; + for (int i=0; i used to specify a configuration file" + + "\n --lang= or --locale= used to specify language" + + "\n --langfile= used to specify an alternative language file\n"); + } + // Initialise configuration if selected + try + { + if (configFilename != null) { + Config.loadFile(new File(configFilename)); + } + else { + Config.loadDefaultFile(); + } + } + catch (ConfigException ce) { + System.err.println("Failed to load config file: " + configFilename); + } + boolean overrideLang = (locale != null); + if (overrideLang) { + // Make sure Config holds chosen language + Config.setConfigString(Config.KEY_LANGUAGE_CODE, localeCode); + } + else { + // Set locale according to Config's language property + String configLang = Config.getConfigString(Config.KEY_LANGUAGE_CODE); + if (configLang != null) { + Locale configLocale = getLanguage(configLang); + if (configLocale != null) {locale = configLocale;} } } I18nManager.init(locale); - launch(); + // Load the external language file, either from config file or from command line params + if (langFilename == null && !overrideLang) { + // If langfilename is blank on command line parameters then don't use setting from config + langFilename = Config.getConfigString(Config.KEY_LANGUAGE_FILE); + } + if (langFilename != null && !langFilename.equals("")) { + try { + I18nManager.addLanguageFile(langFilename); + Config.setConfigString(Config.KEY_LANGUAGE_FILE, langFilename); + } + catch (FileNotFoundException fnfe) { + System.err.println("Failed to load language file: " + langFilename); + } + } + // Set up the window and go + launch(dataFiles); } @@ -81,14 +164,15 @@ public class GpsPruner /** * Launch the main application + * @param inDataFiles list of data files to load on startup */ - private static void launch() + private static void launch(ArrayList inDataFiles) { JFrame frame = new JFrame("Prune"); APP = new App(frame); // make menu - MenuManager menuManager = new MenuManager(frame, APP, APP.getTrackInfo()); + MenuManager menuManager = new MenuManager(APP, APP.getTrackInfo()); frame.setJMenuBar(menuManager.createMenuBar()); APP.setMenuManager(menuManager); UpdateMessageBroker.addSubscriber(menuManager); @@ -100,8 +184,10 @@ public class GpsPruner UpdateMessageBroker.addSubscriber(leftPanel); DetailsDisplay rightPanel = new DetailsDisplay(APP.getTrackInfo()); UpdateMessageBroker.addSubscriber(rightPanel); - MapChart mapDisp = new MapChart(APP, APP.getTrackInfo()); + MapCanvas mapDisp = new MapCanvas(APP, APP.getTrackInfo()); UpdateMessageBroker.addSubscriber(mapDisp); + Viewport viewport = new Viewport(mapDisp); + APP.setViewport(viewport); ProfileChart profileDisp = new ProfileChart(APP.getTrackInfo()); UpdateMessageBroker.addSubscriber(profileDisp); StatusBar statusBar = new StatusBar(); @@ -131,15 +217,18 @@ public class GpsPruner // set icon try { - frame.setIconImage(new ImageIcon(GpsPruner.class.getResource("gui/images/window_icon.png")).getImage()); + frame.setIconImage(IconManager.getImageIcon(IconManager.WINDOW_ICON).getImage()); } catch (Exception e) {} // ignore // finish off and display frame frame.pack(); frame.setSize(650, 450); - frame.show(); + frame.setVisible(true); // Set position of map/profile splitter midPane.setDividerLocation(0.75); + + // Finally, give the files to load to the App + APP.loadDataFiles(inDataFiles); } }