source: josm/trunk/src/org/openstreetmap/josm/gui/MainApplication.java@ 1724

Last change on this file since 1724 was 1677, checked in by stoecker, 15 years ago

remove all these ugly tab stops introduced in the last half year

  • Property svn:eol-style set to native
File size: 8.7 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2//Licence: GPL
3package org.openstreetmap.josm.gui;
4
5import static org.openstreetmap.josm.tools.I18n.i18n;
6import static org.openstreetmap.josm.tools.I18n.tr;
7
8import java.awt.EventQueue;
9import java.awt.Toolkit;
10import java.awt.event.WindowAdapter;
11import java.awt.event.WindowEvent;
12import java.util.Arrays;
13import java.util.Collection;
14import java.util.HashMap;
15import java.util.LinkedList;
16import java.util.List;
17import java.util.Locale;
18import java.util.Map;
19import java.util.MissingResourceException;
20
21import javax.swing.JFrame;
22
23import org.openstreetmap.josm.Main;
24import org.openstreetmap.josm.plugins.PluginHandler;
25import org.openstreetmap.josm.tools.BugReportExceptionHandler;
26import org.openstreetmap.josm.tools.ImageProvider;
27import org.xnap.commons.i18n.I18nFactory;
28
29/**
30 * Main window class application.
31 *
32 * @author imi
33 */
34public 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 System.out.println(tr("Unable to find translation for the locale {0}. Reverting to {1}.",
119 l.getDisplayName(), d.getDisplayName()));
120 Locale.setDefault(d);
121 } else {
122 i18n = null;
123 }
124 }
125 }
126
127 if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) {
128 // TODO: put in a platformHook for system that have no console by default
129 System.out.println(tr("Java OpenStreetMap Editor")+"\n\n"+
130 tr("usage")+":\n"+
131 "\tjava -jar josm.jar <option> <option> <option>...\n\n"+
132 tr("options")+":\n"+
133 "\t--help|-?|-h "+tr("Show this help")+"\n"+
134 "\t--geometry=widthxheight(+|-)x(+|-)y "+tr("Standard unix geometry argument")+"\n"+
135 "\t[--download=]minlat,minlon,maxlat,maxlon "+tr("Download the bounding box")+"\n"+
136 "\t[--download=]<url> "+tr("Download the location at the url (with lat=x&lon=y&zoom=z)")+"\n"+
137 "\t[--download=]<filename> "+tr("Open file (as raw gps, if .gpx)")+"\n"+
138 "\t--downloadgps=minlat,minlon,maxlat,maxlon "+tr("Download the bounding box as raw gps")+"\n"+
139 "\t--selection=<searchstring> "+tr("Select with the given search")+"\n"+
140 "\t--[no-]maximize "+tr("Launch in maximized mode")+"\n"+
141 "\t--reset-preferences "+tr("Reset the preferences to default")+"\n\n"+
142 "\t--language=<language> "+tr("Set the language.")+"\n\n"+
143 tr("examples")+":\n"+
144 "\tjava -jar josm.jar track1.gpx track2.gpx london.osm\n"+
145 "\tjava -jar josm.jar http://www.openstreetmap.org/index.html?lat=43.2&lon=11.1&zoom=13\n"+
146 "\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml\n"+
147 "\tjava -jar josm.jar 43.2,11.1,43.4,11.4\n\n"+
148 tr("Parameters are read in the order they are specified, so make sure you load\n"+
149 "some data before --selection")+"\n\n"+
150 tr("Instead of --download=<bbox> you may specify osm://<bbox>\n"));
151 System.exit(0);
152 }
153
154 SplashScreen splash = new SplashScreen(Main.pref.getBoolean("draw.splashscreen", true));
155
156 splash.setStatus(tr("Activating updated plugins"));
157 PluginHandler.earlyCleanup();
158
159 splash.setStatus(tr("Loading early plugins"));
160 PluginHandler.loadPlugins(true);
161
162 splash.setStatus(tr("Setting defaults"));
163 preConstructorInit(args);
164 removeObsoletePreferences();
165 splash.setStatus(tr("Creating main GUI"));
166 JFrame mainFrame = new JFrame(tr("Java OpenStreetMap Editor"));
167 Main.parent = mainFrame;
168 final Main main = new MainApplication(mainFrame, splash);
169 splash.setStatus(tr("Loading plugins"));
170 PluginHandler.loadPlugins(false);
171 toolbar.refreshToolbarControl();
172
173 mainFrame.setVisible(true);
174 splash.closeSplash();
175
176 if (((!args.containsKey("no-maximize") && !args.containsKey("geometry")
177 && Main.pref.get("gui.geometry").length() == 0) || args.containsKey("maximize"))
178 && 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 /**
189 * Removes obsolete preference settings. If you throw out a once-used preference
190 * setting, add it to the list here with an expiry date (written as comment). If you
191 * see something with an expiry date in the past, remove it from the list.
192 */
193 public static void removeObsoletePreferences() {
194 String[] obsolete = {
195 "sample.preference.that.does.not.exist", // sample comment, expiry date should go here
196 "osm-server.version", // remove this around 10/2009
197 "osm-server.additional-versions", // remove this around 10/2009
198 null
199 };
200 for (String i : obsolete) {
201 if (i == null) continue;
202 if (Main.pref.hasKey(i)) {
203 Main.pref.removeFromCollection(i, Main.pref.get(i));
204 System.out.println(tr("Preference setting {0} has been removed since it is no longer used.", i));
205 }
206 }
207 }
208}
Note: See TracBrowser for help on using the repository browser.