- Timestamp:
- 2006-04-25T00:11:38+02:00 (18 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 3 added
- 1 deleted
- 40 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r94 r98 1 //Licence: GPL2 1 package org.openstreetmap.josm; 3 2 4 3 import java.awt.BorderLayout; 4 import java.awt.Component; 5 5 import java.awt.Dimension; 6 import java.awt. Point;6 import java.awt.Rectangle; 7 7 import java.awt.Toolkit; 8 import java.awt.event.WindowAdapter;9 import java.awt.event.WindowEvent;10 8 import java.io.File; 11 9 import java.io.IOException; 12 import java.util.Arrays; 13 import java.util.LinkedList; 10 import java.net.URI; 11 import java.net.URISyntaxException; 12 import java.util.Collection; 13 import java.util.Map; 14 14 import java.util.StringTokenizer; 15 15 import java.util.concurrent.Executor; … … 19 19 20 20 import javax.swing.Action; 21 import javax.swing.JFrame;22 21 import javax.swing.JMenu; 23 22 import javax.swing.JMenuBar; … … 44 43 import org.openstreetmap.josm.data.projection.Projection; 45 44 import org.openstreetmap.josm.gui.MapFrame; 46 import org.openstreetmap.josm.gui. ShowModifiers;45 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 47 46 import org.openstreetmap.josm.gui.dialogs.SelectionListDialog; 48 47 import org.openstreetmap.josm.gui.layer.Layer; 49 48 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 50 import org.openstreetmap.josm. tools.BugReportExceptionHandler;49 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener; 51 50 import org.openstreetmap.josm.tools.ImageProvider; 52 51 53 /** 54 * Main window class application. 55 * 56 * @author imi 57 */ 58 public class Main extends JFrame { 59 52 abstract public class Main { 53 /** 54 * Global parent component for all dialogs and message boxes 55 */ 56 public static Component parent; 60 57 /** 61 58 * Global application window. Use this as JOPtionPane-parent to center on application. 62 59 */ 63 60 public static Main main; 64 65 61 /** 66 62 * The worker thread slave. This is for executing all long and intensive … … 68 64 * and sequenciel. 69 65 */ 70 public static Executor worker = Executors.newSingleThreadExecutor(); 71 72 66 public final static Executor worker = Executors.newSingleThreadExecutor(); 67 /** 68 * Global application preferences 69 */ 70 public static Preferences pref = new Preferences(); 71 /** 72 * The global dataset. 73 */ 74 public static DataSet ds = new DataSet(); 75 /** 76 * The projection method used. 77 */ 73 78 public static Projection proj; 74 75 /** 76 * Global application preferences 77 */ 78 public final static Preferences pref = new Preferences(); 79 80 /** 81 * The global dataset. 82 */ 83 public static DataSet ds = new DataSet(); 84 85 /** 86 * The main panel. 87 */ 88 public JPanel panel; 89 /** 90 * The mapFrame currently loaded. 91 */ 92 private MapFrame mapFrame; 93 94 public final UndoAction undoAction; 95 public final RedoAction redoAction; 96 97 private OpenAction openAction; 98 private DownloadAction downloadAction; 99 //private Action wmsServerAction; 100 101 /** 102 * Construct an main frame, ready sized and operating. Does not 103 * display the frame. 104 */ 79 /** 80 * The MapFrame. Use setMapFrame to set or clear it. 81 */ 82 public static MapFrame map; 83 84 /** 85 * Set or clear (if passed <code>null</code>) the map. 86 */ 87 public final void setMapFrame(final MapFrame map) { 88 Main.map = map; 89 panel.setVisible(false); 90 panel.removeAll(); 91 if (map != null) { 92 map.fillPanel(panel); 93 panel.setVisible(true); 94 map.mapView.addLayerChangeListener(new LayerChangeListener(){ 95 public void activeLayerChange(final Layer oldLayer, final Layer newLayer) {} 96 public void layerAdded(final Layer newLayer) { 97 if (newLayer instanceof OsmDataLayer) 98 Main.main.editLayer().listenerCommands.add(redoUndoListener); 99 } 100 public void layerRemoved(final Layer oldLayer) {} 101 }); 102 } 103 redoUndoListener.commandChanged(0,0); 104 } 105 106 /** 107 * Remove the specified layer from the map. If it is the last layer, remove the map as well. 108 */ 109 public final void removeLayer(final Layer layer) { 110 final Collection<Layer> allLayers = map.mapView.getAllLayers(); 111 if (allLayers.size() == 1 && allLayers.iterator().next() == layer) { 112 Main.map.setVisible(false); 113 setMapFrame(null); 114 ds = new DataSet(); 115 } else { 116 map.mapView.removeLayer(layer); 117 if (layer instanceof OsmDataLayer) 118 ds = new DataSet(); 119 } 120 } 105 121 public Main() { 106 super("Java Open Street Map - Editor"); 107 Main.main = this; 108 setLayout(new BorderLayout()); 109 panel = new JPanel(new BorderLayout()); 110 getContentPane().add(panel, BorderLayout.CENTER); 111 setSize(1000,740); // some strange default size 112 113 downloadAction = new DownloadAction(); 114 Action uploadAction = new UploadAction(); 115 //wmsServerAction = new WmsServerAction(); 116 openAction = new OpenAction(); 117 Action saveAction = new SaveAction(); 118 Action gpxExportAction = new GpxExportAction(null); 119 Action exitAction = new ExitAction(); 120 undoAction = new UndoAction(); 121 redoAction = new RedoAction(); 122 Action preferencesAction = new PreferencesAction(); 123 Action aboutAction = new AboutAction(); 124 125 // creating menu 126 JMenuBar mainMenu = new JMenuBar(); 127 setJMenuBar(mainMenu); 128 129 JMenu fileMenu = new JMenu("Files"); 122 main = this; 123 contentPane.add(panel, BorderLayout.CENTER); 124 125 final Action uploadAction = new UploadAction(); 126 final Action saveAction = new SaveAction(); 127 final Action gpxExportAction = new GpxExportAction(null); 128 final Action exitAction = new ExitAction(); 129 final Action preferencesAction = new PreferencesAction(); 130 final Action aboutAction = new AboutAction(); 131 132 final JMenu fileMenu = new JMenu("Files"); 130 133 fileMenu.setMnemonic('F'); 131 134 fileMenu.add(openAction); … … 137 140 138 141 139 JMenu layerMenu = new JMenu("Layer");142 final JMenu layerMenu = new JMenu("Layer"); 140 143 layerMenu.setMnemonic('L'); 141 144 layerMenu.add(downloadAction); 142 145 layerMenu.add(uploadAction); 143 146 layerMenu.addSeparator(); 144 //layerMenu.add(new JCheckBoxMenuItem(wmsServerAction));145 147 mainMenu.add(layerMenu); 146 148 147 JMenu editMenu = new JMenu("Edit");149 final JMenu editMenu = new JMenu("Edit"); 148 150 editMenu.setMnemonic('E'); 149 151 editMenu.add(undoAction); … … 154 156 155 157 mainMenu.add(new JSeparator()); 156 JMenu helpMenu = new JMenu("Help");158 final JMenu helpMenu = new JMenu("Help"); 157 159 helpMenu.setMnemonic('H'); 158 160 helpMenu.add(aboutAction); … … 160 162 161 163 // creating toolbar 162 JToolBar toolBar = new JToolBar();164 final JToolBar toolBar = new JToolBar(); 163 165 toolBar.setFloatable(false); 164 166 toolBar.add(downloadAction); 165 167 toolBar.add(uploadAction); 166 //toolBar.add(new IconToggleButton(wmsServerAction));167 168 toolBar.addSeparator(); 168 169 toolBar.add(openAction); … … 174 175 toolBar.addSeparator(); 175 176 toolBar.add(preferencesAction); 176 177 getContentPane().add(toolBar, BorderLayout.NORTH); 178 179 addWindowListener(new WindowAdapter(){ 180 @Override public void windowClosing(WindowEvent arg0) { 181 if (mapFrame != null) { 182 boolean modified = false; 183 boolean uploadedModified = false; 184 for (Layer l : mapFrame.mapView.getAllLayers()) { 185 if (l instanceof OsmDataLayer && ((OsmDataLayer)l).isModified()) { 186 modified = true; 187 uploadedModified = ((OsmDataLayer)l).uploadedModified; 188 break; 189 } 190 } 191 if (modified) { 192 String msg = uploadedModified ? "\nHint: Some changes came from uploading new data to the server." : ""; 193 int answer = JOptionPane.showConfirmDialog( 194 Main.this, "There are unsaved changes. Really quit?"+msg, 195 "Unsaved Changes", JOptionPane.YES_NO_OPTION); 196 if (answer != JOptionPane.YES_OPTION) 197 return; 198 } 199 } 200 System.exit(0); 201 } 202 }); 203 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); 204 } 205 206 /** 207 * Main application Startup 208 * @param args No parameters accepted. 209 */ 210 public static void main(String[] args) { 211 setupExceptionHandler(); 212 setupUiDefaults(); 213 214 LinkedList<String> arguments = new LinkedList<String>(Arrays.asList(args)); 215 216 if (arguments.contains("--help") || arguments.contains("-?") || arguments.contains("-h")) { 217 System.out.println("Java OpenStreetMap Editor"); 218 System.out.println(); 219 System.out.println("usage:"); 220 System.out.println("\tjava -jar josm.jar <option> <option> <option>..."); 221 System.out.println(); 222 System.out.println("options:"); 223 System.out.println("\t--help|-?|-h Show this help"); 224 System.out.println("\t--geometry=widthxheight(+|-)x(+|-)y Standard unix geometry argument"); 225 System.out.println("\t--download=minlat,minlon,maxlat,maxlon Download the bounding box"); 226 System.out.println("\t--downloadgps=minlat,minlon,maxlat,maxlon Download the bounding box"); 227 System.out.println("\t--selection=<searchstring> Select with the given search"); 228 System.out.println("\t--no-fullscreen Don't launch in fullscreen mode"); 229 System.out.println("\t--reset-preferences Reset the preferences to default"); 230 System.out.println("\tURL|filename(.osm|.xml|.gpx|.txt|.csv) Open file / Download url"); 231 System.out.println(); 232 System.out.println("examples:"); 233 System.out.println("\tjava -jar josm.jar track1.gpx track2.gpx london.osm"); 234 System.out.println("\tjava -jar josm.jar http://www.openstreetmap.org/index.html?lat=43.2&lon=11.1&zoom=13"); 235 System.out.println("\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml"); 236 System.out.println("\tjava -jar josm.jar osm://43.2,11.1,43.4,11.4"); 237 System.out.println(); 238 System.out.println("Parameters are read in the order they are specified, so make sure you load"); 239 System.out.println("some data before --selection"); 240 System.out.println(); 241 System.out.println("Instead of --download=<bbox> you may specify osm://<bbox>"); 242 System.exit(0); 243 } 244 245 File prefDir = new File(Preferences.getPreferencesDir()); 246 if (prefDir.exists() && !prefDir.isDirectory()) { 247 JOptionPane.showMessageDialog(null, "Cannot open preferences directory: "+Preferences.getPreferencesDir()); 248 return; 249 } 250 if (!prefDir.exists()) 251 prefDir.mkdirs(); 252 177 contentPane.add(toolBar, BorderLayout.NORTH); 178 179 contentPane.updateUI(); 180 } 181 /** 182 * Add a new layer to the map. If no map exist, create one. 183 */ 184 public final void addLayer(final Layer layer) { 185 if (map == null) { 186 final MapFrame mapFrame = new MapFrame(layer); 187 setMapFrame(mapFrame); 188 mapFrame.setVisible(true); 189 mapFrame.setVisibleDialogs(); 190 } else 191 map.mapView.addLayer(layer); 192 } 193 /** 194 * @return The edit osm layer. If none exist, it will be created. 195 */ 196 public final OsmDataLayer editLayer() { 197 if (map == null || map.mapView.editLayer == null) 198 addLayer(new OsmDataLayer(ds, "unnamed", false)); 199 return map.mapView.editLayer; 200 } 201 202 203 204 205 /** 206 * Use this to register shortcuts to 207 */ 208 public static JPanel panel = new JPanel(new BorderLayout()); 209 210 211 //////////////////////////////////////////////////////////////////////////////////////// 212 // Implementation part 213 //////////////////////////////////////////////////////////////////////////////////////// 214 215 216 protected final JMenuBar mainMenu = new JMenuBar(); 217 protected static final JPanel contentPane = new JPanel(new BorderLayout()); 218 protected static Rectangle bounds; 219 220 private final UndoAction undoAction = new UndoAction(); 221 private final RedoAction redoAction = new RedoAction(); 222 private final OpenAction openAction = new OpenAction(); 223 private final DownloadAction downloadAction = new DownloadAction(); 224 225 private final CommandQueueListener redoUndoListener = new CommandQueueListener(){ 226 public void commandChanged(final int queueSize, final int redoSize) { 227 undoAction.setEnabled(queueSize > 0); 228 redoAction.setEnabled(redoSize > 0); 229 } 230 }; 231 232 /** 233 * Should be called before the main constructor to setup some parameter stuff 234 * @param args The parsed argument list. 235 */ 236 public static void preConstructorInit(Map<String, Collection<String>> args) { 253 237 // load preferences 254 238 String errMsg = null; 255 239 try { 256 if (arg uments.remove("--reset-preferences")) {257 pref.resetToDefault();240 if (args.containsKey("reset-preferences")) { 241 Main.pref.resetToDefault(); 258 242 } else 259 pref.load();260 } catch ( IOException e1) {243 Main.pref.load(); 244 } catch (final IOException e1) { 261 245 e1.printStackTrace(); 262 errMsg = "Preferences could not be loaded. Write default preference file to '"+ Preferences.getPreferencesDir()+"preferences'.";263 pref.resetToDefault();246 errMsg = "Preferences could not be loaded. Write default preference file to '"+pref.getPreferencesDir()+"preferences'."; 247 Main.pref.resetToDefault(); 264 248 } 265 249 if (errMsg != null) … … 267 251 268 252 try { 269 proj = (Projection)Class.forName(pref.get("projection")).newInstance();270 } catch ( Exception e) {253 Main.proj = (Projection)Class.forName(Main.pref.get("projection")).newInstance(); 254 } catch (final Exception e) { 271 255 e.printStackTrace(); 272 256 JOptionPane.showMessageDialog(null, "The projection could not be read from preferences. Using EPSG:4263."); 273 proj = new Epsg4326();257 Main.proj = new Epsg4326(); 274 258 } 275 259 276 260 try { 277 UIManager.setLookAndFeel(pref.get("laf")); 278 } catch (Exception e) { 261 UIManager.setLookAndFeel(Main.pref.get("laf")); 262 contentPane.updateUI(); 263 panel.updateUI(); 264 } catch (final Exception e) { 279 265 e.printStackTrace(); 280 266 } 281 282 new Main();283 main.setVisible(true);284 285 if (!arguments.remove("--no-fullscreen")) {286 if (Toolkit.getDefaultToolkit().isFrameStateSupported(MAXIMIZED_BOTH))287 main.setExtendedState(MAXIMIZED_BOTH); // some platform are able to maximize288 else {289 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();290 main.setSize(d);291 }292 }293 294 boolean showModifiers = false;295 296 for (String s : arguments) {297 if (s.startsWith("--download=") || s.startsWith("osm:")) {298 downloadFromParamString(false, s);299 } else if (s.startsWith("--downloadgps=")) {300 downloadFromParamString(true, s);301 } else if (s.startsWith("--geometry=")) {302 Matcher m = Pattern.compile("(\\d+)x(\\d+)(([+-])(\\d+)([+-])(\\d+))?").matcher(s.substring(11));303 if (m.matches()) {304 main.setExtendedState(NORMAL);305 Integer w = Integer.valueOf(m.group(1));306 Integer h = Integer.valueOf(m.group(2));307 main.setSize(w, h);308 if (m.group(3) != null) {309 int x = Integer.valueOf(m.group(5));310 int y = Integer.valueOf(m.group(7));311 if (m.group(4).equals("-"))312 x = Toolkit.getDefaultToolkit().getScreenSize().width - x - w;313 if (m.group(6).equals("-"))314 y = Toolkit.getDefaultToolkit().getScreenSize().height - y - h;315 main.setLocation(x,y);316 }317 } else318 System.out.println("Ignoring malformed geometry: "+s.substring(11));319 } else if (s.equals("--show-modifiers")) {320 showModifiers = true;321 } else if (s.startsWith("--selection=")) {322 SelectionListDialog.search(s.substring(12), SelectionListDialog.SearchMode.add);323 } else if (s.startsWith("http:")) {324 Bounds b = DownloadAction.osmurl2bounds(s);325 if (b == null)326 JOptionPane.showMessageDialog(main, "Ignoring malformed url: "+s);327 else328 main.downloadAction.download(false, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon());329 } else {330 main.openAction.openFile(new File(s));331 }332 }333 334 if (showModifiers) {335 Point p = main.getLocationOnScreen();336 Dimension s = main.getSize();337 new ShowModifiers(p.x + s.width - 3, p.y + s.height - 32);338 main.setVisible(true);339 }340 }341 342 343 private static void downloadFromParamString(boolean rawGps, String s) {344 s = s.replaceAll("^(osm:/?/?)|(--download(gps)?=)", "");345 StringTokenizer st = new StringTokenizer(s, ",");346 if (st.countTokens() != 4) {347 JOptionPane.showMessageDialog(main, "Malformed bounding box: "+s);348 return;349 }350 351 try {352 main.downloadAction.download(rawGps, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));353 } catch (NumberFormatException e) {354 JOptionPane.showMessageDialog(main, "Could not parse the Coordinates: "+s);355 }356 }357 358 //TODO: should be solved better.359 public void setMapFrame(MapFrame mapFrame) {360 if (this.mapFrame != null)361 this.mapFrame.setVisible(false);362 this.mapFrame = mapFrame;363 panel.setVisible(false);364 panel.removeAll();365 if (mapFrame != null) {366 mapFrame.fillPanel(panel);367 panel.setVisible(true);368 mapFrame.setVisible(true);369 }370 }371 /**372 * @return Returns the mapFrame.373 */374 public MapFrame getMapFrame() {375 return mapFrame;376 }377 378 379 /**380 * Sets some icons to the ui.381 */382 private static void setupUiDefaults() {383 267 UIManager.put("OptionPane.okIcon", ImageProvider.get("ok")); 384 268 UIManager.put("OptionPane.yesIcon", UIManager.get("OptionPane.okIcon")); 385 269 UIManager.put("OptionPane.cancelIcon", ImageProvider.get("cancel")); 386 270 UIManager.put("OptionPane.noIcon", UIManager.get("OptionPane.cancelIcon")); 387 } 388 389 /** 390 * Setup an exception handler that displays a sorry message and the possibility 391 * to do a bug report. 392 */ 393 private static void setupExceptionHandler() { 394 Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler()); 271 272 Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); 273 if (args.containsKey("geometry")) { 274 String geometry = args.get("geometry").iterator().next(); 275 final Matcher m = Pattern.compile("(\\d+)x(\\d+)(([+-])(\\d+)([+-])(\\d+))?").matcher(geometry); 276 if (m.matches()) { 277 int w = Integer.valueOf(m.group(1)); 278 int h = Integer.valueOf(m.group(2)); 279 int x = 0, y = 0; 280 if (m.group(3) != null) { 281 x = Integer.valueOf(m.group(5)); 282 y = Integer.valueOf(m.group(7)); 283 if (m.group(4).equals("-")) 284 x = screenDimension.width - x - w; 285 if (m.group(6).equals("-")) 286 y = screenDimension.height - y - h; 287 } 288 bounds = new Rectangle(x,y,w,h); 289 } else 290 System.out.println("Ignoring malformed geometry: "+geometry); 291 } 292 if (bounds == null) 293 bounds = !args.containsKey("no-fullscreen") ? new Rectangle(0,0,screenDimension.width,screenDimension.height) : new Rectangle(1000,740); 294 } 295 296 public void postConstructorProcessCmdLine(Map<String, Collection<String>> args) { 297 if (args.containsKey("download")) 298 for (String s : args.get("download")) 299 downloadFromParamString(false, s); 300 if (args.containsKey("downloadgps")) 301 for (String s : args.get("downloadgps")) 302 downloadFromParamString(true, s); 303 if (args.containsKey("selection")) 304 for (String s : args.get("selection")) 305 SelectionListDialog.search(s, SelectionListDialog.SearchMode.add); 306 } 307 308 private static void downloadFromParamString(final boolean rawGps, String s) { 309 if (s.startsWith("http:")) { 310 final Bounds b = DownloadAction.osmurl2bounds(s); 311 if (b == null) 312 JOptionPane.showMessageDialog(Main.parent, "Ignoring malformed url: '"+s+"'"); 313 else 314 main.downloadAction.download(false, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon()); 315 return; 316 } 317 318 if (s.startsWith("file:")) { 319 try { 320 main.openAction.openFile(new File(new URI(s))); 321 } catch (URISyntaxException e) { 322 JOptionPane.showMessageDialog(Main.parent, "Ignoring malformed file url: '"+s+"'"); 323 } 324 return; 325 } 326 327 final StringTokenizer st = new StringTokenizer(s, ","); 328 if (st.countTokens() == 4) { 329 try { 330 main.downloadAction.download(rawGps, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken())); 331 return; 332 } catch (final NumberFormatException e) { 333 } 334 } 335 336 main.openAction.openFile(new File(s)); 395 337 } 396 338 } -
src/org/openstreetmap/josm/actions/AboutAction.java
r71 r98 67 67 about.setPreferredSize(new Dimension(500,300)); 68 68 69 JOptionPane.showMessageDialog(Main. main, about, "About JOSM...",69 JOptionPane.showMessageDialog(Main.parent, about, "About JOSM...", 70 70 JOptionPane.INFORMATION_MESSAGE, ImageProvider.get("logo")); 71 71 } -
src/org/openstreetmap/josm/actions/DiskAccessAction.java
r86 r98 44 44 fc.setAcceptAllFileFilterUsed(true); 45 45 46 int answer = open ? fc.showOpenDialog(Main. main) : fc.showSaveDialog(Main.main);46 int answer = open ? fc.showOpenDialog(Main.parent) : fc.showSaveDialog(Main.parent); 47 47 if (answer != JFileChooser.APPROVE_OPTION) 48 48 return null; … … 54 54 File file = fc.getSelectedFile(); 55 55 if (file == null || (file.exists() && JOptionPane.YES_OPTION != 56 JOptionPane.showConfirmDialog(Main. main, "File exists. Overwrite?", "Overwrite", JOptionPane.YES_NO_OPTION)))56 JOptionPane.showConfirmDialog(Main.parent, "File exists. Overwrite?", "Overwrite", JOptionPane.YES_NO_OPTION))) 57 57 return null; 58 58 } -
src/org/openstreetmap/josm/actions/DownloadAction.java
r95 r98 33 33 import org.openstreetmap.josm.data.osm.DataSet; 34 34 import org.openstreetmap.josm.gui.BookmarkList; 35 import org.openstreetmap.josm.gui.MapFrame;36 35 import org.openstreetmap.josm.gui.MapView; 37 36 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 38 37 import org.openstreetmap.josm.gui.WorldChooser; 39 38 import org.openstreetmap.josm.gui.BookmarkList.Bookmark; 40 import org.openstreetmap.josm.gui.layer.Layer;41 39 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 42 40 import org.openstreetmap.josm.gui.layer.RawGpsDataLayer; … … 79 77 if (dataSet.nodes.isEmpty()) 80 78 errorMessage = "No data imported."; 81 Layer layer = new OsmDataLayer(dataSet, "Data Layer", false); 82 if (Main.main.getMapFrame() == null) 83 Main.main.setMapFrame(new MapFrame(layer)); 84 else 85 Main.main.getMapFrame().mapView.addLayer(layer); 79 Main.main.addLayer(new OsmDataLayer(dataSet, "Data Layer", false)); 86 80 } 87 81 … … 110 104 return; 111 105 String name = latlon[0].getText() + " " + latlon[1].getText() + " x " + latlon[2].getText() + " " + latlon[3].getText(); 112 Layer layer = new RawGpsDataLayer(rawData, name); 113 if (Main.main.getMapFrame() == null) 114 Main.main.setMapFrame(new MapFrame(layer)); 115 else 116 Main.main.getMapFrame().mapView.addLayer(layer); 106 Main.main.addLayer(new RawGpsDataLayer(rawData, name)); 117 107 } 118 108 … … 145 135 //TODO: Remove this in later versions (temporary only) 146 136 if (osmDataServer.endsWith("/0.2") || osmDataServer.endsWith("/0.2/")) { 147 int answer = JOptionPane.showConfirmDialog(Main. main,137 int answer = JOptionPane.showConfirmDialog(Main.parent, 148 138 "You seem to have an outdated server entry in your preferences.\n" + 149 139 "\n" + … … 175 165 dlg.add(new JLabel("max lon"), GBC.std().insets(10,0,5,0)); 176 166 dlg.add(latlon[3], GBC.eol()); 177 if (Main.ma in.getMapFrame()!= null) {178 MapView mv = Main.ma in.getMapFrame().mapView;167 if (Main.map != null) { 168 MapView mv = Main.map.mapView; 179 169 setEditBounds(new Bounds( 180 170 mv.getLatLon(0, mv.getHeight()), … … 260 250 Bookmark b = readBookmark(); 261 251 if (b == null) { 262 JOptionPane.showMessageDialog(Main. main, "Please enter the desired coordinates first.");252 JOptionPane.showMessageDialog(Main.parent, "Please enter the desired coordinates first."); 263 253 return; 264 254 } 265 b.name = JOptionPane.showInputDialog(Main. main, "Please enter a name for the location.");255 b.name = JOptionPane.showInputDialog(Main.parent, "Please enter a name for the location."); 266 256 if (b.name != null && !b.name.equals("")) { 267 257 ((DefaultListModel)bookmarks.getModel()).addElement(b); … … 276 266 Object sel = bookmarks.getSelectedValue(); 277 267 if (sel == null) { 278 JOptionPane.showMessageDialog(Main. main, "Select a bookmark first.");268 JOptionPane.showMessageDialog(Main.parent, "Select a bookmark first."); 279 269 return; 280 270 } … … 293 283 Bookmark b; 294 284 do { 295 int r = JOptionPane.showConfirmDialog(Main. main, dlg, "Choose an area",285 int r = JOptionPane.showConfirmDialog(Main.parent, dlg, "Choose an area", 296 286 JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); 297 287 if (r != JOptionPane.OK_OPTION) … … 299 289 b = readBookmark(); 300 290 if (b == null) 301 JOptionPane.showMessageDialog(Main. main, "Please enter the desired coordinates or click on a bookmark.");291 JOptionPane.showMessageDialog(Main.parent, "Please enter the desired coordinates or click on a bookmark."); 302 292 } while (b == null); 303 293 -
src/org/openstreetmap/josm/actions/GpxExportAction.java
r86 r98 46 46 47 47 public void actionPerformed(ActionEvent e) { 48 if (layer == null && Main.ma in.getMapFrame()== null) {49 JOptionPane.showMessageDialog(Main. main, "Nothing to export. Get some data first.");48 if (layer == null && Main.map == null) { 49 JOptionPane.showMessageDialog(Main.parent, "Nothing to export. Get some data first."); 50 50 return; 51 51 } … … 102 102 p.add(keywords, GBC.eop().fill(GBC.HORIZONTAL)); 103 103 104 int answer = JOptionPane.showConfirmDialog(Main. main, p, "Export options", JOptionPane.OK_CANCEL_OPTION);104 int answer = JOptionPane.showConfirmDialog(Main.parent, p, "Export options", JOptionPane.OK_CANCEL_OPTION); 105 105 if (answer != JOptionPane.OK_OPTION) 106 106 return; … … 113 113 114 114 try { 115 Layer layer = this.layer == null ? Main.main. getMapFrame().mapView.editLayer() : this.layer;115 Layer layer = this.layer == null ? Main.main.editLayer() : this.layer; 116 116 FileWriter out = new FileWriter(file); 117 117 GpxWriter w = new GpxWriter(out, layer.name, desc.getText(), … … 125 125 } catch (IOException x) { 126 126 x.printStackTrace(); 127 JOptionPane.showMessageDialog(Main. main, "Error while exporting "+fn+":\n"+x.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);127 JOptionPane.showMessageDialog(Main.parent, "Error while exporting "+fn+":\n"+x.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 128 128 } 129 129 } … … 179 179 l.setVisibleRowCount(4); 180 180 l.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 181 int answer = JOptionPane.showConfirmDialog(Main. main, new JScrollPane(l), "Choose a predefined license", JOptionPane.OK_CANCEL_OPTION);181 int answer = JOptionPane.showConfirmDialog(Main.parent, new JScrollPane(l), "Choose a predefined license", JOptionPane.OK_CANCEL_OPTION); 182 182 if (answer != JOptionPane.OK_OPTION || l.getSelectedIndex() == -1) 183 183 return; -
src/org/openstreetmap/josm/actions/GroupAction.java
r94 r98 10 10 import javax.swing.Action; 11 11 import javax.swing.Icon; 12 import javax.swing.JComponent; 12 13 import javax.swing.JMenuItem; 13 14 import javax.swing.JPopupMenu; 14 15 import javax.swing.KeyStroke; 15 16 17 import org.openstreetmap.josm.Main; 16 18 import org.openstreetmap.josm.gui.IconToggleButton; 17 19 import org.openstreetmap.josm.tools.ImageProvider; … … 49 51 50 52 public GroupAction(int shortCut, int modifiers) { 51 registerShortCut(getClass().getName(), KeyStroke.getKeyStroke(shortCut, modifiers)); 53 String idName = getClass().getName(); 54 Main.panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(shortCut, modifiers), idName); 55 Main.panel.getActionMap().put(idName, this); 52 56 shortCutName = ShortCutLabel.name(shortCut, modifiers); 53 57 addPropertyChangeListener(new PropertyChangeListener(){ -
src/org/openstreetmap/josm/actions/JosmAction.java
r93 r98 33 33 super(name, ImageProvider.get(iconName)); 34 34 putValue(SHORT_DESCRIPTION, "<html>"+tooltip+" <font size='-2'>"+shortCutName+"</font> </html>"); 35 registerShortCut(name, shortCut); 35 Main.panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(shortCut, name); 36 Main.panel.getActionMap().put(name, this); 36 37 } 37 38 38 39 public JosmAction() { 39 40 } 40 41 public void registerShortCut(String idName, KeyStroke shortCut) {42 Main.main.panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(shortCut, idName);43 Main.main.panel.getActionMap().put(idName, this);44 }45 41 } -
src/org/openstreetmap/josm/actions/OpenAction.java
r79 r98 17 17 import org.openstreetmap.josm.Main; 18 18 import org.openstreetmap.josm.data.osm.DataSet; 19 import org.openstreetmap.josm.gui.MapFrame;20 import org.openstreetmap.josm.gui.layer.Layer;21 19 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 22 20 import org.openstreetmap.josm.gui.layer.RawGpsDataLayer; … … 59 57 String fn = filename.getName(); 60 58 try { 61 Layer layer;62 63 59 if (asRawData(fn)) { 64 60 Collection<Collection<GpsPoint>> data; … … 70 66 } else 71 67 throw new IllegalStateException(); 72 layer = new RawGpsDataLayer(data, filename.getName());68 Main.main.addLayer(new RawGpsDataLayer(data, filename.getName())); 73 69 } else { 74 70 DataSet dataSet; 75 71 if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) { 76 JOptionPane.showMessageDialog(Main. main, "Warning: Soon, it will be no longer possible to open GPX files as osm data. Please convert your files to .osm format.");72 JOptionPane.showMessageDialog(Main.parent, "Warning: Soon, it will be no longer possible to open GPX files as osm data. Please convert your files to .osm format."); 77 73 dataSet = new GpxReader(new FileReader(filename)).parse(); 78 74 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) { … … 82 78 } catch (SAXException x) { 83 79 if (x.getMessage().equals("Unknown version null")) { 84 int answer = JOptionPane.showConfirmDialog(Main. main,80 int answer = JOptionPane.showConfirmDialog(Main.parent, 85 81 fn+" seems to be an old 0.2 API XML file.\n" + 86 82 "JOSM can try to open it with the old parser. This option\n" + … … 96 92 } 97 93 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 98 JOptionPane.showMessageDialog(Main. main, fn+": CSV Data import for non-GPS data is not implemented yet.");94 JOptionPane.showMessageDialog(Main.parent, fn+": CSV Data import for non-GPS data is not implemented yet."); 99 95 return; 100 96 } else { 101 JOptionPane.showMessageDialog(Main. main, fn+": Unknown file extension: "+fn.substring(filename.getName().lastIndexOf('.')+1));97 JOptionPane.showMessageDialog(Main.parent, fn+": Unknown file extension: "+fn.substring(filename.getName().lastIndexOf('.')+1)); 102 98 return; 103 99 } 104 layer = new OsmDataLayer(dataSet, "Data Layer", true);100 Main.main.addLayer(new OsmDataLayer(dataSet, "Data Layer", true)); 105 101 } 106 107 if (Main.main.getMapFrame() == null)108 Main.main.setMapFrame(new MapFrame(layer));109 else110 Main.main.getMapFrame().mapView.addLayer(layer);111 112 102 } catch (SAXException x) { 113 103 x.printStackTrace(); 114 JOptionPane.showMessageDialog(Main. main, "Error while parsing: "+x.getMessage());104 JOptionPane.showMessageDialog(Main.parent, "Error while parsing: "+x.getMessage()); 115 105 } catch (JDOMException x) { 116 106 x.printStackTrace(); 117 JOptionPane.showMessageDialog(Main. main, "Error while parsing: "+x.getMessage());107 JOptionPane.showMessageDialog(Main.parent, "Error while parsing: "+x.getMessage()); 118 108 } catch (IOException x) { 119 109 x.printStackTrace(); 120 JOptionPane.showMessageDialog(Main. main, "Could not read '"+fn+"'\n"+x.getMessage());110 JOptionPane.showMessageDialog(Main.parent, "Could not read '"+fn+"'\n"+x.getMessage()); 121 111 } 122 112 } … … 132 122 return false; 133 123 return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog( 134 Main. main, "Do you want to open "+fn+" as raw gps data?",124 Main.parent, "Do you want to open "+fn+" as raw gps data?", 135 125 "Open as raw data?", JOptionPane.YES_NO_OPTION); 136 126 } -
src/org/openstreetmap/josm/actions/RedoAction.java
r68 r98 26 26 27 27 public void actionPerformed(ActionEvent e) { 28 if (Main.ma in.getMapFrame()== null)28 if (Main.map == null) 29 29 return; 30 Main.ma in.getMapFrame().repaint();31 Main.main. getMapFrame().mapView.editLayer().redo();30 Main.map.repaint(); 31 Main.main.editLayer().redo(); 32 32 } 33 33 } -
src/org/openstreetmap/josm/actions/SaveAction.java
r86 r98 35 35 36 36 public void actionPerformed(ActionEvent event) { 37 if (Main.ma in.getMapFrame()== null) {38 JOptionPane.showMessageDialog(Main. main, "No document open so nothing to save.");37 if (Main.map == null) { 38 JOptionPane.showMessageDialog(Main.parent, "No document open so nothing to save."); 39 39 return; 40 40 } 41 if (isDataSetEmpty() && JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(Main. main, "The document contains no data. Save anyway?", "Empty document", JOptionPane.YES_NO_OPTION))41 if (isDataSetEmpty() && JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(Main.parent, "The document contains no data. Save anyway?", "Empty document", JOptionPane.YES_NO_OPTION)) 42 42 return; 43 if (!Main.ma in.getMapFrame().conflictDialog.conflicts.isEmpty()) {44 int answer = JOptionPane.showConfirmDialog(Main. main,43 if (!Main.map.conflictDialog.conflicts.isEmpty()) { 44 int answer = JOptionPane.showConfirmDialog(Main.parent, 45 45 "There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?", "Conflicts", JOptionPane.YES_NO_OPTION); 46 46 if (answer != JOptionPane.YES_OPTION) … … 68 68 for (Segment ls : Main.ds.segments) { 69 69 if (ls.incomplete) { 70 JOptionPane.showMessageDialog(Main. main, "Export of data containing incomplete ways to GPX is not implemented.\nBe aware, that in future versions of JOSM, GPX support will be kept at a minimum.\nPlease use .osm or .xml as extension for the better OSM support.");70 JOptionPane.showMessageDialog(Main.parent, "Export of data containing incomplete ways to GPX is not implemented.\nBe aware, that in future versions of JOSM, GPX support will be kept at a minimum.\nPlease use .osm or .xml as extension for the better OSM support."); 71 71 return; 72 72 } … … 76 76 OsmWriter.output(fileWriter = new FileWriter(file), Main.ds, false); 77 77 else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 78 JOptionPane.showMessageDialog(Main. main, "CSV output not supported yet.");78 JOptionPane.showMessageDialog(Main.parent, "CSV output not supported yet."); 79 79 return; 80 80 } else { 81 JOptionPane.showMessageDialog(Main. main, "Unknown file extension.");81 JOptionPane.showMessageDialog(Main.parent, "Unknown file extension."); 82 82 return; 83 83 } 84 84 fileWriter.close(); 85 Main.main. getMapFrame().mapView.editLayer().cleanData(null, false);85 Main.main.editLayer().cleanData(null, false); 86 86 } catch (IOException e) { 87 87 e.printStackTrace(); 88 JOptionPane.showMessageDialog(Main. main, "An error occoured while saving.\n"+e.getMessage());88 JOptionPane.showMessageDialog(Main.parent, "An error occoured while saving.\n"+e.getMessage()); 89 89 } 90 90 } -
src/org/openstreetmap/josm/actions/UndoAction.java
r68 r98 26 26 27 27 public void actionPerformed(ActionEvent e) { 28 if (Main.ma in.getMapFrame()== null)28 if (Main.map == null) 29 29 return; 30 Main.ma in.getMapFrame().repaint();31 Main.main. getMapFrame().mapView.editLayer().undo();30 Main.map.repaint(); 31 Main.main.editLayer().undo(); 32 32 } 33 33 } -
src/org/openstreetmap/josm/actions/UploadAction.java
r92 r98 43 43 //TODO: Remove this in later versions (temporary only) 44 44 if (osmDataServer.endsWith("/0.2") || osmDataServer.endsWith("/0.2/")) { 45 int answer = JOptionPane.showConfirmDialog(Main. main,45 int answer = JOptionPane.showConfirmDialog(Main.parent, 46 46 "You seem to have an outdated server entry in your preferences.\n" + 47 47 "\n" + … … 56 56 } 57 57 58 if (!Main.ma in.getMapFrame().conflictDialog.conflicts.isEmpty()) {59 JOptionPane.showMessageDialog(Main. main, "There are unresolved conflicts. You have to resolve these first.");60 Main.ma in.getMapFrame().conflictDialog.action.button.setSelected(true);61 Main.ma in.getMapFrame().conflictDialog.action.actionPerformed(null);58 if (!Main.map.conflictDialog.conflicts.isEmpty()) { 59 JOptionPane.showMessageDialog(Main.parent, "There are unresolved conflicts. You have to resolve these first."); 60 Main.map.conflictDialog.action.button.setSelected(true); 61 Main.map.conflictDialog.action.actionPerformed(null); 62 62 return; 63 63 } … … 90 90 } 91 91 @Override protected void finish() { 92 Main.main. getMapFrame().mapView.editLayer().cleanData(server.processed, !add.isEmpty());92 Main.main.editLayer().cleanData(server.processed, !add.isEmpty()); 93 93 } 94 94 @Override protected void cancel() { … … 108 108 private boolean displayUploadScreen(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete) { 109 109 if (add.isEmpty() && update.isEmpty() && delete.isEmpty()) { 110 JOptionPane.showMessageDialog(Main. main, "No changes to upload.");110 JOptionPane.showMessageDialog(Main.parent, "No changes to upload."); 111 111 return false; 112 112 } … … 140 140 } 141 141 142 return JOptionPane.showConfirmDialog(Main. main, p, "Upload this changes?",142 return JOptionPane.showConfirmDialog(Main.parent, p, "Upload this changes?", 143 143 JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION; 144 144 } -
src/org/openstreetmap/josm/actions/WmsServerAction.java
r93 r98 4 4 import java.awt.event.KeyEvent; 5 5 6 import javax.swing.AbstractButton;7 6 import javax.swing.JOptionPane; 8 7 9 8 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.data.osm.DataSet;11 import org.openstreetmap.josm.gui.MapFrame;12 import org.openstreetmap.josm.gui.MapView;13 import org.openstreetmap.josm.gui.layer.Layer;14 import org.openstreetmap.josm.gui.layer.WmsServerLayer;15 9 16 10 public class WmsServerAction extends JosmAction { … … 21 15 22 16 public void actionPerformed(ActionEvent e) { 23 JOptionPane.showMessageDialog(Main.main, "Not implemented yet."); 24 if (1==1) return; 25 MapFrame mapFrame = Main.main.getMapFrame(); 26 if (!((AbstractButton)e.getSource()).isSelected()) { 27 if (mapFrame != null) { 28 MapView mv = mapFrame.mapView; 29 for (Layer l : mv.getAllLayers()) { 30 if (l instanceof WmsServerLayer) { 31 if (mv.getAllLayers().size() == 1) { 32 Main.main.setMapFrame(null); 33 Main.ds = new DataSet(); 34 } else 35 mv.removeLayer(l); 36 return; 37 } 38 } 39 } 40 } else { 41 WmsServerLayer layer = new WmsServerLayer(Main.pref.get("wms.baseurl", "http://wms.jpl.nasa.gov/wms.cgi?request=GetMap&width=512&height=512&layers=global_mosaic&styles=&srs=EPSG:4326&format=image/jpeg&")); 42 if (mapFrame == null) 43 Main.main.setMapFrame(new MapFrame(layer)); 44 else 45 mapFrame.mapView.addLayer(layer); 46 } 17 JOptionPane.showMessageDialog(Main.parent, "Not implemented yet."); 47 18 } 48 19 } -
src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java
r94 r98 5 5 import java.util.ArrayList; 6 6 import java.util.Collection; 7 import java.util.HashMap; 7 8 import java.util.LinkedList; 8 9 … … 51 52 @Override public void enterMode() { 52 53 super.enterMode(); 53 mv.addMouseListener(this);54 Main.map.mapView.addMouseListener(this); 54 55 } 55 56 56 57 @Override public void exitMode() { 57 58 super.exitMode(); 58 mv.removeMouseListener(this);59 Main.map.mapView.removeMouseListener(this); 59 60 } 60 61 … … 71 72 return; 72 73 73 Node n = new Node( mv.getLatLon(e.getX(), e.getY()));74 Node n = new Node(Main.map.mapView.getLatLon(e.getX(), e.getY())); 74 75 if (n.coor.isOutSideWorld()) { 75 JOptionPane.showMessageDialog(Main. main, "Can not add a node outside of the world.");76 JOptionPane.showMessageDialog(Main.parent, "Can not add a node outside of the world."); 76 77 return; 77 78 } … … 79 80 Command c = new AddCommand(n); 80 81 if (mode == Mode.nodesegment) { 81 Segment s = mv.getNearestSegment(e.getPoint());82 Segment s = Main.map.mapView.getNearestSegment(e.getPoint()); 82 83 if (s == null) 83 84 return; … … 89 90 Segment s2 = new Segment(s.from, s.to); 90 91 s2.from = n; 92 if (s.keys != null) 93 s2.keys = new HashMap<String, String>(s.keys); 91 94 92 95 cmds.add(new ChangeCommand(s, s1)); … … 110 113 c = new SequenceCommand(cmds); 111 114 } 112 mv.editLayer().add(c);113 mv.repaint();115 Main.main.editLayer().add(c); 116 Main.map.mapView.repaint(); 114 117 } 115 118 } -
src/org/openstreetmap/josm/actions/mapmode/AddSegmentAction.java
r94 r98 51 51 @Override public void enterMode() { 52 52 super.enterMode(); 53 mv.addMouseListener(this);54 mv.addMouseMotionListener(this);53 Main.map.mapView.addMouseListener(this); 54 Main.map.mapView.addMouseMotionListener(this); 55 55 } 56 56 57 57 @Override public void exitMode() { 58 58 super.exitMode(); 59 mv.removeMouseListener(this);60 mv.removeMouseMotionListener(this);59 Main.map.mapView.removeMouseListener(this); 60 Main.map.mapView.removeMouseMotionListener(this); 61 61 drawHint(false); 62 62 } … … 75 75 return; 76 76 77 OsmPrimitive clicked = mv.getNearest(e.getPoint(), true);77 OsmPrimitive clicked = Main.map.mapView.getNearest(e.getPoint(), true); 78 78 if (clicked == null || !(clicked instanceof Node)) 79 79 return; … … 91 91 return; 92 92 93 OsmPrimitive clicked = mv.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);93 OsmPrimitive clicked = Main.map.mapView.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0); 94 94 if (clicked == null || clicked == second || !(clicked instanceof Node)) 95 95 return; … … 136 136 137 137 Segment ls = new Segment(start, end); 138 mv.editLayer().add(new AddCommand(ls));138 Main.main.editLayer().add(new AddCommand(ls)); 139 139 } 140 140 141 mv.repaint();141 Main.map.mapView.repaint(); 142 142 } 143 143 … … 153 153 return; 154 154 155 Graphics g = mv.getGraphics();155 Graphics g = Main.map.mapView.getGraphics(); 156 156 g.setColor(Color.BLACK); 157 157 g.setXORMode(Color.WHITE); 158 Point firstDrawn = mv.getPoint(first.eastNorth);159 Point secondDrawn = mv.getPoint(second.eastNorth);158 Point firstDrawn = Main.map.mapView.getPoint(first.eastNorth); 159 Point secondDrawn = Main.map.mapView.getPoint(second.eastNorth); 160 160 g.drawLine(firstDrawn.x, firstDrawn.y, secondDrawn.x, secondDrawn.y); 161 161 hintDrawn = !hintDrawn; -
src/org/openstreetmap/josm/actions/mapmode/AddWayAction.java
r94 r98 69 69 c = new AddCommand(way); 70 70 Main.ds.setSelected(way); 71 mv.editLayer().add(c);71 Main.main.editLayer().add(c); 72 72 } else 73 73 Main.ds.clearSelection(); 74 mv.addMouseListener(this);74 Main.map.mapView.addMouseListener(this); 75 75 } 76 76 … … 78 78 super.exitMode(); 79 79 way = null; 80 mv.removeMouseListener(this);80 Main.map.mapView.removeMouseListener(this); 81 81 } 82 82 … … 85 85 return; 86 86 87 Segment s = mv.getNearestSegment(e.getPoint());87 Segment s = Main.map.mapView.getNearestSegment(e.getPoint()); 88 88 if (s == null) 89 89 return; … … 91 91 // special case for initial selecting one way 92 92 if (way == null && (e.getModifiers() & MouseEvent.ALT_DOWN_MASK) == 0) { 93 Way w = mv.getNearestWay(e.getPoint());93 Way w = Main.map.mapView.getNearestWay(e.getPoint()); 94 94 if (w != null) { 95 95 way = w; … … 104 104 copy.segments.remove(s); 105 105 if (copy.segments.isEmpty()) { 106 mv.editLayer().add(new DeleteCommand(Arrays.asList(new OsmPrimitive[]{way})));106 Main.main.editLayer().add(new DeleteCommand(Arrays.asList(new OsmPrimitive[]{way}))); 107 107 way = null; 108 108 } else 109 mv.editLayer().add(new ChangeCommand(way, copy));109 Main.main.editLayer().add(new ChangeCommand(way, copy)); 110 110 } else { 111 111 if (way == null) { 112 112 way = new Way(); 113 113 way.segments.add(s); 114 mv.editLayer().add(new AddCommand(way));114 Main.main.editLayer().add(new AddCommand(way)); 115 115 } else { 116 116 Way copy = new Way(way); … … 120 120 break; 121 121 copy.segments.add(i, s); 122 mv.editLayer().add(new ChangeCommand(way, copy));122 Main.main.editLayer().add(new ChangeCommand(way, copy)); 123 123 } 124 124 } … … 149 149 if (numberOfSelectedWays > 0) { 150 150 String ways = "way" + (numberOfSelectedWays==1?" has":"s have"); 151 int answer = JOptionPane.showConfirmDialog(Main. main, numberOfSelectedWays+" "+ways+" been selected.\n" +151 int answer = JOptionPane.showConfirmDialog(Main.parent, numberOfSelectedWays+" "+ways+" been selected.\n" + 152 152 "Do you wish to select all segments belonging to the "+ways+" instead?", "Add segments from ways", JOptionPane.YES_NO_OPTION); 153 153 if (answer == JOptionPane.YES_OPTION) { … … 193 193 } 194 194 195 if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(Main. main, "Create a new way out of "+sortedSegments.size()+" segments?", "Create new way", JOptionPane.YES_NO_OPTION))195 if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(Main.parent, "Create a new way out of "+sortedSegments.size()+" segments?", "Create new way", JOptionPane.YES_NO_OPTION)) 196 196 return null; 197 197 -
src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r94 r98 46 46 @Override public void enterMode() { 47 47 super.enterMode(); 48 mv.addMouseListener(this);48 Main.map.mapView.addMouseListener(this); 49 49 } 50 50 51 51 @Override public void exitMode() { 52 52 super.exitMode(); 53 mv.removeMouseListener(this);53 Main.map.mapView.removeMouseListener(this); 54 54 } 55 55 … … 62 62 else 63 63 delete(Main.ds.getSelected(), false); 64 mv.repaint();64 Main.map.repaint(); 65 65 } 66 66 … … 73 73 return; 74 74 75 OsmPrimitive sel = mv.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);75 OsmPrimitive sel = Main.map.mapView.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0); 76 76 if (sel == null) 77 77 return; … … 82 82 delete(Collections.singleton(sel), true); 83 83 84 mv.repaint();84 Main.map.mapView.repaint(); 85 85 } 86 86 … … 107 107 v.data.addAll(selection); 108 108 if (!v.data.isEmpty()) 109 mv.editLayer().add(new DeleteCommand(v.data));109 Main.main.editLayer().add(new DeleteCommand(v.data)); 110 110 } 111 111 … … 125 125 if (!selection.containsAll(v.data)) { 126 126 if (msgBox) { 127 JOptionPane.showMessageDialog(Main. main, "This object is in use.");127 JOptionPane.showMessageDialog(Main.parent, "This object is in use."); 128 128 return; 129 129 } … … 134 134 } 135 135 if (!del.isEmpty()) 136 mv.editLayer().add(new DeleteCommand(del));136 Main.main.editLayer().add(new DeleteCommand(del)); 137 137 } 138 138 } -
src/org/openstreetmap/josm/actions/mapmode/MapMode.java
r94 r98 8 8 import javax.swing.KeyStroke; 9 9 10 import org.openstreetmap.josm.Main; 10 11 import org.openstreetmap.josm.actions.JosmAction; 11 12 import org.openstreetmap.josm.gui.MapFrame; 12 import org.openstreetmap.josm.gui.MapView;13 13 import org.openstreetmap.josm.tools.ImageProvider; 14 14 … … 24 24 25 25 /** 26 * The parent mapframe this mode belongs to.27 */28 protected final MapFrame mapFrame;29 /**30 * Shortcut to the MapView.31 */32 protected final MapView mv;33 34 /**35 26 * Constructor for mapmodes without an menu 36 27 */ 37 28 public MapMode(String name, String iconName, String tooltip, String keyname, int keystroke, MapFrame mapFrame) { 38 29 super(name, "mapmode/"+iconName, tooltip, keyname, KeyStroke.getKeyStroke(keystroke, 0)); 39 this.mapFrame = mapFrame;40 mv = mapFrame.mapView;41 30 putValue("active", false); 42 31 } … … 49 38 putValue(SMALL_ICON, ImageProvider.get("mapmode", iconName)); 50 39 putValue(SHORT_DESCRIPTION, tooltip); 51 this.mapFrame = mapFrame;52 mv = mapFrame.mapView;53 40 } 54 41 … … 64 51 */ 65 52 public void actionPerformed(ActionEvent e) { 66 mapFrame.selectMapMode(this);53 Main.map.selectMapMode(this); 67 54 } 68 55 -
src/org/openstreetmap/josm/actions/mapmode/MoveAction.java
r96 r98 53 53 @Override public void enterMode() { 54 54 super.enterMode(); 55 mv.addMouseListener(this);56 mv.addMouseMotionListener(this);55 Main.map.mapView.addMouseListener(this); 56 Main.map.mapView.addMouseMotionListener(this); 57 57 } 58 58 59 59 @Override public void exitMode() { 60 60 super.exitMode(); 61 mv.removeMouseListener(this);62 mv.removeMouseMotionListener(this);61 Main.map.mapView.removeMouseListener(this); 62 Main.map.mapView.removeMouseMotionListener(this); 63 63 } 64 64 … … 77 77 } 78 78 79 EastNorth mouseGeo = mv.getEastNorth(e.getX(), e.getY());80 EastNorth mouseStartGeo = mv.getEastNorth(mousePos.x, mousePos.y);79 EastNorth mouseGeo = Main.map.mapView.getEastNorth(e.getX(), e.getY()); 80 EastNorth mouseStartGeo = Main.map.mapView.getEastNorth(mousePos.x, mousePos.y); 81 81 double dx = mouseGeo.east() - mouseStartGeo.east(); 82 82 double dy = mouseGeo.north() - mouseStartGeo.north(); … … 90 90 for (OsmPrimitive osm : affectedNodes) { 91 91 if (osm instanceof Node && ((Node)osm).coor.isOutSideWorld()) { 92 JOptionPane.showMessageDialog(Main. main, "Cannot move objects outside of the world.");92 JOptionPane.showMessageDialog(Main.parent, "Cannot move objects outside of the world."); 93 93 return; 94 94 } 95 95 } 96 96 97 Command c = ! mv.editLayer().commands.isEmpty() ? mv.editLayer().commands.getLast() : null;97 Command c = !Main.main.editLayer().commands.isEmpty() ? Main.main.editLayer().commands.getLast() : null; 98 98 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand)c).objects)) 99 99 ((MoveCommand)c).moveAgain(dx,dy); 100 100 else 101 mv.editLayer().add(new MoveCommand(selection, dx, dy));101 Main.main.editLayer().add(new MoveCommand(selection, dx, dy)); 102 102 103 mv.repaint();103 Main.map.mapView.repaint(); 104 104 mousePos = e.getPoint(); 105 105 } … … 119 119 120 120 if (Main.ds.getSelected().size() == 0) { 121 OsmPrimitive osm = mv.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);121 OsmPrimitive osm = Main.map.mapView.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0); 122 122 if (osm != null) 123 123 Main.ds.setSelected(osm); 124 124 singleOsmPrimitive = osm; 125 mv.repaint();125 Main.map.mapView.repaint(); 126 126 } else 127 127 singleOsmPrimitive = null; 128 128 129 129 mousePos = e.getPoint(); 130 oldCursor = mv.getCursor();131 mv.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));130 oldCursor = Main.map.mapView.getCursor(); 131 Main.map.mapView.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 132 132 } 133 133 … … 136 136 */ 137 137 @Override public void mouseReleased(MouseEvent e) { 138 mv.setCursor(oldCursor);138 Main.map.mapView.setCursor(oldCursor); 139 139 if (singleOsmPrimitive != null) { 140 140 Main.ds.clearSelection(); 141 mv.repaint();141 Main.map.mapView.repaint(); 142 142 } 143 143 } -
src/org/openstreetmap/josm/actions/mapmode/SelectionAction.java
r94 r98 65 65 public SelectionAction(MapFrame mapFrame) { 66 66 super("Selection", "selection", "Select objects by dragging or clicking.", "S", KeyEvent.VK_S, mapFrame); 67 this.selectionManager = new SelectionManager(this, false, m v);67 this.selectionManager = new SelectionManager(this, false, mapFrame.mapView); 68 68 } 69 69 70 70 @Override public void enterMode() { 71 71 super.enterMode(); 72 selectionManager.register( mv);72 selectionManager.register(Main.map.mapView); 73 73 } 74 74 75 75 @Override public void exitMode() { 76 76 super.exitMode(); 77 selectionManager.unregister( mv);77 selectionManager.unregister(Main.map.mapView); 78 78 } 79 79 … … 99 99 curSel.add(osm); 100 100 Main.ds.setSelected(curSel); 101 mv.repaint();101 Main.map.mapView.repaint(); 102 102 } 103 103 } -
src/org/openstreetmap/josm/command/Command.java
r94 r98 16 16 * 17 17 * Remember, that the command must be executable and undoable, even if the 18 * Main. main.ds has changed, so the command must save the dataset it operates on18 * Main.ds has changed, so the command must save the dataset it operates on 19 19 * if necessary. 20 20 * -
src/org/openstreetmap/josm/command/ConflictResolveCommand.java
r94 r98 30 30 this.conflicts = conflicts; 31 31 this.resolved = resolved; 32 conflictDialog = Main.ma in.getMapFrame().conflictDialog;32 conflictDialog = Main.map.conflictDialog; 33 33 } 34 34 … … 53 53 conflictDialog.conflicts.remove(k); 54 54 conflictDialog.rebuildList(); 55 Main.ma in.getMapFrame().mapView.recalculateCenterScale(); // in case of auto-zoom55 Main.map.mapView.recalculateCenterScale(); // in case of auto-zoom 56 56 } 57 57 } … … 59 59 @Override public void undoCommand() { 60 60 super.undoCommand(); 61 Main.ma in.getMapFrame().conflictDialog.conflicts.clear();62 Main.ma in.getMapFrame().conflictDialog.conflicts.putAll(origAllConflicts);63 Main.ma in.getMapFrame().conflictDialog.rebuildList();61 Main.map.conflictDialog.conflicts.clear(); 62 Main.map.conflictDialog.conflicts.putAll(origAllConflicts); 63 Main.map.conflictDialog.rebuildList(); 64 64 } 65 65 -
src/org/openstreetmap/josm/data/Preferences.java
r79 r98 31 31 } 32 32 33 ArrayList<PreferenceChangedListener> listener = new ArrayList<PreferenceChangedListener>();33 public final ArrayList<PreferenceChangedListener> listener = new ArrayList<PreferenceChangedListener>(); 34 34 35 35 /** 36 36 * Map the property name to the property object. 37 37 */ 38 private SortedMap<String, String> properties = new TreeMap<String, String>();38 private final SortedMap<String, String> properties = new TreeMap<String, String>(); 39 39 40 40 /** 41 41 * Return the location of the preferences file 42 42 */ 43 public staticString getPreferencesDir() {43 public String getPreferencesDir() { 44 44 return System.getProperty("user.home")+"/.josm/"; 45 45 } 46 46 47 48 public void addPreferenceChangedListener(PreferenceChangedListener listener) { 49 this.listener.add(listener); 50 } 51 public void removePreferenceChangedListener(PreferenceChangedListener listener) { 52 this.listener.remove(listener); 53 } 54 55 56 synchronized public String get(String key) { 47 synchronized final public String get(final String key) { 57 48 if (!properties.containsKey(key)) 58 49 return ""; 59 50 return properties.get(key); 60 51 } 61 synchronized public String get(String key,String def) {62 String prop = properties.get(key);52 synchronized final public String get(final String key, final String def) { 53 final String prop = properties.get(key); 63 54 if (prop == null || prop.equals("")) 64 55 return def; 65 56 return prop; 66 57 } 67 synchronized public Map<String, String> getAllPrefix(String prefix) {68 Map<String,String> all = new TreeMap<String,String>();69 for ( Entry<String,String> e : properties.entrySet())58 synchronized final public Map<String, String> getAllPrefix(final String prefix) { 59 final Map<String,String> all = new TreeMap<String,String>(); 60 for (final Entry<String,String> e : properties.entrySet()) 70 61 if (e.getKey().startsWith(prefix)) 71 62 all.put(e.getKey(), e.getValue()); 72 63 return all; 73 64 } 74 synchronized public boolean getBoolean(String key) {65 synchronized final public boolean getBoolean(final String key) { 75 66 return getBoolean(key, false); 76 67 } 77 synchronized public boolean getBoolean(String key,boolean def) {68 synchronized final public boolean getBoolean(final String key, final boolean def) { 78 69 return properties.containsKey(key) ? Boolean.parseBoolean(properties.get(key)) : def; 79 70 } 80 71 81 72 82 synchronized public void put(String key,String value) {73 synchronized final public void put(final String key, final String value) { 83 74 if (value == null) 84 75 properties.remove(key); … … 88 79 firePreferenceChanged(key, value); 89 80 } 90 synchronized public void put(String key,boolean value) {81 synchronized final public void put(final String key, final boolean value) { 91 82 properties.put(key, Boolean.toString(value)); 92 83 save(); … … 94 85 } 95 86 96 private void firePreferenceChanged(String key,String value) {97 for ( PreferenceChangedListener l : listener)87 private final void firePreferenceChanged(final String key, final String value) { 88 for (final PreferenceChangedListener l : listener) 98 89 l.preferenceChanged(key, value); 99 90 } … … 104 95 * in log. 105 96 */ 106 pr ivatevoid save() {97 protected void save() { 107 98 try { 108 PrintWriter out = new PrintWriter(new FileWriter(99 final PrintWriter out = new PrintWriter(new FileWriter( 109 100 getPreferencesDir() + "preferences")); 110 for ( Entry<String, String> e : properties.entrySet())101 for (final Entry<String, String> e : properties.entrySet()) 111 102 if (!e.getValue().equals("")) 112 103 out.println(e.getKey() + "=" + e.getValue()); 113 104 out.close(); 114 } catch ( IOException e) {105 } catch (final IOException e) { 115 106 e.printStackTrace(); 116 107 // do not message anything, since this can be called from strange … … 122 113 public void load() throws IOException { 123 114 properties.clear(); 124 BufferedReader in = new BufferedReader(new FileReader(getPreferencesDir()+"preferences"));115 final BufferedReader in = new BufferedReader(new FileReader(getPreferencesDir()+"preferences")); 125 116 int lineNumber = 0; 126 117 for (String line = in.readLine(); line != null; line = in.readLine(), lineNumber++) { 127 int i = line.indexOf('=');118 final int i = line.indexOf('='); 128 119 if (i == -1 || i == 0) 129 120 throw new IOException("Malformed config file at line "+lineNumber); … … 132 123 } 133 124 134 public void resetToDefault() {125 public final void resetToDefault() { 135 126 properties.clear(); 136 127 properties.put("laf", "javax.swing.plaf.metal.MetalLookAndFeel"); -
src/org/openstreetmap/josm/gui/BookmarkList.java
r86 r98 17 17 18 18 import org.openstreetmap.josm.Main; 19 import org.openstreetmap.josm.data.Preferences;20 19 import org.openstreetmap.josm.tools.ImageProvider; 21 20 … … 38 37 } 39 38 } 40 39 41 40 /** 42 41 * Create a bookmark list as well as the Buttons add and remove. … … 64 63 DefaultListModel model = (DefaultListModel)getModel(); 65 64 model.removeAllElements(); 66 File bookmarkFile = new File( Preferences.getPreferencesDir()+"bookmarks");65 File bookmarkFile = new File(Main.pref.getPreferencesDir()+"bookmarks"); 67 66 try { 68 67 if (!bookmarkFile.exists()) 69 68 bookmarkFile.createNewFile(); 70 69 BufferedReader in = new BufferedReader(new FileReader(bookmarkFile)); 71 70 72 71 for (String line = in.readLine(); line != null; line = in.readLine()) { 73 72 StringTokenizer st = new StringTokenizer(line, ","); … … 87 86 in.close(); 88 87 } catch (IOException e) { 89 JOptionPane.showMessageDialog(Main. main, "Could not read bookmarks.\n"+e.getMessage());88 JOptionPane.showMessageDialog(Main.parent, "Could not read bookmarks.\n"+e.getMessage()); 90 89 } 91 90 } … … 95 94 */ 96 95 public void save() { 97 File bookmarkFile = new File( Preferences.getPreferencesDir()+"bookmarks");96 File bookmarkFile = new File(Main.pref.getPreferencesDir()+"bookmarks"); 98 97 try { 99 98 if (!bookmarkFile.exists()) … … 111 110 out.close(); 112 111 } catch (IOException e) { 113 JOptionPane.showMessageDialog(Main. main, "Could not write bookmark.\n"+e.getMessage());112 JOptionPane.showMessageDialog(Main.parent, "Could not write bookmark.\n"+e.getMessage()); 114 113 } 115 114 } -
src/org/openstreetmap/josm/gui/MapFrame.java
r94 r98 59 59 60 60 public ConflictDialog conflictDialog; 61 private JPanel toggleDialogs = new JPanel(); 61 62 62 63 /** … … 115 116 }); 116 117 117 JPanel toggleDialogs = new JPanel();118 118 add(toggleDialogs, BorderLayout.EAST); 119 toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS)); 119 120 120 toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS));121 121 addIconToggle(toggleDialogs, new LayerList(this)); 122 122 addIconToggle(toggleDialogs, new PropertiesDialog(this)); … … 129 129 } 130 130 131 /** 132 * Open all ToggleDialogs that have their preferences property set. Close all others. 133 */ 134 public void setVisibleDialogs() { 135 for (Component c : toggleDialogs.getComponents()) 136 if (c instanceof ToggleDialog) 137 c.setVisible(Main.pref.getBoolean(((ToggleDialog)c).prefName+".visible")); 138 } 131 139 132 140 private void addIconToggle(JPanel toggleDialogs, ToggleDialog dlg) { … … 135 143 toolBarActions.add(button); 136 144 toggleDialogs.add(dlg); 137 if (Main.pref.getBoolean(dlg.action.prefname+".visible"))138 dlg.action.actionPerformed(new ActionEvent(this, 0, ""));139 145 } 140 146 -
src/org/openstreetmap/josm/gui/MapView.java
r94 r98 10 10 import java.util.Collections; 11 11 import java.util.LinkedList; 12 13 import javax.swing.JOptionPane; 12 14 13 15 import org.openstreetmap.josm.Main; … … 62 64 * Direct link to the edit layer (if any) in the layers list. 63 65 */ 64 p rivateOsmDataLayer editLayer;66 public OsmDataLayer editLayer; 65 67 /** 66 68 * The layer from the layers list that is currently active. … … 108 110 dataLayer.listenerModified.add(new ModifiedChangedListener(){ 109 111 public void modifiedChanged(boolean value, OsmDataLayer source) { 110 Main.main.setTitle((value?"*":"")+"Java Open Street Map - Editor");112 JOptionPane.getFrameForComponent(Main.parent).setTitle((value?"*":"")+"Java Open Street Map - Editor"); 111 113 } 112 114 }); … … 290 292 291 293 /** 292 * @return The current edit layer. If no edit layer exist, one is created.293 * So editLayer does never return <code>null</code>.294 */295 public OsmDataLayer editLayer() {296 if (editLayer == null)297 addLayer(new OsmDataLayer(Main.ds, "unnamed", false));298 return editLayer;299 }300 301 /**302 294 * In addition to the base class funcitonality, this keep trak of the autoscale 303 295 * feature. -
src/org/openstreetmap/josm/gui/PleaseWaitRunnable.java
r95 r98 44 44 */ 45 45 public PleaseWaitRunnable(String msg) { 46 pleaseWaitDlg = new JDialog( Main.main, msg, true);46 pleaseWaitDlg = new JDialog(JOptionPane.getFrameForComponent(Main.parent), msg, true); 47 47 pleaseWaitDlg.setLayout(new GridBagLayout()); 48 48 JPanel pane = new JPanel(new GridBagLayout()); … … 54 54 pleaseWaitDlg.setContentPane(pane); 55 55 pleaseWaitDlg.setSize(350,100); 56 pleaseWaitDlg.setLocationRelativeTo(Main. main);56 pleaseWaitDlg.setLocationRelativeTo(Main.parent); 57 57 58 58 cancel.addActionListener(new ActionListener(){ … … 122 122 pleaseWaitDlg.dispose(); 123 123 if (errorMessage != null) 124 JOptionPane.showMessageDialog(Main. main, errorMessage);124 JOptionPane.showMessageDialog(Main.parent, errorMessage); 125 125 } 126 126 }); -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r93 r98 86 86 if (requiresRestart) 87 87 JOptionPane.showMessageDialog(PreferenceDialog.this, "You have to restart JOSM for some settings to take effect."); 88 Main. main.repaint();88 Main.parent.repaint(); 89 89 setVisible(false); 90 90 } … … 166 166 */ 167 167 public PreferenceDialog() { 168 super( Main.main, "Preferences");168 super(JOptionPane.getFrameForComponent(Main.parent), "Preferences"); 169 169 170 170 // look and feel combo box … … 346 346 setModal(true); 347 347 pack(); 348 setLocationRelativeTo(Main. main);348 setLocationRelativeTo(Main.parent); 349 349 } 350 350 -
src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
r94 r98 14 14 import javax.swing.tree.DefaultTreeModel; 15 15 16 import org.openstreetmap.josm.Main; 16 17 import org.openstreetmap.josm.command.Command; 17 18 import org.openstreetmap.josm.gui.MapFrame; 19 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 20 import org.openstreetmap.josm.gui.layer.Layer; 21 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 18 22 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener; 19 23 … … 22 26 private DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode()); 23 27 private JTree tree = new JTree(treeModel); 24 private final MapFrame mapFrame;25 28 26 public CommandStackDialog( MapFrame mapFrame) {29 public CommandStackDialog(final MapFrame mapFrame) { 27 30 super("Command Stack", "commandstack", "Open a list of all commands (undo buffer).", KeyEvent.VK_C); 28 this.mapFrame = mapFrame;29 31 setPreferredSize(new Dimension(320,100)); 30 mapFrame.mapView.editLayer().listenerCommands.add(this); 32 mapFrame.mapView.addLayerChangeListener(new LayerChangeListener(){ 33 public void activeLayerChange(Layer oldLayer, Layer newLayer) {} 34 public void layerAdded(Layer newLayer) { 35 if (newLayer instanceof OsmDataLayer) 36 Main.main.editLayer().listenerCommands.add(CommandStackDialog.this); 37 } 38 public void layerRemoved(Layer oldLayer) {} 39 }); 31 40 tree.setRootVisible(false); 32 41 tree.setShowsRootHandles(true); … … 57 66 58 67 private void buildList() { 59 Collection<Command> commands = mapFrame.mapView.editLayer().commands;68 Collection<Command> commands = Main.main.editLayer().commands; 60 69 DefaultMutableTreeNode root = new DefaultMutableTreeNode(); 61 70 for (Command c : commands) … … 64 73 } 65 74 66 public void commandChanged( ) {75 public void commandChanged(int queueSize, int redoSize) { 67 76 if (!isVisible()) 68 77 return; -
src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
r94 r98 36 36 import org.openstreetmap.josm.data.osm.visitor.Visitor; 37 37 import org.openstreetmap.josm.gui.ConflictResolver; 38 import org.openstreetmap.josm.gui.MapView;39 38 import org.openstreetmap.josm.gui.NavigatableComponent; 40 39 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; … … 96 95 displaylist.getSelectionModel().addListSelectionListener(new ListSelectionListener(){ 97 96 public void valueChanged(ListSelectionEvent e) { 98 Main.ma in.getMapFrame().mapView.repaint();97 Main.map.mapView.repaint(); 99 98 } 100 99 }); … … 103 102 private final void resolve() { 104 103 if (displaylist.getSelectedIndex() == -1) { 105 JOptionPane.showMessageDialog(Main. main, "Please select something from the conflict list.");104 JOptionPane.showMessageDialog(Main.parent, "Please select something from the conflict list."); 106 105 return; 107 106 } … … 112 111 } 113 112 ConflictResolver resolver = new ConflictResolver(sel); 114 int answer = JOptionPane.showConfirmDialog(Main. main, resolver, "Resolve Conflicts", JOptionPane.OK_CANCEL_OPTION);113 int answer = JOptionPane.showConfirmDialog(Main.parent, resolver, "Resolve Conflicts", JOptionPane.OK_CANCEL_OPTION); 115 114 if (answer != JOptionPane.OK_OPTION) 116 115 return; 117 MapView mv = Main.main.getMapFrame().mapView; 118 mv.editLayer().add(new ConflictResolveCommand(resolver.conflicts, sel)); 119 mv.repaint(); 116 Main.main.editLayer().add(new ConflictResolveCommand(resolver.conflicts, sel)); 117 Main.map.mapView.repaint(); 120 118 } 121 119 -
src/org/openstreetmap/josm/gui/dialogs/LayerList.java
r94 r98 28 28 29 29 import org.openstreetmap.josm.Main; 30 import org.openstreetmap.josm.data.osm.DataSet;31 30 import org.openstreetmap.josm.gui.MapFrame; 32 31 import org.openstreetmap.josm.gui.MapView; … … 57 56 58 57 public void actionPerformed(ActionEvent e) { 59 if (layers.getModel().getSize() == 1) { 60 Main.main.setMapFrame(null); 61 Main.ds = new DataSet(); 62 } else { 63 int sel = layers.getSelectedIndex(); 64 if (layer != null) 65 Main.main.getMapFrame().mapView.removeLayer(layer); 66 else 67 Main.main.getMapFrame().mapView.removeLayer((Layer)layers.getSelectedValue()); 68 if (sel >= layers.getModel().getSize()) 69 sel = layers.getModel().getSize()-1; 70 if (layers.getSelectedValue() == null) 71 layers.setSelectedIndex(sel); 72 } 58 int sel = layers.getSelectedIndex(); 59 if (layer != null) 60 Main.main.removeLayer(layer); 61 else 62 Main.main.removeLayer((Layer)layers.getSelectedValue()); 63 if (sel >= layers.getModel().getSize()) 64 sel = layers.getModel().getSize()-1; 65 if (layers.getSelectedValue() == null) 66 layers.setSelectedIndex(sel); 73 67 } 74 68 } … … 88 82 Layer l = layer == null ? (Layer)layers.getSelectedValue() : layer; 89 83 l.visible = !l.visible; 90 Main.ma in.getMapFrame().mapView.repaint();84 Main.map.mapView.repaint(); 91 85 layers.repaint(); 92 86 } -
src/org/openstreetmap/josm/gui/dialogs/LayerListPopup.java
r86 r98 24 24 } 25 25 public void actionPerformed(ActionEvent e) { 26 JOptionPane.showMessageDialog(Main. main, layer.getInfoComponent());26 JOptionPane.showMessageDialog(Main.parent, layer.getInfoComponent()); 27 27 } 28 28 } -
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r94 r98 40 40 import org.openstreetmap.josm.data.osm.OsmPrimitive; 41 41 import org.openstreetmap.josm.gui.MapFrame; 42 import org.openstreetmap.josm.gui.MapView;43 42 import org.openstreetmap.josm.tools.ImageProvider; 44 43 … … 95 94 96 95 final JOptionPane optionPane = new JOptionPane(p, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 97 final JDialog dlg = optionPane.createDialog(Main. main, "Change values?");96 final JDialog dlg = optionPane.createDialog(Main.parent, "Change values?"); 98 97 dlg.addWindowFocusListener(new WindowFocusListener(){ 99 98 public void windowGainedFocus(WindowEvent e) { … … 124 123 if (value.equals("")) 125 124 value = null; // delete the key 126 mv.editLayer().add(new ChangePropertyCommand(sel, key, value));125 Main.main.editLayer().add(new ChangePropertyCommand(sel, key, value)); 127 126 128 127 if (value == null) … … 163 162 JTextField values = new JTextField(); 164 163 p2.add(values, BorderLayout.CENTER); 165 int answer = JOptionPane.showConfirmDialog(Main. main, p,164 int answer = JOptionPane.showConfirmDialog(Main.parent, p, 166 165 "Change values?", JOptionPane.OK_CANCEL_OPTION); 167 166 if (answer != JOptionPane.OK_OPTION) … … 171 170 if (value.equals("")) 172 171 return; 173 mv.editLayer().add(new ChangePropertyCommand(sel, key, value));172 Main.main.editLayer().add(new ChangePropertyCommand(sel, key, value)); 174 173 selectionChanged(sel); // update table 175 174 } … … 182 181 String key = data.getValueAt(row, 0).toString(); 183 182 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 184 mv.editLayer().add(new ChangePropertyCommand(sel, key, null));183 Main.main.editLayer().add(new ChangePropertyCommand(sel, key, null)); 185 184 selectionChanged(sel); // update table 186 185 } … … 201 200 */ 202 201 private final JTable propertyTable = new JTable(data); 203 /**204 * The map view this dialog operates on.205 */206 private final MapView mv;207 202 208 203 /** … … 211 206 public PropertiesDialog(MapFrame mapFrame) { 212 207 super("Properties", "propertiesdialog", "Property for selected objects.", KeyEvent.VK_P); 213 mv = mapFrame.mapView;214 208 215 209 setPreferredSize(new Dimension(320,150)); … … 248 242 else if (e.getActionCommand().equals("Edit")) { 249 243 if (sel == -1) 250 JOptionPane.showMessageDialog(Main. main, "Please select the row to edit.");244 JOptionPane.showMessageDialog(Main.parent, "Please select the row to edit."); 251 245 else 252 246 edit(sel); 253 247 } else if (e.getActionCommand().equals("Delete")) { 254 248 if (sel == -1) 255 JOptionPane.showMessageDialog(Main. main, "Please select the row to delete.");249 JOptionPane.showMessageDialog(Main.parent, "Please select the row to delete."); 256 250 else 257 251 delete(sel); -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r94 r98 87 87 } catch (IOException e) { 88 88 e.printStackTrace(); 89 JOptionPane.showMessageDialog(Main. main, "Could not read from url: '"+url+"'");89 JOptionPane.showMessageDialog(Main.parent, "Could not read from url: '"+url+"'"); 90 90 } catch (SAXException e) { 91 91 e.printStackTrace(); 92 JOptionPane.showMessageDialog(Main. main, "Parsing error in url: '"+url+"'");92 JOptionPane.showMessageDialog(Main.parent, "Parsing error in url: '"+url+"'"); 93 93 } 94 94 } … … 185 185 } 186 186 }; 187 pane.createDialog(Main. main, "Search").setVisible(true);187 pane.createDialog(Main.parent, "Search").setVisible(true); 188 188 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) 189 189 return; -
src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r94 r98 44 44 */ 45 45 public ToggleDialogAction action; 46 public final String prefName; 46 47 47 48 public ToggleDialog(String name, String iconName, String tooltip, int shortCut) { 49 this.prefName = iconName; 48 50 action = new ToggleDialogAction(name, "dialogs/"+iconName, tooltip, ShortCutLabel.name(shortCut, KeyEvent.ALT_MASK), KeyStroke.getKeyStroke(shortCut, KeyEvent.ALT_MASK), iconName); 49 51 setLayout(new BorderLayout()); -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r94 r98 50 50 public final String[] names = {"node", "segment", "way"}; 51 51 52 private void inc( OsmPrimitive osm,int i) {52 private void inc(final OsmPrimitive osm, final int i) { 53 53 normal[i]++; 54 54 if (osm.deleted) … … 56 56 } 57 57 58 public void visit( Node n) {58 public void visit(final Node n) { 59 59 inc(n, 0); 60 60 } 61 61 62 public void visit( Segment ls) {62 public void visit(final Segment ls) { 63 63 inc(ls, 1); 64 64 } 65 65 66 public void visit( Way w) {66 public void visit(final Way w) { 67 67 inc(w, 2); 68 68 } … … 73 73 } 74 74 public interface CommandQueueListener { 75 void commandChanged( );75 void commandChanged(int queueSize, int redoSize); 76 76 } 77 77 … … 103 103 * The stack for redoing commands 104 104 */ 105 private Stack<Command> redoCommands = new Stack<Command>();105 private final Stack<Command> redoCommands = new Stack<Command>(); 106 106 107 107 public final LinkedList<ModifiedChangedListener> listenerModified = new LinkedList<ModifiedChangedListener>(); … … 112 112 * Construct a OsmDataLayer. 113 113 */ 114 public OsmDataLayer( DataSet data, String name,boolean fromDisk) {114 public OsmDataLayer(final DataSet data, final String name, final boolean fromDisk) { 115 115 super(name); 116 116 this.data = data; … … 133 133 * Draw nodes last to overlap the segments they belong to. 134 134 */ 135 @Override public void paint( Graphics g,MapView mv) {136 SimplePaintVisitor visitor = new SimplePaintVisitor(g, mv);137 for ( OsmPrimitive osm : data.segments)135 @Override public void paint(final Graphics g, final MapView mv) { 136 final SimplePaintVisitor visitor = new SimplePaintVisitor(g, mv); 137 for (final OsmPrimitive osm : data.segments) 138 138 if (!osm.deleted) 139 139 osm.visit(visitor); 140 for ( OsmPrimitive osm : data.ways)140 for (final OsmPrimitive osm : data.ways) 141 141 if (!osm.deleted) 142 142 osm.visit(visitor); 143 for ( OsmPrimitive osm : data.nodes)143 for (final OsmPrimitive osm : data.nodes) 144 144 if (!osm.deleted) 145 145 osm.visit(visitor); 146 for ( OsmPrimitive osm : data.getSelected())146 for (final OsmPrimitive osm : data.getSelected()) 147 147 if (!osm.deleted) 148 148 osm.visit(visitor); 149 Main.ma in.getMapFrame().conflictDialog.paintConflicts(g, mv);149 Main.map.conflictDialog.paintConflicts(g, mv); 150 150 } 151 151 … … 156 156 } 157 157 158 @Override public void mergeFrom( Layer from) {158 @Override public void mergeFrom(final Layer from) { 159 159 final MergeVisitor visitor = new MergeVisitor(data); 160 for ( OsmPrimitive osm : ((OsmDataLayer)from).data.allPrimitives())160 for (final OsmPrimitive osm : ((OsmDataLayer)from).data.allPrimitives()) 161 161 osm.visit(visitor); 162 162 visitor.fixReferences(); 163 163 if (visitor.conflicts.isEmpty()) 164 164 return; 165 ConflictDialog dlg = Main.main.getMapFrame().conflictDialog;165 final ConflictDialog dlg = Main.map.conflictDialog; 166 166 dlg.add(visitor.conflicts); 167 JOptionPane.showMessageDialog(Main. main, "There were conflicts during import.");167 JOptionPane.showMessageDialog(Main.parent, "There were conflicts during import."); 168 168 if (!dlg.isVisible()) 169 169 dlg.action.actionPerformed(new ActionEvent(this, 0, "")); 170 170 } 171 171 172 @Override public boolean isMergable( Layer other) {172 @Override public boolean isMergable(final Layer other) { 173 173 return other instanceof OsmDataLayer; 174 174 } 175 175 176 @Override public void visitBoundingBox( BoundingXYVisitor v) {177 for ( Node n : data.nodes)176 @Override public void visitBoundingBox(final BoundingXYVisitor v) { 177 for (final Node n : data.nodes) 178 178 if (!n.deleted) 179 179 v.visit(n); … … 184 184 * primitives in the command as modified. 185 185 */ 186 public void add( Command c) {186 public void add(final Command c) { 187 187 c.executeCommand(); 188 188 commands.add(c); 189 189 redoCommands.clear(); 190 // TODO: Replace with listener scheme191 Main.main.undoAction.setEnabled(true);192 Main.main.redoAction.setEnabled(false);193 190 setModified(true); 194 for (CommandQueueListener l : listenerCommands) 195 l.commandChanged(); 191 fireCommandsChanged(); 196 192 } 197 193 … … 202 198 if (commands.isEmpty()) 203 199 return; 204 Command c = commands.removeLast();200 final Command c = commands.removeLast(); 205 201 c.undoCommand(); 206 202 redoCommands.push(c); 207 203 //TODO: Replace with listener scheme 208 Main.main.undoAction.setEnabled(!commands.isEmpty());209 Main.main.redoAction.setEnabled(true);210 if (commands.isEmpty())211 204 setModified(uploadedModified); 212 205 Main.ds.clearSelection(); 213 for (CommandQueueListener l : listenerCommands) 214 l.commandChanged(); 206 fireCommandsChanged(); 215 207 } 216 208 /** … … 220 212 if (redoCommands.isEmpty()) 221 213 return; 222 Command c = redoCommands.pop();214 final Command c = redoCommands.pop(); 223 215 c.executeCommand(); 224 216 commands.add(c); 225 //TODO: Replace with listener scheme226 Main.main.undoAction.setEnabled(true);227 Main.main.redoAction.setEnabled(!redoCommands.isEmpty());228 217 setModified(true); 229 for (CommandQueueListener l : listenerCommands) 230 l.commandChanged(); 218 fireCommandsChanged(); 231 219 } 232 220 … … 240 228 * saved to disk instead. 241 229 */ 242 public void cleanData( Collection<OsmPrimitive> processed, boolean dataAdded) {230 public void cleanData(final Collection<OsmPrimitive> processed, boolean dataAdded) { 243 231 redoCommands.clear(); 244 232 commands.clear(); … … 246 234 // if uploaded, clean the modified flags as well 247 235 if (processed != null) { 248 Set<OsmPrimitive> processedSet = new HashSet<OsmPrimitive>(processed);249 for ( Iterator<Node> it = data.nodes.iterator(); it.hasNext();)236 final Set<OsmPrimitive> processedSet = new HashSet<OsmPrimitive>(processed); 237 for (final Iterator<Node> it = data.nodes.iterator(); it.hasNext();) 250 238 cleanIterator(it, processedSet); 251 for ( Iterator<Segment> it = data.segments.iterator(); it.hasNext();)239 for (final Iterator<Segment> it = data.segments.iterator(); it.hasNext();) 252 240 cleanIterator(it, processedSet); 253 for ( Iterator<Way> it = data.ways.iterator(); it.hasNext();)241 for (final Iterator<Way> it = data.ways.iterator(); it.hasNext();) 254 242 cleanIterator(it, processedSet); 255 243 } … … 263 251 uploadedModified = fromDisk && processed != null && dataAdded; 264 252 setModified(uploadedModified); 265 //TODO: Replace with listener scheme 266 Main.main.undoAction.setEnabled(false); 267 Main.main.redoAction.setEnabled(false); 268 } 253 fireCommandsChanged(); 254 } 255 256 public void fireCommandsChanged() { 257 for (final CommandQueueListener l : listenerCommands) 258 l.commandChanged(commands.size(), redoCommands.size()); 259 } 269 260 270 261 /** … … 276 267 * If the object in the iterator is not in the list, nothing will be changed on it. 277 268 */ 278 private void cleanIterator( Iterator<? extends OsmPrimitive> it,Collection<OsmPrimitive> processed) {279 OsmPrimitive osm = it.next();269 private void cleanIterator(final Iterator<? extends OsmPrimitive> it, final Collection<OsmPrimitive> processed) { 270 final OsmPrimitive osm = it.next(); 280 271 if (!processed.remove(osm)) 281 272 return; … … 289 280 } 290 281 291 public void setModified( boolean modified) {282 public void setModified(final boolean modified) { 292 283 if (modified == this.modified) 293 284 return; 294 285 this.modified = modified; 295 for ( ModifiedChangedListener l : listenerModified)286 for (final ModifiedChangedListener l : listenerModified) 296 287 l.modifiedChanged(modified, this); 297 288 } … … 300 291 * @return The number of not-deleted primitives in the list. 301 292 */ 302 private int undeletedSize( Collection<? extends OsmPrimitive> list) {293 private int undeletedSize(final Collection<? extends OsmPrimitive> list) { 303 294 int size = 0; 304 for ( OsmPrimitive osm : list)295 for (final OsmPrimitive osm : list) 305 296 if (!osm.deleted) 306 297 size++; … … 309 300 310 301 @Override public Object getInfoComponent() { 311 DataCountVisitor counter = new DataCountVisitor();312 for ( OsmPrimitive osm : data.allPrimitives())302 final DataCountVisitor counter = new DataCountVisitor(); 303 for (final OsmPrimitive osm : data.allPrimitives()) 313 304 osm.visit(counter); 314 JPanel p = new JPanel(new GridBagLayout());305 final JPanel p = new JPanel(new GridBagLayout()); 315 306 p.add(new JLabel(name+" consists of:"), GBC.eol()); 316 307 for (int i = 0; i < counter.normal.length; ++i) { … … 323 314 } 324 315 325 @Override public void addMenuEntries( JPopupMenu menu) {316 @Override public void addMenuEntries(final JPopupMenu menu) { 326 317 menu.add(new JMenuItem(new SaveAction())); 327 318 menu.add(new JMenuItem(new GpxExportAction(this))); -
src/org/openstreetmap/josm/gui/layer/RawGpsDataLayer.java
r86 r98 54 54 super(name); 55 55 this.data = data; 56 Main.pref. addPreferenceChangedListener(new PreferenceChangedListener(){57 58 if (Main.main.getMapFrame()!= null && (key.equals("drawRawGpsLines") || key.equals("forceRawGpsLines")))59 Main.main.getMapFrame().repaint();60 61 56 Main.pref.listener.add(new PreferenceChangedListener(){ 57 public void preferenceChanged(String key, String newValue) { 58 if (Main.map != null && (key.equals("drawRawGpsLines") || key.equals("forceRawGpsLines"))) 59 Main.map.repaint(); 60 } 61 }); 62 62 } 63 63 … … 137 137 JColorChooser c = new JColorChooser(ColorHelper.html2color(col)); 138 138 Object[] options = new Object[]{"OK", "Cancel", "Default"}; 139 int answer = JOptionPane.showOptionDialog(Main. main, c, "Choose a color", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]);139 int answer = JOptionPane.showOptionDialog(Main.parent, c, "Choose a color", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); 140 140 switch (answer) { 141 141 case 0: … … 148 148 break; 149 149 } 150 Main.ma in.repaint();150 Main.map.repaint(); 151 151 } 152 152 }); -
src/org/openstreetmap/josm/io/OsmConnection.java
r92 r98 66 66 warning.setFont(warning.getFont().deriveFont(Font.ITALIC)); 67 67 p.add(warning, GBC.eol()); 68 int choice = JOptionPane.showConfirmDialog(Main. main, p, "Enter Password", JOptionPane.OK_CANCEL_OPTION);68 int choice = JOptionPane.showConfirmDialog(Main.parent, p, "Enter Password", JOptionPane.OK_CANCEL_OPTION); 69 69 if (choice == JOptionPane.CANCEL_OPTION) { 70 70 authCancelled = true; -
src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java
r71 r98 28 28 public void uncaughtException(Thread t, Throwable e) { 29 29 e.printStackTrace(); 30 if (Main. main!= null) {30 if (Main.parent != null) { 31 31 Object[] options = new String[]{"Do nothing", "Report Bug"}; 32 int answer = JOptionPane.showOptionDialog(Main. main, "An unexpected exception occoured.\n\n" +32 int answer = JOptionPane.showOptionDialog(Main.parent, "An unexpected exception occoured.\n\n" + 33 33 "This is always a coding error. If you are running the latest\n" + 34 34 "version of JOSM, please consider be kind and file a bug report.", … … 69 69 p.add(new JScrollPane(info), GBC.eop()); 70 70 71 JOptionPane.showMessageDialog(Main. main, p);71 JOptionPane.showMessageDialog(Main.parent, p); 72 72 } catch (Exception e1) { 73 73 e1.printStackTrace(); -
src/org/openstreetmap/josm/tools/TileCache.java
r81 r98 15 15 import org.openstreetmap.josm.Main; 16 16 import org.openstreetmap.josm.data.Bounds; 17 import org.openstreetmap.josm.data.Preferences;18 17 import org.openstreetmap.josm.data.coor.EastNorth; 19 18 import org.openstreetmap.josm.data.coor.LatLon; … … 153 152 */ 154 153 public synchronized Image get(final int tileId, final int zoom) { 155 final File cacheDir = new File(Main.pref.get("cache.directory", Preferences.getPreferencesDir()+"cache")+"/"+Main.proj.getCacheDirectoryName()+"/"+zoom);154 final File cacheDir = new File(Main.pref.get("cache.directory", Main.pref.getPreferencesDir()+"cache")+"/"+Main.proj.getCacheDirectoryName()+"/"+zoom); 156 155 if (!cache.containsKey(zoom)) { 157 156 HashMap<Integer, Image> map = new HashMap<Integer, Image>(); … … 189 188 map.put(tileId, loading); 190 189 currentlyLoading.remove(tileId*256+zoom); 191 Main.ma in.repaint();190 Main.map.repaint(); 192 191 } catch (Exception e) { 193 192 e.printStackTrace();
Note:
See TracChangeset
for help on using the changeset viewer.