1 | //Licence: GPL
|
---|
2 | package org.openstreetmap.josm.gui;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.EventQueue;
|
---|
7 | import java.awt.Toolkit;
|
---|
8 | import java.awt.event.WindowAdapter;
|
---|
9 | import java.awt.event.WindowEvent;
|
---|
10 | import java.io.File;
|
---|
11 | import java.io.IOException;
|
---|
12 | import java.util.Arrays;
|
---|
13 | import java.util.Collection;
|
---|
14 | import java.util.HashMap;
|
---|
15 | import java.util.LinkedList;
|
---|
16 | import java.util.List;
|
---|
17 | import java.util.Map;
|
---|
18 |
|
---|
19 | import javax.swing.JFrame;
|
---|
20 | import javax.swing.JOptionPane;
|
---|
21 |
|
---|
22 | import org.openstreetmap.josm.Main;
|
---|
23 | import org.openstreetmap.josm.tools.BugReportExceptionHandler;
|
---|
24 | /**
|
---|
25 | * Main window class application.
|
---|
26 | *
|
---|
27 | * @author imi
|
---|
28 | */
|
---|
29 | public class MainApplication extends Main {
|
---|
30 | /**
|
---|
31 | * Construct an main frame, ready sized and operating. Does not
|
---|
32 | * display the frame.
|
---|
33 | */
|
---|
34 | public MainApplication(JFrame mainFrame) {
|
---|
35 | mainFrame.setContentPane(contentPane);
|
---|
36 | mainFrame.setJMenuBar(menu);
|
---|
37 | mainFrame.setBounds(bounds);
|
---|
38 | mainFrame.addWindowListener(new WindowAdapter(){
|
---|
39 | @Override public void windowClosing(final WindowEvent arg0) {
|
---|
40 | if (Main.breakBecauseUnsavedChanges())
|
---|
41 | return;
|
---|
42 | System.exit(0);
|
---|
43 | }
|
---|
44 | });
|
---|
45 | mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Main application Startup
|
---|
50 | */
|
---|
51 | @SuppressWarnings("deprecation")
|
---|
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 | // load the early plugins
|
---|
115 | Main.loadPlugins(true);
|
---|
116 |
|
---|
117 | if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) {
|
---|
118 | System.out.println(tr("Java OpenStreetMap Editor")+"\n\n"+
|
---|
119 | tr("usage")+":\n"+
|
---|
120 | "\tjava -jar josm.jar <option> <option> <option>...\n\n"+
|
---|
121 | tr("options")+":\n"+
|
---|
122 | "\t--help|-?|-h "+tr("Show this help")+"\n"+
|
---|
123 | "\t--geometry=widthxheight(+|-)x(+|-)y "+tr("Standard unix geometry argument")+"\n"+
|
---|
124 | "\t[--download=]minlat,minlon,maxlat,maxlon "+tr("Download the bounding box")+"\n"+
|
---|
125 | "\t[--download=]<url> "+tr("Download the location at the url (with lat=x&lon=y&zoom=z)")+"\n"+
|
---|
126 | "\t[--download=]<filename> "+tr("Open file (as raw gps, if .gpx or .csv)")+"\n"+
|
---|
127 | "\t--downloadgps=minlat,minlon,maxlat,maxlon "+tr("Download the bounding box as raw gps")+"\n"+
|
---|
128 | "\t--selection=<searchstring> "+tr("Select with the given search")+"\n"+
|
---|
129 | "\t--no-fullscreen "+tr("Don't launch in fullscreen mode")+"\n"+
|
---|
130 | "\t--reset-preferences "+tr("Reset the preferences to default")+"\n\n"+
|
---|
131 | "\t--language=<language> "+tr("Set the language. Example: ")+"\n\n"+
|
---|
132 | tr("examples")+":\n"+
|
---|
133 | "\tjava -jar josm.jar track1.gpx track2.gpx london.osm\n"+
|
---|
134 | "\tjava -jar josm.jar http://www.openstreetmap.org/index.html?lat=43.2&lon=11.1&zoom=13\n"+
|
---|
135 | "\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml\n"+
|
---|
136 | "\tjava -jar josm.jar 43.2,11.1,43.4,11.4\n\n"+
|
---|
137 |
|
---|
138 | tr("Parameters are read in the order they are specified, so make sure you load\n"+
|
---|
139 | "some data before --selection")+"\n\n"+
|
---|
140 | tr("Instead of --download=<bbox> you may specify osm://<bbox>\n"));
|
---|
141 | System.exit(0);
|
---|
142 | }
|
---|
143 |
|
---|
144 | preConstructorInit(args);
|
---|
145 | JFrame mainFrame = new JFrame(tr("Java Open Street Map - Editor"));
|
---|
146 | Main.parent = mainFrame;
|
---|
147 | final Main main = new MainApplication(mainFrame);
|
---|
148 | Main.loadPlugins(false);
|
---|
149 | toolbar.refreshToolbarControl();
|
---|
150 |
|
---|
151 | mainFrame.setVisible(true);
|
---|
152 |
|
---|
153 | if (!args.containsKey("no-fullscreen") && !args.containsKey("geometry") && Toolkit.getDefaultToolkit().isFrameStateSupported(JFrame.MAXIMIZED_BOTH))
|
---|
154 | mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
---|
155 |
|
---|
156 | EventQueue.invokeLater(new Runnable(){
|
---|
157 | public void run() {
|
---|
158 | main.postConstructorProcessCmdLine(args);
|
---|
159 | }
|
---|
160 | });
|
---|
161 | }
|
---|
162 | }
|
---|