3 import java.awt.event.WindowAdapter;
4 import java.awt.BorderLayout;
5 import java.awt.event.WindowEvent;
6 import java.util.Locale;
8 import javax.swing.ImageIcon;
9 import javax.swing.JFrame;
10 import javax.swing.JSplitPane;
11 import javax.swing.JToolBar;
12 import javax.swing.WindowConstants;
14 import tim.prune.gui.DetailsDisplay;
15 import tim.prune.gui.MapChart;
16 import tim.prune.gui.MenuManager;
17 import tim.prune.gui.ProfileChart;
18 import tim.prune.gui.SelectorDisplay;
19 import tim.prune.gui.StatusBar;
22 * Tool to visualize, edit and prune GPS data
23 * Please see the included readme.txt or http://activityworkshop.net
25 public class GpsPruner
27 // Final build of version 5
28 public static final String VERSION_NUMBER = "5";
29 public static final String BUILD_NUMBER = "100";
30 private static App APP = null;
35 * @param args command line arguments
37 public static void main(String[] args)
42 if (args[0].startsWith("--locale="))
44 locale = getLanguage(args[0].substring(9));
46 else if (args[0].startsWith("--lang="))
48 locale = getLanguage(args[0].substring(7));
52 System.out.println("Unknown parameter '" + args[0] +
53 "'. Possible parameters:\n --locale= or --lang= used for overriding language settings\n");
56 I18nManager.init(locale);
62 * Choose a locale based on the given code
63 * @param inString code for locale
64 * @return Locale object if available, otherwise null
66 private static Locale getLanguage(String inString)
68 if (inString.length() == 2)
70 return new Locale(inString);
72 else if (inString.length() == 5)
74 return new Locale(inString.substring(0, 2), inString.substring(3));
76 System.out.println("Unrecognised locale '" + inString
77 + "' - value should be eg 'DE' or 'DE_ch'");
83 * Launch the main application
85 private static void launch()
87 JFrame frame = new JFrame("Prune");
91 MenuManager menuManager = new MenuManager(frame, APP, APP.getTrackInfo());
92 frame.setJMenuBar(menuManager.createMenuBar());
93 APP.setMenuManager(menuManager);
94 UpdateMessageBroker.addSubscriber(menuManager);
95 // Make toolbar for buttons
96 JToolBar toolbar = menuManager.createToolBar();
98 // Make main GUI components and add as listeners
99 SelectorDisplay leftPanel = new SelectorDisplay(APP.getTrackInfo());
100 UpdateMessageBroker.addSubscriber(leftPanel);
101 DetailsDisplay rightPanel = new DetailsDisplay(APP.getTrackInfo());
102 UpdateMessageBroker.addSubscriber(rightPanel);
103 MapChart mapDisp = new MapChart(APP, APP.getTrackInfo());
104 UpdateMessageBroker.addSubscriber(mapDisp);
105 ProfileChart profileDisp = new ProfileChart(APP.getTrackInfo());
106 UpdateMessageBroker.addSubscriber(profileDisp);
107 StatusBar statusBar = new StatusBar();
108 UpdateMessageBroker.addSubscriber(statusBar);
109 UpdateMessageBroker.informSubscribers("Prune v" + VERSION_NUMBER);
111 // Arrange in the frame using split panes
112 JSplitPane midPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mapDisp, profileDisp);
113 midPane.setResizeWeight(1.0); // allocate as much space as poss to map
114 JSplitPane triplePane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, midPane, rightPanel);
115 triplePane.setResizeWeight(1.0); // allocate as much space as poss to map
117 frame.getContentPane().setLayout(new BorderLayout());
118 frame.getContentPane().add(toolbar, BorderLayout.NORTH);
119 frame.getContentPane().add(new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel,
120 triplePane), BorderLayout.CENTER);
121 frame.getContentPane().add(statusBar, BorderLayout.SOUTH);
123 // add closing listener
124 frame.addWindowListener(new WindowAdapter() {
125 public void windowClosing(WindowEvent e) {
129 // Avoid automatically shutting down if window closed
130 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
134 frame.setIconImage(new ImageIcon(GpsPruner.class.getResource("gui/images/window_icon.png")).getImage());
136 catch (Exception e) {} // ignore
138 // finish off and display frame
140 frame.setSize(650, 450);
142 // Set position of map/profile splitter
143 midPane.setDividerLocation(0.75);