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 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 // Final build of version 6
29 public static final String VERSION_NUMBER = "6";
30 public static final String BUILD_NUMBER = "117";
31 private static App APP = null;
36 * @param args command line arguments
38 public static void main(String[] args)
41 String langFilename = null;
42 String configFilename = null;
43 boolean showUsage = false;
44 for (int i=0; i<args.length; i++)
46 if (args[i].startsWith("--locale="))
48 locale = getLanguage(args[i].substring(9));
50 else if (args[i].startsWith("--lang="))
52 locale = getLanguage(args[i].substring(7));
54 else if (args[i].startsWith("--langfile="))
56 langFilename = args[i].substring(11);
58 else if (args[i].startsWith("--configfile="))
60 configFilename = args[i].substring(13);
64 System.out.println("Unknown parameter '" + args[i] + "'.");
69 System.out.println("Possible parameters:"
70 + "\n --configfile=<file> used to specify a configuration file"
71 + "\n --lang=<code> or --locale=<code> used to specify language"
72 + "\n --langfile=<file> used to specify an alternative language file\n");
74 // Initialise configuration if selected
77 if (configFilename != null) {
78 Config.loadFile(new File(configFilename));
81 Config.loadDefaultFile();
84 catch (ConfigException ce) {
85 System.err.println("Failed to load config file: " + configFilename);
87 // Set locale according to Config's language property
88 String langCode = Config.getLanguageCode();
89 if (locale == null && langCode != null) {
90 Locale configLocale = getLanguage(langCode);
91 if (configLocale != null) {locale = configLocale;}
93 I18nManager.init(locale);
94 if (langFilename != null) {
95 I18nManager.addLanguageFile(langFilename);
97 // Set up the window and go
103 * Choose a locale based on the given code
104 * @param inString code for locale
105 * @return Locale object if available, otherwise null
107 private static Locale getLanguage(String inString)
109 if (inString.length() == 2)
111 return new Locale(inString);
113 else if (inString.length() == 5)
115 return new Locale(inString.substring(0, 2), inString.substring(3));
117 System.out.println("Unrecognised locale '" + inString
118 + "' - value should be eg 'DE' or 'DE_ch'");
124 * Launch the main application
126 private static void launch()
128 JFrame frame = new JFrame("Prune");
129 APP = new App(frame);
132 MenuManager menuManager = new MenuManager(frame, APP, APP.getTrackInfo());
133 frame.setJMenuBar(menuManager.createMenuBar());
134 APP.setMenuManager(menuManager);
135 UpdateMessageBroker.addSubscriber(menuManager);
136 // Make toolbar for buttons
137 JToolBar toolbar = menuManager.createToolBar();
139 // Make main GUI components and add as listeners
140 SelectorDisplay leftPanel = new SelectorDisplay(APP.getTrackInfo());
141 UpdateMessageBroker.addSubscriber(leftPanel);
142 DetailsDisplay rightPanel = new DetailsDisplay(APP.getTrackInfo());
143 UpdateMessageBroker.addSubscriber(rightPanel);
144 MapCanvas mapDisp = new MapCanvas(APP, APP.getTrackInfo());
145 UpdateMessageBroker.addSubscriber(mapDisp);
146 ProfileChart profileDisp = new ProfileChart(APP.getTrackInfo());
147 UpdateMessageBroker.addSubscriber(profileDisp);
148 StatusBar statusBar = new StatusBar();
149 UpdateMessageBroker.addSubscriber(statusBar);
150 UpdateMessageBroker.informSubscribers("Prune v" + VERSION_NUMBER);
152 // Arrange in the frame using split panes
153 JSplitPane midPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mapDisp, profileDisp);
154 midPane.setResizeWeight(1.0); // allocate as much space as poss to map
155 JSplitPane triplePane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, midPane, rightPanel);
156 triplePane.setResizeWeight(1.0); // allocate as much space as poss to map
158 frame.getContentPane().setLayout(new BorderLayout());
159 frame.getContentPane().add(toolbar, BorderLayout.NORTH);
160 frame.getContentPane().add(new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel,
161 triplePane), BorderLayout.CENTER);
162 frame.getContentPane().add(statusBar, BorderLayout.SOUTH);
164 // add closing listener
165 frame.addWindowListener(new WindowAdapter() {
166 public void windowClosing(WindowEvent e) {
170 // Avoid automatically shutting down if window closed
171 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
175 frame.setIconImage(IconManager.getImageIcon(IconManager.WINDOW_ICON).getImage());
177 catch (Exception e) {} // ignore
179 // finish off and display frame
181 frame.setSize(650, 450);
183 // Set position of map/profile splitter
184 midPane.setDividerLocation(0.75);