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

Last change on this file since 2198 was 2085, checked in by stoecker, 15 years ago

applied #3439 - patch by avar - fix broken language selection

  • Property svn:eol-style set to native
File size: 8.1 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.tr;
6
7import java.awt.EventQueue;
8import java.awt.Toolkit;
9import java.awt.event.WindowAdapter;
10import java.awt.event.WindowEvent;
11import java.util.Arrays;
12import java.util.Collection;
13import java.util.HashMap;
14import java.util.LinkedList;
15import java.util.List;
16import java.util.Map;
17
18import javax.swing.JFrame;
19
20import org.openstreetmap.josm.Main;
21import org.openstreetmap.josm.plugins.PluginHandler;
22import org.openstreetmap.josm.tools.BugReportExceptionHandler;
23import org.openstreetmap.josm.tools.I18n;
24import org.openstreetmap.josm.tools.ImageProvider;
25
26/**
27 * Main window class application.
28 *
29 * @author imi
30 */
31public class MainApplication extends Main {
32 /**
33 * Allow subclassing (see JOSM.java)
34 */
35 public MainApplication() {}
36
37 /**
38 * Construct an main frame, ready sized and operating. Does not
39 * display the frame.
40 */
41 public MainApplication(JFrame mainFrame, SplashScreen splash) {
42 super(splash);
43 mainFrame.setContentPane(contentPane);
44 mainFrame.setJMenuBar(menu);
45 mainFrame.setBounds(bounds);
46 mainFrame.setIconImage(ImageProvider.get("logo.png").getImage());
47 mainFrame.addWindowListener(new WindowAdapter(){
48 @Override public void windowClosing(final WindowEvent arg0) {
49 if (!Main.saveUnsavedModifications())
50 return;
51 Main.saveGuiGeometry();
52 System.exit(0);
53 }
54 });
55 mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
56 }
57
58 /**
59 * Main application Startup
60 */
61 public static void main(final String[] argArray) {
62 I18n.init();
63
64 Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler());
65
66 // initialize the plaform hook, and
67 Main.determinePlatformHook();
68 // call the really early hook before we anything else
69 Main.platform.preStartupHook();
70
71 // construct argument table
72 List<String> argList = Arrays.asList(argArray);
73 final Map<String, Collection<String>> args = new HashMap<String, Collection<String>>();
74 for (String arg : argArray) {
75 if (!arg.startsWith("--")) {
76 arg = "--download="+arg;
77 }
78 int i = arg.indexOf('=');
79 String key = i == -1 ? arg.substring(2) : arg.substring(2,i);
80 String value = i == -1 ? "" : arg.substring(i+1);
81 Collection<String> v = args.get(key);
82 if (v == null) {
83 v = new LinkedList<String>();
84 }
85 v.add(value);
86 args.put(key, v);
87 }
88
89 Main.pref.init(args.containsKey("reset-preferences"));
90
91 // Check if passed as parameter
92 if (args.containsKey("language")) {
93 I18n.set((String)(args.get("language").toArray()[0]));
94 } else {
95 I18n.set(Main.pref.get("language", null));
96 }
97
98 if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) {
99 // TODO: put in a platformHook for system that have no console by default
100 System.out.println(tr("Java OpenStreetMap Editor")+"\n\n"+
101 tr("usage")+":\n"+
102 "\tjava -jar josm.jar <options>...\n\n"+
103 tr("options")+":\n"+
104 "\t--help|-?|-h "+tr("Show this help")+"\n"+
105 "\t--geometry=widthxheight(+|-)x(+|-)y "+tr("Standard unix geometry argument")+"\n"+
106 "\t[--download=]minlat,minlon,maxlat,maxlon "+tr("Download the bounding box")+"\n"+
107 "\t[--download=]<url> "+tr("Download the location at the url (with lat=x&lon=y&zoom=z)")+"\n"+
108 "\t[--download=]<filename> "+tr("Open file (as raw gps, if .gpx)")+"\n"+
109 "\t--downloadgps=minlat,minlon,maxlat,maxlon "+tr("Download the bounding box as raw gps")+"\n"+
110 "\t--selection=<searchstring> "+tr("Select with the given search")+"\n"+
111 "\t--[no-]maximize "+tr("Launch in maximized mode")+"\n"+
112 "\t--reset-preferences "+tr("Reset the preferences to default")+"\n\n"+
113 "\t--language=<language> "+tr("Set the language.")+"\n\n"+
114 tr("options provided as Java system properties")+":\n"+
115 "\t-Djosm.home="+tr("/PATH/TO/JOSM/FOLDER/ ")+tr("Change the folder for all user settings")+"\n\n"+
116 tr("note: For some tasks, JOSM needs a lot of memory. It can be necessary to add the following\n" +
117 " Java option to increase the maximum size of allocated memory")+":\n"+
118 "\t-Xmx...m\n\n"+
119 tr("examples")+":\n"+
120 "\tjava -jar josm.jar track1.gpx track2.gpx london.osm\n"+
121 "\tjava -jar josm.jar http://www.openstreetmap.org/index.html?lat=43.2&lon=11.1&zoom=13\n"+
122 "\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml\n"+
123 "\tjava -jar josm.jar 43.2,11.1,43.4,11.4\n"+
124 "\tjava -Djosm.home=/home/user/.josm_dev -jar josm.jar\n"+
125 "\tjava -Xmx400m -jar josm.jar\n\n"+
126 tr("Parameters are read in the order they are specified, so make sure you load\n"+
127 "some data before --selection")+"\n\n"+
128 tr("Instead of --download=<bbox> you may specify osm://<bbox>\n"));
129 System.exit(0);
130 }
131
132 SplashScreen splash = new SplashScreen(Main.pref.getBoolean("draw.splashscreen", true));
133
134 splash.setStatus(tr("Activating updated plugins"));
135 PluginHandler.earlyCleanup();
136
137 splash.setStatus(tr("Loading early plugins"));
138 PluginHandler.loadPlugins(true);
139
140 splash.setStatus(tr("Setting defaults"));
141 preConstructorInit(args);
142 removeObsoletePreferences();
143 splash.setStatus(tr("Creating main GUI"));
144 JFrame mainFrame = new JFrame(tr("Java OpenStreetMap Editor"));
145 Main.parent = mainFrame;
146 final Main main = new MainApplication(mainFrame, splash);
147 splash.setStatus(tr("Loading plugins"));
148 PluginHandler.loadPlugins(false);
149 toolbar.refreshToolbarControl();
150
151 mainFrame.setVisible(true);
152 splash.closeSplash();
153
154 if (((!args.containsKey("no-maximize") && !args.containsKey("geometry")
155 && Main.pref.get("gui.geometry").length() == 0) || args.containsKey("maximize"))
156 && Toolkit.getDefaultToolkit().isFrameStateSupported(JFrame.MAXIMIZED_BOTH)) {
157 mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
158 }
159
160 EventQueue.invokeLater(new Runnable() {
161 public void run() {
162 main.postConstructorProcessCmdLine(args);
163 }
164 });
165 }
166
167 /**
168 * Removes obsolete preference settings. If you throw out a once-used preference
169 * setting, add it to the list here with an expiry date (written as comment). If you
170 * see something with an expiry date in the past, remove it from the list.
171 */
172 public static void removeObsoletePreferences() {
173 String[] obsolete = {
174 "sample.preference.that.does.not.exist", // sample comment, expiry date should go here
175 "osm-server.version", // remove this around 10/2009
176 "osm-server.additional-versions", // remove this around 10/2009
177 null
178 };
179 for (String i : obsolete) {
180 if (i == null) {
181 continue;
182 }
183 if (Main.pref.hasKey(i)) {
184 Main.pref.removeFromCollection(i, Main.pref.get(i));
185 System.out.println(tr("Preference setting {0} has been removed since it is no longer used.", i));
186 }
187 }
188 }
189}
Note: See TracBrowser for help on using the repository browser.