Changeset 1814 in josm
- Timestamp:
- 2009-07-19T19:04:49+02:00 (15 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 deleted
- 78 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r1811 r1814 77 77 */ 78 78 public static Preferences pref = new Preferences(); 79 /** 80 * The global dataset. 81 */ 82 public static DataSet ds = new DataSet(); 79 83 80 /** 84 81 * The global paste buffer. … … 167 164 if (map != null) { 168 165 map.mapView.removeLayer(layer); 169 if (layer instanceof OsmDataLayer) {170 ds = new DataSet();171 }172 166 if (map.mapView.getAllLayers().isEmpty()) { 173 167 setMapFrame(null); … … 224 218 map.mapView.addLayer(layer); 225 219 } 226 /** 227 * Replies the current edit layer. Creates one if no {@see OsmDataLayer}228 * exists. Replies null, if the currently active layer isn't an instance229 * of {@see OsmDataLayer}.220 221 /** 222 * Replies true if there is an edit layer which is currently 223 * active 230 224 * 231 * @return the current edit layer 232 */ 233 public final OsmDataLayer createOrGetEditLayer() { 234 if (map == null || map.mapView.getEditLayer() == null) { 235 menu.newAction.actionPerformed(null); 236 } 237 return map.mapView.getEditLayer(); 238 } 239 240 /** 241 * Replies true if this map view has an edit layer 242 * 243 * @return true if this map view has an edit layer 244 */ 245 public boolean hasEditLayer() { 225 * @return true if there is an edit layer which is currently 226 * active 227 */ 228 public boolean hasActiveEditLayer() { 246 229 if (map == null) return false; 247 230 if (map.mapView == null) return false; 248 231 if (map.mapView.getEditLayer() == null) return false; 249 232 return true; 233 } 234 235 /** 236 * Replies the current edit layer 237 * 238 * @return the current edit layer. null, if no current edit layer exists 239 */ 240 public OsmDataLayer getEditLayer() { 241 if (map == null) return null; 242 if (map.mapView == null) return null; 243 return map.mapView.getEditLayer(); 244 } 245 246 /** 247 * Replies the current data set. 248 * 249 * @return the current data set. null, if no current data set exists 250 */ 251 public DataSet getCurrentDataSet() { 252 if (!hasActiveEditLayer()) return null; 253 return getEditLayer().data; 250 254 } 251 255 … … 495 499 pref.put("gui.geometry", newGeometry); 496 500 } 501 502 497 503 } -
trunk/src/org/openstreetmap/josm/actions/AbstractInfoAction.java
r1779 r1814 46 46 47 47 protected void launchBrowser() { 48 ArrayList<OsmPrimitive> primitivesToShow = new ArrayList<OsmPrimitive>( Main.ds.getSelected());48 ArrayList<OsmPrimitive> primitivesToShow = new ArrayList<OsmPrimitive>(getCurrentDataSet().getSelected()); 49 49 50 50 // filter out new primitives which are not yet uploaded to the server -
trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java
r1807 r1814 79 79 /* Now execute the commands to add the dupicated contents of the paste buffer to the map */ 80 80 Main.main.undoRedo.add(new AddCommand(nnew)); 81 Main.ds.setSelected(nnew);81 getCurrentDataSet().setSelected(nnew); 82 82 Main.map.mapView.repaint(); 83 83 } -
trunk/src/org/openstreetmap/josm/actions/AlignInCircleAction.java
r1768 r1814 79 79 80 80 public void actionPerformed(ActionEvent e) { 81 Collection<OsmPrimitive> sel = Main.ds.getSelected();81 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 82 82 Collection<Node> nodes = new LinkedList<Node>(); 83 83 Collection<Way> ways = new LinkedList<Way>(); -
trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java
r1640 r1814 31 31 public AlignInLineAction() { 32 32 super(tr("Align Nodes in Line"), "alignline", tr("Move the selected nodes in to a line."), 33 Shortcut.registerShortcut("tools:alignline", tr("Tool: {0}", tr("Align Nodes in Line")), KeyEvent.VK_L, Shortcut.GROUP_EDIT), true);33 Shortcut.registerShortcut("tools:alignline", tr("Tool: {0}", tr("Align Nodes in Line")), KeyEvent.VK_L, Shortcut.GROUP_EDIT), true); 34 34 } 35 35 … … 40 40 */ 41 41 public void actionPerformed(ActionEvent e) { 42 Collection<OsmPrimitive> sel = Main.ds.getSelected();42 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 43 43 Collection<Node> nodes = new LinkedList<Node>(); 44 44 Collection<Node> itnodes = new LinkedList<Node>(); … … 50 50 // special case if no single nodes are selected and exactly one way is: 51 51 // then use the way's nodes 52 if ((nodes.size() == 0) && (sel.size() == 1)) 52 if ((nodes.size() == 0) && (sel.size() == 1)) { 53 53 for (OsmPrimitive osm : sel) 54 54 if (osm instanceof Way) { … … 56 56 itnodes.addAll(((Way)osm).nodes); 57 57 } 58 } 58 59 if (nodes.size() < 3) { 59 60 JOptionPane.showMessageDialog(Main.parent, tr("Please select at least three nodes.")); -
trunk/src/org/openstreetmap/josm/actions/ApiPreconditionChecker.java
r1693 r1814 100 100 List<OsmPrimitive> newNodes = new LinkedList<OsmPrimitive>(); 101 101 newNodes.add(osmPrimitive); 102 Main. ds.setSelected(newNodes);102 Main.main.getCurrentDataSet().setSelected(newNodes); 103 103 return false; 104 104 } … … 120 120 newNodes.add(osmPrimitive); 121 121 122 Main. ds.setSelected(newNodes);122 Main.main.getCurrentDataSet().setSelected(newNodes); 123 123 return false; 124 124 } -
trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
r1797 r1814 79 79 Collection<OsmPrimitive> sel = new HashSet<OsmPrimitive>(); 80 80 if (mode.equals("selection")) { 81 sel = Main.ds.getSelected();81 sel = getCurrentDataSet().getSelected(); 82 82 } else if (mode.equals("conflict")) { 83 83 if (Main.map.conflictDialog.getConflicts() != null) { -
trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java
r1621 r1814 52 52 public CombineWayAction() { 53 53 super(tr("Combine Way"), "combineway", tr("Combine several ways into one."), 54 Shortcut.registerShortcut("tools:combineway", tr("Tool: {0}", tr("Combine Way")), KeyEvent.VK_C, Shortcut.GROUP_EDIT), true);54 Shortcut.registerShortcut("tools:combineway", tr("Tool: {0}", tr("Combine Way")), KeyEvent.VK_C, Shortcut.GROUP_EDIT), true); 55 55 DataSet.selListeners.add(this); 56 56 } 57 57 58 58 public void actionPerformed(ActionEvent event) { 59 Collection<OsmPrimitive> selection = Main.ds.getSelected();59 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 60 60 LinkedList<Way> selectedWays = new LinkedList<Way>(); 61 61 62 62 for (OsmPrimitive osm : selection) 63 if (osm instanceof Way) 63 if (osm instanceof Way) { 64 64 selectedWays.add((Way)osm); 65 } 65 66 66 67 if (selectedWays.size() < 2) { … … 82 83 new HashMap<Pair<Relation,String>, HashSet<Way>>(); 83 84 HashSet<Relation> relationsUsingWays = new HashSet<Relation>(); 84 for (Relation r : Main.ds.relations) { 85 if (r.deleted || r.incomplete) continue; 85 for (Relation r : getCurrentDataSet().relations) { 86 if (r.deleted || r.incomplete) { 87 continue; 88 } 86 89 for (RelationMember rm : r.members) { 87 90 if (rm.member instanceof Way) { … … 112 115 tr("Combine ways with different memberships?"), 113 116 tr("The selected ways have differing relation memberships. " 114 + "Do you still want to combine them?"), 115 new String[] {tr("Combine Anyway"), tr("Cancel")}, 116 new String[] {"combineway.png", "cancel.png"}).getValue(); 117 if (option == 1) break; 117 + "Do you still want to combine them?"), 118 new String[] {tr("Combine Anyway"), tr("Cancel")}, 119 new String[] {"combineway.png", "cancel.png"}).getValue(); 120 if (option == 1) { 121 break; 122 } 118 123 119 124 return; … … 125 130 for (Way w : selectedWays) { 126 131 for (Entry<String,String> e : w.entrySet()) { 127 if (!props.containsKey(e.getKey())) 132 if (!props.containsKey(e.getKey())) { 128 133 props.put(e.getKey(), new TreeSet<String>()); 134 } 129 135 props.get(e.getKey()).add(e.getValue()); 130 136 } … … 139 145 if (secondTry instanceof List) { 140 146 int option = new ExtendedDialog(Main.parent, 141 tr("Change directions?"),142 tr("The ways can not be combined in their current directions. "143 + "Do you want to reverse some of them?"),144 new String[] {tr("Reverse and Combine"), tr("Cancel")},145 new String[] {"wayflip.png", "cancel.png"}).getValue();147 tr("Change directions?"), 148 tr("The ways can not be combined in their current directions. " 149 + "Do you want to reverse some of them?"), 150 new String[] {tr("Reverse and Combine"), tr("Cancel")}, 151 new String[] {"wayflip.png", "cancel.png"}).getValue(); 146 152 if (option != 1) return; 147 153 nodeList = (List<Node>) secondTry; … … 160 166 for (Way w : selectedWays) { 161 167 modifyWay = w; 162 if (w.id != 0) break; 168 if (w.id != 0) { 169 break; 170 } 163 171 } 164 172 Way newWay = new Way(modifyWay); … … 188 196 if (!components.isEmpty()) { 189 197 int answer = new ExtendedDialog(Main.parent, 190 tr("Enter values for all conflicts."),191 p,192 new String[] {tr("Solve Conflicts"), tr("Cancel")},193 new String[] {"dialogs/conflict.png", "cancel.png"}).getValue();198 tr("Enter values for all conflicts."), 199 p, 200 new String[] {tr("Solve Conflicts"), tr("Cancel")}, 201 new String[] {"dialogs/conflict.png", "cancel.png"}).getValue(); 194 202 if (answer != 1) return; 195 203 196 for (Entry<String, JComboBox> e : components.entrySet()) 204 for (Entry<String, JComboBox> e : components.entrySet()) { 197 205 newWay.put(e.getKey(), e.getValue().getEditor().getItem().toString()); 206 } 198 207 } 199 208 … … 224 233 } 225 234 Main.main.undoRedo.add(new SequenceCommand(tr("Combine {0} ways", selectedWays.size()), cmds)); 226 Main.ds.setSelected(modifyWay);235 getCurrentDataSet().setSelected(modifyWay); 227 236 } 228 237 … … 242 251 243 252 HashSet<Pair<Node,Node>> chunkSet = new HashSet<Pair<Node,Node>>(); 244 for (Way w : ways) 253 for (Way w : ways) { 245 254 chunkSet.addAll(w.getNodePairs(ignoreDirection)); 255 } 246 256 247 257 LinkedList<Pair<Node,Node>> chunks = new LinkedList<Pair<Node,Node>>(chunkSet); 248 258 249 if (chunks.isEmpty()) {259 if (chunks.isEmpty()) 250 260 return tr("All the ways were empty"); 251 }252 261 253 262 List<Node> nodeList = Pair.toArrayList(chunks.poll()); … … 273 282 break; 274 283 } 275 if (!foundChunk) break; 276 } 277 278 if (!chunks.isEmpty()) { 284 if (!foundChunk) { 285 break; 286 } 287 } 288 289 if (!chunks.isEmpty()) 279 290 return tr("Could not combine ways " 280 + "(They could not be merged into a single string of nodes)"); 281 } 291 + "(They could not be merged into a single string of nodes)"); 282 292 283 293 return nodeList; -
trunk/src/org/openstreetmap/josm/actions/CopyAction.java
r1750 r1814 45 45 46 46 public void actionPerformed(ActionEvent e) { 47 if( noSelection()) return;47 if(isEmptySelection()) return; 48 48 49 49 Main.pasteBuffer = copyData(); 50 Main.pasteSource = Main.main.createOrGetEditLayer();50 Main.pasteSource = getEditLayer(); 51 51 Main.main.menu.paste.setEnabled(true); /* now we have a paste buffer we can make paste available */ 52 52 … … 56 56 } 57 57 58 public staticDataSet copyData() {58 public DataSet copyData() { 59 59 /* New pasteBuffer - will be assigned to the global one at the end */ 60 60 final DataSet pasteBuffer = new DataSet(); … … 62 62 /* temporarily maps old nodes to new so we can do a true deep copy */ 63 63 64 if( noSelection()) return pasteBuffer;64 if(isEmptySelection()) return pasteBuffer; 65 65 66 66 /* scan the selected objects, mapping them to copies; when copying a way or relation, … … 71 71 * or a way and a node in that way is selected, we'll see it twice, once via the 72 72 * way and once directly; and so on. */ 73 if (map.containsKey(n)) { return; } 73 if (map.containsKey(n)) 74 return; 74 75 Node nnew = new Node(n); 75 76 map.put(n, nnew); … … 78 79 public void visit(Way w) { 79 80 /* check if already in pasteBuffer - could have come from a relation, and directly etc. */ 80 if (map.containsKey(w)) { return; } 81 if (map.containsKey(w)) 82 return; 81 83 Way wnew = new Way(); 82 84 wnew.cloneFrom(w); … … 93 95 } 94 96 public void visit(Relation e) { 95 if (map.containsKey(e)) { return; } 97 if (map.containsKey(e)) 98 return; 96 99 Relation enew = new Relation(e); 97 100 List<RelationMember> members = new ArrayList<RelationMember>(); … … 108 111 } 109 112 public void visitAll() { 110 for (OsmPrimitive osm : Main.ds.getSelected())113 for (OsmPrimitive osm : getCurrentDataSet().getSelected()) { 111 114 osm.visit(this); 115 } 112 116 113 117 // Used internally only (in PasteTagsAction), therefore no need to translate these 114 if( Main.ds.getSelectedNodes().size() > 0)118 if(getCurrentDataSet().getSelectedNodes().size() > 0) { 115 119 pasteBuffer.dataSources.add(new DataSource(null, "Copied Nodes")); 116 if(Main.ds.getSelectedWays().size() > 0) 120 } 121 if(getCurrentDataSet().getSelectedWays().size() > 0) { 117 122 pasteBuffer.dataSources.add(new DataSource(null, "Copied Ways")); 118 if(Main.ds.getSelectedRelations().size() > 0) 123 } 124 if(getCurrentDataSet().getSelectedRelations().size() > 0) { 119 125 pasteBuffer.dataSources.add(new DataSource(null, "Copied Relations")); 126 } 120 127 } 121 128 }.visitAll(); … … 128 135 } 129 136 130 private static boolean noSelection() {131 Collection<OsmPrimitive> sel = Main.ds.getSelected();137 private boolean isEmptySelection() { 138 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 132 139 if (sel.isEmpty()) { 133 JOptionPane.showMessageDialog(Main.parent, 134 tr("Please select something to copy.")); 140 JOptionPane.showMessageDialog( 141 Main.parent, 142 tr("Please select something to copy.") 143 ); 135 144 return true; 136 145 } -
trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java
r1741 r1814 80 80 } 81 81 82 Collection<OsmPrimitive> sel = Main.ds.getSelected();82 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 83 83 Collection<Node> nodes = new LinkedList<Node>(); 84 84 Way existingWay = null; … … 170 170 if (a1 < 999) { 171 171 // if it is, delete it 172 CollectBackReferencesVisitor refs = new CollectBackReferencesVisitor( Main.ds);172 CollectBackReferencesVisitor refs = new CollectBackReferencesVisitor(getCurrentDataSet()); 173 173 refs.visit(n1); 174 174 if (refs.data.isEmpty() || ((refs.data.size() == 1) && (refs.data.contains(existingWay)))) { -
trunk/src/org/openstreetmap/josm/actions/DistributeAction.java
r1640 r1814 29 29 public DistributeAction() { 30 30 super(tr("Distribute Nodes"), "distribute", tr("Distribute the selected nodes to equal distances along a line."), 31 Shortcut.registerShortcut("tools:distribute", tr("Tool: {0}", tr("Distribute Nodes")), KeyEvent.VK_B, Shortcut.GROUP_EDIT), true);31 Shortcut.registerShortcut("tools:distribute", tr("Tool: {0}", tr("Distribute Nodes")), KeyEvent.VK_B, Shortcut.GROUP_EDIT), true); 32 32 } 33 33 … … 38 38 */ 39 39 public void actionPerformed(ActionEvent e) { 40 Collection<OsmPrimitive> sel = Main.ds.getSelected();40 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 41 41 Collection<Node> nodes = new LinkedList<Node>(); 42 42 Collection<Node> itnodes = new LinkedList<Node>(); … … 48 48 // special case if no single nodes are selected and exactly one way is: 49 49 // then use the way's nodes 50 if ((nodes.size() == 0) && (sel.size() == 1)) 50 if ((nodes.size() == 0) && (sel.size() == 1)) { 51 51 for (OsmPrimitive osm : sel) 52 52 if (osm instanceof Way) { … … 54 54 itnodes.addAll(((Way)osm).nodes); 55 55 } 56 } 56 57 57 58 if (nodes.size() < 3) { -
trunk/src/org/openstreetmap/josm/actions/DuplicateAction.java
r1750 r1814 9 9 import java.util.Collection; 10 10 11 import org.openstreetmap.josm.actions.CopyAction;12 import org.openstreetmap.josm.actions.PasteAction;13 11 import org.openstreetmap.josm.data.SelectionChangedListener; 14 12 import org.openstreetmap.josm.data.osm.DataSet; 15 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 import org.openstreetmap.josm.gui.layer.Layer; 15 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 16 16 import org.openstreetmap.josm.tools.Shortcut; 17 import org.openstreetmap.josm.Main;18 17 19 public final class DuplicateAction extends JosmAction implements SelectionChangedListener {18 public final class DuplicateAction extends JosmAction implements SelectionChangedListener, LayerChangeListener { 20 19 21 20 public DuplicateAction() { 22 21 super(tr("Duplicate"), "duplicate", 23 tr("Duplicate selection by copy and immediate paste."),24 Shortcut.registerShortcut("system:duplicate", tr("Edit: {0}", tr("Duplicate")), KeyEvent.VK_D, Shortcut.GROUP_MENU), true);22 tr("Duplicate selection by copy and immediate paste."), 23 Shortcut.registerShortcut("system:duplicate", tr("Edit: {0}", tr("Duplicate")), KeyEvent.VK_D, Shortcut.GROUP_MENU), true); 25 24 setEnabled(false); 26 25 DataSet.selListeners.add(this); 26 Layer.listeners.add(this); 27 27 } 28 28 29 29 public void actionPerformed(ActionEvent e) { 30 PasteAction.pasteData(CopyAction.copyData(), Main.main.createOrGetEditLayer(), e);30 new PasteAction().pasteData(new CopyAction().copyData(), getEditLayer(), e); 31 31 } 32 32 33 34 protected void refreshEnabled() { 35 setEnabled(getCurrentDataSet() != null 36 && ! getCurrentDataSet().getSelected().isEmpty() 37 ); 38 } 39 40 /* ---------------------------------------------------------------------------------- */ 41 /* Interface SelectionChangeListener */ 42 /* ---------------------------------------------------------------------------------- */ 33 43 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 34 setEnabled(! newSelection.isEmpty()); 44 refreshEnabled(); 45 } 46 47 /* ---------------------------------------------------------------------------------- */ 48 /* Interface LayerChangeListener */ 49 /* ---------------------------------------------------------------------------------- */ 50 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 51 refreshEnabled(); 52 } 53 54 public void layerAdded(Layer newLayer) { 55 refreshEnabled(); 56 } 57 58 public void layerRemoved(Layer oldLayer) { 59 refreshEnabled(); 35 60 } 36 61 } -
trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java
r1808 r1814 84 84 public void export(Layer layer) { 85 85 if (layer == null) 86 throw new IllegalArgumentException(tr("paramenter ''{0 '' must not be null", "layer"));86 throw new IllegalArgumentException(tr("paramenter ''{0}'' must not be null", "layer")); 87 87 if (! (layer instanceof OsmDataLayer) && ! (layer instanceof GpxLayer)) 88 88 throw new IllegalArgumentException(tr("expected instance of OsmDataLayer or GpxLayer. Got ''{0}''.", layer.getClass().getName())); … … 98 98 } 99 99 100 public static void exportGpx(File file, Layer layer) { 100 /** 101 * Exports a layer to a file. 102 * 103 * <code>layer</code> must not be null. <code>layer</code> must be an instance of 104 * {@see OsmDataLayer} or {@see GpxLayer}. 105 * 106 * @param layer the layer 107 * @exception IllegalArgumentException thrown if layer is null 108 * @exception IllegalArgumentException thrown if layer is neither an instance of {@see OsmDataLayer} 109 * nor of {@see GpxLayer} 110 */ 111 112 public void exportGpx(File file, Layer layer) { 113 if (layer == null) 114 throw new IllegalArgumentException(tr("paramenter ''{0}'' must not be null", "layer")); 115 if (! (layer instanceof OsmDataLayer) && ! (layer instanceof GpxLayer)) 116 throw new IllegalArgumentException(tr("expected instance of OsmDataLayer or GpxLayer. Got ''{0}''.", layer.getClass().getName())); 117 if (file == null) 118 throw new IllegalArgumentException(tr("paramenter ''{0}'' must not be null", "file")); 119 101 120 String fn = file.getPath(); 102 121 if (fn.indexOf('.') == -1) { … … 172 191 gpxData = ((GpxLayer)layer).data; 173 192 } else { 174 gpxData = OsmDataLayer.toGpxData( Main.ds, file);193 gpxData = OsmDataLayer.toGpxData(getCurrentDataSet(), file); 175 194 } 176 195 -
trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java
r1725 r1814 28 28 public JoinNodeWayAction() { 29 29 super(tr("Join Node to Way"), "joinnodeway", tr("Join a node into the nearest way segments"), 30 Shortcut.registerShortcut("tools:joinnodeway", tr("Tool: {0}", tr("Join Node to Way")), KeyEvent.VK_J, Shortcut.GROUP_EDIT), true);30 Shortcut.registerShortcut("tools:joinnodeway", tr("Tool: {0}", tr("Join Node to Way")), KeyEvent.VK_J, Shortcut.GROUP_EDIT), true); 31 31 } 32 32 33 33 public void actionPerformed(ActionEvent e) { 34 Collection<OsmPrimitive> sel = Main.ds.getSelected();34 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 35 35 if (sel.size() != 1 || !(sel.iterator().next() instanceof Node)) return; 36 36 Node node = (Node) sel.iterator().next(); 37 37 38 38 List<WaySegment> wss = Main.map.mapView.getNearestWaySegments( 39 Main.map.mapView.getPoint(node));39 Main.map.mapView.getPoint(node)); 40 40 HashMap<Way, List<Integer>> insertPoints = new HashMap<Way, List<Integer>>(); 41 41 for (WaySegment ws : wss) { … … 60 60 List<Integer> is = insertPoint.getValue(); 61 61 pruneSuccsAndReverse(is); 62 for (int i : is) wnew.nodes.add(i+1, node); 62 for (int i : is) { 63 wnew.nodes.add(i+1, node); 64 } 63 65 cmds.add(new ChangeCommand(w, wnew)); 64 66 } -
trunk/src/org/openstreetmap/josm/actions/JosmAction.java
r1415 r1814 9 9 import org.openstreetmap.josm.Main; 10 10 import org.openstreetmap.josm.data.osm.DataSet; 11 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 11 12 import org.openstreetmap.josm.tools.Destroyable; 12 13 import org.openstreetmap.josm.tools.ImageProvider; … … 61 62 putValue(SHORT_DESCRIPTION, Main.platform.makeTooltip(tooltip, sc)); 62 63 putValue("toolbar", iconName); 63 if (register) 64 if (register) { 64 65 Main.toolbar.register(this); 66 } 65 67 } 66 68 … … 92 94 private void setHelpId() { 93 95 String helpId = "Action/"+getClass().getName().substring(getClass().getName().lastIndexOf('.')+1); 94 if (helpId.endsWith("Action")) 96 if (helpId.endsWith("Action")) { 95 97 helpId = helpId.substring(0, helpId.length()-6); 98 } 96 99 putValue("help", helpId); 97 100 } 101 102 /** 103 * Replies the current edit layer 104 * 105 * @return the current edit layer. null, if no edit layer exists 106 */ 107 protected OsmDataLayer getEditLayer() { 108 return Main.main.getEditLayer(); 109 } 110 111 /** 112 * Replies the current dataset 113 * 114 * @return the current dataset. null, if no current dataset exists 115 */ 116 protected DataSet getCurrentDataSet() { 117 return Main.main.getCurrentDataSet(); 118 } 98 119 } -
trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java
r1677 r1814 55 55 public MergeNodesAction() { 56 56 super(tr("Merge Nodes"), "mergenodes", tr("Merge nodes into the oldest one."), 57 Shortcut.registerShortcut("tools:mergenodes", tr("Tool: {0}", tr("Merge Nodes")), KeyEvent.VK_M, Shortcut.GROUP_EDIT), true);57 Shortcut.registerShortcut("tools:mergenodes", tr("Tool: {0}", tr("Merge Nodes")), KeyEvent.VK_M, Shortcut.GROUP_EDIT), true); 58 58 DataSet.selListeners.add(this); 59 59 } 60 60 61 61 public void actionPerformed(ActionEvent event) { 62 Collection<OsmPrimitive> selection = Main.ds.getSelected();62 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 63 63 LinkedList<Node> selectedNodes = new LinkedList<Node>(); 64 64 … … 67 67 // anyway as long as we have at least two nodes 68 68 for (OsmPrimitive osm : selection) 69 if (osm instanceof Node) 69 if (osm instanceof Node) { 70 70 selectedNodes.add((Node)osm); 71 } 71 72 72 73 if (selectedNodes.size() < 2) { … … 93 94 } 94 95 } 95 if (useNode == null) 96 if (useNode == null) { 96 97 useNode = selectedNodes.iterator().next(); 98 } 97 99 98 100 mergeNodes(selectedNodes, useNode); … … 102 104 * really do the merging - returns the node that is left 103 105 */ 104 public staticNode mergeNodes(LinkedList<Node> allNodes, Node dest) {106 public Node mergeNodes(LinkedList<Node> allNodes, Node dest) { 105 107 Node newNode = new Node(dest); 106 108 … … 118 120 new HashMap<Pair<Relation,String>, HashSet<Node>>(); 119 121 HashSet<Relation> relationsUsingNodes = new HashSet<Relation>(); 120 for (Relation r : Main.ds.relations) { 121 if (r.deleted || r.incomplete) continue; 122 for (Relation r : getCurrentDataSet().relations) { 123 if (r.deleted || r.incomplete) { 124 continue; 125 } 122 126 for (RelationMember rm : r.members) { 123 127 if (rm.member instanceof Node) { … … 148 152 tr("Merge nodes with different memberships?"), 149 153 tr("The selected nodes have differing relation memberships. " 150 + "Do you still want to merge them?"), 151 new String[] {tr("Merge Anyway"), tr("Cancel")}, 152 new String[] {"mergenodes.png", "cancel.png"}).getValue(); 153 if (option == 1) break; 154 + "Do you still want to merge them?"), 155 new String[] {tr("Merge Anyway"), tr("Cancel")}, 156 new String[] {"mergenodes.png", "cancel.png"}).getValue(); 157 if (option == 1) { 158 break; 159 } 154 160 return null; 155 161 } … … 160 166 for (Node n : allNodes) { 161 167 for (Entry<String,String> e : n.entrySet()) { 162 if (!props.containsKey(e.getKey())) 168 if (!props.containsKey(e.getKey())) { 163 169 props.put(e.getKey(), new TreeSet<String>()); 170 } 164 171 props.get(e.getKey()).add(e.getValue()); 165 172 } … … 187 194 if (!components.isEmpty()) { 188 195 int answer = new ExtendedDialog(Main.parent, 189 tr("Enter values for all conflicts."),190 p,191 new String[] {tr("Solve Conflicts"), tr("Cancel")},192 new String[] {"dialogs/conflict.png", "cancel.png"}).getValue();196 tr("Enter values for all conflicts."), 197 p, 198 new String[] {tr("Solve Conflicts"), tr("Cancel")}, 199 new String[] {"dialogs/conflict.png", "cancel.png"}).getValue(); 193 200 if (answer != 1) 194 201 return null; 195 for (Entry<String, JComboBox> e : components.entrySet()) 202 for (Entry<String, JComboBox> e : components.entrySet()) { 196 203 newNode.put(e.getKey(), e.getValue().getEditor().getItem().toString()); 204 } 197 205 } 198 206 … … 202 210 Collection<OsmPrimitive> del = new HashSet<OsmPrimitive>(); 203 211 204 for (Way w : Main.ds.ways) { 205 if (w.deleted || w.incomplete || w.nodes.size() < 1) continue; 212 for (Way w : getCurrentDataSet().ways) { 213 if (w.deleted || w.incomplete || w.nodes.size() < 1) { 214 continue; 215 } 206 216 boolean modify = false; 207 217 for (Node sn : allNodes) { 208 if (sn == dest) continue; 218 if (sn == dest) { 219 continue; 220 } 209 221 if (w.nodes.contains(sn)) { 210 222 modify = true; 211 223 } 212 224 } 213 if (!modify) continue; 225 if (!modify) { 226 continue; 227 } 214 228 // OK - this way contains one or more nodes to change 215 229 ArrayList<Node> nn = new ArrayList<Node>(); … … 227 241 if (nn.size() < 2) { 228 242 CollectBackReferencesVisitor backRefs = 229 new CollectBackReferencesVisitor( Main.ds, false);243 new CollectBackReferencesVisitor(getCurrentDataSet(), false); 230 244 w.visit(backRefs); 231 245 if (!backRefs.data.isEmpty()) { 232 246 JOptionPane.showMessageDialog(Main.parent, 233 tr("Cannot merge nodes: " +247 tr("Cannot merge nodes: " + 234 248 "Would have to delete a way that is still used.")); 235 249 return null; … … 247 261 del.addAll(allNodes); 248 262 del.remove(dest); 249 if (!del.isEmpty()) cmds.add(new DeleteCommand(del)); 263 if (!del.isEmpty()) { 264 cmds.add(new DeleteCommand(del)); 265 } 250 266 251 267 // modify all relations containing the now-deleted nodes … … 270 286 271 287 Main.main.undoRedo.add(new SequenceCommand(tr("Merge {0} nodes", allNodes.size()), cmds)); 272 Main.ds.setSelected(dest);288 getCurrentDataSet().setSelected(dest); 273 289 274 290 return dest; -
trunk/src/org/openstreetmap/josm/actions/MirrorAction.java
r1722 r1814 14 14 import org.openstreetmap.josm.Main; 15 15 import org.openstreetmap.josm.command.Command; 16 import org.openstreetmap.josm.command.ChangeCommand;17 16 import org.openstreetmap.josm.command.MoveCommand; 18 17 import org.openstreetmap.josm.command.SequenceCommand; 19 import org.openstreetmap.josm.data.coor.EastNorth;20 18 import org.openstreetmap.josm.data.osm.Node; 21 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 34 32 public MirrorAction() { 35 33 super(tr("Mirror"), "mirror", tr("Mirror selected nodes and ways."), 36 Shortcut.registerShortcut("tools:mirror", tr("Tool: {0}", tr("Mirror")),37 KeyEvent.VK_M, Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true);34 Shortcut.registerShortcut("tools:mirror", tr("Tool: {0}", tr("Mirror")), 35 KeyEvent.VK_M, Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true); 38 36 } 39 37 40 38 public void actionPerformed(ActionEvent e) { 41 Collection<OsmPrimitive> sel = Main.ds.getSelected();39 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 42 40 HashSet<Node> nodes = new HashSet<Node>(); 43 41 … … 66 64 Collection<Command> cmds = new LinkedList<Command>(); 67 65 68 for (Node n : nodes) 66 for (Node n : nodes) { 69 67 cmds.add(new MoveCommand(n, 2 * (middle - n.getEastNorth().east()), 0.0)); 68 } 70 69 71 70 Main.main.undoRedo.add(new SequenceCommand(tr("Mirror"), cmds)); -
trunk/src/org/openstreetmap/josm/actions/MoveAction.java
r1750 r1814 85 85 } 86 86 87 Collection<OsmPrimitive> selection = Main.ds.getSelected();87 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 88 88 Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection); 89 89 -
trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
r1640 r1814 38 38 public OrthogonalizeAction() { 39 39 super(tr("Orthogonalize Shape"), 40 "ortho",41 tr("Move nodes so all angles are 90 or 270 degree"),42 Shortcut.registerShortcut("tools:orthogonalize", tr("Tool: {0}", tr("Orthogonalize Shape")),43 KeyEvent.VK_Q,44 Shortcut.GROUP_EDIT), true);40 "ortho", 41 tr("Move nodes so all angles are 90 or 270 degree"), 42 Shortcut.registerShortcut("tools:orthogonalize", tr("Tool: {0}", tr("Orthogonalize Shape")), 43 KeyEvent.VK_Q, 44 Shortcut.GROUP_EDIT), true); 45 45 } 46 46 47 47 public void actionPerformed(ActionEvent e) { 48 48 49 Collection<OsmPrimitive> sel = Main.ds.getSelected();49 Collection<OsmPrimitive> sel = getCurrentDataSet().getSelected(); 50 50 51 51 ArrayList<Node> dirnodes = new ArrayList<Node>(); … … 84 84 double angle2 = Math.abs(way.nodes.get(i2).getEastNorth().heading(way.nodes.get(i3).getEastNorth())); 85 85 double delta = Math.abs(angle2 - angle1); 86 while(delta > Math.PI) delta -= Math.PI; 86 while(delta > Math.PI) { 87 delta -= Math.PI; 88 } 87 89 if(delta < Math.PI/4) { 88 90 JOptionPane.showMessageDialog(Main.parent, tr("Please select ways with almost right angles to orthogonalize.")); … … 96 98 "to undesirable results when doing rectangular alignments.<br>" + 97 99 "Change your projection to get rid of this warning.<br>" + 98 99 100 if (!DontShowAgainInfo.show("align_rectangular_4326", msg, false)) {100 "Do you want to continue?"); 101 102 if (!DontShowAgainInfo.show("align_rectangular_4326", msg, false)) 101 103 return; 102 }103 104 } 104 105 // Check, if selection held neither none nor two nodes … … 122 123 123 124 for (OsmPrimitive osm : sel) { 124 if(!(osm instanceof Way)) 125 if(!(osm instanceof Way)) { 125 126 continue; 127 } 126 128 127 129 Way way = (Way)osm; … … 158 160 diff = heading_diff(headings[i], headings[i - 1]); 159 161 } 160 if (diff > angle_diff_max) angle_diff_max = diff; 162 if (diff > angle_diff_max) { 163 angle_diff_max = diff; 164 } 161 165 } 162 166 … … 164 168 // rearrange headings: everything < 0 gets PI/2-rotated 165 169 for (int i=0; i < sides; i++) { 166 if (headings[i] < 0) 170 if (headings[i] < 0) { 167 171 headings[i] += Math.PI/2; 172 } 168 173 } 169 174 } … … 217 222 // been duplicated 218 223 219 if (u == 0) continue; 224 if (u == 0) { 225 continue; 226 } 220 227 221 228 // q is a number between 0 and 1 … … 257 264 double llimit = -Math.PI/4; 258 265 double ulimit = Math.PI/4; 259 while (h - align_to > ulimit) h -= Math.PI/2; 260 while (h - align_to < llimit) h += Math.PI/2; 266 while (h - align_to > ulimit) { 267 h -= Math.PI/2; 268 } 269 while (h - align_to < llimit) { 270 h += Math.PI/2; 271 } 261 272 262 273 return h; -
trunk/src/org/openstreetmap/josm/actions/PasteAction.java
r1750 r1814 31 31 public PasteAction() { 32 32 super(tr("Paste"), "paste", tr("Paste contents of paste buffer."), 33 Shortcut.registerShortcut("system:paste", tr("Edit: {0}", tr("Paste")), KeyEvent.VK_V, Shortcut.GROUP_MENU), true);33 Shortcut.registerShortcut("system:paste", tr("Edit: {0}", tr("Paste")), KeyEvent.VK_V, Shortcut.GROUP_MENU), true); 34 34 setEnabled(false); 35 35 } … … 39 39 } 40 40 41 public staticvoid pasteData(DataSet pasteBuffer, Layer source, ActionEvent e) {41 public void pasteData(DataSet pasteBuffer, Layer source, ActionEvent e) { 42 42 /* Find the middle of the pasteBuffer area */ 43 43 double maxEast = -1E100, minEast = 1E100, maxNorth = -1E100, minNorth = 1E100; … … 63 63 64 64 HashMap<OsmPrimitive,OsmPrimitive> map = new HashMap<OsmPrimitive,OsmPrimitive>(); 65 65 /* temporarily maps old nodes to new so we can do a true deep copy */ 66 66 67 67 /* do the deep copy of the paste buffer contents, leaving the pasteBuffer unchanged */ … … 69 69 Node nnew = new Node(n); 70 70 nnew.id = 0; 71 if (Main.ma in.createOrGetEditLayer() == source) {71 if (Main.map.mapView.getEditLayer() == source) { 72 72 nnew.setEastNorth(nnew.getEastNorth().add(offsetEast, offsetNorth)); 73 73 } … … 113 113 114 114 Main.main.undoRedo.add(new SequenceCommand(tr("Paste"), clist)); 115 Main.ds.setSelected(osms);115 getCurrentDataSet().setSelected(osms); 116 116 Main.map.mapView.repaint(); 117 117 } -
trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java
r1613 r1814 27 27 public PasteTagsAction(JosmAction copyAction) { 28 28 super(tr("Paste Tags"), "pastetags", 29 tr("Apply tags of contents of paste buffer to all selected items."),30 Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")), KeyEvent.VK_V, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT), true);29 tr("Apply tags of contents of paste buffer to all selected items."), 30 Shortcut.registerShortcut("system:pastestyle", tr("Edit: {0}", tr("Paste Tags")), KeyEvent.VK_V, Shortcut.GROUP_MENU, Shortcut.SHIFT_DEFAULT), true); 31 31 DataSet.selListeners.add(this); 32 32 copyAction.addListener(this); … … 43 43 OsmPrimitive osm = it.next(); 44 44 Map<String, String> m = osm.keys; 45 if(m == null) 45 if(m == null) { 46 46 continue; 47 } 47 48 48 49 for (String key : m.keySet()) { … … 55 56 Collection<Command> clist = new LinkedList<Command>(); 56 57 String pbSource = "Multiple Sources"; 57 if(Main.pasteBuffer.dataSources.size() == 1) 58 if(Main.pasteBuffer.dataSources.size() == 1) { 58 59 pbSource = ((DataSource) Main.pasteBuffer.dataSources.toArray()[0]).origin; 60 } 59 61 60 62 boolean pbNodes = Main.pasteBuffer.nodes.size() > 0; 61 63 boolean pbWays = Main.pasteBuffer.ways.size() > 0; 62 64 63 boolean seNodes = Main.ds.getSelectedNodes().size() > 0;64 boolean seWays = Main.ds.getSelectedWays().size() > 0;65 boolean seRels = Main.ds.getSelectedRelations().size() > 0;65 boolean seNodes = getCurrentDataSet().getSelectedNodes().size() > 0; 66 boolean seWays = getCurrentDataSet().getSelectedWays().size() > 0; 67 boolean seRels = getCurrentDataSet().getSelectedRelations().size() > 0; 66 68 67 69 if(!seNodes && seWays && !seRels && pbNodes && pbSource.equals("Copied Nodes")) { 68 70 // Copy from nodes to ways 69 pasteKeys(clist, Main.pasteBuffer.nodes, Main.ds.getSelectedWays());71 pasteKeys(clist, Main.pasteBuffer.nodes, getCurrentDataSet().getSelectedWays()); 70 72 } else if(seNodes && !seWays && !seRels && pbWays && pbSource.equals("Copied Ways")) { 71 73 // Copy from ways to nodes 72 pasteKeys(clist, Main.pasteBuffer.ways, Main.ds.getSelectedNodes());74 pasteKeys(clist, Main.pasteBuffer.ways, getCurrentDataSet().getSelectedNodes()); 73 75 } else { 74 76 // Copy from equal to equal 75 pasteKeys(clist, Main.pasteBuffer.nodes, Main.ds.getSelectedNodes());76 pasteKeys(clist, Main.pasteBuffer.ways, Main.ds.getSelectedWays());77 pasteKeys(clist, Main.pasteBuffer.relations, Main.ds.getSelectedRelations());77 pasteKeys(clist, Main.pasteBuffer.nodes, getCurrentDataSet().getSelectedNodes()); 78 pasteKeys(clist, Main.pasteBuffer.ways, getCurrentDataSet().getSelectedWays()); 79 pasteKeys(clist, Main.pasteBuffer.relations, getCurrentDataSet().getSelectedRelations()); 78 80 } 79 81 Main.main.undoRedo.add(new SequenceCommand(tr("Paste Tags"), clist)); 80 Main.ds.setSelected(Main.ds.getSelected()); // to force selection listeners, in particular the tag panel, to update82 getCurrentDataSet().setSelected(getCurrentDataSet().getSelected()); // to force selection listeners, in particular the tag panel, to update 81 83 Main.map.mapView.repaint(); 82 84 } … … 86 88 for (Iterator<? extends OsmPrimitive> it = osms.iterator(); it.hasNext();) { 87 89 OsmPrimitive osm = it.next(); 88 if (osm.keys == null || osm.keys.isEmpty()) 90 if (osm.keys == null || osm.keys.isEmpty()) { 89 91 continue; 92 } 90 93 for (String key : osm.keys.keySet()) { 91 94 String value = osm.keys.get(key); 92 if (! kvSeen.containsKey(key)) 95 if (! kvSeen.containsKey(key)) { 93 96 kvSeen.put(key, value); 94 else if (! kvSeen.get(key).equals(value))97 } else if (! kvSeen.get(key).equals(value)) 95 98 return true; 96 99 } … … 110 113 ! selection.isEmpty() && 111 114 ! pasteBuffer.allPrimitives().isEmpty() && 112 ( Main.ds.getSelectedNodes().isEmpty() ||113 ! containsSameKeysWithDifferentValues(pasteBuffer.nodes)) &&114 (Main.ds.getSelectedWays().isEmpty() ||115 ! containsSameKeysWithDifferentValues(pasteBuffer.ways)) &&116 (Main.ds.getSelectedRelations().isEmpty() ||117 ! containsSameKeysWithDifferentValues(pasteBuffer.relations)));115 (getCurrentDataSet().getSelectedNodes().isEmpty() || 116 ! containsSameKeysWithDifferentValues(pasteBuffer.nodes)) && 117 (getCurrentDataSet().getSelectedWays().isEmpty() || 118 ! containsSameKeysWithDifferentValues(pasteBuffer.ways)) && 119 (getCurrentDataSet().getSelectedRelations().isEmpty() || 120 ! containsSameKeysWithDifferentValues(pasteBuffer.relations))); 118 121 } 119 122 120 123 @Override public void pasteBufferChanged(DataSet newPasteBuffer) { 121 possiblyEnable( Main.ds.getSelected(), newPasteBuffer);124 possiblyEnable(getCurrentDataSet().getSelected(), newPasteBuffer); 122 125 } 123 126 -
trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java
r1613 r1814 30 30 public ReverseWayAction() { 31 31 super(tr("Reverse Ways"), "wayflip", tr("Reverse the direction of all selected ways."), 32 Shortcut.registerShortcut("tools:reverse", tr("Tool: {0}", tr("Reverse Ways")), KeyEvent.VK_R, Shortcut.GROUP_EDIT), true);32 Shortcut.registerShortcut("tools:reverse", tr("Tool: {0}", tr("Reverse Ways")), KeyEvent.VK_R, Shortcut.GROUP_EDIT), true); 33 33 } 34 34 … … 47 47 48 48 public void visitAll() { 49 for (OsmPrimitive osm : Main.ds.getSelected())49 for (OsmPrimitive osm : getCurrentDataSet().getSelected()) { 50 50 osm.visit(this); 51 } 51 52 } 52 53 }.visitAll(); … … 69 70 final Collection<Command> changePropertyCommands = reverseWayTagCorrector.execute(w, wnew); 70 71 propertiesUpdated = propertiesUpdated 71 72 || (changePropertyCommands != null && !changePropertyCommands.isEmpty()); 72 73 c.addAll(changePropertyCommands); 73 74 } … … 80 81 } 81 82 Main.main.undoRedo.add(new SequenceCommand(tr("Reverse ways"), c)); 82 if (propertiesUpdated) 83 DataSet.fireSelectionChanged(Main.ds.getSelected()); 83 if (propertiesUpdated) { 84 DataSet.fireSelectionChanged(getCurrentDataSet().getSelected()); 85 } 84 86 Main.map.repaint(); 85 87 } -
trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
r1808 r1814 160 160 OsmBzip2Importer osmBzip2Importer = new OsmBzip2Importer(); 161 161 if (gpxImExporter.acceptFile(file)) { 162 GpxExportAction.exportGpx(file, layer);162 new GpxExportAction().exportGpx(file, layer); 163 163 } else if (osmImExporter.acceptFile(file) 164 164 || osmGzipImporter.acceptFile(file) -
trunk/src/org/openstreetmap/josm/actions/SelectAllAction.java
r1808 r1814 7 7 import java.awt.event.KeyEvent; 8 8 9 import org.openstreetmap.josm.Main;10 9 import org.openstreetmap.josm.gui.layer.Layer; 11 10 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; … … 24 23 if (!isEnabled()) 25 24 return; 26 Main.ds.setSelected(Main.ds.allNonDeletedCompletePrimitives());25 getCurrentDataSet().setSelected(getCurrentDataSet().allNonDeletedCompletePrimitives()); 27 26 } 28 27 … … 32 31 */ 33 32 protected void refreshEnabled() { 34 setEnabled(Main.map != null 35 && Main.map.mapView !=null 36 && Main.map.mapView.getEditLayer() != null 37 ); 33 setEnabled(getEditLayer() != null); 38 34 } 39 35 -
trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
r1809 r1814 32 32 import org.openstreetmap.josm.data.osm.Way; 33 33 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; 34 import org.openstreetmap.josm.data.osm.visitor.NameVisitor;35 34 import org.openstreetmap.josm.data.osm.visitor.Visitor; 35 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 36 36 import org.openstreetmap.josm.tools.Shortcut; 37 37 … … 65 65 public void actionPerformed(ActionEvent e) { 66 66 67 Collection<OsmPrimitive> selection = Main.ds.getSelected();67 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 68 68 69 69 if (!checkSelection(selection)) { … … 99 99 HashMap<Way, Integer> wayOccurenceCounter = new HashMap<Way, Integer>(); 100 100 for (Node n : selectedNodes) { 101 for (Way w : Main.ds.ways) {101 for (Way w : getCurrentDataSet().ways) { 102 102 if (w.deleted || w.incomplete) { 103 103 continue; … … 272 272 Boolean warnme=false; 273 273 // now copy all relations to new way also 274 for (Relation r : Main.ds.relations) { 274 275 for (Relation r : getCurrentDataSet().relations) { 275 276 if (r.deleted || r.incomplete) { 276 277 continue; … … 329 330 } 330 331 331 NameVisitor v = new NameVisitor();332 v.visit(selectedWay);333 332 Main.main.undoRedo.add( 334 333 new SequenceCommand(tr("Split way {0} into {1} parts", 335 v.name, wayChunks.size()),334 new PrimitiveNameFormatter().getName(selectedWay), wayChunks.size()), 336 335 commandList)); 337 Main.ds.setSelected(newSelection);336 getCurrentDataSet().setSelected(newSelection); 338 337 } 339 338 -
trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java
r1722 r1814 50 50 public UnGlueAction() { 51 51 super(tr("UnGlue Ways"), "unglueways", tr("Duplicate nodes that are used by multiple ways."), 52 Shortcut.registerShortcut("tools:unglue", tr("Tool: {0}", tr("UnGlue Ways")), KeyEvent.VK_G, Shortcut.GROUP_EDIT), true);52 Shortcut.registerShortcut("tools:unglue", tr("Tool: {0}", tr("UnGlue Ways")), KeyEvent.VK_G, Shortcut.GROUP_EDIT), true); 53 53 //DataSet.selListeners.add(this); 54 54 } … … 61 61 public void actionPerformed(ActionEvent e) { 62 62 63 Collection<OsmPrimitive> selection = Main.ds.getSelected();63 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 64 64 65 65 String errMsg = null; 66 66 if (checkSelection(selection)) { 67 67 int count = 0; 68 for (Way w : Main.ds.ways) { 69 if (w.deleted || w.incomplete || w.nodes.size() < 1) continue; 70 if (!w.nodes.contains(selectedNode)) continue; 68 for (Way w : getCurrentDataSet().ways) { 69 if (w.deleted || w.incomplete || w.nodes.size() < 1) { 70 continue; 71 } 72 if (!w.nodes.contains(selectedNode)) { 73 continue; 74 } 71 75 count++; 72 76 } … … 74 78 // If there aren't enough ways, maybe the user wanted to unglue the nodes 75 79 // (= copy tags to a new node) 76 if(checkForUnglueNode(selection)) 80 if(checkForUnglueNode(selection)) { 77 81 unglueNode(e); 78 else82 } else { 79 83 errMsg = tr("This node is not glued to anything else."); 84 } 80 85 } else { 81 86 // and then do the work. … … 86 91 for (Node n : selectedNodes) { 87 92 int count = 0; 88 for (Way w : Main.ds.ways) { 89 if (w.deleted || w.incomplete || w.nodes.size() < 1) continue; 90 if (!w.nodes.contains(n)) continue; 93 for (Way w : getCurrentDataSet().ways) { 94 if (w.deleted || w.incomplete || w.nodes.size() < 1) { 95 continue; 96 } 97 if (!w.nodes.contains(n)) { 98 continue; 99 } 91 100 count++; 92 101 } … … 118 127 "\n"+ 119 128 tr("Note: If a way is selected, this way will get fresh copies of the unglued\n"+ 120 "nodes and the new nodes will be selected. Otherwise, all ways will get their\n"+121 122 } 123 124 if(errMsg != null) 129 "nodes and the new nodes will be selected. Otherwise, all ways will get their\n"+ 130 "own copy and all nodes will be selected."); 131 } 132 133 if(errMsg != null) { 125 134 JOptionPane.showMessageDialog(Main.parent, errMsg); 135 } 126 136 127 137 selectedNode = null; … … 156 166 157 167 Main.main.undoRedo.add(new SequenceCommand(tr("Unglued Node"), cmds)); 158 Main.ds.setSelected(n);168 getCurrentDataSet().setSelected(n); 159 169 Main.map.mapView.repaint(); 160 170 } … … 176 186 return false; 177 187 boolean isPartOfWay = false; 178 for(Way w : Main.ds.ways) {188 for(Way w : getCurrentDataSet().ways) { 179 189 if(w.nodes.contains(n)) { 180 190 isPartOfWay = true; … … 250 260 for (OsmPrimitive p : selection) { 251 261 if (p instanceof Way) { 252 if (selectedWay != null) {262 if (selectedWay != null) 253 263 return false; 254 }255 264 selectedWay = (Way) p; 256 265 } 257 266 } 258 if (selectedWay == null) { 259 return false; 260 } 267 if (selectedWay == null) 268 return false; 261 269 262 270 selectedNodes = new ArrayList<Node>(); … … 264 272 if (p instanceof Node) { 265 273 Node n = (Node) p; 266 if (!selectedWay.nodes.contains(n)) {274 if (!selectedWay.nodes.contains(n)) 267 275 return false; 268 }269 276 selectedNodes.add(n); 270 277 } … … 311 318 Relation newRel = null; 312 319 HashSet<String> rolesToReAdd = null; 313 for (Relation r : Main.ds.relations) { 314 if (r.deleted || r.incomplete) continue; 320 for (Relation r : getCurrentDataSet().relations) { 321 if (r.deleted || r.incomplete) { 322 continue; 323 } 315 324 newRel = null; 316 325 rolesToReAdd = null; … … 330 339 for (RelationMember rm : r.members) { 331 340 //if (rm.member != selectedNode) { 332 341 newRel.members.add(rm); 333 342 //} 334 343 } … … 356 365 boolean firstway = true; 357 366 // modify all ways containing the nodes 358 for (Way w : Main.ds.ways) { 359 if (w.deleted || w.incomplete || w.nodes.size() < 1) continue; 360 if (!w.nodes.contains(selectedNode)) continue; 361 if (!firstway) cmds.add(new ChangeCommand(w, modifyWay(selectedNode, w, cmds, newNodes))); 367 for (Way w : getCurrentDataSet().ways) { 368 if (w.deleted || w.incomplete || w.nodes.size() < 1) { 369 continue; 370 } 371 if (!w.nodes.contains(selectedNode)) { 372 continue; 373 } 374 if (!firstway) { 375 cmds.add(new ChangeCommand(w, modifyWay(selectedNode, w, cmds, newNodes))); 376 } 362 377 firstway = false; 363 378 } … … 372 387 newNodes.add(selectedNode); 373 388 } // if a node and a way has been selected, new selection is only the new node that was added to the selected way 374 Main.ds.setSelected(newNodes);389 getCurrentDataSet().setSelected(newNodes); 375 390 } 376 391 … … 393 408 394 409 Main.main.undoRedo.add(new SequenceCommand(tr("Dupe {0} nodes into {1} nodes", selectedNodes.size(), selectedNodes.size()+allNewNodes.size()), cmds)); 395 Main.ds.setSelected(allNewNodes); 396 } 397 398 // Disabled because we have such a nice help text that would not be shown otherwise. 399 // 400 // /** 401 // * Enable the menu option if the selection looks like we could use it. 402 // */ 403 // public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 404 // setEnabled(checkSelection(newSelection) || checkSelection2(newSelection)); 405 // selectedNode = null; 406 // selectedWay = null; 407 // selectedNodes = null; 408 // } 410 getCurrentDataSet().setSelected(allNewNodes); 411 } 409 412 } -
trunk/src/org/openstreetmap/josm/actions/UnselectAllAction.java
r1808 r1814 44 44 if (!isEnabled()) 45 45 return; 46 Main.ds.setSelected();46 getCurrentDataSet().setSelected(); 47 47 } 48 48 /** … … 51 51 */ 52 52 protected void refreshEnabled() { 53 setEnabled(Main.map != null 54 && Main.map.mapView !=null 55 && Main.map.mapView.getEditLayer() != null 56 ); 53 setEnabled(getEditLayer() != null); 57 54 } 58 55 -
trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java
r1808 r1814 16 16 import org.openstreetmap.josm.data.osm.DataSource; 17 17 import org.openstreetmap.josm.gui.layer.Layer; 18 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 18 19 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 19 20 import org.openstreetmap.josm.tools.Shortcut; … … 38 39 */ 39 40 protected void refreshEnabled() { 40 setEnabled(Main.main != null 41 && Main.map != null 42 && Main.map.mapView !=null 43 && Main.map.mapView.getEditLayer() != null 44 ); 41 setEnabled(getEditLayer() != null); 45 42 } 46 43 … … 50 47 int bboxCount = 0; 51 48 List<Area> areas = new ArrayList<Area>(); 52 for(DataSource ds : Main.ma in.createOrGetEditLayer().data.dataSources) {49 for(DataSource ds : Main.map.mapView.getEditLayer().data.dataSources) { 53 50 areas.add(new Area(ds.bounds.asRect())); 54 51 } -
trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java
r1811 r1814 42 42 protected void handlePrimitiveGoneException(long id) { 43 43 MultiFetchServerObjectReader reader = new MultiFetchServerObjectReader(); 44 reader.append( Main.main.createOrGetEditLayer().data,id);44 reader.append(getCurrentDataSet(),id); 45 45 DataSet ds = null; 46 46 try { … … 194 194 */ 195 195 protected void refreshEnabled() { 196 setEnabled(Main.main != null 197 && Main.map != null 198 && Main.map.mapView !=null 199 && Main.map.mapView.getEditLayer() != null 200 && ! Main.map.mapView.getEditLayer().data.getSelected().isEmpty() 196 setEnabled(getCurrentDataSet() != null 197 && ! getCurrentDataSet().getSelected().isEmpty() 201 198 ); 202 199 } … … 208 205 if (! isEnabled()) 209 206 return; 210 Collection<OsmPrimitive> selection = Main.ds.getSelected();207 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 211 208 if (selection.size() == 0) { 212 209 JOptionPane.showMessageDialog( -
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r1811 r1814 178 178 } 179 179 180 ConflictCollection conflicts = Main.ma in.createOrGetEditLayer().getConflicts();180 ConflictCollection conflicts = Main.map.mapView.getEditLayer().getConflicts(); 181 181 if (conflicts !=null && !conflicts.isEmpty()) { 182 182 JOptionPane.showMessageDialog(Main.parent,tr("There are unresolved conflicts. You have to resolve these first.")); … … 189 189 final LinkedList<OsmPrimitive> update = new LinkedList<OsmPrimitive>(); 190 190 final LinkedList<OsmPrimitive> delete = new LinkedList<OsmPrimitive>(); 191 for (OsmPrimitive osm : Main.ds.allPrimitives()) {191 for (OsmPrimitive osm : getCurrentDataSet().allPrimitives()) { 192 192 if (osm.get("josm/ignore") != null) { 193 193 continue; … … 231 231 @Override protected void realRun() throws SAXException, IOException { 232 232 try { 233 server.uploadOsm( Main.ds.version, all, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));234 Main.main.createOrGetEditLayer().cleanData(server.processed, !add.isEmpty());233 server.uploadOsm(getCurrentDataSet().version, all, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 234 getEditLayer().cleanData(server.processed, !add.isEmpty()); 235 235 } catch (Exception sxe) { 236 236 if (uploadCancelled) { -
trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r1750 r1814 77 77 Command c; 78 78 if (ctrl) { 79 c = DeleteCommand.deleteWithReferences( Main.ds.getSelected());79 c = DeleteCommand.deleteWithReferences(getCurrentDataSet().getSelected()); 80 80 } else { 81 c = DeleteCommand.delete( Main.ds.getSelected(), !alt);81 c = DeleteCommand.delete(getCurrentDataSet().getSelected(), !alt); 82 82 } 83 83 if (c != null) { … … 85 85 } 86 86 87 Main.ds.setSelected();87 getCurrentDataSet().setSelected(); 88 88 Main.map.repaint(); 89 89 } … … 124 124 } 125 125 126 Main.ds.setSelected();126 getCurrentDataSet().setSelected(); 127 127 Main.map.mapView.repaint(); 128 128 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r1750 r1814 94 94 // Add extra shortcut N 95 95 Main.contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( 96 Shortcut.registerShortcut("mapmode:drawfocus", tr("Mode: Draw Focus"), KeyEvent.VK_N, Shortcut.GROUP_EDIT).getKeyStroke(), tr("Draw"));96 Shortcut.registerShortcut("mapmode:drawfocus", tr("Mode: Draw Focus"), KeyEvent.VK_N, Shortcut.GROUP_EDIT).getKeyStroke(), tr("Draw")); 97 97 98 98 cursorCrosshair = getCursor(); … … 124 124 return; 125 125 switch(c) { 126 127 128 129 130 131 132 133 134 126 case way: 127 Main.map.mapView.setCursor(cursorJoinWay); 128 break; 129 case node: 130 Main.map.mapView.setCursor(cursorJoinNode); 131 break; 132 default: 133 Main.map.mapView.setCursor(cursorCrosshair); 134 break; 135 135 } 136 136 } … … 162 162 163 163 // This happens when nothing is selected, but we still want to highlight the "target node" 164 if (mouseOnExistingNode == null && Main.ds.getSelected().size() == 0165 && mousePos != null) 164 if (mouseOnExistingNode == null && getCurrentDataSet().getSelected().size() == 0 165 && mousePos != null) { 166 166 mouseOnExistingNode = Main.map.mapView.getNearestNode(mousePos); 167 } 167 168 168 169 if (mouseOnExistingNode != null) { … … 170 171 // We also need this list for the statusbar help text 171 172 oldHighlights.add(mouseOnExistingNode); 172 if(drawTargetHighlight) 173 if(drawTargetHighlight) { 173 174 mouseOnExistingNode.highlighted = true; 175 } 174 176 return; 175 177 } … … 259 261 260 262 private void tryAgain(MouseEvent e) { 261 Main.ds.setSelected();263 getCurrentDataSet().setSelected(); 262 264 mouseClicked(e); 263 265 } … … 306 308 mousePos = e.getPoint(); 307 309 308 Collection<OsmPrimitive> selection = Main.ds.getSelected();310 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 309 311 Collection<Command> cmds = new LinkedList<Command>(); 310 312 311 313 ArrayList<Way> reuseWays = new ArrayList<Way>(), 312 314 replacedWays = new ArrayList<Way>(); 313 315 boolean newNode = false; 314 316 Node n = null; 315 317 316 if (!ctrl) 318 if (!ctrl) { 317 319 n = Main.map.mapView.getNearestNode(mousePos); 320 } 318 321 319 322 if (n != null) { … … 323 326 // (this is just a convenience option so that people don't 324 327 // have to switch modes) 325 Main.ds.setSelected(n);326 selection = Main.ds.getSelected();328 getCurrentDataSet().setSelected(n); 329 selection = getCurrentDataSet().getSelected(); 327 330 // The user explicitly selected a node, so let him continue drawing 328 331 wayIsFinished = false; … … 334 337 if (n.getCoor().isOutSideWorld()) { 335 338 JOptionPane.showMessageDialog(Main.parent, 336 tr("Cannot add a node outside of the world."));339 tr("Cannot add a node outside of the world.")); 337 340 return; 338 341 } … … 366 369 367 370 pruneSuccsAndReverse(is); 368 for (int i : is) segSet.add( 369 Pair.sort(new Pair<Node,Node>(w.nodes.get(i), w.nodes.get(i+1)))); 370 for (int i : is) wnew.addNode(i + 1, n); 371 for (int i : is) { 372 segSet.add( 373 Pair.sort(new Pair<Node,Node>(w.nodes.get(i), w.nodes.get(i+1)))); 374 } 375 for (int i : is) { 376 wnew.addNode(i + 1, n); 377 } 371 378 372 379 // If ALT is pressed, a new way should be created and that new way should get … … 375 382 // but pressing ALT prevents this. Therefore we must de-select the way manually 376 383 // here so /only/ the new way will be selected after this method finishes. 377 if(alt) wnew.selected = false; 384 if(alt) { 385 wnew.selected = false; 386 } 378 387 379 388 cmds.add(new ChangeCommand(insertPoint.getKey(), wnew)); … … 450 459 int nodeCount=0; 451 460 for (Node p : way.nodes) 452 if(p.equals(n0)) nodeCount++; 453 if(nodeCount > 1) way = null; 461 if(p.equals(n0)) { 462 nodeCount++; 463 } 464 if(nodeCount > 1) { 465 way = null; 466 } 454 467 } 455 468 … … 476 489 477 490 // Add new node to way 478 if (way.nodes.get(way.nodes.size() - 1) == n0) 491 if (way.nodes.get(way.nodes.size() - 1) == n0) { 479 492 way.addNode(n); 480 else493 } else { 481 494 way.addNode(0, n); 495 } 482 496 483 497 extendedWay = true; 484 Main.ds.setSelected(way);498 getCurrentDataSet().setSelected(way); 485 499 } 486 500 } … … 488 502 String title; 489 503 if (!extendedWay) { 490 if (!newNode) {504 if (!newNode) 491 505 return; // We didn't do anything. 492 }else if (reuseWays.isEmpty()) {506 else if (reuseWays.isEmpty()) { 493 507 title = tr("Add node"); 494 508 } else { 495 509 title = tr("Add node into way"); 496 for (Way w : reuseWays) w.selected = false; 497 } 498 Main.ds.setSelected(n); 510 for (Way w : reuseWays) { 511 w.selected = false; 512 } 513 } 514 getCurrentDataSet().setSelected(n); 499 515 } else if (!newNode) { 500 516 title = tr("Connect existing way to node"); … … 508 524 509 525 Main.main.undoRedo.add(c); 510 if(!wayIsFinished) lastUsedNode = n; 526 if(!wayIsFinished) { 527 lastUsedNode = n; 528 } 511 529 512 530 computeHelperLine(); … … 534 552 int posn0 = selectedWay.nodes.indexOf(currentNode); 535 553 if( posn0 != -1 && // n0 is part of way 536 (posn0 >= 1 && targetNode.equals(selectedWay.nodes.get(posn0-1))) || // previous node537 (posn0 < selectedWay.nodes.size()-1) && targetNode.equals(selectedWay.nodes.get(posn0+1))) { // next node538 Main.ds.setSelected(targetNode);554 (posn0 >= 1 && targetNode.equals(selectedWay.nodes.get(posn0-1))) || // previous node 555 (posn0 < selectedWay.nodes.size()-1) && targetNode.equals(selectedWay.nodes.get(posn0+1))) { // next node 556 getCurrentDataSet().setSelected(targetNode); 539 557 lastUsedNode = targetNode; 540 558 return true; … … 618 636 double angle = -1; 619 637 620 Collection<OsmPrimitive> selection = Main.ds.getSelected();638 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 621 639 622 640 Node selectedNode = null; … … 638 656 if(!ctrl && currentMouseNode == null) { 639 657 List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(mousePos); 640 for(WaySegment ws : wss) 658 for(WaySegment ws : wss) { 641 659 mouseOnExistingWays.add(ws.way); 660 } 642 661 } 643 662 … … 692 711 if (previousNode != null) { 693 712 angle = hdg - Math.toDegrees(previousNode.getCoor().heading(currentBaseNode.getCoor())); 694 if (angle < 0) angle += 360; 713 if (angle < 0) { 714 angle += 360; 715 } 695 716 } 696 717 Main.map.statusLine.setAngle(angle); … … 715 736 * <code>null</code> otherwise. 716 737 */ 717 public staticWay getWayForNode(Node n) {738 public Way getWayForNode(Node n) { 718 739 Way way = null; 719 for (Way w : Main.ds.ways) { 720 if (w.deleted || w.incomplete || w.nodes.size() < 1) continue; 740 for (Way w : getCurrentDataSet().ways) { 741 if (w.deleted || w.incomplete || w.nodes.size() < 1) { 742 continue; 743 } 721 744 Node firstNode = w.nodes.get(0); 722 745 Node lastNode = w.nodes.get(w.nodes.size() - 1); … … 805 828 default: 806 829 EastNorth P = n.getEastNorth(); 807 808 809 810 811 812 813 814 830 seg = segs.iterator().next(); 831 A = seg.a.getEastNorth(); 832 B = seg.b.getEastNorth(); 833 double a = P.distanceSq(B); 834 double b = P.distanceSq(A); 835 double c = A.distanceSq(B); 836 q = (a - b + c) / (2*c); 837 n.setEastNorth(new EastNorth(B.east() + q * (A.east() - B.east()), B.north() + q * (A.north() - B.north()))); 815 838 } 816 839 } … … 883 906 // oldHighlights may store a node or way, check if it's a node 884 907 OsmPrimitive x = oldHighlights.iterator().next(); 885 if (x instanceof Node) 908 if (x instanceof Node) { 886 909 rv = tr("Select node under cursor."); 887 else910 } else { 888 911 rv = trn("Insert new node into way.", "Insert new node into {0} ways.", 889 oldHighlights.size(), oldHighlights.size()); 912 oldHighlights.size(), oldHighlights.size()); 913 } 890 914 } 891 915 … … 894 918 */ 895 919 if (currentBaseNode != null && !wayIsFinished) { 896 if (alt) 920 if (alt) { 897 921 rv += " " + tr("Start new way from last node."); 898 else922 } else { 899 923 rv += " " + tr("Continue way from last node."); 924 } 900 925 } 901 926 … … 904 929 * Handle special case: Highlighted node == selected node => finish drawing 905 930 */ 906 if (n != null && Main.ds.getSelectedNodes().contains(n)) {907 if (wayIsFinished) 931 if (n != null && getCurrentDataSet().getSelectedNodes().contains(n)) { 932 if (wayIsFinished) { 908 933 rv = tr("Select node under cursor."); 909 else934 } else { 910 935 rv = tr("Finish drawing."); 936 } 911 937 } 912 938 … … 914 940 * Handle special case: Self-Overlapping or closing way 915 941 */ 916 if ( Main.ds.getSelectedWays().size() > 0 && !wayIsFinished && !alt) {917 Way w = (Way) Main.ds.getSelectedWays().iterator().next();942 if (getCurrentDataSet().getSelectedWays().size() > 0 && !wayIsFinished && !alt) { 943 Way w = (Way) getCurrentDataSet().getSelectedWays().iterator().next(); 918 944 for (Node m : w.nodes) { 919 945 if (m.equals(mouseOnExistingNode) || mouseOnExistingWays.contains(w)) { -
trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
r1750 r1814 77 77 super(tr("Extrude"), "extrude/extrude", tr("Create areas"), 78 78 Shortcut.registerShortcut("mapmode:extrude", tr("Mode: {0}", tr("Extrude")), KeyEvent.VK_X, Shortcut.GROUP_EDIT), 79 mapFrame,80 getCursor("normal", "rectangle", Cursor.DEFAULT_CURSOR));79 mapFrame, 80 getCursor("normal", "rectangle", Cursor.DEFAULT_CURSOR)); 81 81 putValue("help", "Action/Extrude/Extrude"); 82 82 initialMoveDelay = Main.pref.getInteger("edit.initial-move-delay",200); … … 160 160 161 161 double u = ((en3.east() - en1.east()) * (en2.east() - en1.east()) + 162 163 162 (en3.north() - en1.north()) * (en2.north() - en1.north())) / 163 en2.distanceSq(en1); 164 164 // the point on the segment from which the distance to mouse pos is shortest 165 165 EastNorth base = new EastNorth(en1.east() + u * (en2.east() - en1.east()), 166 166 en1.north() + u * (en2.north() - en1.north())); 167 167 168 168 // find out the distance, in metres, between the base point and the mouse cursor … … 219 219 initialMousePos = e.getPoint(); 220 220 221 if(selectedSegment != null) 222 Main.ds.setSelected(selectedSegment.way); 221 if(selectedSegment != null) { 222 getCurrentDataSet().setSelected(selectedSegment.way); 223 } 223 224 } 224 225 … … 241 242 wnew.addNode(selectedSegment.lowerIndex+1, n3); 242 243 wnew.addNode(selectedSegment.lowerIndex+1, n4); 243 if (wnew.nodes.size() == 4) wnew.addNode(n1); 244 if (wnew.nodes.size() == 4) { 245 wnew.addNode(n1); 246 } 244 247 Collection<Command> cmds = new LinkedList<Command>(); 245 248 cmds.add(new AddCommand(n4)); … … 258 261 259 262 @Override public String getModeHelpText() { 260 if (mode == Mode.select) {263 if (mode == Mode.select) 261 264 return tr("Release the mouse button to select the objects in the rectangle."); 262 } else if (mode == Mode.EXTRUDE) {265 else if (mode == Mode.EXTRUDE) 263 266 return tr("Draw a rectangle of the desired size, then release the mouse button."); 264 } else if (mode == Mode.rotate) {267 else if (mode == Mode.rotate) 265 268 return tr("Release the mouse button to stop rotating."); 266 } else {269 else 267 270 return tr("Drag a way segment to make a rectangle."); 268 } 269 } 270 271 @Override public boolean layerIsSupported(Layer l) { 272 return l instanceof OsmDataLayer; 273 } 271 } 272 273 @Override public boolean layerIsSupported(Layer l) { 274 return l instanceof OsmDataLayer; 275 } 274 276 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r1750 r1814 207 207 // Currently we support moving and rotating, which do not affect relations. 208 208 // So don't add them in the first place to make handling easier 209 Collection<OsmPrimitive> selection = Main.ds.getSelectedNodesAndWays();209 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelectedNodesAndWays(); 210 210 Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection); 211 211 … … 355 355 356 356 if (ctrl && shift) { 357 if ( Main.ds.getSelected().isEmpty()) {357 if (getCurrentDataSet().getSelected().isEmpty()) { 358 358 selectPrims(osmColl, true, false, false, false); 359 359 } … … 366 366 // move. 367 367 selectPrims(osmColl, 368 shift || Main.ds.getSelected().containsAll(osmColl),368 shift || getCurrentDataSet().getSelected().containsAll(osmColl), 369 369 ctrl, false, false); 370 370 mode = Mode.move; … … 403 403 404 404 // Select Draw Tool if no selection has been made 405 if( Main.ds.getSelected().size() == 0 && !cancelDrawMode) {405 if(getCurrentDataSet().getSelected().size() == 0 && !cancelDrawMode) { 406 406 Main.map.selectDrawTool(true); 407 407 return; … … 419 419 420 420 // If the user double-clicked a node, change to draw mode 421 List<OsmPrimitive> sel = new ArrayList<OsmPrimitive>( Main.ds.getSelected());421 List<OsmPrimitive> sel = new ArrayList<OsmPrimitive>(getCurrentDataSet().getSelected()); 422 422 if(e.getClickCount() >=2 && sel.size() == 1 && sel.get(0) instanceof Node) { 423 423 // We need to do it like this as otherwise drawAction will see a double … … 431 431 } 432 432 } else { 433 Collection<OsmPrimitive> selection = Main.ds.getSelected();433 Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 434 434 Collection<OsmPrimitive> s = new TreeSet<OsmPrimitive>(); 435 435 int max = Main.pref.getInteger("warn.move.maxelements", 20); … … 469 469 if (selNodes.size() > 0) { 470 470 selNodes.add(n); 471 MergeNodesAction.mergeNodes(selNodes, n);471 new MergeNodesAction().mergeNodes(selNodes, n); 472 472 } 473 473 } … … 496 496 curSel = new LinkedList<OsmPrimitive>(); // new selection will replace the old. 497 497 } else { 498 curSel = Main.ds.getSelected();498 curSel = getCurrentDataSet().getSelected(); 499 499 } 500 500 … … 512 512 } 513 513 } 514 Main.ds.setSelected(curSel);514 getCurrentDataSet().setSelected(curSel); 515 515 Main.map.mapView.repaint(); 516 516 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java
r1722 r1814 7 7 import java.awt.event.KeyEvent; 8 8 9 import org.openstreetmap.josm.data.coor.EastNorth;10 9 import org.openstreetmap.josm.gui.MapFrame; 11 10 import org.openstreetmap.josm.gui.MapView; … … 47 46 public ZoomAction(MapFrame mapFrame) { 48 47 super(tr("Zoom"), "zoom", tr("Zoom and move map"), 49 Shortcut.registerShortcut("mapmode:zoom", tr("Mode: {0}", tr("Zoom")), KeyEvent.VK_Z, Shortcut.GROUP_EDIT),50 mapFrame, ImageProvider.getCursor("normal", "zoom"));48 Shortcut.registerShortcut("mapmode:zoom", tr("Mode: {0}", tr("Zoom")), KeyEvent.VK_Z, Shortcut.GROUP_EDIT), 49 mapFrame, ImageProvider.getCursor("normal", "zoom")); 51 50 mv = mapFrame.mapView; 52 51 selectionManager = new SelectionManager(this, true, mv); … … 57 56 */ 58 57 public void selectionEnded(Rectangle r, boolean alt, boolean shift, boolean ctrl) { 59 if (r.width >= 3 && r.height >= 3) 58 if (r.width >= 3 && r.height >= 3) { 60 59 mv.zoomToFactor(mv.getEastNorth(r.x+r.width/2, r.y+r.height/2), r.getWidth()/mv.getWidth()); 60 } 61 61 } 62 62 -
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r1808 r1814 164 164 } 165 165 try { 166 Collection<OsmPrimitive> sel = Main. ds.getSelected();166 Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected(); 167 167 SearchCompiler.Match matcher = SearchCompiler.compile(search, caseSensitive, regexSearch); 168 168 int foundMatches = 0; 169 for (OsmPrimitive osm : Main. ds.allNonDeletedCompletePrimitives()) {169 for (OsmPrimitive osm : Main.main.getCurrentDataSet().allNonDeletedCompletePrimitives()) { 170 170 if (mode == SearchMode.replace) { 171 171 if (matcher.match(osm)) { … … 183 183 } 184 184 } 185 Main. ds.setSelected(sel);185 Main.main.getCurrentDataSet().setSelected(sel); 186 186 if (foundMatches == 0) { 187 187 String msg = null; … … 241 241 */ 242 242 protected void refreshEnabled() { 243 setEnabled(Main.map != null 244 && Main.map.mapView !=null 245 && Main.map.mapView.getEditLayer() != null 246 ); 243 setEnabled(getEditLayer() != null); 247 244 } 248 245 -
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r1786 r1814 133 133 String value = null; 134 134 135 if (key.equals("timestamp")) 135 if (key.equals("timestamp")) { 136 136 value = DateUtils.fromDate(osm.getTimestamp()); 137 else137 } else { 138 138 value = osm.get(key); 139 } 139 140 140 141 if (value == null) … … 169 170 170 171 public ExactKeyValue(boolean regexp, String key, String value) throws ParseError { 171 if (key == "") {172 if (key == "") 172 173 throw new ParseError(tr("Key cannot be empty when tag operator is used. Sample use: key=value")); 173 }174 174 this.key = key; 175 175 this.value = value; … … 223 223 public boolean match(OsmPrimitive osm) throws ParseError { 224 224 225 if (osm.keys == null || osm.keys.isEmpty()) {225 if (osm.keys == null || osm.keys.isEmpty()) 226 226 return mode == Mode.NONE; 227 }228 227 229 228 switch (mode) { … … 238 237 case ANY_KEY: 239 238 for (String v:osm.keys.values()) { 240 if (v.equals(value)) {239 if (v.equals(value)) 241 240 return true; 242 }243 241 } 244 242 return false; … … 247 245 case ANY_KEY_REGEXP: 248 246 for (String v:osm.keys.values()) { 249 if (valuePattern.matcher(v).matches()) {247 if (valuePattern.matcher(v).matches()) 250 248 return true; 251 }252 249 } 253 250 return false; … … 257 254 if (keyPattern.matcher(entry.getKey()).matches()) { 258 255 if (mode == Mode.ANY_VALUE_REGEXP 259 || valuePattern.matcher(entry.getValue()).matches()) {256 || valuePattern.matcher(entry.getValue()).matches()) 260 257 return true; 261 }262 258 } 263 259 } … … 265 261 case MISSING_KEY_REGEXP: 266 262 for (String k:osm.keys.keySet()) { 267 if (keyPattern.matcher(k).matches()) {263 if (keyPattern.matcher(k).matches()) 268 264 return false; 269 }270 265 } 271 266 return true; … … 337 332 // is not Java 1.5 338 333 //String name = java.text.Normalizer.normalize(name, java.text.Normalizer.Form.NFC); 339 if (!caseSensitive) 334 if (!caseSensitive) { 340 335 name = name.toLowerCase(); 336 } 341 337 if (name.indexOf(search) != -1) 342 338 return true; … … 356 352 } else if ("relation".equals(type)) { 357 353 this.type = Relation.class; 358 } else {354 } else 359 355 throw new ParseError(tr("Unknown primitive type: {0}. Allowed values are node, way or relation", 360 356 type)); 361 }362 357 } 363 358 @Override public boolean match(OsmPrimitive osm) { … … 441 436 // "parent" (null) should mean the same as "parent()" 442 437 // (Always). I.e. match everything 443 if (child == null) 438 if (child == null) { 444 439 child = new Always(); 440 } 445 441 446 442 if (osm instanceof Way) { 447 for (Node n : ((Way)osm).nodes) 443 for (Node n : ((Way)osm).nodes) { 448 444 isParent |= child.match(n); 445 } 449 446 } else if (osm instanceof Relation) { 450 447 for (RelationMember member : ((Relation)osm).members) { 451 if (member.member != null) 448 if (member.member != null) { 452 449 isParent |= child.match(member.member); 450 } 453 451 } 454 452 } … … 464 462 // "child" (null) should mean the same as "child()" 465 463 // (Always). I.e. match everything 466 if (parent == null) 464 if (parent == null) { 467 465 parent = new Always(); 466 } 468 467 469 468 boolean isChild = false; 470 CollectBackReferencesVisitor backRefs = new CollectBackReferencesVisitor(Main. ds);469 CollectBackReferencesVisitor backRefs = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet()); 471 470 osm.visit(backRefs); 472 471 for (OsmPrimitive p : backRefs.data) { … … 485 484 486 485 public static Match compile(String searchStr, boolean caseSensitive, boolean regexSearch) 487 486 throws ParseError { 488 487 return new SearchCompiler(caseSensitive, regexSearch, 489 488 new PushbackTokenizer( 490 new PushbackReader(new StringReader(searchStr))))491 489 new PushbackReader(new StringReader(searchStr)))) 490 .parse(); 492 491 } 493 492 494 493 public Match parse() throws ParseError { 495 494 Match m = parseJuxta(); 496 if (!tokenizer.readIfEqual(null)) {495 if (!tokenizer.readIfEqual(null)) 497 496 throw new ParseError(tr("Unexpected token: {0}", tokenizer.nextToken())); 498 }499 497 return m; 500 498 } … … 515 513 if (tokenizer.readIfEqual("|")) { 516 514 Match b = parseNot(); 517 if (a == null || b == null) {515 if (a == null || b == null) 518 516 throw new ParseError(tr("Missing arguments for or.")); 519 }520 517 return new Or(a, b); 521 518 } … … 526 523 if (tokenizer.readIfEqual("-")) { 527 524 Match m = parseParens(); 528 if (m == null) {525 if (m == null) 529 526 throw new ParseError(tr("Missing argument for not.")); 530 }531 527 return new Not(m); 532 528 } … … 537 533 if (tokenizer.readIfEqual("(")) { 538 534 Match m = parseJuxta(); 539 if (!tokenizer.readIfEqual(")")) {535 if (!tokenizer.readIfEqual(")")) 540 536 throw new ParseError(tr("Expected closing parenthesis.")); 541 }542 537 return m; 543 538 } … … 550 545 if (tokenizer.readIfEqual(":")) { 551 546 String tok2 = tokenizer.readText(); 552 if (tok == null) tok = ""; 553 if (tok2 == null) tok2 = ""; 547 if (tok == null) { 548 tok = ""; 549 } 550 if (tok2 == null) { 551 tok2 = ""; 552 } 554 553 return parseKV(tok, tok2); 555 554 } … … 557 556 if (tokenizer.readIfEqual("=")) { 558 557 String tok2 = tokenizer.readText(); 559 if (tok == null) tok = ""; 560 if (tok2 == null) tok2 = ""; 558 if (tok == null) { 559 tok = ""; 560 } 561 if (tok2 == null) { 562 tok2 = ""; 563 } 561 564 return new ExactKeyValue(regexSearch, tok, tok2); 562 565 } 563 566 564 if (tok == null) {567 if (tok == null) 565 568 return null; 566 } else if (tok.equals("modified")) {569 else if (tok.equals("modified")) 567 570 return new Modified(); 568 } else if (tok.equals("incomplete")) {571 else if (tok.equals("incomplete")) 569 572 return new Incomplete(); 570 } else if (tok.equals("untagged")) {573 else if (tok.equals("untagged")) 571 574 return new Untagged(); 572 } else if (tok.equals("selected")) {575 else if (tok.equals("selected")) 573 576 return new Selected(); 574 } else if (tok.equals("child")) {577 else if (tok.equals("child")) 575 578 return new Child(parseParens()); 576 } else if (tok.equals("parent")) {579 else if (tok.equals("parent")) 577 580 return new Parent(parseParens()); 578 } else {581 else 579 582 return new Any(tok); 580 }581 583 } 582 584 583 585 private Match parseKV(String key, String value) throws ParseError { 584 if (key.equals("type")) {586 if (key.equals("type")) 585 587 return new ExactType(value); 586 } else if (key.equals("user")) {588 else if (key.equals("user")) 587 589 return new UserMatch(value); 588 }else if (key.equals("nodes")) {590 else if (key.equals("nodes")) { 589 591 try { 590 592 String[] range = value.split("-"); 591 if (range.length == 1) {593 if (range.length == 1) 592 594 return new NodeCount(Integer.parseInt(value)); 593 } else if (range.length == 2) {595 else if (range.length == 2) 594 596 return new NodeCountRange(Integer.parseInt(range[0]), Integer.parseInt(range[1])); 595 } else {597 else 596 598 throw new ParseError(tr("Wrong number of parameters for nodes operator.")); 597 }598 599 } catch (NumberFormatException e) { 599 600 throw new ParseError(tr("Incorrect value of nodes operator: {0}. Nodes operator expects number of nodes or range, for example nodes:10-20", value)); … … 606 607 throw new ParseError(tr("Incorrect value of id operator: {0}. Number is expected.", value)); 607 608 } 608 } else {609 } else 609 610 return new KeyValue(key, value); 610 }611 611 } 612 612 … … 627 627 // insensitively, but the OSM data is in Unicode. With 628 628 // UNICODE_CASE casefolding is made Unicode-aware. 629 if (!caseSensitive) 629 if (!caseSensitive) { 630 630 searchFlags |= (Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); 631 } 631 632 632 633 return searchFlags; -
trunk/src/org/openstreetmap/josm/actions/search/SelectionWebsiteLoader.java
r1811 r1814 40 40 @Override protected void realRun() { 41 41 progressMonitor.setTicksCount(2); 42 sel = mode != SearchAction.SearchMode.remove ? new LinkedList<OsmPrimitive>() : Main. ds.allNonDeletedPrimitives();42 sel = mode != SearchAction.SearchMode.remove ? new LinkedList<OsmPrimitive>() : Main.main.getCurrentDataSet().allNonDeletedPrimitives(); 43 43 try { 44 44 URLConnection con = url.openConnection(); … … 47 47 progressMonitor.subTask(tr("Downloading...")); 48 48 Map<Long, String> ids = idReader.parseIds(in); 49 for (OsmPrimitive osm : Main. ds.allNonDeletedPrimitives()) {49 for (OsmPrimitive osm : Main.main.getCurrentDataSet().allNonDeletedPrimitives()) { 50 50 if (ids.containsKey(osm.id) && osm.getClass().getName().toLowerCase().endsWith(ids.get(osm.id))) { 51 51 if (mode == SearchAction.SearchMode.remove) { … … 86 86 @Override protected void finish() { 87 87 if (sel != null) { 88 Main. ds.setSelected(sel);88 Main.main.getCurrentDataSet().setSelected(sel); 89 89 } 90 90 } -
trunk/src/org/openstreetmap/josm/command/AddCommand.java
r1750 r1814 11 11 12 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 import org.openstreetmap.josm.data.osm. visitor.AddVisitor;14 import org.openstreetmap.josm. data.osm.visitor.DeleteVisitor;15 import org.openstreetmap.josm. data.osm.visitor.NameVisitor;13 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 14 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 15 import org.openstreetmap.josm.tools.ImageProvider; 16 16 17 17 /** … … 39 39 40 40 @Override public boolean executeCommand() { 41 osm.visit(new AddVisitor(getLayer().data));41 getLayer().data.addPrimitive(osm); 42 42 return true; 43 43 } 44 44 45 45 @Override public void undoCommand() { 46 osm.visit(new DeleteVisitor(getLayer().data));46 getLayer().data.removePrimitive(osm); 47 47 } 48 48 … … 52 52 53 53 @Override public MutableTreeNode description() { 54 NameVisitor v = new NameVisitor();55 osm.visit(v);56 54 return new DefaultMutableTreeNode( 57 new JLabel(tr("Add {0} {1}", tr(v.className), v.name), v.icon, JLabel.HORIZONTAL)); 55 new JLabel( 56 tr("Add {0} {1}", 57 OsmPrimitiveType.from(osm).getLocalizedDisplayNameSingular(), 58 new PrimitiveNameFormatter().getName(osm) 59 ), 60 ImageProvider.get(OsmPrimitiveType.from(osm)), 61 JLabel.HORIZONTAL 62 ) 63 ); 58 64 } 59 65 } -
trunk/src/org/openstreetmap/josm/command/ChangeCommand.java
r1750 r1814 11 11 12 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 13 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 14 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 15 import org.openstreetmap.josm.tools.ImageProvider; 14 16 15 17 /** … … 42 44 43 45 @Override public MutableTreeNode description() { 44 NameVisitor v = new NameVisitor(); 45 osm.visit(v); 46 return new DefaultMutableTreeNode(new JLabel(tr("Change {0} {1}", tr(v.className), v.name), v.icon, JLabel.HORIZONTAL)); 46 return new DefaultMutableTreeNode( 47 new JLabel(tr("Change {0} {1}", 48 OsmPrimitiveType.from(osm).getLocalizedDisplayNameSingular(), 49 new PrimitiveNameFormatter().getName(osm)), 50 ImageProvider.get(OsmPrimitiveType.from(osm)), 51 JLabel.HORIZONTAL)); 47 52 } 48 53 } -
trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java
r1750 r1814 14 14 15 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 17 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 17 18 import org.openstreetmap.josm.tools.ImageProvider; 18 19 … … 93 94 @Override public MutableTreeNode description() { 94 95 String text; 96 PrimitiveNameFormatter formatter = new PrimitiveNameFormatter(); 95 97 if (objects.size() == 1) { 96 NameVisitor v = new NameVisitor();97 objects.iterator().next().visit(v);98 OsmPrimitive primitive = objects.iterator().next(); 99 String name = formatter.getName(primitive); 98 100 text = value == null 99 ? tr("Remove \"{0}\" for {1} ''{2}''", key, tr(v.className), v.name) 100 : tr("Set {0}={1} for {2} ''{3}''",key,value, tr(v.className), v.name); 101 ? tr("Remove \"{0}\" for {1} ''{2}''", key, 102 OsmPrimitiveType.from(primitive).getLocalizedDisplayNameSingular(), 103 name) 104 : tr("Set {0}={1} for {2} ''{3}''", 105 key, 106 value, 107 OsmPrimitiveType.from(primitive).getLocalizedDisplayNameSingular(), 108 name 109 ); 101 110 } 102 111 else … … 109 118 if (objects.size() == 1) 110 119 return root; 111 NameVisitor v = new NameVisitor();112 120 for (OsmPrimitive osm : objects) { 113 osm.visit(v); 114 root.add(new DefaultMutableTreeNode(v.toLabel())); 121 root.add(new DefaultMutableTreeNode( 122 new JLabel( 123 formatter.getName(osm), 124 ImageProvider.get(OsmPrimitiveType.from(osm)), 125 JLabel.HORIZONTAL) 126 ) 127 ); 115 128 } 116 129 return root; -
trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java
r1766 r1814 12 12 import org.openstreetmap.josm.Main; 13 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 14 15 import org.openstreetmap.josm.data.osm.Relation; 15 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 16 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 17 import org.openstreetmap.josm.tools.ImageProvider; 16 18 17 19 /** … … 64 66 65 67 @Override public MutableTreeNode description() { 66 NameVisitor v = new NameVisitor(); 67 relation.visit(v); 68 return new DefaultMutableTreeNode(new JLabel(tr("Change relation member role for {0} {1}", tr(v.className), v.name), v.icon, JLabel.HORIZONTAL)); 68 return new DefaultMutableTreeNode( 69 new JLabel( 70 tr("Change relation member role for {0} {1}", 71 OsmPrimitiveType.from(relation), 72 new PrimitiveNameFormatter().getName(relation) 73 ), 74 ImageProvider.get(OsmPrimitiveType.from(relation)), 75 JLabel.HORIZONTAL) 76 ); 69 77 } 70 78 } -
trunk/src/org/openstreetmap/josm/command/Command.java
r1750 r1814 51 51 52 52 public Command() { 53 this.layer = Main.ma in.map.mapView.getEditLayer();53 this.layer = Main.map.mapView.getEditLayer(); 54 54 } 55 55 /** -
trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
r1750 r1814 25 25 import org.openstreetmap.josm.data.osm.Node; 26 26 import org.openstreetmap.josm.data.osm.OsmPrimitive; 27 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 27 28 import org.openstreetmap.josm.data.osm.Relation; 28 29 import org.openstreetmap.josm.data.osm.RelationMember; … … 30 31 import org.openstreetmap.josm.data.osm.WaySegment; 31 32 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; 32 import org.openstreetmap.josm.data.osm.visitor.NameVisitor;33 33 import org.openstreetmap.josm.gui.ExtendedDialog; 34 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 34 35 import org.openstreetmap.josm.tools.DontShowAgainInfo; 35 36 import org.openstreetmap.josm.tools.ImageProvider; … … 76 77 77 78 @Override public MutableTreeNode description() { 78 NameVisitor v = new NameVisitor();79 80 79 if (toDelete.size() == 1) { 81 toDelete.iterator().next().visit(v); 82 return new DefaultMutableTreeNode(new JLabel(tr("Delete {1} {0}", v.name, tr(v.className)), v.icon, 83 JLabel.HORIZONTAL)); 80 OsmPrimitive primitive = toDelete.iterator().next(); 81 return new DefaultMutableTreeNode( 82 new JLabel( 83 tr("Delete {1} {0}", 84 new PrimitiveNameFormatter().getName(primitive), 85 OsmPrimitiveType.from(primitive).getLocalizedDisplayNameSingular() 86 ), 87 ImageProvider.get(OsmPrimitiveType.from(primitive)), 88 JLabel.HORIZONTAL)); 84 89 } 85 90 … … 87 92 String cnamem = null; 88 93 for (OsmPrimitive osm : toDelete) { 89 osm.visit(v);90 94 if (cname == null) { 91 cname = v.className;92 cnamem = v.classNamePlural;93 } else if (!cname.equals( v.className)) {95 cname = OsmPrimitiveType.from(osm).getLocalizedDisplayNameSingular(); 96 cnamem = OsmPrimitiveType.from(osm).getLocalizedDisplayNameSingular(); 97 } else if (!cname.equals(OsmPrimitiveType.from(osm).getLocalizedDisplayNameSingular())) { 94 98 cname = "object"; 95 99 cnamem = trn("object", "objects", 2); … … 99 103 cname, cnamem, toDelete.size())), ImageProvider.get("data", cname), JLabel.HORIZONTAL)); 100 104 for (OsmPrimitive osm : toDelete) { 101 osm.visit(v); 102 root.add(new DefaultMutableTreeNode(v.toLabel())); 105 root.add(new DefaultMutableTreeNode( 106 new JLabel( 107 new PrimitiveNameFormatter().getName(osm), 108 ImageProvider.get(OsmPrimitiveType.from(osm)), 109 JLabel.HORIZONTAL) 110 ) 111 ); 103 112 } 104 113 return root; … … 119 128 */ 120 129 public static Command deleteWithReferences(Collection<? extends OsmPrimitive> selection) { 121 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main. ds);130 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet()); 122 131 for (OsmPrimitive osm : selection) { 123 132 osm.visit(v); … … 132 141 133 142 private static int testRelation(Relation ref, OsmPrimitive osm) { 134 NameVisitor n = new NameVisitor(); 135 ref.visit(n); 136 NameVisitor s = new NameVisitor(); 137 osm.visit(s); 143 PrimitiveNameFormatter formatter = new PrimitiveNameFormatter(); 138 144 String role = new String(); 139 145 for (RelationMember m : ref.members) { … … 144 150 } 145 151 if (role.length() > 0) 146 return new ExtendedDialog(Main.parent, 152 return new ExtendedDialog( 153 Main.parent, 147 154 tr("Conflicting relation"), 148 155 tr("Selection \"{0}\" is used by relation \"{1}\" with role {2}.\nDelete from relation?", 149 s.name, n.name, role),156 formatter.getName(osm), formatter.getName(ref), role), 150 157 new String[] {tr("Delete from relation"), tr("Cancel")}, 151 158 new String[] {"dialogs/delete.png", "cancel.png"}).getValue(); … … 154 161 tr("Conflicting relation"), 155 162 tr("Selection \"{0}\" is used by relation \"{1}\".\nDelete from relation?", 156 s.name, n.name),163 formatter.getName(osm), formatter.getName(ref)), 157 164 new String[] {tr("Delete from relation"), tr("Cancel")}, 158 165 new String[] {"dialogs/delete.png", "cancel.png"}).getValue(); … … 191 198 for (Node n : ((Way) osm).nodes) { 192 199 if (!n.isTagged()) { 193 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main. ds, false);200 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet(), false); 194 201 n.visit(v); 195 202 v.data.removeAll(del); … … 208 215 209 216 for (OsmPrimitive osm : del) { 210 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main. ds, false);217 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet(), false); 211 218 osm.visit(v); 212 219 for (OsmPrimitive ref : v.data) { … … 238 245 del.add(w); 239 246 240 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main. ds, false);247 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet(), false); 241 248 w.visit(v); 242 249 for (OsmPrimitive ref : v.data) { … … 366 373 */ 367 374 private static boolean checkAndConfirmOutlyingDeletes(Collection<OsmPrimitive> del) { 368 Area a = Main. ds.getDataSourceArea();375 Area a = Main.main.getCurrentDataSet().getDataSourceArea(); 369 376 if (a != null) { 370 377 for (OsmPrimitive osm : del) { -
trunk/src/org/openstreetmap/josm/command/PurgePrimitivesCommand.java
r1750 r1814 179 179 protected void purge(OsmPrimitive toPurge, DataSet ds, ArrayList<OsmPrimitive> hive) { 180 180 ArrayList<OsmPrimitive> parents = new ArrayList<OsmPrimitive>(); 181 parents.addAll( Main.ds.ways);182 parents.addAll( Main.ds.relations);181 parents.addAll(getLayer().data.ways); 182 parents.addAll(getLayer().data.relations); 183 183 List<OsmParentChildPair> pairs = getParentChildPairs(parents, primitive); 184 184 hive.remove(toPurge); … … 217 217 while(! hive.isEmpty()) { 218 218 OsmPrimitive toPurge = hive.get(0); 219 purge(toPurge, Main.ds, hive);219 purge(toPurge, getLayer().data, hive); 220 220 if (toPurge instanceof Node) { 221 221 getLayer().data.nodes.remove(toPurge); -
trunk/src/org/openstreetmap/josm/command/RemoveRelationMemberCommand.java
r1774 r1814 12 12 import org.openstreetmap.josm.Main; 13 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 import org.openstreetmap.josm.data.osm.*; 15 16 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 14 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 15 import org.openstreetmap.josm.data.osm.Relation; 16 import org.openstreetmap.josm.data.osm.RelationMember; 17 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 18 import org.openstreetmap.josm.tools.ImageProvider; 17 19 18 20 /** … … 62 64 63 65 @Override public MutableTreeNode description() { 64 NameVisitor v = new NameVisitor(); 65 relation.visit(v); 66 return new DefaultMutableTreeNode(new JLabel(tr("Remove relation member {0} {1}", tr(v.className), v.name), v.icon, JLabel.HORIZONTAL)); 66 return new DefaultMutableTreeNode( 67 new JLabel( 68 tr("Remove relation member {0} {1}", 69 OsmPrimitiveType.from(relation).getLocalizedDisplayNameSingular(), 70 new PrimitiveNameFormatter().getName(relation) 71 ), 72 ImageProvider.get(OsmPrimitiveType.from(relation)), 73 JLabel.HORIZONTAL 74 ) 75 ); 67 76 } 68 77 } -
trunk/src/org/openstreetmap/josm/corrector/ReverseWayTagCorrector.java
r1762 r1814 115 115 roleCorrectionMap.put(way, new ArrayList<RoleCorrection>()); 116 116 117 for (Relation relation : Main. ds.relations) {117 for (Relation relation : Main.main.getCurrentDataSet().relations) { 118 118 int position = 0; 119 119 for (RelationMember member : relation.members) { -
trunk/src/org/openstreetmap/josm/corrector/RoleCorrectionTableModel.java
r1001 r1814 6 6 import java.util.List; 7 7 8 import org.openstreetmap.josm. data.osm.visitor.NameVisitor;8 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 9 9 10 10 public class RoleCorrectionTableModel extends 11 CorrectionTableModel<RoleCorrection> { 12 13 private static NameVisitor nameVisitor = new NameVisitor(); 11 CorrectionTableModel<RoleCorrection> { 12 private static final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter(); 14 13 15 14 public RoleCorrectionTableModel(List<RoleCorrection> roleCorrections) { … … 41 40 switch (colIndex) { 42 41 case 0: 43 roleCorrection.relation.visit(nameVisitor); 44 return nameVisitor.name; 42 return NAME_FORMATTER.getName(roleCorrection.relation); 45 43 case 1: 46 44 return roleCorrection.member.role; -
trunk/src/org/openstreetmap/josm/corrector/TagCorrector.java
r1617 r1814 25 25 import org.openstreetmap.josm.data.osm.Node; 26 26 import org.openstreetmap.josm.data.osm.OsmPrimitive; 27 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 27 28 import org.openstreetmap.josm.data.osm.Relation; 28 import org.openstreetmap.josm.data.osm.RelationMember;29 29 import org.openstreetmap.josm.data.osm.Way; 30 import org.openstreetmap.josm.data.osm.visitor.NameVisitor;31 30 import org.openstreetmap.josm.gui.JMultilineLabel; 31 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 32 32 import org.openstreetmap.josm.tools.GBC; 33 import org.openstreetmap.josm.tools.ImageProvider; 33 34 34 35 public abstract class TagCorrector<P extends OsmPrimitive> { 36 private static final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter(); 35 37 36 38 public abstract Collection<Command> execute(P primitive, P oldprimitive) 37 39 throws UserCancelException; 38 40 39 41 private String[] applicationOptions = new String[] { 40 tr("Apply selected changes"),41 tr("Don't apply changes"),42 tr("Cancel")42 tr("Apply selected changes"), 43 tr("Don't apply changes"), 44 tr("Cancel") 43 45 }; 44 46 … … 56 58 } 57 59 58 if (!hasCorrections) 60 if (!hasCorrections) { 59 61 for (List<RoleCorrection> roleCorrectionList : roleCorrectionMap 60 62 .values()) { … … 64 66 } 65 67 } 68 } 66 69 67 70 if (hasCorrections) { … … 72 75 new HashMap<OsmPrimitive, RoleCorrectionTable>(); 73 76 74 NameVisitor nameVisitor = new NameVisitor();77 //NameVisitor nameVisitor = new NameVisitor(); 75 78 76 79 final JPanel p = new JPanel(new GridBagLayout()); … … 87 90 for (OsmPrimitive primitive : tagCorrectionsMap.keySet()) { 88 91 final List<TagCorrection> tagCorrections = tagCorrectionsMap 89 90 91 if (tagCorrections.isEmpty()) 92 .get(primitive); 93 94 if (tagCorrections.isEmpty()) { 92 95 continue; 93 94 primitive.visit(nameVisitor); 96 } 95 97 96 98 final JLabel propertiesLabel = new JLabel(tr("Properties of ")); … … 98 100 99 101 final JLabel primitiveLabel = new JLabel( 100 nameVisitor.name + ":", nameVisitor.icon, JLabel.LEFT); 102 NAME_FORMATTER.getName(primitive) + ":", 103 ImageProvider.get(OsmPrimitiveType.from(primitive)), 104 JLabel.LEFT 105 ); 101 106 p.add(primitiveLabel, GBC.eol()); 102 107 … … 111 116 for (OsmPrimitive primitive : roleCorrectionMap.keySet()) { 112 117 final List<RoleCorrection> roleCorrections = roleCorrectionMap 113 114 if (roleCorrections.isEmpty()) 118 .get(primitive); 119 if (roleCorrections.isEmpty()) { 115 120 continue; 116 117 primitive.visit(nameVisitor); 121 } 118 122 119 123 final JLabel rolesLabel = new JLabel( … … 122 126 123 127 final JLabel primitiveLabel = new JLabel( 124 nameVisitor.name + ":", nameVisitor.icon, JLabel.LEFT); 128 NAME_FORMATTER.getName(primitive), 129 ImageProvider.get(OsmPrimitiveType.from(primitive)), 130 JLabel.LEFT 131 ); 125 132 p.add(primitiveLabel, GBC.eol()); 126 133 … … 145 152 // create the clone 146 153 OsmPrimitive clone = null; 147 if (primitive instanceof Way) clone = new Way((Way)primitive); 148 else if (primitive instanceof Node) clone = new Node((Node)primitive); 149 else if (primitive instanceof Relation) clone = new Relation((Relation)primitive); 154 if (primitive instanceof Way) { 155 clone = new Way((Way)primitive); 156 } else if (primitive instanceof Node) { 157 clone = new Node((Node)primitive); 158 } else if (primitive instanceof Relation) { 159 clone = new Relation((Relation)primitive); 160 } 150 161 151 162 // use this structure to remember keys that have been set already so that … … 157 168 if (tagTableMap.get(primitive).getCorrectionTableModel().getApply(i)) { 158 169 TagCorrection tagCorrection = tagCorrections.get(i); 159 if (tagCorrection.isKeyChanged() && !keysChanged.contains(tagCorrection.oldKey)) clone.remove(tagCorrection.oldKey); 170 if (tagCorrection.isKeyChanged() && !keysChanged.contains(tagCorrection.oldKey)) { 171 clone.remove(tagCorrection.oldKey); 172 } 160 173 clone.put(tagCorrection.newKey, tagCorrection.newValue); 161 174 keysChanged.add(tagCorrection.newKey); … … 164 177 165 178 // save the clone 166 if (!keysChanged.isEmpty()) commands.add(new ChangeCommand(primitive, clone)); 179 if (!keysChanged.isEmpty()) { 180 commands.add(new ChangeCommand(primitive, clone)); 181 } 167 182 } 168 183 for (OsmPrimitive primitive : roleCorrectionMap.keySet()) { 169 184 List<RoleCorrection> roleCorrections = roleCorrectionMap 170 185 .get(primitive); 171 186 172 187 for (int i = 0; i < roleCorrections.size(); i++) { … … 177 192 } 178 193 } 179 } else if (answer != JOptionPane.NO_OPTION) {194 } else if (answer != JOptionPane.NO_OPTION) 180 195 throw new UserCancelException(); 181 }182 196 return commands; 183 197 } -
trunk/src/org/openstreetmap/josm/data/DataSetChecker.java
r1169 r1814 33 33 if (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer) { 34 34 OsmDataLayer l = (OsmDataLayer)Main.map.mapView.getActiveLayer(); 35 if (l.data != Main. ds) {35 if (l.data != Main.main.getCurrentDataSet()) { 36 36 JOptionPane.showMessageDialog(Main.parent, "Main.ds / active layer mismatch"); 37 37 return; -
trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java
r1169 r1814 62 62 } 63 63 fireCommandsChanged(); 64 Main. ds.setSelected();64 Main.main.getCurrentDataSet().setSelected(); 65 65 } 66 66 … … 84 84 85 85 public void fireCommandsChanged() { 86 for (final CommandQueueListener l : listenerCommands) 86 for (final CommandQueueListener l : listenerCommands) { 87 87 l.commandChanged(commands.size(), redoCommands.size()); 88 } 88 89 } 89 90 … … 108 109 } 109 110 } 110 if (changed) 111 if (changed) { 111 112 fireCommandsChanged(); 113 } 112 114 } 113 115 -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r1756 r1814 105 105 } 106 106 107 public void addPrimitive(OsmPrimitive osm) { 108 if (osm instanceof Node) { 109 nodes.add((Node) osm); 110 } else if (osm instanceof Way) { 111 ways.add((Way) osm); 112 } else if (osm instanceof Relation) { 113 relations.add((Relation) osm); 107 /** 108 * Adds a primitive to the dataset 109 * 110 * @param primitive the primitive. Ignored if null. 111 */ 112 public void addPrimitive(OsmPrimitive primitive) { 113 if (primitive == null) 114 return; 115 if (primitive instanceof Node) { 116 nodes.add((Node) primitive); 117 } else if (primitive instanceof Way) { 118 ways.add((Way) primitive); 119 } else if (primitive instanceof Relation) { 120 relations.add((Relation) primitive); 121 } 122 } 123 124 /** 125 * Removes a primitive from the dataset. This method only removes the 126 * primitive form the respective collection of primitives managed 127 * by this dataset, i.e. from {@see #nodes}, {@see #ways}, or 128 * {@see #relations}. References from other primitives to this 129 * primitive are left unchanged. 130 * 131 * @param primitive the primitive. Ignored if null. 132 */ 133 public void removePrimitive(OsmPrimitive primitive) { 134 if (primitive == null) 135 return; 136 if (primitive instanceof Node) { 137 nodes.remove(primitive); 138 } else if (primitive instanceof Way) { 139 ways.remove(primitive); 140 } else if (primitive instanceof Relation) { 141 relations.remove(primitive); 114 142 } 115 143 } … … 120 148 return sel; 121 149 } 150 151 122 152 /** 123 153 * Return a list of all selected objects. Even keys are returned. … … 391 421 } 392 422 } 423 424 393 425 } -
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r1762 r1814 140 140 return name; 141 141 } 142 143 142 } -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveType.java
r1670 r1814 2 2 package org.openstreetmap.josm.data.osm; 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 import javax.swing.ImageIcon; 4 6 5 7 public enum OsmPrimitiveType { -
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r1722 r1814 21 21 import java.awt.event.MouseAdapter; 22 22 import java.awt.event.MouseEvent; 23 import java.awt.event.MouseListener; 23 24 import java.awt.event.MouseMotionListener; 24 import java.awt.event.MouseListener;25 25 import java.lang.reflect.InvocationTargetException; 26 26 import java.util.Collection; … … 39 39 import org.openstreetmap.josm.data.coor.LatLon; 40 40 import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat; 41 import org.openstreetmap.josm.data.osm.Node; 41 42 import org.openstreetmap.josm.data.osm.OsmPrimitive; 42 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 43 import org.openstreetmap.josm.data.osm.Node; 43 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 44 44 import org.openstreetmap.josm.tools.GBC; 45 45 import org.openstreetmap.josm.tools.ImageProvider; … … 59 59 */ 60 60 public class MapStatus extends JPanel implements Helpful { 61 private static final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter(); 61 62 62 63 /** … … 145 146 if (parent != Main.map) 146 147 return; // exit, if new parent. 147 if ((ms.modifiers & MouseEvent.CTRL_DOWN_MASK) != 0 || ms.mousePos == null) 148 if ((ms.modifiers & MouseEvent.CTRL_DOWN_MASK) != 0 || ms.mousePos == null) { 148 149 continue; // freeze display when holding down ctrl 149 150 if (mv.center == null) 150 } 151 152 if (mv.center == null) { 151 153 continue; 154 } 152 155 153 156 // This try/catch is a hack to stop the flooding bug reports about this. … … 160 163 osmNearest = mv.getNearest(ms.mousePos); 161 164 if (osmNearest != null) { 162 NameVisitor visitor = new NameVisitor(); 163 osmNearest.visit(visitor); 164 nameText.setText(visitor.name); 165 } else 165 nameText.setText(NAME_FORMATTER.getName(osmNearest)); 166 } else { 166 167 nameText.setText(tr("(no object)")); 168 } 167 169 168 170 // Popup Information … … 170 172 Collection<OsmPrimitive> osms = mv.getAllNearest(ms.mousePos); 171 173 172 if (osms == null) 174 if (osms == null) { 173 175 continue; 174 if (osms != null && osms.equals(osmStatus) && ms.modifiers == oldModifiers) 176 } 177 if (osms != null && osms.equals(osmStatus) && ms.modifiers == oldModifiers) { 175 178 continue; 179 } 176 180 177 181 if (popup != null) { … … 190 194 JPanel c = new JPanel(new GridBagLayout()); 191 195 for (final OsmPrimitive osm : osms) { 192 NameVisitor visitor = new NameVisitor();193 osm.visit(visitor);194 196 final StringBuilder text = new StringBuilder(); 195 if (osm.id == 0 || osm.modified) 196 visitor.name = "<i><b>"+visitor.name+"*</b></i>"; 197 text.append(visitor.name); 198 if (osm.id != 0) 197 String name = NAME_FORMATTER.getName(osm); 198 if (osm.id == 0 || osm.modified) { 199 name = "<i><b>"+ new PrimitiveNameFormatter().getName(osm)+"*</b></i>"; 200 } 201 text.append(name); 202 if (osm.id != 0) { 199 203 text.append("<br>id="+osm.id); 200 for (Entry<String, String> e : osm.entrySet()) 204 } 205 for (Entry<String, String> e : osm.entrySet()) { 201 206 text.append("<br>"+e.getKey()+"="+e.getValue()); 202 final JLabel l = new JLabel("<html>"+text.toString()+"</html>", visitor.icon, JLabel.HORIZONTAL); 207 } 208 final JLabel l = new JLabel( 209 "<html>"+text.toString()+"</html>", 210 ImageProvider.get(OsmPrimitiveType.from(osm)), 211 JLabel.HORIZONTAL 212 ); 203 213 l.setFont(l.getFont().deriveFont(Font.PLAIN)); 204 214 l.setVerticalTextPosition(JLabel.TOP); … … 212 222 } 213 223 @Override public void mouseClicked(MouseEvent e) { 214 Main. ds.setSelected(osm);224 Main.main.getCurrentDataSet().setSelected(osm); 215 225 mv.repaint(); 216 226 } … … 306 316 public void eventDispatched(AWTEvent event) { 307 317 if (event instanceof ComponentEvent && 308 ((ComponentEvent)event).getComponent() == mapFrame.mapView) {318 ((ComponentEvent)event).getComponent() == mapFrame.mapView) { 309 319 synchronized (collector) { 310 320 mouseState.modifiers = ((InputEvent)event).getModifiersEx(); 311 if (event instanceof MouseEvent) 321 if (event instanceof MouseEvent) { 312 322 mouseState.mousePos = ((MouseEvent)event).getPoint(); 323 } 313 324 collector.notify(); 314 325 } -
trunk/src/org/openstreetmap/josm/gui/MapView.java
r1808 r1814 148 148 if (layer instanceof OsmDataLayer) { 149 149 OsmDataLayer editLayer = (OsmDataLayer)layer; 150 Main.ds = editLayer.data;151 150 editLayer.listenerModified.add(new ModifiedChangedListener(){ 152 151 public void modifiedChanged(boolean value, OsmDataLayer source) { … … 181 180 182 181 @Override 183 protected DataSet get Data() {182 protected DataSet getCurrentDataSet() { 184 183 if(activeLayer != null && activeLayer instanceof OsmDataLayer) 185 184 return ((OsmDataLayer)activeLayer).data; … … 211 210 public void removeLayer(Layer layer) { 212 211 if (layer == activeLayer) { 213 if (layer instanceof OsmDataLayer) {214 Main.ds = null;215 }216 212 activeLayer = null; 217 213 } … … 351 347 public void setActiveLayer(Layer layer) { 352 348 if (!layers.contains(layer)) 353 throw new IllegalArgumentException(tr("Layer {0} must be in list of layers", layer.toString())); 354 if (layer instanceof OsmDataLayer) { 355 OsmDataLayer editLayer = (OsmDataLayer)layer; 356 Main.ds = editLayer.data; 357 } else { 358 Main.ds.setSelected(); 359 } 360 DataSet.fireSelectionChanged(Main.ds.getSelected()); 349 throw new IllegalArgumentException(tr("Layer ''{0}'' must be in list of layers", layer.toString())); 350 if (! (layer instanceof OsmDataLayer)) { 351 if (getCurrentDataSet() != null) { 352 getCurrentDataSet().setSelected(); 353 DataSet.fireSelectionChanged(getCurrentDataSet().getSelected()); 354 } 355 } 361 356 Layer old = activeLayer; 362 357 activeLayer = layer; -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r1797 r1814 27 27 import org.openstreetmap.josm.data.osm.WaySegment; 28 28 import org.openstreetmap.josm.data.projection.Projection; 29 import org.openstreetmap.josm.data.projection.Mercator;30 29 31 30 /** … … 55 54 } 56 55 57 protected DataSet getData() 58 { 59 return Main.ds; 56 protected DataSet getCurrentDataSet() { 57 return Main.main.getCurrentDataSet(); 60 58 } 61 59 … … 102 100 public ProjectionBounds getProjectionBounds() { 103 101 return new ProjectionBounds( 104 new EastNorth(105 center.east() - getWidth()/2.0*scale,106 center.north() - getHeight()/2.0*scale),107 new EastNorth(108 center.east() + getWidth()/2.0*scale,109 center.north() + getHeight()/2.0*scale));102 new EastNorth( 103 center.east() - getWidth()/2.0*scale, 104 center.north() - getHeight()/2.0*scale), 105 new EastNorth( 106 center.east() + getWidth()/2.0*scale, 107 center.north() + getHeight()/2.0*scale)); 110 108 }; 111 109 112 110 public Bounds getRealBounds() { 113 111 return new Bounds( 114 getProjection().eastNorth2latlon(new EastNorth(115 center.east() - getWidth()/2.0*scale,116 center.north() - getHeight()/2.0*scale)),117 getProjection().eastNorth2latlon(new EastNorth(118 center.east() + getWidth()/2.0*scale,119 center.north() + getHeight()/2.0*scale)));112 getProjection().eastNorth2latlon(new EastNorth( 113 center.east() - getWidth()/2.0*scale, 114 center.north() - getHeight()/2.0*scale)), 115 getProjection().eastNorth2latlon(new EastNorth( 116 center.east() + getWidth()/2.0*scale, 117 center.north() + getHeight()/2.0*scale))); 120 118 }; 121 119 … … 163 161 */ 164 162 private void zoomTo(EastNorth newCenter, double newScale) { 165 /* TODO: check that newCenter is really inside visible world and that scale is correct, don't allow zooming out to much */163 /* TODO: check that newCenter is really inside visible world and that scale is correct, don't allow zooming out to much */ 166 164 boolean rep = false; 167 165 if (!newCenter.equals(center)) { … … 177 175 firePropertyChange("scale", oldScale, newScale); 178 176 } 179 if(rep) 177 if(rep) { 180 178 repaint(); 179 } 181 180 } 182 181 … … 186 185 187 186 public void zoomTo(LatLon newCenter) { 188 if (newCenter instanceof CachedLatLon)187 if(newCenter instanceof CachedLatLon) { 189 188 zoomTo(((CachedLatLon)newCenter).getEastNorth(), scale); 190 else189 } else { 191 190 zoomTo(getProjection().latlon2eastNorth(newCenter), scale); 191 } 192 192 } 193 193 … … 197 197 // You will get the formula by simplifying this expression: newCenter = oldCenter + mouseCoordinatesInNewZoom - mouseCoordinatesInOldZoom 198 198 zoomTo(new EastNorth( 199 center.east() - (x - getWidth()/2.0) * (newScale - scale),200 center.north() + (y - getHeight()/2.0) * (newScale - scale)),201 newScale);199 center.east() - (x - getWidth()/2.0) * (newScale - scale), 200 center.north() + (y - getHeight()/2.0) * (newScale - scale)), 201 newScale); 202 202 } 203 203 … … 213 213 // -20 to leave some border 214 214 int w = getWidth()-20; 215 if (w < 20) 215 if (w < 20) { 216 216 w = 20; 217 } 217 218 int h = getHeight()-20; 218 if (h < 20) 219 if (h < 20) { 219 220 h = 20; 221 } 220 222 221 223 double scaleX = (box.max.east()-box.min.east())/w; … … 228 230 public void zoomTo(Bounds box) { 229 231 zoomTo(new ProjectionBounds(getProjection().latlon2eastNorth(box.min), 230 getProjection().latlon2eastNorth(box.max)));232 getProjection().latlon2eastNorth(box.max))); 231 233 } 232 234 … … 238 240 double minDistanceSq = snapDistance; 239 241 Node minPrimitive = null; 240 for (Node n : get Data().nodes) {241 if (n.deleted || n.incomplete) 242 for (Node n : getCurrentDataSet().nodes) { 243 if (n.deleted || n.incomplete) { 242 244 continue; 245 } 243 246 Point sp = getPoint(n); 244 247 double dist = p.distanceSq(sp); … … 249 252 // when multiple nodes on one point, prefer new or selected nodes 250 253 else if(dist == minDistanceSq && minPrimitive != null 251 && ((n.id == 0 && n.selected)252 || (!minPrimitive.selected && (n.selected || n.id == 0))))254 && ((n.id == 0 && n.selected) 255 || (!minPrimitive.selected && (n.selected || n.id == 0)))) { 253 256 minPrimitive = n; 257 } 254 258 } 255 259 return minPrimitive; … … 264 268 public final List<WaySegment> getNearestWaySegments(Point p) { 265 269 TreeMap<Double, List<WaySegment>> nearest = new TreeMap<Double, List<WaySegment>>(); 266 for (Way w : getData().ways) { 267 if (w.deleted || w.incomplete) continue; 270 for (Way w : getCurrentDataSet().ways) { 271 if (w.deleted || w.incomplete) { 272 continue; 273 } 268 274 Node lastN = null; 269 275 int i = -2; 270 276 for (Node n : w.nodes) { 271 277 i++; 272 if (n.deleted || n.incomplete) continue; 278 if (n.deleted || n.incomplete) { 279 continue; 280 } 273 281 if (lastN == null) { 274 282 lastN = n; … … 283 291 double perDist = a-(a-b+c)*(a-b+c)/4/c; // perpendicular distance squared 284 292 if (perDist < snapDistance && a < c+snapDistance && b < c+snapDistance) { 285 if(w.selected) // prefer selected ways a little bit293 if(w.selected) { 286 294 perDist -= 0.00001; 295 } 287 296 List<WaySegment> l; 288 297 if (nearest.containsKey(perDist)) { … … 315 324 public final WaySegment getNearestWaySegment(Point p, Collection<WaySegment> ignore) { 316 325 List<WaySegment> nearest = getNearestWaySegments(p); 317 if (ignore != null) nearest.removeAll(ignore); 326 if (ignore != null) { 327 nearest.removeAll(ignore); 328 } 318 329 return nearest.isEmpty() ? null : nearest.get(0); 319 330 } … … 376 387 public Collection<OsmPrimitive> getAllNearest(Point p) { 377 388 Collection<OsmPrimitive> nearest = new HashSet<OsmPrimitive>(); 378 for (Way w : getData().ways) { 379 if (w.deleted || w.incomplete) continue; 389 for (Way w : getCurrentDataSet().ways) { 390 if (w.deleted || w.incomplete) { 391 continue; 392 } 380 393 Node lastN = null; 381 394 for (Node n : w.nodes) { 382 if (n.deleted || n.incomplete) continue; 395 if (n.deleted || n.incomplete) { 396 continue; 397 } 383 398 if (lastN == null) { 384 399 lastN = n; … … 393 408 if (perDist < snapDistance && a < c+snapDistance && b < c+snapDistance) { 394 409 nearest.add(w); 395 396 410 break; 411 } 397 412 lastN = n; 398 399 400 for (Node n : get Data().nodes) {413 } 414 } 415 for (Node n : getCurrentDataSet().nodes) { 401 416 if (!n.deleted && !n.incomplete 402 417 && getPoint(n).distanceSq(p) < snapDistance) { … … 417 432 public Collection<Node> getNearestNodes(Point p) { 418 433 Collection<Node> nearest = new HashSet<Node>(); 419 for (Node n : get Data().nodes) {434 for (Node n : getCurrentDataSet().nodes) { 420 435 if (!n.deleted && !n.incomplete 421 436 && getPoint(n).distanceSq(p) < snapDistance) { … … 436 451 public final Collection<Node> getNearestNodes(Point p, Collection<Node> ignore) { 437 452 Collection<Node> nearest = getNearestNodes(p); 438 if (nearest == null) return null; 439 if (ignore != null) nearest.removeAll(ignore); 453 if (nearest == null) return null; 454 if (ignore != null) { 455 nearest.removeAll(ignore); 456 } 440 457 return nearest.isEmpty() ? null : nearest; 441 458 } -
trunk/src/org/openstreetmap/josm/gui/OsmPrimitivRenderer.java
r1169 r1814 13 13 14 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 15 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 16 import org.openstreetmap.josm.tools.ImageProvider; 16 17 17 18 /** … … 24 25 */ 25 26 public class OsmPrimitivRenderer implements ListCellRenderer, TableCellRenderer { 26 27 /** 28 * NameVisitor provides proper names and icons for OsmPrimitives 29 */ 30 private NameVisitor visitor = new NameVisitor(); 27 static private final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter(); 31 28 32 29 /** … … 65 62 private Component renderer(Component def, OsmPrimitive value) { 66 63 if (def != null && value != null && def instanceof JLabel) { 67 (value).visit(visitor); 68 ((JLabel)def).setText(visitor.name); 69 ((JLabel)def).setIcon(visitor.icon); 64 ((JLabel)def).setText(NAME_FORMATTER.getName(value)); 65 ((JLabel)def).setIcon(ImageProvider.get(OsmPrimitiveType.from(value))); 70 66 } 71 67 return def; -
trunk/src/org/openstreetmap/josm/gui/SelectionManager.java
r1725 r1814 279 279 } else { 280 280 // nodes 281 for (Node n : nc.get Data().nodes) {281 for (Node n : nc.getCurrentDataSet().nodes) { 282 282 if (!n.deleted && !n.incomplete && r.contains(nc.getPoint(n))) 283 283 selection.add(n); … … 285 285 286 286 // ways 287 for (Way w : nc.get Data().ways) {287 for (Way w : nc.getCurrentDataSet().ways) { 288 288 if (w.deleted || w.nodes.isEmpty() || w.incomplete) 289 289 continue; -
trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
r1787 r1814 353 353 sel.add((OsmPrimitive)o); 354 354 } 355 Main. ds.setSelected(sel);355 Main.main.getCurrentDataSet().setSelected(sel); 356 356 } 357 357 -
trunk/src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java
r1811 r1814 288 288 public void refresh() { 289 289 data.clear(); 290 for (OsmPrimitive primitive: Main. ds.getSelected()) {290 for (OsmPrimitive primitive: Main.main.getCurrentDataSet().getSelected()) { 291 291 if (primitive.id == 0) { 292 292 continue; … … 398 398 @Override 399 399 protected void realRun() throws SAXException, IOException, OsmTransferException { 400 Collection<OsmPrimitive> selection = Main. ds.getSelected();400 Collection<OsmPrimitive> selection = Main.main.getCurrentDataSet().getSelected(); 401 401 Iterator<OsmPrimitive> it = selection.iterator(); 402 402 try { … … 454 454 455 455 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 456 setEnabled(Main. ds.getSelected().size() > 0);456 setEnabled(Main.main.getCurrentDataSet().getSelected().size() > 0); 457 457 458 458 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r1790 r1814 60 60 import org.openstreetmap.josm.data.osm.RelationMember; 61 61 import org.openstreetmap.josm.data.osm.Way; 62 import org.openstreetmap.josm.data.osm.visitor.NameVisitor;63 62 import org.openstreetmap.josm.gui.ExtendedDialog; 64 63 import org.openstreetmap.josm.gui.MapFrame; 64 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 65 65 import org.openstreetmap.josm.gui.SideButton; 66 66 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 67 import org.openstreetmap.josm.gui.layer.Layer; 68 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 69 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 67 70 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference; 68 71 import org.openstreetmap.josm.gui.tagging.TaggingPreset; … … 88 91 * @author imi 89 92 */ 90 public class PropertiesDialog extends ToggleDialog implements SelectionChangedListener { 91 92 /** 93 * Used to display relation names in the membership table 94 */ 95 private NameVisitor nameVisitor = new NameVisitor(); 93 public class PropertiesDialog extends ToggleDialog implements SelectionChangedListener, LayerChangeListener { 94 static private final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter(); 96 95 97 96 /** … … 135 134 */ 136 135 void propertyEdit(int row) { 137 Collection<OsmPrimitive> sel = Main. ds.getSelected();136 Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected(); 138 137 if (sel.isEmpty()) return; 139 138 … … 318 317 */ 319 318 void add() { 320 Collection<OsmPrimitive> sel = Main. ds.getSelected();319 Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected(); 321 320 if (sel.isEmpty()) return; 322 321 … … 387 386 boolean edit) { 388 387 final TreeMap<String, TreeSet<String>> allData = new TreeMap<String, TreeSet<String>>(); 389 for (OsmPrimitive osm : Main. ds.allNonDeletedPrimitives()) {388 for (OsmPrimitive osm : Main.main.getCurrentDataSet().allNonDeletedPrimitives()) { 390 389 for (String key : osm.keySet()) { 391 390 TreeSet<String> values = null; … … 413 412 private void delete(int row) { 414 413 String key = propertyData.getValueAt(row, 0).toString(); 415 Collection<OsmPrimitive> sel = Main. ds.getSelected();414 Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected(); 416 415 Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, null)); 417 416 DataSet.fireSelectionChanged(sel); … … 513 512 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 514 513 if (c instanceof JLabel) { 515 nameVisitor.visit((Relation)value); 516 ((JLabel)c).setText(nameVisitor.name); 514 ((JLabel)c).setText(NAME_FORMATTER.getName((Relation)value)); 517 515 } 518 516 return c; … … 576 574 } else if (e.getActionCommand().equals("Delete")) { 577 575 Relation cur = (Relation)membershipData.getValueAt(row, 0); 578 NameVisitor n = new NameVisitor();579 cur.visit(n);580 581 576 int result = new ExtendedDialog(Main.parent, 582 577 tr("Change relation"), 583 tr("Really delete selection from relation {0}?", n.name),578 tr("Really delete selection from relation {0}?", NAME_FORMATTER.getName(cur)), 584 579 new String[] {tr("Delete from relation"), tr("Cancel")}, 585 580 new String[] {"dialogs/delete.png", "cancel.png"}).getValue(); … … 588 583 { 589 584 Relation rel = new Relation(cur); 590 Collection<OsmPrimitive> sel = Main. ds.getSelected();585 Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected(); 591 586 for (RelationMember rm : cur.members) { 592 587 for (OsmPrimitive osm : sel) { … … 642 637 643 638 DataSet.selListeners.add(this); 639 Layer.listeners.add(this); 644 640 } 645 641 646 642 @Override public void setVisible(boolean b) { 647 643 super.setVisible(b); 648 if (b ) {649 selectionChanged(Main. ds.getSelected());644 if (b && Main.main.getCurrentDataSet() != null) { 645 selectionChanged(Main.main.getCurrentDataSet().getSelected()); 650 646 } 651 647 } … … 796 792 797 793 Map<Relation, Collection<RelationMember>> roles = new HashMap<Relation, Collection<RelationMember>>(); 798 for (Relation r : Main. ds.relations) {794 for (Relation r : Main.main.getCurrentDataSet().relations) { 799 795 if (!r.deleted && !r.incomplete) { 800 796 for (RelationMember m : r.members) { … … 842 838 } 843 839 } 840 841 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 842 if (newLayer instanceof OsmDataLayer) { 843 OsmDataLayer dataLayer = (OsmDataLayer)newLayer; 844 selectionChanged(dataLayer.data.getSelected()); 845 } 846 } 847 848 public void layerAdded(Layer newLayer) { 849 // do nothing 850 } 851 852 public void layerRemoved(Layer oldLayer) { 853 // do nothing 854 } 855 856 844 857 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r1787 r1814 77 77 @Override public void mouseClicked(MouseEvent e) { 78 78 if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { 79 Main. ds.setSelected((Relation)displaylist.getSelectedValue());79 Main.main.getCurrentDataSet().setSelected((Relation)displaylist.getSelectedValue()); 80 80 } 81 81 } … … 125 125 } 126 126 127 protected int getNumRelations() { 128 if (Main.main.getCurrentDataSet() == null) return 0; 129 return Main.main.getCurrentDataSet().relations.size(); 130 } 131 127 132 public void updateList() { 128 133 Relation selected = getSelected(); 129 list.setSize(Main.ds.relations.size()); 130 int i = 0; 131 for (OsmPrimitive e : DataSet.sort(Main.ds.relations)) { 132 if (!e.deleted && !e.incomplete) { 133 list.setElementAt(e, i++); 134 } 135 } 136 list.setSize(i); 137 138 if(Main.ds.relations.size() != 0) { 139 setTitle(tr("Relations: {0}", Main.ds.relations.size()), true); 134 list.setSize(getNumRelations()); 135 if (getNumRelations() > 0 ) { 136 int i = 0; 137 for (OsmPrimitive e : DataSet.sort(Main.main.getCurrentDataSet().relations)) { 138 if (!e.deleted && !e.incomplete) { 139 list.setElementAt(e, i++); 140 } 141 } 142 list.setSize(i); 143 } 144 if(getNumRelations() != 0) { 145 setTitle(tr("Relations: {0}", Main.main.getCurrentDataSet().relations.size()), true); 140 146 } else { 141 147 setTitle(tr("Relations"), false); -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r1722 r1814 43 43 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 44 44 import org.openstreetmap.josm.gui.SideButton; 45 import org.openstreetmap.josm.gui.layer.Layer; 46 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 47 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 45 48 import org.openstreetmap.josm.tools.Shortcut; 46 49 … … 52 55 * @author imi 53 56 */ 54 public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener {57 public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener, LayerChangeListener { 55 58 56 59 private static final int SELECTION_HISTORY_SIZE = 10; … … 80 83 public SelectionListDialog() { 81 84 super(tr("Current Selection"), "selectionlist", tr("Open a selection list window."), 82 Shortcut.registerShortcut("subwindow:selection", tr("Toggle: {0}", tr("Current Selection")), KeyEvent.VK_T, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150);85 Shortcut.registerShortcut("subwindow:selection", tr("Toggle: {0}", tr("Current Selection")), KeyEvent.VK_T, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150); 83 86 84 87 selectionHistory = new LinkedList<Collection<? extends OsmPrimitive>>(); … … 89 92 @Override 90 93 public void mouseClicked(MouseEvent e) { 91 if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) 94 if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { 92 95 updateMap(); 96 } 93 97 } 94 98 … … 112 116 tr("Set the selected elements on the map to the selected items in the list above."), 113 117 new ActionListener() { 114 115 116 117 118 public void actionPerformed(ActionEvent e) { 119 updateMap(); 120 } 121 }); 118 122 buttonPanel.add(selectButton); 119 123 BasicArrowButton selectionHistoryMenuButton = createArrowButton(selectButton); … … 134 138 buttonPanel.add(new SideButton(marktr("Reload"), "refresh", "SelectionList", tr("Refresh the selection list."), 135 139 new ActionListener() { 136 137 selectionChanged(Main.ds.getSelected());138 139 140 public void actionPerformed(ActionEvent e) { 141 selectionChanged(Main.main.getCurrentDataSet().getSelected()); 142 } 143 })); 140 144 141 145 searchButton = new SideButton(marktr("Search"), "search", "SelectionList", tr("Search for objects."), … … 159 163 popupMenu.add(zoomToSelection); 160 164 161 selectionChanged(Main.ds.getSelected()); 165 if (Main.main.getCurrentDataSet() != null) { 166 selectionChanged(Main.main.getCurrentDataSet().getSelected()); 167 } 162 168 163 169 DataSet.selListeners.add(this); 170 Layer.listeners.add(this); 164 171 } 165 172 … … 179 186 public void setVisible(boolean b) { 180 187 super.setVisible(b); 181 if (b) 182 selectionChanged(Main.ds.getSelected()); 188 if (b && Main.main.getCurrentDataSet() != null) { 189 selectionChanged(Main.main.getCurrentDataSet().getSelected()); 190 } 183 191 } 184 192 … … 204 212 for (int i = 0; i < selected.length; i++) { 205 213 Object o = list.get(selected[i]); 206 if (o instanceof OsmPrimitive) 214 if (o instanceof OsmPrimitive) { 207 215 ((OsmPrimitive) o).visit(box); 216 } 208 217 } 209 218 if (box.getBounds() == null) … … 247 256 list.setSize(selArr.length); 248 257 int i = 0; 249 for (OsmPrimitive osm : selArr) 258 for (OsmPrimitive osm : selArr) { 250 259 list.setElementAt(osm, i++); 260 } 251 261 if (selectionHistory != null && newSelection.size() > 0 && !newSelection.equals(historyIgnoreSelection)) { 252 262 historyIgnoreSelection = null; … … 259 269 } 260 270 selectionHistory.addFirst(newSelection); 261 while (selectionHistory.size() > SELECTION_HISTORY_SIZE) 271 while (selectionHistory.size() > SELECTION_HISTORY_SIZE) { 262 272 selectionHistory.removeLast(); 273 } 263 274 } 264 275 … … 267 278 int relations = 0; 268 279 for (OsmPrimitive o : newSelection) { 269 if (o instanceof Way) 280 if (o instanceof Way) { 270 281 ways++; 271 else if (o instanceof Node)282 } else if (o instanceof Node) { 272 283 nodes++; 273 else if (o instanceof Relation)284 } else if (o instanceof Relation) { 274 285 relations++; 286 } 275 287 } 276 288 … … 288 300 Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>(); 289 301 for (int i = 0; i < list.getSize(); ++i) 290 if (displaylist.isSelectedIndex(i)) 302 if (displaylist.isSelectedIndex(i)) { 291 303 sel.add((OsmPrimitive) list.get(i)); 292 Main.ds.setSelected(sel); 304 } 305 Main.main.getCurrentDataSet().setSelected(sel); 293 306 } 294 307 … … 308 321 int relations = 0; 309 322 for (OsmPrimitive o : sel) { 310 if (o instanceof Way) 323 if (o instanceof Way) { 311 324 ways++; 312 else if (o instanceof Node)325 } else if (o instanceof Node) { 313 326 nodes++; 314 else if (o instanceof Relation)327 } else if (o instanceof Relation) { 315 328 relations++; 329 } 316 330 } 317 331 String text = ""; 318 if(ways != 0) 332 if(ways != 0) { 319 333 text += (text.length() > 0 ? ", " : "") 320 334 + trn("{0} way", "{0} ways", ways, ways); 321 if(nodes != 0) 335 } 336 if(nodes != 0) { 322 337 text += (text.length() > 0 ? ", " : "") 323 338 + trn("{0} node", "{0} nodes", nodes, nodes); 324 if(relations != 0) 339 } 340 if(relations != 0) { 325 341 text += (text.length() > 0 ? ", " : "") 326 342 + trn("{0} relation", "{0} relations", relations, relations); 343 } 327 344 setText(tr("Selection: {0}", text)); 328 345 addActionListener(this); … … 331 348 public void actionPerformed(ActionEvent e) { 332 349 historyIgnoreSelection = sel; 333 Main. ds.setSelected(sel);350 Main.main.getCurrentDataSet().setSelected(sel); 334 351 } 335 352 … … 355 372 356 373 } 374 375 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 376 if (newLayer instanceof OsmDataLayer) { 377 OsmDataLayer dataLayer = (OsmDataLayer)newLayer; 378 selectionChanged(dataLayer.data.getSelected()); 379 380 } 381 382 } 383 384 public void layerAdded(Layer newLayer) { 385 // do nothing 386 387 } 388 389 public void layerRemoved(Layer oldLayer) { 390 // do nothing 391 392 } 357 393 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java
r1228 r1814 24 24 import org.openstreetmap.josm.data.osm.OsmPrimitive; 25 25 import org.openstreetmap.josm.data.osm.User; 26 import org.openstreetmap.josm.gui.layer.Layer; 27 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 28 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 26 29 import org.openstreetmap.josm.tools.Shortcut; 27 30 … … 32 35 * @author Frederik Ramm <frederik@remote.org> 33 36 */ 34 public class UserListDialog extends ToggleDialog implements SelectionChangedListener, MouseListener {37 public class UserListDialog extends ToggleDialog implements SelectionChangedListener, MouseListener, LayerChangeListener { 35 38 36 39 /** … … 52 55 public UserListDialog() { 53 56 super(tr("Authors"), "userlist", tr("Open a list of people working on the selected objects."), 54 Shortcut.registerShortcut("subwindow:authors", tr("Toggle: {0}", tr("Authors")), KeyEvent.VK_A, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150);57 Shortcut.registerShortcut("subwindow:authors", tr("Toggle: {0}", tr("Authors")), KeyEvent.VK_A, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150); 55 58 56 59 data.setColumnIdentifiers(new String[]{tr("Author"),tr("# Objects"),"%"}); 57 60 userTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 58 61 add(new JScrollPane(userTable), BorderLayout.CENTER); 59 selectionChanged(Main.ds.getSelected()); 62 if (Main.main.getCurrentDataSet() != null) { 63 selectionChanged(Main.main.getCurrentDataSet().getSelected()); 64 } 60 65 userTable.addMouseListener(this); 61 66 DataSet.selListeners.add(this); 67 Layer.listeners.add(this); 62 68 } 63 69 64 70 @Override public void setVisible(boolean b) { 65 71 super.setVisible(b); 66 if (b) 67 selectionChanged(Main.ds.getSelected()); 72 if (b && Main.main.getCurrentDataSet() != null) { 73 selectionChanged(Main.main.getCurrentDataSet().getSelected()); 74 } 68 75 } 69 76 … … 91 98 for (OsmPrimitive p : newSelection) { 92 99 User u = p.user; 93 if (u == null) u = anonymousUser; 100 if (u == null) { 101 u = anonymousUser; 102 } 94 103 UserCount uc = counters.get(u); 95 if (uc == null) 104 if (uc == null) { 96 105 counters.put(u, uc = new UserCount(u, 0)); 106 } 97 107 uc.count++; 98 108 all++; … … 123 133 if (userName==null) 124 134 return; 125 Collection<OsmPrimitive> selected = Main. ds.getSelected();135 Collection<OsmPrimitive> selected = Main.main.getCurrentDataSet().getSelected(); 126 136 Collection<OsmPrimitive> byUser = new LinkedList<OsmPrimitive>(); 127 137 for (OsmPrimitive p : selected) { 128 if (p.user!= null && userName.equals(p.user.name)) 138 if (p.user!= null && userName.equals(p.user.name)) { 129 139 byUser.add(p); 140 } 130 141 } 131 Main. ds.setSelected(byUser);142 Main.main.getCurrentDataSet().setSelected(byUser); 132 143 } 133 144 } … … 145 156 } 146 157 158 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 159 if (newLayer instanceof OsmDataLayer) { 160 OsmDataLayer dataLayer = (OsmDataLayer)newLayer; 161 selectionChanged(dataLayer.data.getSelected()); 162 163 } 164 } 165 166 public void layerAdded(Layer newLayer) { 167 // do nothing 168 } 169 170 public void layerRemoved(Layer oldLayer) { 171 // do nothing 172 } 147 173 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r1811 r1814 315 315 } 316 316 } 317 Main.ds.setSelected(sel);317 getLayer().data.setSelected(sel); 318 318 } 319 319 }); … … 564 564 memberTableModel.applyToRelation(newRelation); 565 565 Main.main.undoRedo.add(new AddCommand(newRelation)); 566 DataSet.fireSelectionChanged( Main.ds.getSelected());566 DataSet.fireSelectionChanged(getLayer().data.getSelected()); 567 567 } else if (! memberTableModel.hasSameMembersAs(getRelation()) || tagEditorModel.isDirty()) { 568 568 Relation editedRelation = new Relation(getRelation()); … … 588 588 memberTableModel.applyToRelation(clone); 589 589 Main.main.undoRedo.add(new ChangeCommand(getRelation(), clone)); 590 DataSet.fireSelectionChanged( Main.ds.getSelected());590 DataSet.fireSelectionChanged(getLayer().data.getSelected()); 591 591 } 592 592 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableCellRenderer.java
r1793 r1814 15 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 17 import org.openstreetmap.josm. data.osm.visitor.NameVisitor;17 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 18 18 import org.openstreetmap.josm.tools.ImageProvider; 19 19 … … 23 23 */ 24 24 public class MemberTableCellRenderer extends JLabel implements TableCellRenderer { 25 static private final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter(); 26 25 27 public final static Color BGCOLOR_SELECTED = new Color(143,170,255); 26 28 public final static Color BGCOLOR_EMPTY_ROW = new Color(234,234,234); … … 112 114 113 115 protected void renderPrimitive(OsmPrimitive primitive) { 114 NameVisitor visitor = new NameVisitor();115 primitive.visit(visitor);116 116 setIcon(icons.get(OsmPrimitiveType.from(primitive))); 117 setText( visitor.name);117 setText(NAME_FORMATTER.getName(primitive)); 118 118 setToolTipText(buildToolTipText(primitive)); 119 119 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableColumnModel.java
r1790 r1814 20 20 col.setResizable(true); 21 21 col.setCellRenderer(renderer); 22 22 23 addColumn(col); 23 24 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableCellRenderer.java
r1806 r1814 15 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 17 import org.openstreetmap.josm. data.osm.visitor.NameVisitor;17 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 18 18 import org.openstreetmap.josm.tools.ImageProvider; 19 19 … … 23 23 */ 24 24 public class SelectionTableCellRenderer extends JLabel implements TableCellRenderer { 25 static private final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter(); 26 25 27 public final static Color BGCOLOR_SELECTED = new Color(143,170,255); 26 28 public final static Color BGCOLOR_DOUBLE_ENTRY = new Color(255,234,213); … … 115 117 116 118 protected void renderPrimitive(OsmPrimitive primitive) { 117 NameVisitor visitor = new NameVisitor();118 primitive.visit(visitor);119 119 setIcon(icons.get(OsmPrimitiveType.from(primitive))); 120 setText( visitor.name);120 setText(NAME_FORMATTER.getName(primitive)); 121 121 setToolTipText(buildToolTipText(primitive)); 122 122 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/TagEditorModel.java
r1790 r1814 260 260 261 261 /** 262 * initializes the model with the tags in the current JOSM selection263 */264 public void initFromJOSMSelection() {265 Collection<OsmPrimitive> selection = Main.ds.getSelected();266 clear();267 for (OsmPrimitive element : selection) {268 for (String key : element.keySet()) {269 String value = element.get(key);270 add(key,value);271 }272 }273 sort();274 setDirty(false);275 }276 277 /**278 262 * initializes the model with the tags of an OSM primitive 279 263 * … … 291 275 setDirty(false); 292 276 } 293 294 277 295 278 /** … … 381 364 return command; 382 365 } 383 384 /**385 * updates the tags of the primitives in the current selection with the386 * values in the current tag model387 *388 */389 public void updateJOSMSelection() {390 ArrayList<Command> commands = new ArrayList<Command>();391 Collection<OsmPrimitive> selection = Main.ds.getSelected();392 if (selection == null)393 return;394 for (TagModel tag : tags) {395 Command command = createUpdateTagCommand(selection,tag);396 if (command != null) {397 commands.add(command);398 }399 }400 Command deleteCommand = createDeleteTagsCommand(selection);401 if (deleteCommand != null) {402 commands.add(deleteCommand);403 }404 405 SequenceCommand command = new SequenceCommand(406 trn("Updating properties of up to {0} object", "Updating properties of up to {0} objects", selection.size(), selection.size()),407 commands408 );409 410 // executes the commands and adds them to the undo/redo chains411 Main.main.undoRedo.add(command);412 }413 414 366 415 367 /** -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r1759 r1814 101 101 for (OsmPrimitive s : sel) { 102 102 String v = s.get(key); 103 if (v != null) 103 if (v != null) { 104 104 returnValue.values.add(v); 105 else105 } else { 106 106 returnValue.hadEmpty = true; 107 if(s.keys != null && s.keys.size() > 0) 107 } 108 if(s.keys != null && s.keys.size() > 0) { 108 109 returnValue.hadKeys = true; 110 } 109 111 } 110 112 return returnValue; … … 149 151 // all objects use the same value 150 152 value = new JTextField(); 151 for (String s : usage.values) ((JTextField) value).setText(s); 153 for (String s : usage.values) { 154 ((JTextField) value).setText(s); 155 } 152 156 originalValue = ((JTextField)value).getText(); 153 157 } else { … … 158 162 originalValue = DIFFERENT; 159 163 } 160 if(locale_text == null) 164 if(locale_text == null) { 161 165 locale_text = tr(text); 166 } 162 167 p.add(new JLabel(locale_text+":"), GBC.std().insets(0,0,10,0)); 163 168 p.add(value, GBC.eol().fill(GBC.HORIZONTAL)); … … 169 174 // return if unchanged 170 175 String v = (value instanceof JComboBox) ? 171 ((JComboBox)value).getEditor().getItem().toString() : 172 ((JTextField)value).getText(); 173 174 if (use_last_as_default) lastValue.put(key, v); 175 if (v.equals(originalValue) || (originalValue == null && v.length() == 0)) return; 176 177 if (delete_if_empty && v.length() == 0) 178 v = null; 179 cmds.add(new ChangePropertyCommand(sel, key, v)); 176 ((JComboBox)value).getEditor().getItem().toString() : 177 ((JTextField)value).getText(); 178 179 if (use_last_as_default) { 180 lastValue.put(key, v); 181 } 182 if (v.equals(originalValue) || (originalValue == null && v.length() == 0)) return; 183 184 if (delete_if_empty && v.length() == 0) { 185 v = null; 186 } 187 cmds.add(new ChangePropertyCommand(sel, key, v)); 180 188 } 181 189 @Override boolean requestFocusInWindow() {return value.requestFocusInWindow();} … … 200 208 def = default_; 201 209 202 if(locale_text == null) 210 if(locale_text == null) { 203 211 locale_text = tr(text); 212 } 204 213 205 214 String oneValue = null; 206 for (String s : usage.values) oneValue = s; 215 for (String s : usage.values) { 216 oneValue = s; 217 } 207 218 if (usage.values.size() < 2 && (oneValue == null || OsmUtils.trueval.equals(oneValue) || OsmUtils.falseval.equals(oneValue))) { 208 219 if(def) 209 220 { 210 221 for (OsmPrimitive s : sel) 211 if(s.keys != null && s.keys.size() > 0) def = false; 222 if(s.keys != null && s.keys.size() > 0) { 223 def = false; 224 } 212 225 } 213 226 … … 215 228 // we can display a standard check box. 216 229 initialState = OsmUtils.trueval.equals(oneValue) ? 217 230 QuadStateCheckBox.State.SELECTED : 218 231 OsmUtils.falseval.equals(oneValue) ? 219 QuadStateCheckBox.State.NOT_SELECTED :220 def ? QuadStateCheckBox.State.SELECTED221 : QuadStateCheckBox.State.UNSET;232 QuadStateCheckBox.State.NOT_SELECTED : 233 def ? QuadStateCheckBox.State.SELECTED 234 : QuadStateCheckBox.State.UNSET; 222 235 check = new QuadStateCheckBox(locale_text, initialState, 223 236 new QuadStateCheckBox.State[] { … … 249 262 cmds.add(new ChangePropertyCommand(sel, key, 250 263 check.getState() == QuadStateCheckBox.State.SELECTED ? OsmUtils.trueval : 251 check.getState() == QuadStateCheckBox.State.NOT_SELECTED ? OsmUtils.falseval :252 null));264 check.getState() == QuadStateCheckBox.State.NOT_SELECTED ? OsmUtils.falseval : 265 null)); 253 266 } 254 267 @Override boolean requestFocusInWindow() {return check.requestFocusInWindow();} … … 280 293 String[] value_array = values.split(","); 281 294 String[] display_array; 282 if(locale_display_values != null) 295 if(locale_display_values != null) { 283 296 display_array = locale_display_values.split(","); 284 else if(display_values != null)297 } else if(display_values != null) { 285 298 display_array = display_values.split(","); 286 else299 } else { 287 300 display_array = value_array; 301 } 288 302 289 303 lhm = new LinkedHashMap<String,String>(); … … 294 308 for (int i=0; i<value_array.length; i++) { 295 309 lhm.put(value_array[i], 296 (locale_display_values == null) ?297 tr(display_array[i]) : display_array[i]);310 (locale_display_values == null) ? 311 tr(display_array[i]) : display_array[i]); 298 312 } 299 313 if(!usage.unused()) 300 314 { 301 315 for (String s : usage.values) { 302 if (!lhm.containsKey(s)) lhm.put(s, s); 303 } 304 } 305 if (default_ != null && !lhm.containsKey(default_)) lhm.put(default_, default_); 306 if(!lhm.containsKey("")) lhm.put("", ""); 316 if (!lhm.containsKey(s)) { 317 lhm.put(s, s); 318 } 319 } 320 } 321 if (default_ != null && !lhm.containsKey(default_)) { 322 lhm.put(default_, default_); 323 } 324 if(!lhm.containsKey("")) { 325 lhm.put("", ""); 326 } 307 327 308 328 combo = new JComboBox(lhm.values().toArray()); … … 330 350 } 331 351 332 if(locale_text == null) 352 if(locale_text == null) { 333 353 locale_text = tr(text); 354 } 334 355 p.add(new JLabel(locale_text+":"), GBC.std().insets(0,0,10,0)); 335 356 p.add(combo, GBC.eol().fill(GBC.HORIZONTAL)); … … 340 361 String display = (obj == null) ? null : obj.toString(); 341 362 String value = null; 342 if(display == null && combo.isEditable()) 363 if(display == null && combo.isEditable()) { 343 364 display = combo.getEditor().getItem().toString(); 365 } 344 366 345 367 if (display != null) … … 347 369 for (String key : lhm.keySet()) { 348 370 String k = lhm.get(key); 349 if (k != null && k.equals(display)) value=key; 350 } 351 if(value == null) 371 if (k != null && k.equals(display)) { 372 value=key; 373 } 374 } 375 if(value == null) { 352 376 value = display; 353 }354 else377 } 378 } else { 355 379 value = ""; 380 } 356 381 357 382 // no change if same as before 358 383 if (value.equals(originalValue) || (originalValue == null && (value == null || value.length() == 0))) return; 359 384 360 if (delete_if_empty && value != null && value.length() == 0) 385 if (delete_if_empty && value != null && value.length() == 0) { 361 386 value = null; 387 } 362 388 cmds.add(new ChangePropertyCommand(sel, key, value)); 363 389 } … … 370 396 371 397 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 372 if(locale_text == null) 398 if(locale_text == null) { 373 399 locale_text = tr(text); 400 } 374 401 p.add(new JLabel(locale_text), GBC.eol()); 375 402 return false; … … 385 412 386 413 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 387 if(locale_text == null) 414 if(locale_text == null) { 388 415 locale_text = text == null ? tr("More information about this feature") : tr(text); 416 } 389 417 String url = locale_href; 390 418 if (url == null) { … … 449 477 putValue("toolbar", "tagging_" + getRawName()); 450 478 putValue(SHORT_DESCRIPTION, (group != null ? 451 tr("Use preset ''{0}'' of group ''{1}''", getLocaleName(), group.getName()) :452 tr("Use preset ''{0}''", getLocaleName())));479 tr("Use preset ''{0}'' of group ''{1}''", getLocaleName(), group.getName()) : 480 tr("Use preset ''{0}''", getLocaleName()))); 453 481 } 454 482 455 483 public String getLocaleName() { 456 if(locale_name == null) 484 if(locale_name == null) { 457 485 locale_name = tr(name); 486 } 458 487 return locale_name; 459 488 } … … 479 508 icon = new ImageIcon(iconName); 480 509 } 481 if (Math.max(icon.getIconHeight(), icon.getIconWidth()) != 16) 510 if (Math.max(icon.getIconHeight(), icon.getIconWidth()) != 16) { 482 511 icon = new ImageIcon(icon.getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH)); 512 } 483 513 putValue(Action.SMALL_ICON, icon); 484 514 } … … 488 518 */ 489 519 private static Collection<String> allowedtypes = Arrays.asList(new String[] 490 {marktr("way"), marktr("node"), marktr("relation"), marktr("closedway")});520 {marktr("way"), marktr("node"), marktr("relation"), marktr("closedway")}); 491 521 public void setType(String types) throws SAXException { 492 522 this.types = Arrays.asList(types.split(",")); … … 517 547 if (o instanceof TaggingPresetMenu) { 518 548 TaggingPresetMenu tp = (TaggingPresetMenu) o; 519 if(tp == lastmenu) 549 if(tp == lastmenu) { 520 550 lastmenu = tp.group; 521 else551 } else 522 552 { 523 553 tp.setDisplayName(); … … 538 568 all.add(tp); 539 569 Main.toolbar.register(tp); 540 } else 570 } else { 541 571 all.getLast().data.add((Item)o); 572 } 542 573 } 543 574 return all; … … 548 579 LinkedList<String> sources = new LinkedList<String>(); 549 580 550 if(Main.pref.getBoolean("taggingpreset.enable-defaults", true)) 581 if(Main.pref.getBoolean("taggingpreset.enable-defaults", true)) { 551 582 sources.add("resource://presets/presets.xml"); 583 } 552 584 sources.addAll(Main.pref.getCollection("taggingpreset.sources", new LinkedList<String>())); 553 585 … … 604 636 for (Item i : data) 605 637 { 606 if(i instanceof Link) 638 if(i instanceof Link) { 607 639 l.add(i); 608 else609 { 610 if(i.addToPanel(p, selected)) 640 } else 641 { 642 if(i.addToPanel(p, selected)) { 611 643 p.hasElements = true; 612 } 613 } 614 for(Item link : l) 644 } 645 } 646 } 647 for(Item link : l) { 615 648 link.addToPanel(p, selected); 649 } 616 650 return p; 617 651 } 618 652 619 653 public void actionPerformed(ActionEvent e) { 620 Collection<OsmPrimitive> sel = createSelection(Main. ds.getSelected());654 Collection<OsmPrimitive> sel = createSelection(Main.main.getCurrentDataSet().getSelected()); 621 655 PresetPanel p = createPanel(sel); 622 656 if (p == null) … … 627 661 String title = trn("Change {0} object", "Change {0} objects", sel.size(), sel.size()); 628 662 if(sel.size() == 0) { 629 if(originalSelectionEmpty) 663 if(originalSelectionEmpty) { 630 664 title = tr("Nothing selected!"); 631 else665 } else { 632 666 title = tr("Selection unsuitable!"); 667 } 633 668 } 634 669 … … 651 686 if (sel.size() != 0 && answer == 1) { 652 687 Command cmd = createCommand(sel); 653 if (cmd != null) 688 if (cmd != null) { 654 689 Main.main.undoRedo.add(cmd); 655 } 656 Main.ds.setSelected(Main.ds.getSelected()); // force update 690 } 691 } 692 Main.main.getCurrentDataSet().setSelected(Main.main.getCurrentDataSet().getSelected()); // force update 657 693 } 658 694 … … 676 712 if(osm instanceof Relation) 677 713 { 678 if(!types.contains("relation")) continue; 714 if(!types.contains("relation")) { 715 continue; 716 } 679 717 } 680 718 else if(osm instanceof Node) 681 719 { 682 if(!types.contains("node")) continue; 720 if(!types.contains("node")) { 721 continue; 722 } 683 723 } 684 724 else if(osm instanceof Way) 685 725 { 686 726 if(!types.contains("way") && 687 !(types.contains("closedway") && ((Way)osm).isClosed()))727 !(types.contains("closedway") && ((Way)osm).isClosed())) { 688 728 continue; 729 } 689 730 } 690 731 } … … 696 737 private Command createCommand(Collection<OsmPrimitive> sel) { 697 738 List<Command> cmds = new LinkedList<Command>(); 698 for (Item i : data) 739 for (Item i : data) { 699 740 i.addCommands(sel, cmds); 741 } 700 742 if (cmds.size() == 0) 701 743 return null; -
trunk/src/org/openstreetmap/josm/io/GpxImporter.java
r1696 r1814 29 29 GpxReader r = null; 30 30 InputStream is; 31 if (file.getName().endsWith(".gpx.gz")) 31 if (file.getName().endsWith(".gpx.gz")) { 32 32 is = new GZIPInputStream(new FileInputStream(file)); 33 else33 } else { 34 34 is = new FileInputStream(file); 35 } 35 36 // Workaround for SAX BOM bug 36 37 // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6206835 37 38 if (!((is.read() == 0xef) && (is.read() == 0xbb) && (is.read() == 0xbf))) { 38 39 is.close(); 39 if (file.getName().endsWith(".gpx.gz")) 40 if (file.getName().endsWith(".gpx.gz")) { 40 41 is = new GZIPInputStream(new FileInputStream(file)); 41 else42 } else { 42 43 is = new FileInputStream(file); 44 } 43 45 } 44 46 r = new GpxReader(is, file.getAbsoluteFile().getParentFile()); … … 48 50 if (Main.pref.getBoolean("marker.makeautomarkers", true)) { 49 51 MarkerLayer ml = new MarkerLayer(r.data, tr("Markers from {0}", fn), file, gpxLayer); 50 if (ml.data.size() > 0) 52 if (ml.data.size() > 0) { 51 53 Main.main.addLayer(ml); 54 } 52 55 } 53 56 } catch (FileNotFoundException e) { -
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r1811 r1814 29 29 import org.openstreetmap.josm.data.osm.User; 30 30 import org.openstreetmap.josm.data.osm.Way; 31 import org.openstreetmap.josm.data.osm.visitor.AddVisitor;32 31 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 33 32 import org.openstreetmap.josm.tools.DateUtils; … … 55 54 private DataSet ds = new DataSet(); 56 55 public DataSet getDs() { return ds; } 57 58 /**59 * The visitor to use to add the data to the set.60 */61 private AddVisitor adder = new AddVisitor(ds);62 56 63 57 /** … … 349 343 w.incomplete = true; 350 344 w.nodes.clear(); 351 adder.visit(w);345 ds.addPrimitive(w); 352 346 } else { 353 347 e.getKey().copyTo(w); 354 348 w.incomplete = false; 355 adder.visit(w);349 ds.addPrimitive(w); 356 350 } 357 351 } … … 401 395 Relation en = new Relation(); 402 396 e.getKey().copyTo(en); 403 adder.visit(en);397 ds.addPrimitive(en); 404 398 } 405 399 … … 421 415 if (em.member == null) { 422 416 em.member = new Node(emd.id); 423 adder.visit((Node)em.member);417 ds.addPrimitive(em.member); 424 418 } 425 419 } else if (emd.type.equals("way")) { … … 430 424 if (em.member == null) { 431 425 em.member = new Way(emd.id); 432 adder.visit((Way)em.member);426 ds.addPrimitive(em.member); 433 427 } 434 428 } else if (emd.type.equals("relation")) { … … 436 430 if (em.member == null) { 437 431 em.member = new Relation(emd.id); 438 adder.visit((Relation)em.member);432 ds.addPrimitive(em.member); 439 433 } 440 434 } else { … … 458 452 459 453 public static OsmReader parseDataSetOsm(InputStream source, ProgressMonitor progressMonitor) throws SAXException, IOException { 460 OsmReader osm= new OsmReader();454 OsmReader reader = new OsmReader(); 461 455 462 456 // phase 1: Parse nodes and read in raw ways 463 457 InputSource inputSource = new InputSource(new InputStreamReader(source, "UTF-8")); 464 458 try { 465 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, osm.new Parser());459 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, reader.new Parser()); 466 460 } catch (ParserConfigurationException e1) { 467 461 e1.printStackTrace(); // broken SAXException chaining … … 471 465 progressMonitor.beginTask(tr("Prepare OSM data...", 2)); 472 466 try { 473 for (Node n : osm.nodes.values()) {474 osm.adder.visit(n);467 for (Node n : reader.nodes.values()) { 468 reader.ds.addPrimitive(n); 475 469 } 476 470 … … 478 472 479 473 try { 480 osm.createWays();481 osm.createRelations();474 reader.createWays(); 475 reader.createRelations(); 482 476 } catch (NumberFormatException e) { 483 477 e.printStackTrace(); … … 486 480 487 481 // clear all negative ids (new to this file) 488 for (OsmPrimitive o : osm.ds.allPrimitives())482 for (OsmPrimitive o : reader.ds.allPrimitives()) 489 483 if (o.id < 0) { 490 484 o.id = 0; 491 485 } 492 486 493 return osm;487 return reader; 494 488 } finally { 495 489 progressMonitor.finishTask(); -
trunk/src/org/openstreetmap/josm/io/OsmServerHistoryReader.java
r1811 r1814 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.IOException;7 6 import java.io.InputStream; 8 7 … … 11 10 import org.openstreetmap.josm.data.osm.history.HistoryDataSet; 12 11 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 13 import org.xml.sax.SAXException;14 12 15 13 import sun.reflect.generics.reflectiveObjects.NotImplementedException; -
trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
r1811 r1814 12 12 import org.openstreetmap.josm.actions.UploadAction; 13 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 14 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 15 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 15 16 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 16 17 … … 23 24 */ 24 25 public class OsmServerWriter { 26 static private final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter(); 25 27 static private final Logger logger = Logger.getLogger(OsmServerWriter.class.getName()); 26 28 … … 123 125 progressMonitor.setTicksCount(primitives.size()); 124 126 api.createChangeset(getChangesetComment(), progressMonitor.createSubTaskMonitor(0, false)); 125 NameVisitor v = new NameVisitor();126 127 uploadStartTime = System.currentTimeMillis(); 127 128 for (OsmPrimitive osm : primitives) { 128 osm.visit(v);129 129 int progress = progressMonitor.getTicks(); 130 130 String time_left_str = timeLeft(progress, primitives.size()); … … 132 132 tr("{0}% ({1}/{2}), {3} left. Uploading {4}: {5} (id: {6})", 133 133 Math.round(100.0*progress/primitives.size()), progress, 134 primitives.size(), time_left_str, tr(v.className), v.name, osm.id)); 134 primitives.size(), time_left_str, 135 OsmPrimitiveType.from(osm).getLocalizedDisplayNameSingular(), 136 NAME_FORMATTER.getName(osm), 137 osm.id)); 135 138 makeApiRequest(osm); 136 139 processed.add(osm); … … 139 142 api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false)); 140 143 } 144 141 145 } finally { 142 146 progressMonitor.finishTask(); -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r1748 r1814 29 29 30 30 import org.openstreetmap.josm.Main; 31 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 31 32 import org.openstreetmap.josm.io.MirroredInputStream; 33 import static org.openstreetmap.josm.tools.I18n.tr; 32 34 33 35 /** … … 95 97 { 96 98 MirroredInputStream is = new MirroredInputStream(name, 97 new File(Main.pref.getPreferencesDir(), "images").toString());99 new File(Main.pref.getPreferencesDir(), "images").toString()); 98 100 if(is != null) 99 101 { 100 img = Toolkit.getDefaultToolkit().createImage(is.getFile().toURI().toURL());101 cache.put(name, img);102 img = Toolkit.getDefaultToolkit().createImage(is.getFile().toURI().toURL()); 103 cache.put(name, img); 102 104 } 103 105 } … … 107 109 return img == null ? null : new ImageIcon(img); 108 110 } 109 if (subdir == null) 111 if (subdir == null) { 110 112 subdir = ""; 111 else if (!subdir.equals(""))113 } else if (!subdir.equals("")) { 112 114 subdir += "/"; 115 } 113 116 String ext = name.indexOf('.') != -1 ? "" : ".png"; 114 117 String full_name = subdir+name+ext; 115 118 String cache_name = full_name; 116 119 /* cache separately */ 117 if(dirs != null && dirs.size() > 0) 120 if(dirs != null && dirs.size() > 0) { 118 121 cache_name = "id:"+id+":"+full_name; 122 } 119 123 120 124 Image img = cache.get(cache_name); … … 198 202 public static Cursor getCursor(String name, String overlay) { 199 203 ImageIcon img = get("cursor",name); 200 if (overlay != null) 204 if (overlay != null) { 201 205 img = overlay(img, "cursor/modifier/"+overlay, OverlayPosition.SOUTHEAST); 206 } 202 207 Cursor c = Toolkit.getDefaultToolkit().createCustomCursor(img.getImage(), 203 208 name.equals("crosshair") ? new Point(10,10) : new Point(3,2), "Cursor"); … … 251 256 } 252 257 253 /* from: http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/254 * License: "feel free to use"255 */256 final static double DEGREE_90 = 90.0 * Math.PI / 180.0;258 /* from: http://www.jidesoft.com/blog/2008/02/29/rotate-an-icon-in-java/ 259 * License: "feel free to use" 260 */ 261 final static double DEGREE_90 = 90.0 * Math.PI / 180.0; 257 262 258 263 /** … … 315 320 return new ImageIcon(image); 316 321 } 322 323 /** 324 * Replies the icon for an OSM primitive type 325 * @param type the type 326 * @return the icon 327 */ 328 public static ImageIcon get(OsmPrimitiveType type) throws IllegalArgumentException { 329 if (type == null) 330 throw new IllegalArgumentException(tr("parameter ''{0}'' must not be null", "type")); 331 return get("data",type.getAPIName()); 332 } 317 333 } -
trunk/test/functional/org/openstreetmap/josm/io/MultiFetchServerObjectReaderTest.java
r1813 r1814 33 33 import org.openstreetmap.josm.data.projection.Mercator; 34 34 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 35 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 35 36 import org.xml.sax.SAXException; 36 37 -
trunk/test/functional/org/openstreetmap/josm/io/OsmServerBackreferenceReaderTest.java
r1813 r1814 32 32 import org.openstreetmap.josm.data.projection.Mercator; 33 33 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 34 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 34 35 import org.xml.sax.SAXException; 35 36
Note:
See TracChangeset
for help on using the changeset viewer.