1 | //Licence: GPL
|
---|
2 | package org.openstreetmap.josm.gui;
|
---|
3 |
|
---|
4 | import java.awt.Toolkit;
|
---|
5 | import java.awt.event.WindowAdapter;
|
---|
6 | import java.awt.event.WindowEvent;
|
---|
7 | import java.io.File;
|
---|
8 | import java.util.Arrays;
|
---|
9 | import java.util.Collection;
|
---|
10 | import java.util.HashMap;
|
---|
11 | import java.util.LinkedList;
|
---|
12 | import java.util.List;
|
---|
13 | import java.util.Map;
|
---|
14 |
|
---|
15 | import javax.swing.JFrame;
|
---|
16 | import javax.swing.JOptionPane;
|
---|
17 |
|
---|
18 | import org.openstreetmap.josm.Main;
|
---|
19 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
20 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
21 | import org.openstreetmap.josm.tools.BugReportExceptionHandler;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Main window class application.
|
---|
25 | *
|
---|
26 | * @author imi
|
---|
27 | */
|
---|
28 | public class MainApplication extends Main {
|
---|
29 |
|
---|
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(mainMenu);
|
---|
37 | mainFrame.setBounds(bounds);
|
---|
38 | mainFrame.addWindowListener(new WindowAdapter(){
|
---|
39 | @Override public void windowClosing(final WindowEvent arg0) {
|
---|
40 | if (Main.map != null) {
|
---|
41 | boolean modified = false;
|
---|
42 | boolean uploadedModified = false;
|
---|
43 | for (final Layer l : Main.map.mapView.getAllLayers()) {
|
---|
44 | if (l instanceof OsmDataLayer && ((OsmDataLayer)l).isModified()) {
|
---|
45 | modified = true;
|
---|
46 | uploadedModified = ((OsmDataLayer)l).uploadedModified;
|
---|
47 | break;
|
---|
48 | }
|
---|
49 | }
|
---|
50 | if (modified) {
|
---|
51 | final String msg = uploadedModified ? "\nHint: Some changes came from uploading new data to the server." : "";
|
---|
52 | final int answer = JOptionPane.showConfirmDialog(
|
---|
53 | Main.parent, "There are unsaved changes. Really quit?"+msg,
|
---|
54 | "Unsaved Changes", JOptionPane.YES_NO_OPTION);
|
---|
55 | if (answer != JOptionPane.YES_OPTION)
|
---|
56 | return;
|
---|
57 | }
|
---|
58 | }
|
---|
59 | System.exit(0);
|
---|
60 | }
|
---|
61 | });
|
---|
62 | mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Main application Startup
|
---|
67 | * @param args No parameters accepted.
|
---|
68 | */
|
---|
69 | public static void main(final String[] argArray) {
|
---|
70 | Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler());
|
---|
71 |
|
---|
72 | List<String> argList = Arrays.asList(argArray);
|
---|
73 | if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) {
|
---|
74 | System.out.println("Java OpenStreetMap Editor");
|
---|
75 | System.out.println();
|
---|
76 | System.out.println("usage:");
|
---|
77 | System.out.println("\tjava -jar josm.jar <option> <option> <option>...");
|
---|
78 | System.out.println();
|
---|
79 | System.out.println("options:");
|
---|
80 | System.out.println("\t--help|-?|-h Show this help");
|
---|
81 | System.out.println("\t--geometry=widthxheight(+|-)x(+|-)y Standard unix geometry argument");
|
---|
82 | System.out.println("\t[--download=]minlat,minlon,maxlat,maxlon Download the bounding box");
|
---|
83 | System.out.println("\t[--download=]<url> Download the location at the url (with lat=x&lon=y&zoom=z)");
|
---|
84 | System.out.println("\t[--download=]<filename> Open file (as raw gps, if .gpx or .csv)");
|
---|
85 | System.out.println("\t--downloadgps=minlat,minlon,maxlat,maxlon Download the bounding box as raw gps");
|
---|
86 | System.out.println("\t--selection=<searchstring> Select with the given search");
|
---|
87 | System.out.println("\t--no-fullscreen Don't launch in fullscreen mode");
|
---|
88 | System.out.println("\t--reset-preferences Reset the preferences to default");
|
---|
89 | System.out.println();
|
---|
90 | System.out.println("examples:");
|
---|
91 | System.out.println("\tjava -jar josm.jar track1.gpx track2.gpx london.osm");
|
---|
92 | System.out.println("\tjava -jar josm.jar http://www.openstreetmap.org/index.html?lat=43.2&lon=11.1&zoom=13");
|
---|
93 | System.out.println("\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml");
|
---|
94 | System.out.println("\tjava -jar josm.jar 43.2,11.1,43.4,11.4");
|
---|
95 | System.out.println();
|
---|
96 | System.out.println("Parameters are read in the order they are specified, so make sure you load");
|
---|
97 | System.out.println("some data before --selection");
|
---|
98 | System.out.println();
|
---|
99 | System.out.println("Instead of --download=<bbox> you may specify osm://<bbox>");
|
---|
100 | System.exit(0);
|
---|
101 | }
|
---|
102 |
|
---|
103 | final File prefDir = new File(Main.pref.getPreferencesDir());
|
---|
104 | if (prefDir.exists() && !prefDir.isDirectory()) {
|
---|
105 | JOptionPane.showMessageDialog(null, "Cannot open preferences directory: "+Main.pref.getPreferencesDir());
|
---|
106 | return;
|
---|
107 | }
|
---|
108 | if (!prefDir.exists())
|
---|
109 | prefDir.mkdirs();
|
---|
110 |
|
---|
111 | // construct argument table
|
---|
112 | Map<String, Collection<String>> args = new HashMap<String, Collection<String>>();
|
---|
113 | for (String arg : argArray) {
|
---|
114 | if (!arg.startsWith("--"))
|
---|
115 | arg = "--download="+arg;
|
---|
116 | int i = arg.indexOf('=');
|
---|
117 | String key = i == -1 ? arg.substring(2) : arg.substring(2,i);
|
---|
118 | String value = i == -1 ? "" : arg.substring(i+1);
|
---|
119 | Collection<String> v = args.get(key);
|
---|
120 | if (v == null)
|
---|
121 | v = new LinkedList<String>();
|
---|
122 | v.add(value);
|
---|
123 | args.put(key, v);
|
---|
124 | }
|
---|
125 |
|
---|
126 | preConstructorInit(args);
|
---|
127 | JFrame mainFrame = new JFrame("Java Open Street Map - Editor");
|
---|
128 | Main.parent = mainFrame;
|
---|
129 | Main main = new MainApplication(mainFrame);
|
---|
130 |
|
---|
131 | mainFrame.setVisible(true);
|
---|
132 |
|
---|
133 | if (!args.containsKey("no-fullscreen") && !args.containsKey("geometry") && Toolkit.getDefaultToolkit().isFrameStateSupported(JFrame.MAXIMIZED_BOTH))
|
---|
134 | mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
|
---|
135 |
|
---|
136 | main.postConstructorProcessCmdLine(args);
|
---|
137 | }
|
---|
138 | }
|
---|