1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | //Licence: GPL
|
---|
3 | package org.openstreetmap.josm.gui;
|
---|
4 |
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.awt.EventQueue;
|
---|
8 | import java.awt.Toolkit;
|
---|
9 | import java.awt.event.WindowAdapter;
|
---|
10 | import java.awt.event.WindowEvent;
|
---|
11 | import java.io.File;
|
---|
12 | import java.io.IOException;
|
---|
13 | import java.util.Arrays;
|
---|
14 | import java.util.Collection;
|
---|
15 | import java.util.HashMap;
|
---|
16 | import java.util.LinkedList;
|
---|
17 | import java.util.List;
|
---|
18 | import java.util.Map;
|
---|
19 |
|
---|
20 | import javax.swing.JFrame;
|
---|
21 | import javax.swing.JOptionPane;
|
---|
22 |
|
---|
23 | import org.openstreetmap.josm.Main;
|
---|
24 | import org.openstreetmap.josm.tools.BugReportExceptionHandler;
|
---|
25 | /**
|
---|
26 | * Main window class application.
|
---|
27 | *
|
---|
28 | * @author imi
|
---|
29 | */
|
---|
30 | public 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 | @SuppressWarnings("deprecation")
|
---|
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 | final 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 |
|
---|
86 | // check if preferences directory has moved (TODO: Update code. Remove this after some time)
|
---|
87 | File oldPrefDir = new File(System.getProperty("user.home")+"/.josm");
|
---|
88 | if (!prefDir.isDirectory() && oldPrefDir.isDirectory()) {
|
---|
89 | if (oldPrefDir.renameTo(prefDir)) {
|
---|
90 | // do not translate this
|
---|
91 | JOptionPane.showMessageDialog(null, "The preference directory has been moved to "+prefDir);
|
---|
92 | } else {
|
---|
93 | JOptionPane.showMessageDialog(null, "The preference directory location has changed. Please move "+oldPrefDir+" to "+prefDir);
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | if (prefDir.exists() && !prefDir.isDirectory()) {
|
---|
98 | JOptionPane.showMessageDialog(null, "Cannot open preferences directory: "+Main.pref.getPreferencesDir());
|
---|
99 | return;
|
---|
100 | }
|
---|
101 | if (!prefDir.exists())
|
---|
102 | prefDir.mkdirs();
|
---|
103 | try {
|
---|
104 | if (args.containsKey("reset-preferences")) {
|
---|
105 | Main.pref.resetToDefault();
|
---|
106 | } else {
|
---|
107 | Main.pref.load();
|
---|
108 | }
|
---|
109 | } catch (final IOException e1) {
|
---|
110 | e1.printStackTrace();
|
---|
111 | JOptionPane.showMessageDialog(null, "Preferences could not be loaded. Writing default preference file to "+pref.getPreferencesDir()+"preferences");
|
---|
112 | Main.pref.resetToDefault();
|
---|
113 | }
|
---|
114 |
|
---|
115 | // load the early plugins
|
---|
116 | Main.loadPlugins(true);
|
---|
117 |
|
---|
118 | if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) {
|
---|
119 | System.out.println(tr("Java OpenStreetMap Editor")+"\n\n"+
|
---|
120 | tr("usage")+":\n"+
|
---|
121 | "\tjava -jar josm.jar <option> <option> <option>...\n\n"+
|
---|
122 | tr("options")+":\n"+
|
---|
123 | "\t--help|-?|-h "+tr("Show this help")+"\n"+
|
---|
124 | "\t--geometry=widthxheight(+|-)x(+|-)y "+tr("Standard unix geometry argument")+"\n"+
|
---|
125 | "\t[--download=]minlat,minlon,maxlat,maxlon "+tr("Download the bounding box")+"\n"+
|
---|
126 | "\t[--download=]<url> "+tr("Download the location at the url (with lat=x&lon=y&zoom=z)")+"\n"+
|
---|
127 | "\t[--download=]<filename> "+tr("Open file (as raw gps, if .gpx or .csv)")+"\n"+
|
---|
128 | "\t--downloadgps=minlat,minlon,maxlat,maxlon "+tr("Download the bounding box as raw gps")+"\n"+
|
---|
129 | "\t--selection=<searchstring> "+tr("Select with the given search")+"\n"+
|
---|
130 | "\t--no-fullscreen "+tr("Don't launch in fullscreen mode")+"\n"+
|
---|
131 | "\t--reset-preferences "+tr("Reset the preferences to default")+"\n\n"+
|
---|
132 | "\t--language=<language> "+tr("Set the language. Example: ")+"\n\n"+
|
---|
133 | tr("examples")+":\n"+
|
---|
134 | "\tjava -jar josm.jar track1.gpx track2.gpx london.osm\n"+
|
---|
135 | "\tjava -jar josm.jar http://www.openstreetmap.org/index.html?lat=43.2&lon=11.1&zoom=13\n"+
|
---|
136 | "\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml\n"+
|
---|
137 | "\tjava -jar josm.jar 43.2,11.1,43.4,11.4\n\n"+
|
---|
138 |
|
---|
139 | tr("Parameters are read in the order they are specified, so make sure you load\n"+
|
---|
140 | "some data before --selection")+"\n\n"+
|
---|
141 | tr("Instead of --download=<bbox> you may specify osm://<bbox>\n"));
|
---|
142 | System.exit(0);
|
---|
143 | }
|
---|
144 |
|
---|
145 | preConstructorInit(args);
|
---|
146 | JFrame mainFrame = new JFrame(tr("Java OpenStreetMap - Editor"));
|
---|
147 | Main.parent = mainFrame;
|
---|
148 | final Main main = new MainApplication(mainFrame);
|
---|
149 | Main.loadPlugins(false);
|
---|
150 | toolbar.refreshToolbarControl();
|
---|
151 |
|
---|
152 | mainFrame.setVisible(true);
|
---|
153 |
|
---|
154 | if (!args.containsKey("no-fullscreen") && !args.containsKey("geometry") && Toolkit.getDefaultToolkit().isFrameStateSupported(JFrame.MAXIMIZED_BOTH))
|
---|
155 | mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
---|
156 |
|
---|
157 | EventQueue.invokeLater(new Runnable(){
|
---|
158 | public void run() {
|
---|
159 | main.postConstructorProcessCmdLine(args);
|
---|
160 | }
|
---|
161 | });
|
---|
162 | }
|
---|
163 | }
|
---|