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

Last change on this file since 153 was 153, checked in by imi, 18 years ago
  • added possibility to create new download tasks (download data types).
  • removed WMS stuff (now available as landsat - plugin)
  • updated translation files
File size: 7.1 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.Locale;
17import java.util.Map;
18
19import javax.swing.JFrame;
20import javax.swing.JOptionPane;
21
22import org.openstreetmap.josm.Main;
23import org.openstreetmap.josm.gui.layer.Layer;
24import org.openstreetmap.josm.gui.layer.OsmDataLayer;
25import org.openstreetmap.josm.tools.BugReportExceptionHandler;
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(mainMenu);
39 mainFrame.setBounds(bounds);
40 mainFrame.addWindowListener(new WindowAdapter(){
41 @Override public void windowClosing(final WindowEvent arg0) {
42 if (Main.map != null) {
43 boolean modified = false;
44 boolean uploadedModified = false;
45 for (final Layer l : Main.map.mapView.getAllLayers()) {
46 if (l instanceof OsmDataLayer && ((OsmDataLayer)l).isModified()) {
47 modified = true;
48 uploadedModified = ((OsmDataLayer)l).uploadedModified;
49 break;
50 }
51 }
52 if (modified) {
53 final String msg = uploadedModified ? "\n"+tr("Hint: Some changes came from uploading new data to the server.") : "";
54 final int answer = JOptionPane.showConfirmDialog(
55 Main.parent, tr("There are unsaved changes. Really quit?")+msg,
56 tr("Unsaved Changes"), JOptionPane.YES_NO_OPTION);
57 if (answer != JOptionPane.YES_OPTION)
58 return;
59 }
60 }
61 System.exit(0);
62 }
63 });
64 mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
65 }
66
67 /**
68 * Main application Startup
69 */
70 public static void main(final String[] argArray) {
71 /////////////////////////////////////////////////////////////////////////
72 // TO ALL TRANSLATORS
73 /////////////////////////////////////////////////////////////////////////
74 // Do not translate the early strings below until the locale is set up.
75 // These strings cannot be translated. That's live. Really. Sorry.
76 //
77 // The next one sending me a patch translating these strings owe me a beer!
78 //
79 // Imi.
80 /////////////////////////////////////////////////////////////////////////
81
82 Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler());
83
84 // construct argument table
85 List<String> argList = Arrays.asList(argArray);
86 Map<String, Collection<String>> args = new HashMap<String, Collection<String>>();
87 for (String arg : argArray) {
88 if (!arg.startsWith("--"))
89 arg = "--download="+arg;
90 int i = arg.indexOf('=');
91 String key = i == -1 ? arg.substring(2) : arg.substring(2,i);
92 String value = i == -1 ? "" : arg.substring(i+1);
93 Collection<String> v = args.get(key);
94 if (v == null)
95 v = new LinkedList<String>();
96 v.add(value);
97 args.put(key, v);
98 }
99
100 // get the preferences.
101 final File prefDir = new File(Main.pref.getPreferencesDir());
102 if (prefDir.exists() && !prefDir.isDirectory()) {
103 JOptionPane.showMessageDialog(null, "Cannot open preferences directory: "+Main.pref.getPreferencesDir());
104 return;
105 }
106 if (!prefDir.exists())
107 prefDir.mkdirs();
108 try {
109 if (args.containsKey("reset-preferences")) {
110 Main.pref.resetToDefault();
111 } else {
112 Main.pref.load();
113 }
114 } catch (final IOException e1) {
115 e1.printStackTrace();
116 JOptionPane.showMessageDialog(null, "Preferences could not be loaded. Writing default preference file to "+pref.getPreferencesDir()+"preferences");
117 Main.pref.resetToDefault();
118 }
119
120 // setup the locale
121 if (args.containsKey("language") && !args.get("language").isEmpty() && args.get("language").iterator().next().length() >= 2) {
122 String s = args.get("language").iterator().next();
123 Locale l = null;
124 if (s.length() <= 2 || s.charAt(2) != '_')
125 l = new Locale(s);
126 else if (s.length() <= 5 || s.charAt(5) != '.')
127 l = new Locale(s.substring(0,2), s.substring(3));
128 else
129 l = new Locale(s.substring(0,2), s.substring(3,5), s.substring(6));
130 Locale.setDefault(l);
131 } else if (!Main.pref.get("language").equals("")) {
132 String lang = Main.pref.get("language");
133 for (Locale l : Locale.getAvailableLocales()) {
134 if (l.toString().equals(lang)) {
135 Locale.setDefault(l);
136 break;
137 }
138 }
139 }
140
141 // Locale is set. From now on, tr(), trn() and trc() may be called.
142
143 if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) {
144 System.out.println(tr("Java OpenStreetMap Editor")+"\n\n"+
145 tr("usage")+":\n"+
146 "\tjava -jar josm.jar <option> <option> <option>...\n\n"+
147 tr("options")+":\n"+
148 "\t--help|-?|-h "+tr("Show this help")+"\n"+
149 "\t--geometry=widthxheight(+|-)x(+|-)y "+tr("Standard unix geometry argument")+"\n"+
150 "\t[--download=]minlat,minlon,maxlat,maxlon "+tr("Download the bounding box")+"\n"+
151 "\t[--download=]<url> "+tr("Download the location at the url (with lat=x&lon=y&zoom=z)")+"\n"+
152 "\t[--download=]<filename> "+tr("Open file (as raw gps, if .gpx or .csv)")+"\n"+
153 "\t--downloadgps=minlat,minlon,maxlat,maxlon "+tr("Download the bounding box as raw gps")+"\n"+
154 "\t--selection=<searchstring> "+tr("Select with the given search")+"\n"+
155 "\t--no-fullscreen "+tr("Don't launch in fullscreen mode")+"\n"+
156 "\t--reset-preferences "+tr("Reset the preferences to default")+"\n\n"+
157 "\t--language=<language> "+tr("Set the language. Example: ")+"\n\n"+
158 tr("examples")+":\n"+
159 "\tjava -jar josm.jar track1.gpx track2.gpx london.osm\n"+
160 "\tjava -jar josm.jar http://www.openstreetmap.org/index.html?lat=43.2&lon=11.1&zoom=13\n"+
161 "\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml\n"+
162 "\tjava -jar josm.jar 43.2,11.1,43.4,11.4\n\n"+
163
164 tr("Parameters are read in the order they are specified, so make sure you load\n"+
165 "some data before --selection")+"\n\n"+
166 tr("Instead of --download=<bbox> you may specify osm://<bbox>\n"));
167 System.exit(0);
168 }
169
170 preConstructorInit(args);
171 JFrame mainFrame = new JFrame(tr("Java Open Street Map - Editor"));
172 Main.parent = mainFrame;
173 Main main = new MainApplication(mainFrame);
174
175 mainFrame.setVisible(true);
176
177 if (!args.containsKey("no-fullscreen") && !args.containsKey("geometry") && Toolkit.getDefaultToolkit().isFrameStateSupported(JFrame.MAXIMIZED_BOTH))
178 mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
179
180 main.postConstructorProcessCmdLine(args);
181 }
182}
Note: See TracBrowser for help on using the repository browser.