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

Last change on this file since 192 was 192, checked in by imi, 18 years ago
  • added command line parameter --default-classloader (for debug and packaging purpose)
File size: 6.6 KB
Line 
1//Licence: GPL
2package org.openstreetmap.josm.gui;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Toolkit;
7import java.awt.event.WindowAdapter;
8import java.awt.event.WindowEvent;
9import java.io.File;
10import java.io.IOException;
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;
19import javax.swing.JOptionPane;
20
21import org.openstreetmap.josm.Main;
22import org.openstreetmap.josm.plugins.PluginException;
23import org.openstreetmap.josm.plugins.PluginInformation;
24import org.openstreetmap.josm.tools.BugReportExceptionHandler;
25import org.openstreetmap.josm.tools.ImageProvider;
26/**
27 * Main window class application.
28 *
29 * @author imi
30 */
31public class MainApplication extends Main {
32 /**
33 * Construct an main frame, ready sized and operating. Does not
34 * display the frame.
35 */
36 public MainApplication(JFrame mainFrame) {
37 mainFrame.setContentPane(contentPane);
38 mainFrame.setJMenuBar(menu);
39 mainFrame.setBounds(bounds);
40 mainFrame.addWindowListener(new WindowAdapter(){
41 @Override public void windowClosing(final WindowEvent arg0) {
42 if (Main.breakBecauseUnsavedChanges())
43 return;
44 System.exit(0);
45 }
46 });
47 mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
48 }
49
50 /**
51 * Main application Startup
52 */
53 public static void main(final String[] argArray) {
54 /////////////////////////////////////////////////////////////////////////
55 // TO ALL TRANSLATORS
56 /////////////////////////////////////////////////////////////////////////
57 // Do not translate the early strings below until the locale is set up.
58 // (By the eager loaded plugins)
59 //
60 // These strings cannot be translated. That's live. Really. Sorry.
61 //
62 // Imi.
63 /////////////////////////////////////////////////////////////////////////
64
65 Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler());
66
67 // construct argument table
68 List<String> argList = Arrays.asList(argArray);
69 Map<String, Collection<String>> args = new HashMap<String, Collection<String>>();
70 for (String arg : argArray) {
71 if (!arg.startsWith("--"))
72 arg = "--download="+arg;
73 int i = arg.indexOf('=');
74 String key = i == -1 ? arg.substring(2) : arg.substring(2,i);
75 String value = i == -1 ? "" : arg.substring(i+1);
76 Collection<String> v = args.get(key);
77 if (v == null)
78 v = new LinkedList<String>();
79 v.add(value);
80 args.put(key, v);
81 }
82
83 // get the preferences.
84 final File prefDir = new File(Main.pref.getPreferencesDir());
85 if (prefDir.exists() && !prefDir.isDirectory()) {
86 JOptionPane.showMessageDialog(null, "Cannot open preferences directory: "+Main.pref.getPreferencesDir());
87 return;
88 }
89 if (!prefDir.exists())
90 prefDir.mkdirs();
91 try {
92 if (args.containsKey("reset-preferences")) {
93 Main.pref.resetToDefault();
94 } else {
95 Main.pref.load();
96 }
97 } catch (final IOException e1) {
98 e1.printStackTrace();
99 JOptionPane.showMessageDialog(null, "Preferences could not be loaded. Writing default preference file to "+pref.getPreferencesDir()+"preferences");
100 Main.pref.resetToDefault();
101 }
102
103 // determine what classloader to be used for plugins
104 if (args.containsKey("default-classloader"))
105 PluginInformation.useJosmClassloader = true;
106
107 // load the early plugins
108 if (Main.pref.hasKey("plugins")) {
109 for (String pluginName : Main.pref.get("plugins").split(",")) {
110 try {
111 File pluginFile = new File(pref.getPreferencesDir()+"plugins/"+pluginName+".jar");
112 if (pluginFile.exists()) {
113 PluginInformation info = new PluginInformation(pluginFile);
114 if (!info.early)
115 continue;
116 Class<?> klass = info.loadClass();
117 ImageProvider.sources.add(0, klass);
118 Main.plugins.add(info.load(klass));
119 } else
120 System.out.println("Plugin not found: "+pluginName);
121 } catch (PluginException e) {
122 System.out.println("Could not load plugin "+pluginName);
123 e.printStackTrace();
124 }
125 }
126 }
127
128 if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) {
129 System.out.println(tr("Java OpenStreetMap Editor")+"\n\n"+
130 tr("usage")+":\n"+
131 "\tjava -jar josm.jar <option> <option> <option>...\n\n"+
132 tr("options")+":\n"+
133 "\t--help|-?|-h "+tr("Show this help")+"\n"+
134 "\t--geometry=widthxheight(+|-)x(+|-)y "+tr("Standard unix geometry argument")+"\n"+
135 "\t[--download=]minlat,minlon,maxlat,maxlon "+tr("Download the bounding box")+"\n"+
136 "\t[--download=]<url> "+tr("Download the location at the url (with lat=x&lon=y&zoom=z)")+"\n"+
137 "\t[--download=]<filename> "+tr("Open file (as raw gps, if .gpx or .csv)")+"\n"+
138 "\t--downloadgps=minlat,minlon,maxlat,maxlon "+tr("Download the bounding box as raw gps")+"\n"+
139 "\t--selection=<searchstring> "+tr("Select with the given search")+"\n"+
140 "\t--default-classloader "+tr("Load all plugins with the default class loader")+"\n"+
141 "\t--no-fullscreen "+tr("Don't launch in fullscreen mode")+"\n"+
142 "\t--reset-preferences "+tr("Reset the preferences to default")+"\n\n"+
143 "\t--language=<language> "+tr("Set the language. Example: ")+"\n\n"+
144 tr("examples")+":\n"+
145 "\tjava -jar josm.jar track1.gpx track2.gpx london.osm\n"+
146 "\tjava -jar josm.jar http://www.openstreetmap.org/index.html?lat=43.2&lon=11.1&zoom=13\n"+
147 "\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml\n"+
148 "\tjava -jar josm.jar 43.2,11.1,43.4,11.4\n\n"+
149
150 tr("Parameters are read in the order they are specified, so make sure you load\n"+
151 "some data before --selection")+"\n\n"+
152 tr("Instead of --download=<bbox> you may specify osm://<bbox>\n"));
153 System.exit(0);
154 }
155
156 preConstructorInit(args);
157 JFrame mainFrame = new JFrame(tr("Java Open Street Map - Editor"));
158 Main.parent = mainFrame;
159 Main main = new MainApplication(mainFrame);
160 main.loadPlugins();
161
162 mainFrame.setVisible(true);
163
164 if (!args.containsKey("no-fullscreen") && !args.containsKey("geometry") && Toolkit.getDefaultToolkit().isFrameStateSupported(JFrame.MAXIMIZED_BOTH))
165 mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
166
167 main.postConstructorProcessCmdLine(args);
168 }
169}
Note: See TracBrowser for help on using the repository browser.