Changeset 1857 in josm
- Timestamp:
- 2009-07-26T22:52:23+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r1849 r1857 41 41 import org.openstreetmap.josm.gui.MainMenu; 42 42 import org.openstreetmap.josm.gui.MapFrame; 43 import org.openstreetmap.josm.gui.OptionPaneUtil; 43 44 import org.openstreetmap.josm.gui.SplashScreen; 44 45 import org.openstreetmap.josm.gui.download.DownloadDialog.DownloadTask; … … 279 280 Main.proj = (Projection)Class.forName(name).newInstance(); 280 281 } catch (final Exception e) { 281 JOptionPane.showMessageDialog(null, tr("The projection {0} could not be activated. Using Mercator", name)); 282 OptionPaneUtil.showMessageDialog( 283 Main.parent, 284 tr("The projection {0} could not be activated. Using Mercator", name), 285 tr("Error"), 286 JOptionPane.ERROR_MESSAGE 287 ); 282 288 Main.proj = new Mercator(); 283 289 } … … 416 422 final Bounds b = OsmUrlToBounds.parse(s); 417 423 if (b == null) { 418 JOptionPane.showMessageDialog(Main.parent, tr("Ignoring malformed URL: \"{0}\"", s)); 424 OptionPaneUtil.showMessageDialog( 425 Main.parent, 426 tr("Ignoring malformed URL: \"{0}\"", s), 427 tr("Warning"), 428 JOptionPane.WARNING_MESSAGE 429 ); 419 430 } else { 420 431 //DownloadTask osmTask = main.menu.download.downloadTasks.get(0); … … 429 440 main.menu.openFile.openFile(new File(new URI(s))); 430 441 } catch (URISyntaxException e) { 431 JOptionPane.showMessageDialog(Main.parent, tr("Ignoring malformed file URL: \"{0}\"", s)); 442 OptionPaneUtil.showMessageDialog( 443 Main.parent, 444 tr("Ignoring malformed file URL: \"{0}\"", s), 445 tr("Warning"), 446 JOptionPane.WARNING_MESSAGE 447 ); 432 448 } 433 449 return; -
trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java
r1847 r1857 231 231 } catch (IOException x) { 232 232 x.printStackTrace(); 233 JOptionPane.showMessageDialog(Main.parent, tr("Error while exporting {0}:\n{1}", fn,x.getMessage()), tr("Error"), JOptionPane.ERROR_MESSAGE); 233 OptionPaneUtil.showMessageDialog( 234 Main.parent, 235 tr("Error while exporting {0}:\n{1}", fn,x.getMessage()), 236 tr("Error"), 237 JOptionPane.ERROR_MESSAGE 238 ); 234 239 } 235 240 } … … 285 290 l.setVisibleRowCount(4); 286 291 l.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 287 int answer = JOptionPane.showConfirmDialog(Main.parent, new JScrollPane(l),tr("Choose a predefined license"), JOptionPane.OK_CANCEL_OPTION); 292 int answer = OptionPaneUtil.showConfirmationDialog( 293 Main.parent, 294 new JScrollPane(l), 295 tr("Choose a predefined license"), 296 JOptionPane.OK_CANCEL_OPTION, 297 JOptionPane.QUESTION_MESSAGE 298 ); 288 299 if (answer != JOptionPane.OK_OPTION || l.getSelectedIndex() == -1) 289 300 return; -
trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java
r1847 r1857 37 37 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; 38 38 import org.openstreetmap.josm.gui.ExtendedDialog; 39 import org.openstreetmap.josm.gui.OptionPaneUtil; 39 40 import org.openstreetmap.josm.tools.GBC; 40 41 import org.openstreetmap.josm.tools.Pair; … … 72 73 73 74 if (selectedNodes.size() < 2) { 74 JOptionPane.showMessageDialog(75 OptionPaneUtil.showMessageDialog( 75 76 Main.parent, 76 77 tr("Please select at least two nodes to merge."), … … 249 250 w.visit(backRefs); 250 251 if (!backRefs.data.isEmpty()) { 251 JOptionPane.showMessageDialog(Main.parent, 252 OptionPaneUtil.showMessageDialog( 253 Main.parent, 252 254 tr("Cannot merge nodes: " + 253 "Would have to delete a way that is still used.")); 255 "Would have to delete a way that is still used."), 256 tr("Warning"), 257 JOptionPane.WARNING_MESSAGE 258 ); 254 259 return null; 255 260 } -
trunk/src/org/openstreetmap/josm/actions/MirrorAction.java
r1847 r1857 19 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 20 20 import org.openstreetmap.josm.data.osm.Way; 21 import org.openstreetmap.josm.gui.OptionPaneUtil; 21 22 import org.openstreetmap.josm.tools.Shortcut; 22 23 … … 49 50 50 51 if (nodes.size() == 0) { 51 JOptionPane.showMessageDialog(52 OptionPaneUtil.showMessageDialog( 52 53 Main.parent, 53 54 tr("Please select at least one node or way."), -
trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
r1847 r1857 106 106 } 107 107 if(delta < Math.PI/4) { 108 JOptionPane.showMessageDialog(Main.parent, tr("Please select ways with almost right angles to orthogonalize.")); 108 OptionPaneUtil.showMessageDialog( 109 Main.parent, 110 tr("Please select ways with almost right angles to orthogonalize."), 111 tr("Information"), 112 JOptionPane.INFORMATION_MESSAGE 113 ); 109 114 return; 110 115 } -
trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
r1847 r1857 87 87 public boolean checkSaveConditions(Layer layer) { 88 88 if (layer == null) { 89 JOptionPane.showMessageDialog(Main.parent, tr("Internal Error: cannot check conditions for no layer. Please report this as a bug.")); 89 OptionPaneUtil.showMessageDialog( 90 Main.parent, 91 tr("Internal Error: cannot check conditions for no layer. Please report this as a bug."), 92 tr("Error"), 93 JOptionPane.ERROR_MESSAGE 94 ); 90 95 return false; 91 96 } 92 97 if (Main.map == null) { 93 JOptionPane.showMessageDialog(98 OptionPaneUtil.showMessageDialog( 94 99 Main.parent, 95 100 tr("No document open so nothing to save."), … … 271 276 } catch (IOException e) { 272 277 e.printStackTrace(); 273 JOptionPane.showMessageDialog(Main.parent, tr("An error occurred while saving.")+"\n"+e.getMessage()); 278 OptionPaneUtil.showMessageDialog( 279 Main.parent, 280 tr("An error occurred while saving. Error is: {0}", e.getMessage()), 281 tr("Error"), 282 JOptionPane.ERROR_MESSAGE 283 ); 274 284 } 275 285 try { -
trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
r1843 r1857 31 31 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; 32 32 import org.openstreetmap.josm.data.osm.visitor.Visitor; 33 import org.openstreetmap.josm.gui.OptionPaneUtil; 33 34 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 34 35 import org.openstreetmap.josm.tools.Shortcut; … … 65 66 66 67 if (!checkSelection(selection)) { 67 JOptionPane.showMessageDialog(Main.parent, tr("The current selection cannot be used for splitting.")); 68 OptionPaneUtil.showMessageDialog( 69 Main.parent, 70 tr("The current selection cannot be used for splitting."), 71 tr("Warning"), 72 JOptionPane.WARNING_MESSAGE 73 ); 68 74 return; 69 75 } … … 117 123 } 118 124 if (wayOccurenceCounter.isEmpty()) { 119 JOptionPane.showMessageDialog(Main.parent,125 OptionPaneUtil.showMessageDialog(Main.parent, 120 126 trn("The selected node is not in the middle of any way.", 121 127 "The selected nodes are not in the middle of any way.", 122 selectedNodes.size())); 128 selectedNodes.size()), 129 tr("Warning"), 130 JOptionPane.WARNING_MESSAGE); 123 131 return; 124 132 } … … 127 135 if (entry.getValue().equals(selectedNodes.size())) { 128 136 if (selectedWay != null) { 129 JOptionPane.showMessageDialog(Main.parent,137 OptionPaneUtil.showMessageDialog(Main.parent, 130 138 trn("There is more than one way using the node you selected. Please select the way also.", 131 139 "There is more than one way using the nodes you selected. Please select the way also.", 132 selectedNodes.size())); 140 selectedNodes.size()), 141 tr("Warning"), 142 JOptionPane.WARNING_MESSAGE); 133 143 return; 134 144 } … … 138 148 139 149 if (selectedWay == null) { 140 JOptionPane.showMessageDialog(Main.parent, 141 tr("The selected nodes do not share the same way.")); 150 OptionPaneUtil.showMessageDialog(Main.parent, 151 tr("The selected nodes do not share the same way."), 152 tr("Warning"), 153 JOptionPane.WARNING_MESSAGE); 142 154 return; 143 155 } … … 151 163 } 152 164 if (!nds.isEmpty()) { 153 JOptionPane.showMessageDialog(Main.parent,165 OptionPaneUtil.showMessageDialog(Main.parent, 154 166 trn("The selected way does not contain the selected node.", 155 167 "The selected way does not contain all the selected nodes.", 156 selectedNodes.size())); 168 selectedNodes.size()), 169 tr("Warning"), 170 JOptionPane.WARNING_MESSAGE); 157 171 return; 158 172 } … … 219 233 && !nodeSet.contains(wayChunks.get(0).get(0))) { 220 234 if (wayChunks.size() == 2) { 221 JOptionPane.showMessageDialog(Main.parent, tr("You must select two or more nodes to split a circular way.")); 235 OptionPaneUtil.showMessageDialog( 236 Main.parent, 237 tr("You must select two or more nodes to split a circular way."), 238 tr("Warning"), 239 JOptionPane.WARNING_MESSAGE); 222 240 return; 223 241 } … … 230 248 if (wayChunks.size() < 2) { 231 249 if(wayChunks.get(0).get(0) == wayChunks.get(0).get(wayChunks.get(0).size()-1)) { 232 JOptionPane.showMessageDialog(Main.parent, tr("You must select two or more nodes to split a circular way.")); 250 OptionPaneUtil.showMessageDialog( 251 Main.parent, 252 tr("You must select two or more nodes to split a circular way."), 253 tr("Warning"), 254 JOptionPane.WARNING_MESSAGE); 233 255 } else { 234 JOptionPane.showMessageDialog(Main.parent, tr("The way cannot be split at the selected nodes. (Hint: Select nodes in the middle of the way.)")); 256 OptionPaneUtil.showMessageDialog( 257 Main.parent, 258 tr("The way cannot be split at the selected nodes. (Hint: Select nodes in the middle of the way.)"), 259 tr("Warning"), 260 JOptionPane.WARNING_MESSAGE); 235 261 } 236 262 return; … … 321 347 } 322 348 if(warnmerole) { 323 JOptionPane.showMessageDialog(Main.parent, tr("A role based relation membership was copied to all new ways.\nYou should verify this and correct it when necessary.")); 349 OptionPaneUtil.showMessageDialog( 350 Main.parent, 351 tr("<html>A role based relation membership was copied to all new ways.<br>You should verify this and correct it when necessary.</html>"), 352 tr("Warning"), 353 JOptionPane.WARNING_MESSAGE); 324 354 } else if(warnme) { 325 JOptionPane.showMessageDialog(Main.parent, tr("A relation membership was copied to all new ways.\nYou should verify this and correct it when necessary.")); 355 OptionPaneUtil.showMessageDialog( 356 Main.parent, 357 tr("<html>A relation membership was copied to all new ways.<br>You should verify this and correct it when necessary.</html>"), 358 tr("Warning"), 359 JOptionPane.WARNING_MESSAGE); 326 360 } 327 361 -
trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java
r1820 r1857 27 27 import org.openstreetmap.josm.data.osm.Way; 28 28 import org.openstreetmap.josm.gui.MapView; 29 import org.openstreetmap.josm.gui.OptionPaneUtil; 29 30 import org.openstreetmap.josm.tools.Shortcut; 30 31 … … 131 132 132 133 if(errMsg != null) { 133 JOptionPane.showMessageDialog(Main.parent, errMsg); 134 OptionPaneUtil.showMessageDialog( 135 Main.parent, 136 errMsg, 137 tr("Error"), 138 JOptionPane.ERROR_MESSAGE); 134 139 } 135 140 -
trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java
r1820 r1857 15 15 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTaskList; 16 16 import org.openstreetmap.josm.data.osm.DataSource; 17 import org.openstreetmap.josm.gui.OptionPaneUtil; 17 18 import org.openstreetmap.josm.gui.layer.Layer; 18 19 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; … … 73 74 74 75 if(bboxCount == 0) { 75 JOptionPane.showMessageDialog(76 OptionPaneUtil.showMessageDialog( 76 77 Main.parent, 77 78 tr("No data to update found. Have you already opened or downloaded a data layer?"), -
trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java
r1820 r1857 17 17 import org.openstreetmap.josm.data.osm.DataSet; 18 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 import org.openstreetmap.josm.gui.OptionPaneUtil; 19 20 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 20 21 import org.openstreetmap.josm.gui.layer.Layer; … … 205 206 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 206 207 if (selection.size() == 0) { 207 JOptionPane.showMessageDialog(208 OptionPaneUtil.showMessageDialog( 208 209 Main.parent, 209 210 tr("There are no selected primitives to update."), -
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r1820 r1857 26 26 import org.openstreetmap.josm.data.osm.OsmPrimitive; 27 27 import org.openstreetmap.josm.gui.ExtendedDialog; 28 import org.openstreetmap.josm.gui.OptionPaneUtil; 28 29 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 29 30 import org.openstreetmap.josm.gui.PleaseWaitRunnable; … … 174 175 ConflictCollection conflicts = Main.map.mapView.getEditLayer().getConflicts(); 175 176 if (conflicts !=null && !conflicts.isEmpty()) { 176 JOptionPane.showMessageDialog(Main.parent,tr("There are unresolved conflicts. You have to resolve these first.")); 177 OptionPaneUtil.showMessageDialog( 178 Main.parent, 179 tr("There are unresolved conflicts. You have to resolve these first."), 180 tr("Warning"), 181 JOptionPane.WARNING_MESSAGE 182 ); 177 183 Main.map.conflictDialog.action.button.setSelected(true); 178 184 Main.map.conflictDialog.action.actionPerformed(null); -
trunk/src/org/openstreetmap/josm/actions/search/SelectionWebsiteLoader.java
r1814 r1857 20 20 import org.openstreetmap.josm.Main; 21 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 import org.openstreetmap.josm.gui.OptionPaneUtil; 22 23 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 23 24 import org.openstreetmap.josm.io.OsmIdReader; … … 59 60 } catch (IOException e) { 60 61 e.printStackTrace(); 61 JOptionPane.showMessageDialog(Main.parent, tr("Could not read from URL: \"{0}\"",url)); 62 OptionPaneUtil.showMessageDialog( 63 Main.parent, 64 tr("Could not read from URL: \"{0}\"",url), 65 tr("Error"), 66 JOptionPane.ERROR_MESSAGE 67 ); 62 68 } catch (SAXException e) { 63 69 e.printStackTrace(); 64 JOptionPane.showMessageDialog(Main.parent,tr("Parsing error in URL: \"{0}\"",url)); 70 OptionPaneUtil.showMessageDialog( 71 Main.parent, 72 tr("Parsing error in URL: \"{0}\"",url), 73 tr("Error"), 74 JOptionPane.ERROR_MESSAGE 75 ); 65 76 } catch(OsmTransferException e) { 66 77 e.printStackTrace(); 67 78 if (e.getCause() != null) { 68 79 if (e.getCause() instanceof IOException ) { 69 JOptionPane.showMessageDialog(Main.parent, tr("Could not read from URL: \"{0}\"",url), 80 OptionPaneUtil.showMessageDialog( 81 Main.parent, tr("Could not read from URL: \"{0}\"",url), 70 82 tr("Error"), JOptionPane.ERROR_MESSAGE); 71 83 } else if (e.getCause() instanceof SAXException) { 72 JOptionPane.showMessageDialog(Main.parent,tr("Parsing error in URL: \"{0}\"",url),84 OptionPaneUtil.showMessageDialog(Main.parent,tr("Parsing error in URL: \"{0}\"",url), 73 85 tr("Error"), JOptionPane.ERROR_MESSAGE); 74 86 } 75 87 } else { 76 JOptionPane.showMessageDialog(Main.parent,tr("Error while communicating with server.",url),88 OptionPaneUtil.showMessageDialog(Main.parent,tr("Error while communicating with server.",url), 77 89 tr("Error"), JOptionPane.ERROR_MESSAGE); 78 90 } -
trunk/src/org/openstreetmap/josm/command/AddCommand.java
r1814 r1857 13 13 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 14 14 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 15 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 15 16 import org.openstreetmap.josm.tools.ImageProvider; 16 17 … … 35 36 public AddCommand(OsmPrimitive osm) { 36 37 super(); 38 this.osm = osm; 39 } 40 41 /** 42 * Create the command and specify the element to add. 43 */ 44 public AddCommand(OsmDataLayer layer, OsmPrimitive osm) { 45 super(layer); 37 46 this.osm = osm; 38 47 } -
trunk/src/org/openstreetmap/josm/corrector/TagCorrector.java
r1814 r1857 29 29 import org.openstreetmap.josm.data.osm.Way; 30 30 import org.openstreetmap.josm.gui.JMultilineLabel; 31 import org.openstreetmap.josm.gui.OptionPaneUtil; 31 32 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 32 33 import org.openstreetmap.josm.tools.GBC; … … 140 141 } 141 142 142 int answer = JOptionPane.showOptionDialog(Main.parent, p, 143 tr("Automatic tag correction"), JOptionPane.YES_NO_CANCEL_OPTION, 144 JOptionPane.PLAIN_MESSAGE, null, 145 applicationOptions, applicationOptions[0]); 143 int answer = OptionPaneUtil.showOptionDialog( 144 Main.parent, 145 p, 146 tr("Automatic tag correction"), 147 JOptionPane.YES_NO_CANCEL_OPTION, 148 JOptionPane.PLAIN_MESSAGE, 149 applicationOptions, 150 applicationOptions[0] 151 ); 146 152 147 153 if (answer == JOptionPane.YES_OPTION) { -
trunk/src/org/openstreetmap/josm/data/DataSetChecker.java
r1814 r1857 9 9 import org.openstreetmap.josm.Main; 10 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 import org.openstreetmap.josm.gui.OptionPaneUtil; 11 12 import org.openstreetmap.josm.gui.layer.Layer; 12 13 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 14 15 // FIXME: class still needed? 13 16 14 17 public class DataSetChecker { … … 23 26 for (OsmPrimitive osm : ((OsmDataLayer)l).data.allPrimitives()) { 24 27 if (s.contains(osm)) { 25 JOptionPane.showMessageDialog(Main.parent, "cross references"); 28 // FIXME: better message 29 // FIXME: translate message and title 30 OptionPaneUtil.showMessageDialog( 31 Main.parent, 32 "cross references", 33 "Information", 34 JOptionPane.INFORMATION_MESSAGE); 26 35 return; 27 36 } … … 34 43 OsmDataLayer l = (OsmDataLayer)Main.map.mapView.getActiveLayer(); 35 44 if (l.data != Main.main.getCurrentDataSet()) { 36 JOptionPane.showMessageDialog(Main.parent, "Main.ds / active layer mismatch"); 45 OptionPaneUtil.showMessageDialog( 46 Main.parent, 47 "Main.ds / active layer mismatch", 48 "Error", 49 JOptionPane.ERROR_MESSAGE 50 ); 37 51 return; 38 52 } 39 53 } 40 54 41 JOptionPane.showMessageDialog(Main.parent, "working"); 55 OptionPaneUtil.showMessageDialog( 56 Main.parent, "working", "", JOptionPane.INFORMATION_MESSAGE); 42 57 } 43 58 } -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r1722 r1857 31 31 import org.openstreetmap.josm.actions.AboutAction; 32 32 import org.openstreetmap.josm.data.projection.Mercator; 33 import org.openstreetmap.josm.gui.OptionPaneUtil; 33 34 import org.openstreetmap.josm.gui.preferences.ProxyPreferences; 34 35 import org.openstreetmap.josm.tools.ColorHelper; … … 45 46 46 47 /** 47 * Internal storage for the preferenced directory.48 * Do not access this variable directly!49 * @see #getPreferencesDirFile()50 */48 * Internal storage for the preferenced directory. 49 * Do not access this variable directly! 50 * @see #getPreferencesDirFile() 51 */ 51 52 private File preferencesDirFile = null; 52 53 … … 131 132 String s; 132 133 if ((s = System.getenv("JOSM_RESOURCES")) != null) { 133 if (!s.endsWith(File.separator)) 134 if (!s.endsWith(File.separator)) { 134 135 s = s + File.separator; 136 } 135 137 locations.add(s); 136 138 } 137 139 if ((s = System.getProperty("josm.resources")) != null) { 138 if (!s.endsWith(File.separator)) 140 if (!s.endsWith(File.separator)) { 139 141 s = s + File.separator; 142 } 140 143 locations.add(s); 141 144 } … … 180 183 final Map<String,String> all = new TreeMap<String,String>(); 181 184 for (final Entry<String,String> e : properties.entrySet()) 182 if (e.getKey().startsWith(prefix)) 185 if (e.getKey().startsWith(prefix)) { 183 186 all.put(e.getKey(), e.getValue()); 187 } 184 188 for (final Entry<String,String> e : override.entrySet()) 185 189 if (e.getKey().startsWith(prefix)) 186 if (e.getValue() == null) 190 if (e.getValue() == null) { 187 191 all.remove(e.getKey()); 188 else192 } else { 189 193 all.put(e.getKey(), e.getValue()); 194 } 190 195 return all; 191 196 } … … 194 199 final TreeMap<String,String> all = new TreeMap<String,String>(); 195 200 for (final Entry<String,String> e : defaults.entrySet()) 196 if (e.getKey().startsWith("color.") && e.getValue() != null) 201 if (e.getKey().startsWith("color.") && e.getValue() != null) { 197 202 all.put(e.getKey().substring(6), e.getValue()); 203 } 198 204 for (final Entry<String,String> e : properties.entrySet()) 199 if (e.getKey().startsWith("color.")) 205 if (e.getKey().startsWith("color.")) { 200 206 all.put(e.getKey().substring(6), e.getValue()); 207 } 201 208 for (final Entry<String,String> e : override.entrySet()) 202 209 if (e.getKey().startsWith("color.")) 203 if (e.getValue() == null) 210 if (e.getValue() == null) { 204 211 all.remove(e.getKey().substring(6)); 205 else212 } else { 206 213 all.put(e.getKey().substring(6), e.getValue()); 214 } 207 215 return all; 208 216 } … … 213 221 214 222 synchronized public void putDefault(final String key, final String def) { 215 if(!defaults.containsKey(key) || defaults.get(key) == null) 223 if(!defaults.containsKey(key) || defaults.get(key) == null) { 216 224 defaults.put(key, def); 217 else if(def != null && !defaults.get(key).equals(def))225 } else if(def != null && !defaults.get(key).equals(def)) { 218 226 System.out.println("Defaults for " + key + " differ: " + def + " != " + defaults.get(key)); 227 } 219 228 } 220 229 … … 235 244 synchronized public boolean put(final String key, String value) { 236 245 String oldvalue = properties.get(key); 237 if(value != null && value.length() == 0) 246 if(value != null && value.length() == 0) { 238 247 value = null; 248 } 239 249 if(!((oldvalue == null && (value == null || value.equals(defaults.get(key)))) 240 || (value != null && oldvalue != null && oldvalue.equals(value))))250 || (value != null && oldvalue != null && oldvalue.equals(value)))) 241 251 { 242 if (value == null) 252 if (value == null) { 243 253 properties.remove(key); 244 else254 } else { 245 255 properties.put(key, value); 256 } 246 257 save(); 247 258 firePreferenceChanged(key, value); … … 268 279 269 280 private final void firePreferenceChanged(final String key, final String value) { 270 for (final PreferenceChangedListener l : listener) 281 for (final PreferenceChangedListener l : listener) { 271 282 l.preferenceChanged(key, value); 283 } 272 284 } 273 285 … … 282 294 setSystemProperties(); 283 295 final PrintWriter out = new PrintWriter(new OutputStreamWriter( 284 new FileOutputStream(getPreferencesDir() + "preferences"), "utf-8"), false);296 new FileOutputStream(getPreferencesDir() + "preferences"), "utf-8"), false); 285 297 for (final Entry<String, String> e : properties.entrySet()) { 286 298 String s = defaults.get(e.getKey()); 287 299 /* don't save default values */ 288 if(s == null || !s.equals(e.getValue())) 300 if(s == null || !s.equals(e.getValue())) { 289 301 out.println(e.getKey() + "=" + e.getValue()); 302 } 290 303 } 291 304 out.close(); … … 300 313 properties.clear(); 301 314 final BufferedReader in = new BufferedReader(new InputStreamReader( 302 new FileInputStream(getPreferencesDir()+"preferences"), "utf-8"));315 new FileInputStream(getPreferencesDir()+"preferences"), "utf-8")); 303 316 int lineNumber = 0; 304 317 ArrayList<Integer> errLines = new ArrayList<Integer>(); … … 322 335 if (prefDir.exists()) { 323 336 if(!prefDir.isDirectory()) { 324 JOptionPane.showMessageDialog(null, tr("Cannot open preferences directory: {0}",Main.pref.getPreferencesDir())); 337 OptionPaneUtil.showMessageDialog( 338 Main.parent, 339 tr("Cannot open preferences directory: {0}",Main.pref.getPreferencesDir()), 340 tr("Error"), 341 JOptionPane.ERROR_MESSAGE 342 ); 325 343 return; 326 344 } 327 } 328 else 345 } else { 329 346 prefDir.mkdirs(); 330 331 if (!new File(getPreferencesDir()+"preferences").exists()) 347 } 348 349 if (!new File(getPreferencesDir()+"preferences").exists()) { 332 350 resetToDefault(); 351 } 333 352 334 353 try { 335 if (reset) 354 if (reset) { 336 355 resetToDefault(); 337 else356 } else { 338 357 load(); 358 } 339 359 } catch (final IOException e1) { 340 360 e1.printStackTrace(); 341 361 String backup = getPreferencesDir() + "preferences.bak"; 342 JOptionPane.showMessageDialog(null, tr("Preferences file had errors. Making backup of old one to {0}.", backup)); 362 OptionPaneUtil.showMessageDialog( 363 Main.parent, 364 tr("Preferences file had errors. Making backup of old one to {0}.", backup), 365 tr("Error"), 366 JOptionPane.ERROR_MESSAGE 367 ); 343 368 new File(getPreferencesDir() + "preferences").renameTo(new File(backup)); 344 369 save(); … … 362 387 public Collection<Bookmark> loadBookmarks() throws IOException { 363 388 File bookmarkFile = new File(getPreferencesDir()+"bookmarks"); 364 if (!bookmarkFile.exists()) 389 if (!bookmarkFile.exists()) { 365 390 bookmarkFile.createNewFile(); 391 } 366 392 BufferedReader in = new BufferedReader(new InputStreamReader( 367 new FileInputStream(bookmarkFile), "utf-8"));393 new FileInputStream(bookmarkFile), "utf-8")); 368 394 369 395 LinkedList<Bookmark> bookmarks = new LinkedList<Bookmark>(); … … 375 401 Bookmark b = new Bookmark(); 376 402 b.name = m.group(1); 377 for (int i = 0; i < b.latlon.length; ++i) 403 for (int i = 0; i < b.latlon.length; ++i) { 378 404 b.latlon[i] = Double.parseDouble(m.group(i+2)); 405 } 379 406 bookmarks.add(b); 380 407 } … … 387 414 public void saveBookmarks(Collection<Bookmark> bookmarks) throws IOException { 388 415 File bookmarkFile = new File(Main.pref.getPreferencesDir()+"bookmarks"); 389 if (!bookmarkFile.exists()) 416 if (!bookmarkFile.exists()) { 390 417 bookmarkFile.createNewFile(); 418 } 391 419 PrintWriter out = new PrintWriter(new OutputStreamWriter( 392 new FileOutputStream(bookmarkFile), "utf-8"));420 new FileOutputStream(bookmarkFile), "utf-8")); 393 421 for (Bookmark b : bookmarks) { 394 422 out.print(b.name+"\u001e"); 395 for (int i = 0; i < b.latlon.length; ++i) 423 for (int i = 0; i < b.latlon.length; ++i) { 396 424 out.print(b.latlon[i]+(i<b.latlon.length-1?"\u001e":"")); 425 } 397 426 out.println(); 398 427 } … … 422 451 putDefault("color."+colName, ColorHelper.color2html(def)); 423 452 String colStr = specName != null ? get("color."+specName) : ""; 424 if(colStr.equals("")) 453 if(colStr.equals("")) { 425 454 colStr = get("color."+colName); 455 } 426 456 return colStr.equals("") ? def : ColorHelper.html2color(colStr); 427 457 } … … 481 511 putDefault(key, def); 482 512 String v = get(key); 483 if(v != null && v.length() != 0) 513 if(v != null && v.length() != 0) { 484 514 try { return Double.parseDouble(v); } catch(NumberFormatException e) {} 515 } 485 516 try { return Double.parseDouble(def); } catch(NumberFormatException e) {} 486 517 return 0.0; … … 494 525 for(String a : def) 495 526 { 496 if(d != null) 527 if(d != null) { 497 528 d += "\u001e" + a; 498 else529 } else { 499 530 d = a; 531 } 500 532 } 501 533 putDefault(key, d); … … 506 538 { 507 539 String r =s; 508 if(r.indexOf("§§§") > 0) /* history dialog */540 if(r.indexOf("§§§") > 0) { 509 541 r = r.replaceAll("§§§","\u001e"); 510 else /* old style ';' separation */542 } else { 511 543 r = r.replace(';','\u001e'); 544 } 512 545 if(!r.equals(s)) /* save the converted string */ 513 546 { … … 534 567 for(String a : val) 535 568 { 536 if(s != null) 569 if(s != null) { 537 570 s += "\u001e" + a; 538 else571 } else { 539 572 s = a; 573 } 540 574 } 541 575 } -
trunk/src/org/openstreetmap/josm/data/ServerSidePreferences.java
r1169 r1857 24 24 25 25 import org.openstreetmap.josm.Main; 26 import org.openstreetmap.josm.gui.OptionPaneUtil; 26 27 import org.openstreetmap.josm.io.OsmConnection; 27 28 import org.openstreetmap.josm.io.XmlWriter; … … 48 49 System.out.println("reading preferences from "+serverUrl); 49 50 URLConnection con = serverUrl.openConnection(); 50 if (con instanceof HttpURLConnection) addAuth((HttpURLConnection) con); 51 if (con instanceof HttpURLConnection) { 52 addAuth((HttpURLConnection) con); 53 } 51 54 con.connect(); 52 55 BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream())); … … 56 59 b.append("\n"); 57 60 } 58 if (con instanceof HttpURLConnection) ((HttpURLConnection) con).disconnect(); 61 if (con instanceof HttpURLConnection) { 62 ((HttpURLConnection) con).disconnect(); 63 } 59 64 return b.toString(); 60 65 } catch (IOException e) { … … 77 82 con.getInputStream().close(); 78 83 con.disconnect(); 79 JOptionPane.showMessageDialog(Main.parent, tr("Preferences stored on {0}", u.getHost())); 84 OptionPaneUtil.showMessageDialog( 85 Main.parent, 86 tr("Preferences stored on {0}", u.getHost()), 87 tr("Information"), 88 JOptionPane.INFORMATION_MESSAGE 89 ); 80 90 } catch (Exception e) { 81 91 e.printStackTrace(); 82 JOptionPane.showMessageDialog(Main.parent, tr("Could not upload preferences. Reason: {0}", e.getMessage())); 92 OptionPaneUtil.showMessageDialog( 93 Main.parent, 94 tr("Could not upload preferences. Reason: {0}", e.getMessage()), 95 tr("Error"), 96 JOptionPane.ERROR_MESSAGE 97 ); 83 98 } 84 99 } … … 119 134 public void download(String userName, String password) { 120 135 resetToDefault(); 121 if (!properties.containsKey("osm-server.username") && userName != null) 136 if (!properties.containsKey("osm-server.username") && userName != null) { 122 137 properties.put("osm-server.username", userName); 123 if (!properties.containsKey("osm-server.password") && password != null) 138 } 139 if (!properties.containsKey("osm-server.password") && password != null) { 124 140 properties.put("osm-server.password", password); 141 } 125 142 String cont = connection.download(); 126 143 if (cont == null) return; … … 128 145 try { 129 146 XmlObjectParser.Uniform<Prop> parser = new XmlObjectParser.Uniform<Prop>(in, "tag", Prop.class); 130 for (Prop p : parser) 147 for (Prop p : parser) { 131 148 properties.put(p.key, p.value); 149 } 132 150 } catch (RuntimeException e) { 133 151 e.printStackTrace(); … … 144 162 StringBuilder b = new StringBuilder("<preferences>\n"); 145 163 for (Entry<String, String> p : properties.entrySet()) { 146 if (p.getKey().equals("osm-server.password")) 164 if (p.getKey().equals("osm-server.password")) { 147 165 continue; // do not upload password. It would get stored in plain! 166 } 148 167 b.append("<tag key='"); 149 168 b.append(XmlWriter.encode(p.getKey())); … … 163 182 for (String line = in.readLine(); line != null; line = in.readLine()) { 164 183 StringTokenizer st = new StringTokenizer(line, ","); 165 if (st.countTokens() < 5) 184 if (st.countTokens() < 5) { 166 185 continue; 186 } 167 187 Bookmark b = new Bookmark(); 168 188 b.name = st.nextToken(); 169 189 try { 170 for (int i = 0; i < b.latlon.length; ++i) 190 for (int i = 0; i < b.latlon.length; ++i) { 171 191 b.latlon[i] = Double.parseDouble(st.nextToken()); 192 } 172 193 bookmarks.add(b); 173 194 } catch (NumberFormatException x) { -
trunk/src/org/openstreetmap/josm/data/conflict/ConflictCollection.java
r1750 r1857 67 67 } 68 68 69 protected void addConflict(Conflict<?> conflict) { 69 /** 70 * Adds a conflict to the collection 71 * 72 * @param conflict the conflict 73 * @exception IllegalStateException thrown, if this collection already includes a 74 * conflict for conflict.getMy() 75 */ 76 protected void addConflict(Conflict<?> conflict) throws IllegalStateException { 70 77 if (hasConflictForMy(conflict.getMy())) 71 78 throw new IllegalStateException(tr("already registered a conflict for primitive ''{0}''", conflict.getMy().toString())); -
trunk/src/org/openstreetmap/josm/data/projection/Lambert.java
r1849 r1857 13 13 import org.openstreetmap.josm.data.coor.LatLon; 14 14 import org.openstreetmap.josm.data.Bounds; 15 import org.openstreetmap.josm.gui.OptionPaneUtil; 15 16 16 17 public class Lambert implements Projection { … … 52 53 53 54 public static final double zoneLimits[] = { Math.toRadians(53.5 * 0.9), // between Zone 1 and Zone 2 (in grad *0.9) 54 55 56 55 Math.toRadians(50.5 * 0.9), // between Zone 2 and Zone 3 56 Math.toRadians(47.51963 * 0.9), // between Zone 3 and Zone 4 57 Math.toRadians(46.17821 * 0.9) };// lowest latitude of Zone 4 57 58 58 59 public static final double cMinLonZones = Math.toRadians(-4.9074074074074059 * 0.9); … … 84 85 if (lt >= zoneLimits[3] && lt <= cMaxLatZone1 && lg >= cMinLonZones && lg <= cMaxLonZones) { 85 86 // zone I 86 if (lt > zoneLimits[0]) 87 if (lt > zoneLimits[0]) { 87 88 currentZone = 0; 88 // zone II 89 else if (lt > zoneLimits[1]) 89 } else if (lt > zoneLimits[1]) { 90 90 currentZone = 1; 91 // zone III 92 else if (lt > zoneLimits[2]) 91 } else if (lt > zoneLimits[2]) { 93 92 currentZone = 2; 94 // zone III or IV 95 else if (lt > zoneLimits[3]) 93 } else if (lt > zoneLimits[3]) 96 94 // Note: zone IV is dedicated to Corsica island and extends from 47.8 to 97 95 // 45.9 degrees of latitude. There is an overlap with zone III that can be 98 96 // solved only with longitude (covers Corsica if lon > 7.2 degree) 99 if (lg < Math.toRadians(8 * 0.9)) 97 if (lg < Math.toRadians(8 * 0.9)) { 100 98 currentZone = 2; 101 else99 } else { 102 100 currentZone = 3; 101 } 103 102 } else { 104 103 outOfLambertZones = true; // possible when MAX_LAT is used … … 109 108 } else if (layoutZone != currentZone) { 110 109 if ((currentZone < layoutZone && Math.abs(zoneLimits[currentZone] - lt) > cMaxOverlappingZones) 111 || (currentZone > layoutZone && Math.abs(zoneLimits[layoutZone] - lt) > cMaxOverlappingZones)) { 112 JOptionPane.showMessageDialog(Main.parent, 113 tr("IMPORTANT : data positioned far away from\n" 114 + "the current Lambert zone limits.\n" 115 + "Do not upload any data after this message.\n" 116 + "Undo your last action, save your work\n" 117 + "and start a new layer on the new zone.")); 110 || (currentZone > layoutZone && Math.abs(zoneLimits[layoutZone] - lt) > cMaxOverlappingZones)) { 111 OptionPaneUtil.showMessageDialog(Main.parent, 112 tr("IMPORTANT : data positioned far away from\n" 113 + "the current Lambert zone limits.\n" 114 + "Do not upload any data after this message.\n" 115 + "Undo your last action, save your work\n" 116 + "and start a new layer on the new zone."), 117 tr("Warning"), 118 JOptionPane.WARNING_MESSAGE); 118 119 layoutZone = -1; 119 120 } else { … … 130 131 public LatLon eastNorth2latlon(EastNorth p) { 131 132 LatLon geo; 132 if (layoutZone == -1) 133 if (layoutZone == -1) { 133 134 // possible until the Lambert zone is determined by latlon2eastNorth() with a valid LatLon 134 135 geo = Geographic(p, Xs[currentZone], Ys[currentZone], c[currentZone], n[currentZone]); 135 else136 } else { 136 137 geo = Geographic(p, Xs[layoutZone], Ys[layoutZone], c[layoutZone], n[layoutZone]); 138 } 137 139 // translate ellipsoid Clark => GRS80 (WGS83) 138 140 LatLon wgs = Clark2GRS80(geo); … … 197 199 double eslt = Ellipsoid.clarke.e * Math.sin(lat); 198 200 double nlt = 2.0 * Math.atan(Math.pow((1.0 + eslt) / (1.0 - eslt), Ellipsoid.clarke.e / 2.0) * l) - Math.PI 199 201 / 2.0; 200 202 delta = Math.abs(nlt - lat); 201 203 lat = nlt; … … 261 263 s2 *= s2; 262 264 double l = Math.atan((Z / norm) 263 / (1.0 - (ell.a * ell.e2 * Math.cos(lt) / (norm * Math.sqrt(1.0 - ell.e2 * s2)))));265 / (1.0 - (ell.a * ell.e2 * Math.cos(lt) / (norm * Math.sqrt(1.0 - ell.e2 * s2))))); 264 266 delta = Math.abs(l - lt); 265 267 lt = l; -
trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictResolutionDialog.java
r1847 r1857 98 98 if (isVisible){ 99 99 restorePositionAndDimension(); 100 toFront(); 100 101 } else { 101 102 rememberPositionAndDimension(); … … 130 131 protected void build() { 131 132 setTitle(tr("Resolve conflicts")); 133 try { 134 setAlwaysOnTop(true); 135 } catch(SecurityException e) { 136 System.out.println(tr("Warning: couldn't setAlwaysOnTop(true) for ConflictResolution Dialog. Exception: {0}", e.toString())); 137 } 132 138 getContentPane().setLayout(new BorderLayout()); 133 139 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r1856 r1857 52 52 53 53 import org.openstreetmap.josm.Main; 54 import org.openstreetmap.josm.actions.DeleteAction;55 54 import org.openstreetmap.josm.command.AddCommand; 56 55 import org.openstreetmap.josm.command.ChangeCommand; 56 import org.openstreetmap.josm.command.ConflictAddCommand; 57 57 import org.openstreetmap.josm.data.conflict.Conflict; 58 58 import org.openstreetmap.josm.data.osm.DataSet; … … 604 604 // --- copy relation action 605 605 buttonPanel.add(new SideButton(new DuplicateRelationAction())); 606 607 // --- apply relation action 608 buttonPanel.add(new SideButton(new ApplyAction())); 606 609 607 610 // --- delete relation action … … 1002 1005 } 1003 1006 1004 class OKAction extends AbstractAction {1007 abstract class SavingAction extends AbstractAction { 1005 1008 /** 1006 1009 * apply updates to a new relation … … 1014 1017 tagEditorModel.applyToPrimitive(newRelation); 1015 1018 memberTableModel.applyToRelation(newRelation); 1016 Main.main.undoRedo.add(new AddCommand(newRelation)); 1019 Main.main.undoRedo.add(new AddCommand(getLayer(),newRelation)); 1020 1021 // make sure everybody is notified about the changes 1022 // 1017 1023 DataSet.fireSelectionChanged(getLayer().data.getSelected()); 1024 getLayer().fireDataChange(); 1025 GenericRelationEditor.this.setRelation(newRelation); 1026 RelationDialogManager.getRelationDialogManager().updateContext( 1027 getLayer(), 1028 getRelation(), 1029 GenericRelationEditor.this 1030 ); 1018 1031 } 1019 1032 1020 1033 /** 1021 * apply updates to an existing relation 1034 * Apply the updates for an existing relation which has not been changed 1035 * outside of the relation editor. 1036 * 1022 1037 */ 1023 protected void applyExisting Relation() {1038 protected void applyExistingConflictingRelation() { 1024 1039 Relation editedRelation = new Relation(getRelation()); 1025 1040 tagEditorModel.applyToPrimitive(editedRelation); 1026 1041 memberTableModel.applyToRelation(editedRelation); 1027 if (isDirtyRelation()) { 1028 Conflict<Relation> conflict = new Conflict<Relation>(getRelation(), editedRelation); 1029 getLayer().getConflicts().add(conflict); 1030 OptionPaneUtil.showMessageDialog( 1031 Main.parent, 1032 tr("<html>The relation has changed outside of the editor.<br>" 1033 + "Your edits can't be applied directly, a conflict has been created instead.</html>"), 1034 tr("Warning"), 1035 JOptionPane.WARNING_MESSAGE 1036 ); 1037 } else { 1038 tagEditorModel.applyToPrimitive(editedRelation); 1039 memberTableModel.applyToRelation(editedRelation); 1040 Main.main.undoRedo.add(new ChangeCommand(getRelation(), editedRelation)); 1041 DataSet.fireSelectionChanged(getLayer().data.getSelected()); 1042 } 1042 Conflict<Relation> conflict = new Conflict<Relation>(getRelation(), editedRelation); 1043 Main.main.undoRedo.add(new ConflictAddCommand(getLayer(),conflict)); 1043 1044 } 1044 1045 1045 1046 /** 1046 * Applies updates 1047 * Apply the updates for an existing relation which has been changed 1048 * outside of the relation editor. 1049 * 1047 1050 */ 1048 protected void applyChanges() { 1051 protected void applyExistingNonConflictingRelation() { 1052 Relation editedRelation = new Relation(getRelation()); 1053 tagEditorModel.applyToPrimitive(editedRelation); 1054 memberTableModel.applyToRelation(editedRelation); 1055 Main.main.undoRedo.add(new ChangeCommand(getRelation(), editedRelation)); 1056 DataSet.fireSelectionChanged(getLayer().data.getSelected()); 1057 getLayer().fireDataChange(); 1058 // this will refresh the snapshot and update the dialog title 1059 // 1060 setRelation(getRelation()); 1061 } 1062 1063 protected boolean confirmClosingBecauseOfDirtyState() { 1064 String [] options = new String[] { 1065 tr("Yes, create a conflict and close"), 1066 tr("No, continue editing") 1067 }; 1068 int ret = OptionPaneUtil.showOptionDialog( 1069 Main.parent, 1070 tr("<html>This relation has been changed outside of the editor.<br>" 1071 + "You can't apply your changes and continue editing.<br>" 1072 + "<br>" 1073 + "Do you want to create a conflict and close the editor?</html>"), 1074 tr("Conflict in data"), 1075 JOptionPane.YES_NO_OPTION, 1076 JOptionPane.WARNING_MESSAGE, 1077 options, 1078 options[0] 1079 ); 1080 switch(ret) { 1081 case JOptionPane.CANCEL_OPTION: return false; 1082 case JOptionPane.YES_OPTION: return true; 1083 case JOptionPane.NO_OPTION: return false; 1084 } 1085 return false; 1086 } 1087 1088 protected void warnDoubleConflict() { 1089 OptionPaneUtil.showMessageDialog( 1090 Main.parent, 1091 tr("<html>Layer ''{0}'' already has a conflict for primitive<br>" 1092 + "''{1}''.<br>" 1093 + "Please resolve this conflict first, then try again.</html>", 1094 getLayer().getName(), 1095 new PrimitiveNameFormatter().getName(getRelation()) 1096 ), 1097 tr("Double conflict"), 1098 JOptionPane.WARNING_MESSAGE 1099 ); 1100 } 1101 } 1102 1103 class ApplyAction extends SavingAction { 1104 public ApplyAction() { 1105 putValue(SHORT_DESCRIPTION, tr("Apply the current updates")); 1106 putValue(SMALL_ICON, ImageProvider.get("save")); 1107 putValue(NAME, tr("Apply")); 1108 setEnabled(true); 1109 } 1110 1111 public void run() { 1049 1112 if (getRelation() == null) { 1050 1113 applyNewRelation(); 1051 1114 } else if (!memberTableModel.hasSameMembersAs(getRelationSnapshot()) 1052 1115 || tagEditorModel.isDirty()) { 1053 applyExistingRelation(); 1054 } 1055 } 1056 1116 if (isDirtyRelation()) { 1117 if (confirmClosingBecauseOfDirtyState()) { 1118 if (getLayer().getConflicts().hasConflictForMy(getRelation())) { 1119 warnDoubleConflict(); 1120 return; 1121 } 1122 applyExistingConflictingRelation(); 1123 setVisible(false); 1124 } 1125 } else { 1126 applyExistingNonConflictingRelation(); 1127 } 1128 } 1129 } 1130 1131 public void actionPerformed(ActionEvent e) { 1132 run(); 1133 } 1134 } 1135 1136 class OKAction extends SavingAction { 1057 1137 public OKAction() { 1058 1138 putValue(SHORT_DESCRIPTION, tr("Apply the updates and close the dialog")); 1059 1139 putValue(SMALL_ICON, ImageProvider.get("ok")); 1060 putValue(NAME, tr(" Apply"));1140 putValue(NAME, tr("OK")); 1061 1141 setEnabled(true); 1062 1142 } 1063 1143 1064 public void actionPerformed(ActionEvent e) { 1065 applyChanges(); 1144 public void run() { 1145 if (getRelation() == null) { 1146 applyNewRelation(); 1147 } else if (!memberTableModel.hasSameMembersAs(getRelationSnapshot()) 1148 || tagEditorModel.isDirty()) { 1149 if (isDirtyRelation()) { 1150 if (confirmClosingBecauseOfDirtyState()) { 1151 if (getLayer().getConflicts().hasConflictForMy(getRelation())) { 1152 warnDoubleConflict(); 1153 return; 1154 } 1155 applyExistingConflictingRelation(); 1156 } else 1157 return; 1158 } else { 1159 applyExistingNonConflictingRelation(); 1160 } 1161 } 1066 1162 setVisible(false); 1163 } 1164 1165 public void actionPerformed(ActionEvent e) { 1166 run(); 1067 1167 } 1068 1168 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
r1845 r1857 440 440 } 441 441 442 /** 443 * get a node we can link against when sorting members 444 * @param element the element we want to link against 445 * @param linked_element already linked against element 446 * @return the unlinked node if element is a way, the node itself if element is a node, null otherwise 447 */ 448 private static Node getUnusedNode(RelationMember element, RelationMember linked_element) 449 { 450 Node result = null; 451 452 if (element.member instanceof Way) { 453 Way w = (Way) element.member; 454 if (linked_element.member instanceof Way) { 455 Way x = (Way) linked_element.member; 456 if ((w.firstNode() == x.firstNode()) || (w.firstNode() == x.lastNode())) { 457 result = w.lastNode(); 458 } else { 459 result = w.firstNode(); 460 } 461 } else if (linked_element.member instanceof Node) { 462 Node m = (Node) linked_element.member; 463 if (w.firstNode() == m) { 464 result = w.lastNode(); 465 } else { 466 result = w.firstNode(); 467 } 468 } 469 } else if (element.member instanceof Node) { 470 Node n = (Node) element.member; 471 result = n; 472 } 473 474 return result; 475 } 476 442 477 void sort() { 443 478 RelationNodeMap map = new RelationNodeMap(members); … … 450 485 /* 451 486 * sort any 2 or more connected elements together may be slow with many unconnected members 452 * TODO: cleanup again, too much code in 1 method453 487 */ 454 488 455 if (map.isEmpty()) 489 if (map.isEmpty()) { 456 490 // empty relation or incomplete members 457 491 return; 492 } 458 493 segments = new Vector<LinkedList<Integer>>(); 459 494 … … 482 517 endSearchNode = null; 483 518 if (segment.size() == 1) { 519 // only one element in segment, so try to link against each linkable node of element 484 520 RelationMember m = members.get(segment.getFirst()); 485 521 if (m.member instanceof Way) { 486 522 Way w = (Way) m.member; 487 523 endSearchNode = w.lastNode(); 488 startSearchNode = w.firstNode(); 524 if (w.lastNode() != w.firstNode()) 525 { 526 startSearchNode = w.firstNode(); 527 } 489 528 } else if (m.member instanceof Node) { 490 529 Node n = (Node) m.member; … … 493 532 } else { 494 533 // add unused node of first element and unused node of last element 495 // start with the first element 496 RelationMember element = members.get(segment.getFirst()); 497 RelationMember other_element = members.get(segment.get(1)); 498 499 if (element.member instanceof Way) { 500 Way w = (Way) element.member; 501 if (other_element.member instanceof Way) { 502 Way x = (Way) other_element.member; 503 if ((w.firstNode() == x.firstNode()) || (w.firstNode() == x.lastNode())) { 504 startSearchNode = w.lastNode(); 505 } else { 506 startSearchNode = w.firstNode(); 507 } 508 } else if (other_element.member instanceof Node) { 509 Node m = (Node) other_element.member; 510 if (w.firstNode() == m) { 511 startSearchNode = w.lastNode(); 512 } else { 513 startSearchNode = w.firstNode(); 514 } 515 } 516 } else if (element.member instanceof Node) { 517 Node n = (Node) element.member; 518 startSearchNode = n; 519 } 520 521 // now the same for the last element 522 element = members.get(segment.getLast()); 523 other_element = members.get(segment.get(segment.size() - 2)); 524 525 if (element.member instanceof Way) { 526 Way w = (Way) element.member; 527 if (other_element.member instanceof Way) { 528 Way x = (Way) other_element.member; 529 if ((w.firstNode() == x.firstNode()) || (w.firstNode() == x.lastNode())) { 530 endSearchNode = w.lastNode(); 531 } else { 532 endSearchNode = w.firstNode(); 533 } 534 } else if (other_element.member instanceof Node) { 535 Node m = (Node) other_element.member; 536 if (w.firstNode() == m) { 537 endSearchNode = w.lastNode(); 538 } else { 539 endSearchNode = w.firstNode(); 540 } 541 } 542 } else if (element.member instanceof Node) { 543 Node n = (Node) element.member; 544 endSearchNode = n; 545 } 534 // start with the first element (compared to next element) 535 startSearchNode = getUnusedNode(members.get(segment.getFirst()), members.get(segment.get(1))); 536 537 // now the same for the last element (compared to previous element) 538 endSearchNode = getUnusedNode(members.get(segment.getLast()), members.get(segment.get(segment.size() - 2))); 546 539 } 547 540 … … 566 559 567 560 } 561 568 562 if (segments.size() > 0) { 569 563 // append map.remaining() to segments list (as a single segment) -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java
r1856 r1857 119 119 openDialogs.put(context, editor); 120 120 editor.addWindowListener(this); 121 } 122 123 public void updateContext(OsmDataLayer layer, Relation relation, RelationEditor editor) { 124 // lookup the entry for editor and remove it 125 // 126 for (DialogContext context: openDialogs.keySet()) { 127 if (openDialogs.get(context) == editor) { 128 openDialogs.remove(context); 129 break; 130 } 131 } 132 // don't add a window listener. Editor is already known to the relation dialog manager 133 // 134 DialogContext context = new DialogContext(layer, relation); 135 openDialogs.put(context, editor); 121 136 } 122 137 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditor.java
r1830 r1857 89 89 } 90 90 91 protected RelationEditor(OsmDataLayer layer, Relation relation, Collection<RelationMember> selectedMembers) 92 { 91 protected RelationEditor(OsmDataLayer layer, Relation relation, Collection<RelationMember> selectedMembers) { 93 92 // Initalizes ExtendedDialog 94 93 super(Main.parent, 95 relation == null 96 ? tr("Create new relation in layer ''{0}''", layer.getName()) 97 : (relation.id == 0 98 ? tr ("Edit new relation in layer ''{0}''", layer.getName()) 99 : tr("Edit relation #{0} in layer ''{1}''", relation.id, layer.getName()) 100 ), 101 new String[] { tr("Apply Changes"), tr("Cancel")}, 102 false 94 "", 95 new String[] { tr("Apply Changes"), tr("Cancel")}, 96 false 103 97 ); 104 105 this.relationSnapshot = (relation == null) ? null : new Relation(relation);106 this.relation = relation;107 98 this.layer = layer; 99 setRelation(relation); 108 100 } 109 101 102 /** 103 * updates the title of the relation editor 104 */ 105 protected void updateTitle() { 106 if (getRelation() == null) { 107 setTitle(tr("Create new relation in layer ''{0}''", layer.getName())); 108 } else if (getRelation().id == 0) { 109 setTitle(tr("Edit new relation in layer ''{0}''", layer.getName())); 110 } else { 111 setTitle(tr("Edit relation #{0} in layer ''{1}''", relation.id, layer.getName())); 112 } 113 } 110 114 /** 111 115 * Replies the currently edited relation … … 115 119 protected Relation getRelation() { 116 120 return relation; 121 } 122 123 /** 124 * Sets the currently edited relation. Creates a snapshot of the current 125 * state of the relation. See {@see #getRelationSnapshot()} 126 * 127 * @param relation the relation 128 */ 129 protected void setRelation(Relation relation) { 130 this.relationSnapshot = (relation == null) ? null : new Relation(relation); 131 this.relation = relation; 132 updateTitle(); 117 133 } 118 134 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationNodeMap.java
r1822 r1857 57 57 if (m.member instanceof Way) { 58 58 Way w = (Way) m.member; 59 if (!points.containsKey(w.firstNode())) { 60 points.put(w.firstNode(), new java.util.TreeSet<Integer>()); 59 if (w.lastNode() == w.firstNode()) 60 { 61 nodes.put(w.firstNode(), Integer.valueOf(n)); 61 62 } 62 points.get(w.firstNode()).add(Integer.valueOf(n)); 63 else 64 { 65 if (!points.containsKey(w.firstNode())) { 66 points.put(w.firstNode(), new java.util.TreeSet<Integer>()); 67 } 68 points.get(w.firstNode()).add(Integer.valueOf(n)); 63 69 64 if (!points.containsKey(w.lastNode())) { 65 points.put(w.lastNode(), new java.util.TreeSet<Integer>()); 70 if (!points.containsKey(w.lastNode())) { 71 points.put(w.lastNode(), new java.util.TreeSet<Integer>()); 72 } 73 points.get(w.lastNode()).add(Integer.valueOf(n)); 66 74 } 67 points.get(w.lastNode()).add(Integer.valueOf(n));68 75 } else if (m.member instanceof Node) { 69 76 Node node = (Node) m.member; … … 77 84 boolean result; 78 85 if (a.member instanceof Way) { 79 result = points.get(((Way) a.member).firstNode()).remove(n); 80 result &= points.get(((Way) a.member).lastNode()).remove(n); 86 Way w = (Way) a.member; 87 if (w.firstNode() == w.lastNode()) 88 { 89 result = (nodes.remove(w.firstNode()) != null); 90 } 91 else 92 { 93 result = points.get(w.firstNode()).remove(n); 94 result &= points.get(w.lastNode()).remove(n); 95 } 81 96 } else { 82 97 result = (nodes.remove(a.member) != null); -
trunk/src/org/openstreetmap/josm/gui/download/PlaceSelection.java
r1847 r1857 190 190 catch (Exception x) 191 191 { 192 JOptionPane.showMessageDialog(Main.parent,tr("Cannot read place search results from server"));193 192 x.printStackTrace(); 193 OptionPaneUtil.showMessageDialog( 194 Main.parent, 195 tr("Cannot read place search results from server"), 196 tr("Error"), 197 JOptionPane.ERROR_MESSAGE 198 ); 194 199 } 195 200 component.setCursor(oldCursor); -
trunk/src/org/openstreetmap/josm/io/NMEAImporter.java
r1637 r1857 12 12 import org.openstreetmap.josm.Main; 13 13 import org.openstreetmap.josm.actions.ExtensionFileFilter; 14 import org.openstreetmap.josm.gui.OptionPaneUtil; 14 15 import org.openstreetmap.josm.gui.layer.GpxLayer; 15 16 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; … … 42 43 private void showNmeaInfobox(boolean success, NmeaReader r) { 43 44 String msg = tr("Coordinates imported: ") + r.getNumberOfCoordinates() + "\n" + tr("Malformed sentences: ") 44 45 if (!success) // don't scare the user unneccessarily45 + r.getParserMalformed() + "\n" + tr("Checksum errors: ") + r.getParserChecksumErrors() + "\n"; 46 if (!success) { 46 47 msg += tr("Unknown sentences: ") + r.getParserUnknown() + "\n"; 48 } 47 49 msg += tr("Zero coordinates: ") + r.getParserZeroCoordinates(); 48 50 if (success) { 49 JOptionPane.showMessageDialog(Main.parent, msg, tr("NMEA import success"), JOptionPane.INFORMATION_MESSAGE); 51 OptionPaneUtil.showMessageDialog( 52 Main.parent, 53 msg, 54 tr("NMEA import success"), 55 JOptionPane.INFORMATION_MESSAGE); 50 56 } else { 51 JOptionPane.showMessageDialog(Main.parent, msg, tr("NMEA import faliure!"), JOptionPane.ERROR_MESSAGE);57 OptionPaneUtil.showMessageDialog(Main.parent, msg, tr("NMEA import faliure!"), JOptionPane.ERROR_MESSAGE); 52 58 } 53 59 }
Note:
See TracChangeset
for help on using the changeset viewer.