1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | //Licence: GPL
|
---|
3 | package org.openstreetmap.josm.gui;
|
---|
4 |
|
---|
5 | import org.xnap.commons.i18n.I18nFactory;
|
---|
6 | import static org.openstreetmap.josm.tools.I18n.i18n;
|
---|
7 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
8 |
|
---|
9 | import java.awt.EventQueue;
|
---|
10 | import java.awt.Toolkit;
|
---|
11 | import java.awt.event.WindowAdapter;
|
---|
12 | import java.awt.event.WindowEvent;
|
---|
13 | import java.util.Arrays;
|
---|
14 | import java.util.Collection;
|
---|
15 | import java.util.HashMap;
|
---|
16 | import java.util.LinkedList;
|
---|
17 | import java.util.List;
|
---|
18 | import java.util.Locale;
|
---|
19 | import java.util.Map;
|
---|
20 | import java.util.MissingResourceException;
|
---|
21 |
|
---|
22 | import javax.swing.JFrame;
|
---|
23 |
|
---|
24 | import org.openstreetmap.josm.Main;
|
---|
25 | import org.openstreetmap.josm.plugins.PluginHandler;
|
---|
26 | import org.openstreetmap.josm.tools.BugReportExceptionHandler;
|
---|
27 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Main window class application.
|
---|
31 | *
|
---|
32 | * @author imi
|
---|
33 | */
|
---|
34 | public class MainApplication extends Main {
|
---|
35 | /**
|
---|
36 | * Allow subclassing (see JOSM.java)
|
---|
37 | */
|
---|
38 | public MainApplication() {}
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Construct an main frame, ready sized and operating. Does not
|
---|
42 | * display the frame.
|
---|
43 | */
|
---|
44 | public MainApplication(JFrame mainFrame, SplashScreen splash) {
|
---|
45 | super(splash);
|
---|
46 | mainFrame.setContentPane(contentPane);
|
---|
47 | mainFrame.setJMenuBar(menu);
|
---|
48 | mainFrame.setBounds(bounds);
|
---|
49 | mainFrame.setIconImage(ImageProvider.get("logo.png").getImage());
|
---|
50 | mainFrame.addWindowListener(new WindowAdapter(){
|
---|
51 | @Override public void windowClosing(final WindowEvent arg0) {
|
---|
52 | if (Main.breakBecauseUnsavedChanges())
|
---|
53 | return;
|
---|
54 | Main.saveGuiGeometry();
|
---|
55 | System.exit(0);
|
---|
56 | }
|
---|
57 | });
|
---|
58 | mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Main application Startup
|
---|
63 | */
|
---|
64 | public static void main(final String[] argArray) {
|
---|
65 | /* try initial language settings, may be changed later again */
|
---|
66 | try { i18n = I18nFactory.getI18n(MainApplication.class); }
|
---|
67 | catch (MissingResourceException ex) { Locale.setDefault(Locale.ENGLISH);}
|
---|
68 |
|
---|
69 | Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler());
|
---|
70 |
|
---|
71 | // initialize the plaform hook, and
|
---|
72 | Main.determinePlatformHook();
|
---|
73 | // call the really early hook before we anything else
|
---|
74 | Main.platform.preStartupHook();
|
---|
75 |
|
---|
76 | // construct argument table
|
---|
77 | List<String> argList = Arrays.asList(argArray);
|
---|
78 | final Map<String, Collection<String>> args = new HashMap<String, Collection<String>>();
|
---|
79 | for (String arg : argArray) {
|
---|
80 | if (!arg.startsWith("--"))
|
---|
81 | arg = "--download="+arg;
|
---|
82 | int i = arg.indexOf('=');
|
---|
83 | String key = i == -1 ? arg.substring(2) : arg.substring(2,i);
|
---|
84 | String value = i == -1 ? "" : arg.substring(i+1);
|
---|
85 | Collection<String> v = args.get(key);
|
---|
86 | if (v == null)
|
---|
87 | v = new LinkedList<String>();
|
---|
88 | v.add(value);
|
---|
89 | args.put(key, v);
|
---|
90 | }
|
---|
91 |
|
---|
92 | Main.pref.init(args.containsKey("reset-preferences"));
|
---|
93 |
|
---|
94 | String localeName = null; // The locale to use
|
---|
95 |
|
---|
96 | //Check if passed as parameter
|
---|
97 | if(args.containsKey("language"))
|
---|
98 | localeName = (String)(args.get("language").toArray()[0]);
|
---|
99 |
|
---|
100 | if (localeName == null)
|
---|
101 | localeName = Main.pref.get("language", null);
|
---|
102 |
|
---|
103 | if (localeName != null) {
|
---|
104 | Locale l;
|
---|
105 | Locale d = Locale.getDefault();
|
---|
106 | if(localeName.equals("he")) localeName = "iw_IL";
|
---|
107 | int i = localeName.indexOf('_');
|
---|
108 | if (i > 0) {
|
---|
109 | l = new Locale(localeName.substring(0, i), localeName.substring(i + 1));
|
---|
110 | } else {
|
---|
111 | l = new Locale(localeName);
|
---|
112 | }
|
---|
113 | try {
|
---|
114 | Locale.setDefault(l);
|
---|
115 | i18n = I18nFactory.getI18n(MainApplication.class);
|
---|
116 | } catch (MissingResourceException ex) {
|
---|
117 | if(!l.getLanguage().equals("en"))
|
---|
118 | {
|
---|
119 | System.out.println(tr("Unable to find translation for the locale {0}. Reverting to {1}.",
|
---|
120 | l.getDisplayName(), d.getDisplayName()));
|
---|
121 | Locale.setDefault(d);
|
---|
122 | }
|
---|
123 | else
|
---|
124 | {
|
---|
125 | i18n = null;
|
---|
126 | }
|
---|
127 | }
|
---|
128 | }
|
---|
129 |
|
---|
130 | if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) {
|
---|
131 | // TODO: put in a platformHook for system that have no console by default
|
---|
132 | System.out.println(tr("Java OpenStreetMap Editor")+"\n\n"+
|
---|
133 | tr("usage")+":\n"+
|
---|
134 | "\tjava -jar josm.jar <option> <option> <option>...\n\n"+
|
---|
135 | tr("options")+":\n"+
|
---|
136 | "\t--help|-?|-h "+tr("Show this help")+"\n"+
|
---|
137 | "\t--geometry=widthxheight(+|-)x(+|-)y "+tr("Standard unix geometry argument")+"\n"+
|
---|
138 | "\t[--download=]minlat,minlon,maxlat,maxlon "+tr("Download the bounding box")+"\n"+
|
---|
139 | "\t[--download=]<url> "+tr("Download the location at the url (with lat=x&lon=y&zoom=z)")+"\n"+
|
---|
140 | "\t[--download=]<filename> "+tr("Open file (as raw gps, if .gpx)")+"\n"+
|
---|
141 | "\t--downloadgps=minlat,minlon,maxlat,maxlon "+tr("Download the bounding box as raw gps")+"\n"+
|
---|
142 | "\t--selection=<searchstring> "+tr("Select with the given search")+"\n"+
|
---|
143 | "\t--no-fullscreen "+tr("Don't launch in fullscreen mode")+"\n"+
|
---|
144 | "\t--reset-preferences "+tr("Reset the preferences to default")+"\n\n"+
|
---|
145 | "\t--language=<language> "+tr("Set the language.")+"\n\n"+
|
---|
146 | tr("examples")+":\n"+
|
---|
147 | "\tjava -jar josm.jar track1.gpx track2.gpx london.osm\n"+
|
---|
148 | "\tjava -jar josm.jar http://www.openstreetmap.org/index.html?lat=43.2&lon=11.1&zoom=13\n"+
|
---|
149 | "\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml\n"+
|
---|
150 | "\tjava -jar josm.jar 43.2,11.1,43.4,11.4\n\n"+
|
---|
151 | tr("Parameters are read in the order they are specified, so make sure you load\n"+
|
---|
152 | "some data before --selection")+"\n\n"+
|
---|
153 | tr("Instead of --download=<bbox> you may specify osm://<bbox>\n"));
|
---|
154 | System.exit(0);
|
---|
155 | }
|
---|
156 |
|
---|
157 | SplashScreen splash = new SplashScreen(Main.pref.getBoolean("draw.splashscreen", true));
|
---|
158 |
|
---|
159 | splash.setStatus(tr("Activating updated plugins"));
|
---|
160 | PluginHandler.earlyCleanup();
|
---|
161 |
|
---|
162 | splash.setStatus(tr("Loading early plugins"));
|
---|
163 | PluginHandler.loadPlugins(true);
|
---|
164 |
|
---|
165 | splash.setStatus(tr("Setting defaults"));
|
---|
166 | preConstructorInit(args);
|
---|
167 | splash.setStatus(tr("Creating main GUI"));
|
---|
168 | JFrame mainFrame = new JFrame(tr("Java OpenStreetMap Editor"));
|
---|
169 | Main.parent = mainFrame;
|
---|
170 | final Main main = new MainApplication(mainFrame, splash);
|
---|
171 | splash.setStatus(tr("Loading plugins"));
|
---|
172 | PluginHandler.loadPlugins(false);
|
---|
173 | toolbar.refreshToolbarControl();
|
---|
174 |
|
---|
175 | mainFrame.setVisible(true);
|
---|
176 | splash.closeSplash();
|
---|
177 |
|
---|
178 | if (!args.containsKey("no-fullscreen") && !args.containsKey("geometry") && Main.pref.get("gui.geometry").length() == 0 && Toolkit.getDefaultToolkit().isFrameStateSupported(JFrame.MAXIMIZED_BOTH))
|
---|
179 | mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
---|
180 |
|
---|
181 | EventQueue.invokeLater(new Runnable(){
|
---|
182 | public void run() {
|
---|
183 | main.postConstructorProcessCmdLine(args);
|
---|
184 | }
|
---|
185 | });
|
---|
186 | }
|
---|
187 |
|
---|
188 | }
|
---|