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

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