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

Last change on this file since 2683 was 2641, checked in by Gubaer, 14 years ago

new: supports system defined proxies if JOSM is started with -Djava.net.useSystemProxies=true
fixed #1641: JOSM doesn't allow for setting HTTP proxy user/password distrinct from OSM server user/password
fixed #2865: SOCKS Proxy Support
fixed #4182: Proxy Authentication

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