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

Last change on this file since 231 was 231, checked in by framm, 17 years ago

Refresh toolbar after plugin initialisation so that plugins may add things to the toolbar. Patch by Francisco R. Santos <frsantos@…>.

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