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

Last change on this file since 1926 was 1802, checked in by stoecker, 15 years ago

cleanup license and contributions a bit

  • Property svn:eol-style set to native
File size: 7.4 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.ImageProvider;
24import org.openstreetmap.josm.tools.I18n;
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.breakBecauseUnsavedChanges())
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 int i = arg.indexOf('=');
78 String key = i == -1 ? arg.substring(2) : arg.substring(2,i);
79 String value = i == -1 ? "" : arg.substring(i+1);
80 Collection<String> v = args.get(key);
81 if (v == null)
82 v = new LinkedList<String>();
83 v.add(value);
84 args.put(key, v);
85 }
86
87 Main.pref.init(args.containsKey("reset-preferences"));
88
89 // Check if passed as parameter
90 if (args.containsKey("language"))
91 I18n.set((String)(args.get("language").toArray()[0]));
92 else
93 I18n.set(Main.pref.get("language", null));
94
95 if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) {
96 // TODO: put in a platformHook for system that have no console by default
97 System.out.println(tr("Java OpenStreetMap Editor")+"\n\n"+
98 tr("usage")+":\n"+
99 "\tjava -jar josm.jar <option> <option> <option>...\n\n"+
100 tr("options")+":\n"+
101 "\t--help|-?|-h "+tr("Show this help")+"\n"+
102 "\t--geometry=widthxheight(+|-)x(+|-)y "+tr("Standard unix geometry argument")+"\n"+
103 "\t[--download=]minlat,minlon,maxlat,maxlon "+tr("Download the bounding box")+"\n"+
104 "\t[--download=]<url> "+tr("Download the location at the url (with lat=x&lon=y&zoom=z)")+"\n"+
105 "\t[--download=]<filename> "+tr("Open file (as raw gps, if .gpx)")+"\n"+
106 "\t--downloadgps=minlat,minlon,maxlat,maxlon "+tr("Download the bounding box as raw gps")+"\n"+
107 "\t--selection=<searchstring> "+tr("Select with the given search")+"\n"+
108 "\t--[no-]maximize "+tr("Launch in maximized mode")+"\n"+
109 "\t--reset-preferences "+tr("Reset the preferences to default")+"\n\n"+
110 "\t--language=<language> "+tr("Set the language.")+"\n\n"+
111 tr("examples")+":\n"+
112 "\tjava -jar josm.jar track1.gpx track2.gpx london.osm\n"+
113 "\tjava -jar josm.jar http://www.openstreetmap.org/index.html?lat=43.2&lon=11.1&zoom=13\n"+
114 "\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml\n"+
115 "\tjava -jar josm.jar 43.2,11.1,43.4,11.4\n\n"+
116 tr("Parameters are read in the order they are specified, so make sure you load\n"+
117 "some data before --selection")+"\n\n"+
118 tr("Instead of --download=<bbox> you may specify osm://<bbox>\n"));
119 System.exit(0);
120 }
121
122 SplashScreen splash = new SplashScreen(Main.pref.getBoolean("draw.splashscreen", true));
123
124 splash.setStatus(tr("Activating updated plugins"));
125 PluginHandler.earlyCleanup();
126
127 splash.setStatus(tr("Loading early plugins"));
128 PluginHandler.loadPlugins(true);
129
130 splash.setStatus(tr("Setting defaults"));
131 preConstructorInit(args);
132 removeObsoletePreferences();
133 splash.setStatus(tr("Creating main GUI"));
134 JFrame mainFrame = new JFrame(tr("Java OpenStreetMap Editor"));
135 Main.parent = mainFrame;
136 final Main main = new MainApplication(mainFrame, splash);
137 splash.setStatus(tr("Loading plugins"));
138 PluginHandler.loadPlugins(false);
139 toolbar.refreshToolbarControl();
140
141 mainFrame.setVisible(true);
142 splash.closeSplash();
143
144 if (((!args.containsKey("no-maximize") && !args.containsKey("geometry")
145 && Main.pref.get("gui.geometry").length() == 0) || args.containsKey("maximize"))
146 && Toolkit.getDefaultToolkit().isFrameStateSupported(JFrame.MAXIMIZED_BOTH))
147 mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
148
149 EventQueue.invokeLater(new Runnable() {
150 public void run() {
151 main.postConstructorProcessCmdLine(args);
152 }
153 });
154 }
155
156 /**
157 * Removes obsolete preference settings. If you throw out a once-used preference
158 * setting, add it to the list here with an expiry date (written as comment). If you
159 * see something with an expiry date in the past, remove it from the list.
160 */
161 public static void removeObsoletePreferences() {
162 String[] obsolete = {
163 "sample.preference.that.does.not.exist", // sample comment, expiry date should go here
164 "osm-server.version", // remove this around 10/2009
165 "osm-server.additional-versions", // remove this around 10/2009
166 null
167 };
168 for (String i : obsolete) {
169 if (i == null) continue;
170 if (Main.pref.hasKey(i)) {
171 Main.pref.removeFromCollection(i, Main.pref.get(i));
172 System.out.println(tr("Preference setting {0} has been removed since it is no longer used.", i));
173 }
174 }
175 }
176}
Note: See TracBrowser for help on using the repository browser.