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

Last change on this file since 169 was 169, checked in by imi, 19 years ago
  • added "new empty map" action
  • added osm-server.version property (set the OSM server verion. For expert users only)
  • added first support for ongoing 0.4 server api
  • fixed Class-Path manifest attribute for plugins (" " is Seperator)
File size: 6.3 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 // load the early plugins
104 if (Main.pref.hasKey("plugins")) {
105 for (String pluginName : Main.pref.get("plugins").split(",")) {
106 try {
107 File pluginFile = new File(pref.getPreferencesDir()+"plugins/"+pluginName+".jar");
108 if (pluginFile.exists()) {
109 PluginInformation info = new PluginInformation(pluginFile);
110 if (!info.early)
111 continue;
112 Class<?> klass = info.loadClass();
113 ImageProvider.sources.add(0, klass);
114 Main.plugins.add(info.load(klass));
115 } else
116 System.out.println("Plugin not found: "+pluginName);
117 } catch (PluginException e) {
118 System.out.println("Could not load plugin "+pluginName);
119 e.printStackTrace();
120 }
121 }
122 }
123
124 if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) {
125 System.out.println(tr("Java OpenStreetMap Editor")+"\n\n"+
126 tr("usage")+":\n"+
127 "\tjava -jar josm.jar <option> <option> <option>...\n\n"+
128 tr("options")+":\n"+
129 "\t--help|-?|-h "+tr("Show this help")+"\n"+
130 "\t--geometry=widthxheight(+|-)x(+|-)y "+tr("Standard unix geometry argument")+"\n"+
131 "\t[--download=]minlat,minlon,maxlat,maxlon "+tr("Download the bounding box")+"\n"+
132 "\t[--download=]<url> "+tr("Download the location at the url (with lat=x&lon=y&zoom=z)")+"\n"+
133 "\t[--download=]<filename> "+tr("Open file (as raw gps, if .gpx or .csv)")+"\n"+
134 "\t--downloadgps=minlat,minlon,maxlat,maxlon "+tr("Download the bounding box as raw gps")+"\n"+
135 "\t--selection=<searchstring> "+tr("Select with the given search")+"\n"+
136 "\t--no-fullscreen "+tr("Don't launch in fullscreen mode")+"\n"+
137 "\t--reset-preferences "+tr("Reset the preferences to default")+"\n\n"+
138 "\t--language=<language> "+tr("Set the language. Example: ")+"\n\n"+
139 tr("examples")+":\n"+
140 "\tjava -jar josm.jar track1.gpx track2.gpx london.osm\n"+
141 "\tjava -jar josm.jar http://www.openstreetmap.org/index.html?lat=43.2&lon=11.1&zoom=13\n"+
142 "\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml\n"+
143 "\tjava -jar josm.jar 43.2,11.1,43.4,11.4\n\n"+
144
145 tr("Parameters are read in the order they are specified, so make sure you load\n"+
146 "some data before --selection")+"\n\n"+
147 tr("Instead of --download=<bbox> you may specify osm://<bbox>\n"));
148 System.exit(0);
149 }
150
151 preConstructorInit(args);
152 JFrame mainFrame = new JFrame(tr("Java Open Street Map - Editor"));
153 Main.parent = mainFrame;
154 Main main = new MainApplication(mainFrame);
155 main.loadPlugins();
156
157 mainFrame.setVisible(true);
158
159 if (!args.containsKey("no-fullscreen") && !args.containsKey("geometry") && Toolkit.getDefaultToolkit().isFrameStateSupported(JFrame.MAXIMIZED_BOTH))
160 mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
161
162 main.postConstructorProcessCmdLine(args);
163 }
164}
Note: See TracBrowser for help on using the repository browser.