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

Last change on this file since 2751 was 2748, checked in by Gubaer, 14 years ago

new: JOSM now supports OAuth

See also online help for server preferences and new OAuth Authorisation Wizard

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