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

Last change on this file since 2587 was 2358, checked in by Gubaer, 14 years ago

fixed #3305: Version is UNKNOWN
fixed #3429: created_by=* includes the wrong language when uploading from a new layer

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