]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/GpsPruner.java
2511cf7981dcba09eafe474290a314edfff8a6f7
[GpsPrune.git] / tim / prune / GpsPruner.java
1 package tim.prune;
2
3 import java.awt.BorderLayout;
4 import java.awt.event.WindowAdapter;
5 import java.awt.event.WindowEvent;
6 import java.util.Locale;
7
8 import javax.swing.JFrame;
9 import javax.swing.JSplitPane;
10 import javax.swing.JToolBar;
11 import javax.swing.WindowConstants;
12
13 import tim.prune.gui.DetailsDisplay;
14 import tim.prune.gui.MapChart;
15 import tim.prune.gui.MenuManager;
16 import tim.prune.gui.ProfileChart;
17 import tim.prune.gui.SelectorDisplay;
18
19 /**
20  * Tool to visualize, edit and prune GPS data
21  */
22 public class GpsPruner
23 {
24         // Final release of version 3
25         public static final String VERSION_NUMBER = "3";
26         public static final String BUILD_NUMBER = "074";
27         private static App APP = null;
28
29
30         /**
31          * Main method
32          * @param args command line arguments
33          */
34         public static void main(String[] args)
35         {
36                 Locale locale = null;
37                 if (args.length == 1)
38                 {
39                         if (args[0].startsWith("--locale="))
40                         {
41                                 locale = getLanguage(args[0].substring(9));
42                         }
43                         else if (args[0].startsWith("--lang="))
44                         {
45                                 locale = getLanguage(args[0].substring(7));
46                         }
47                         else
48                         {
49                                 System.out.println("Unknown parameter '" + args[0] +
50                                         "'. Possible parameters:\n   --locale= or --lang=  used for overriding language settings\n");
51                         }
52                 }
53                 I18nManager.init(locale);
54                 launch();
55         }
56
57
58         /**
59          * Choose a locale based on the given code
60          * @param inString code for locale
61          * @return Locale object if available, otherwise null
62          */
63         private static Locale getLanguage(String inString)
64         {
65                 if (inString.length() == 2)
66                 {
67                         return new Locale(inString);
68                 }
69                 else if (inString.length() == 5)
70                 {
71                         return new Locale(inString.substring(0, 2), inString.substring(3));
72                 }
73                 System.out.println("Unrecognised locale '" + inString
74                         + "' - value should be eg 'DE' or 'DE_ch'");
75                 return null;
76         }
77
78
79         /**
80          * Launch the main application
81          */
82         private static void launch()
83         {
84                 JFrame frame = new JFrame("Prune");
85                 UpdateMessageBroker broker = new UpdateMessageBroker();
86                 APP = new App(frame, broker);
87
88                 // make menu
89                 MenuManager menuManager = new MenuManager(frame, APP, APP.getTrackInfo());
90                 frame.setJMenuBar(menuManager.createMenuBar());
91                 APP.setMenuManager(menuManager);
92                 broker.addSubscriber(menuManager);
93                 // Make toolbar for buttons
94                 JToolBar toolbar = menuManager.createToolBar();
95
96                 // Make three GUI components and add as listeners
97                 SelectorDisplay leftPanel = new SelectorDisplay(APP.getTrackInfo());
98                 broker.addSubscriber(leftPanel);
99                 DetailsDisplay rightPanel = new DetailsDisplay(APP.getTrackInfo());
100                 broker.addSubscriber(rightPanel);
101                 MapChart mapDisp = new MapChart(APP, APP.getTrackInfo());
102                 broker.addSubscriber(mapDisp);
103                 ProfileChart profileDisp = new ProfileChart(APP.getTrackInfo());
104                 broker.addSubscriber(profileDisp);
105
106                 JSplitPane midPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mapDisp, profileDisp);
107                 midPane.setResizeWeight(1.0); // allocate as much space as poss to map
108                 JSplitPane triplePane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, midPane, rightPanel);
109                 triplePane.setResizeWeight(1.0); // allocate as much space as poss to map
110
111                 frame.getContentPane().setLayout(new BorderLayout());
112                 frame.getContentPane().add(toolbar, BorderLayout.NORTH);
113                 frame.getContentPane().add(new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel,
114                         triplePane), BorderLayout.CENTER);
115                 // add closing listener
116                 frame.addWindowListener(new WindowAdapter() {
117                         public void windowClosing(WindowEvent e) {
118                                 APP.exit();
119                         }
120                 });
121                 // Avoid automatically shutting down if window closed
122                 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
123
124                 // finish off and display frame
125                 frame.pack();
126                 frame.setSize(650, 450);
127                 frame.show();
128         }
129 }