Changeset 86 in josm for src/org/openstreetmap
- Timestamp:
- 2006-04-21T14:31:51+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 12 added
- 1 deleted
- 71 edited
- 1 copied
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r81 r86 78 78 * The global dataset. 79 79 */ 80 public DataSet ds = new DataSet();80 public static DataSet ds = new DataSet(); 81 81 82 82 /** … … 176 176 177 177 addWindowListener(new WindowAdapter(){ 178 @Override 179 public void windowClosing(WindowEvent arg0) { 178 @Override public void windowClosing(WindowEvent arg0) { 180 179 if (mapFrame != null) { 181 180 boolean modified = false; … … 217 216 System.out.println(); 218 217 System.out.println("usage:"); 219 System.out.println("\tjava -jar josm.jar <options> ");218 System.out.println("\tjava -jar josm.jar <options> file file file..."); 220 219 System.out.println(); 221 220 System.out.println("options:"); 222 221 System.out.println("\t--help Show this help"); 223 222 System.out.println("\t--download=minlat,minlon,maxlat,maxlon Download the bounding box"); 224 System.out.println("\t--open=file(.osm|.xml|.gpx|.txt|.csv) Open the specific file");225 223 System.out.println("\t--no-fullscreen Don't launch in fullscreen mode"); 226 224 System.out.println("\t--reset-preferences Reset the preferences to default"); 225 System.out.println("file(.osm|.xml|.gpx|.txt|.csv) Open the specific file"); 227 226 System.exit(0); 228 227 } … … 287 286 for (Iterator<String> it = arguments.iterator(); it.hasNext();) { 288 287 String s = it.next(); 289 if (s.startsWith("--open=")) { 290 main.openAction.openFile(new File(s.substring(7))); 291 it.remove(); 292 } else if (s.startsWith("--download=")) { 288 if (s.startsWith("--download=")) { 293 289 downloadFromParamString(false, s.substring(11)); 294 290 it.remove(); … … 299 295 } 300 296 301 if (!arguments.isEmpty()) { 302 String s = "Unknown Parameter:\n"; 303 for (String arg : arguments) 304 s += arg+"\n"; 305 JOptionPane.showMessageDialog(main, s); 306 } 297 for (String s : arguments) 298 main.openAction.openFile(new File(s)); 307 299 } 308 300 -
src/org/openstreetmap/josm/actions/DiskAccessAction.java
r79 r86 28 28 */ 29 29 protected boolean isDataSetEmpty() { 30 for (OsmPrimitive osm : Main. main.ds.allNonDeletedPrimitives())31 if (!osm. isDeleted()|| osm.id > 0)30 for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) 31 if (!osm.deleted || osm.id > 0) 32 32 return false; 33 33 return true; -
src/org/openstreetmap/josm/actions/DownloadAction.java
r83 r86 69 69 } 70 70 71 @Override 72 public void realRun() throws IOException, SAXException { 71 @Override public void realRun() throws IOException, SAXException { 73 72 dataSet = reader.parseOsm(); 74 73 if (dataSet == null) … … 78 77 } 79 78 80 @Override 81 protected void finish() { 79 @Override protected void finish() { 82 80 if (dataSet == null) 83 81 return; // user cancelled download or error occoured … … 101 99 } 102 100 103 @Override 104 public void realRun() throws IOException, JDOMException { 101 @Override public void realRun() throws IOException, JDOMException { 105 102 rawData = reader.parseRawGps(); 106 103 } 107 104 108 @Override 109 protected void finish() { 105 @Override protected void finish() { 110 106 if (rawData == null) 111 107 return; … … 188 184 dlg.add(osmUrl, GBC.eop().fill(GBC.HORIZONTAL)); 189 185 final KeyListener osmUrlRefresher = new KeyAdapter(){ 190 @Override 191 public void keyTyped(KeyEvent e) { 186 @Override public void keyTyped(KeyEvent e) { 192 187 SwingUtilities.invokeLater(new Runnable() { 193 188 public void run() { … … 223 218 SwingUtilities.invokeLater(new Runnable() {public void run() {osmUrlRefresher.keyTyped(null);}}); 224 219 osmUrl.addKeyListener(new KeyAdapter(){ 225 @Override 226 public void keyTyped(KeyEvent e) { 220 @Override public void keyTyped(KeyEvent e) { 227 221 SwingUtilities.invokeLater(new Runnable() { 228 222 public void run() { -
src/org/openstreetmap/josm/actions/ExtensionFileFilter.java
r51 r86 45 45 } 46 46 47 @Override 48 public boolean accept(File pathname) { 47 @Override public boolean accept(File pathname) { 49 48 if (pathname.isDirectory()) 50 49 return true; … … 52 51 } 53 52 54 @Override 55 public String getDescription() { 53 @Override public String getDescription() { 56 54 return description; 57 55 } -
src/org/openstreetmap/josm/actions/GpxExportAction.java
r79 r86 121 121 w.output(((RawGpsDataLayer)layer).data); 122 122 else 123 w.output(Main. main.ds);123 w.output(Main.ds); 124 124 out.close(); 125 125 } catch (IOException x) { -
src/org/openstreetmap/josm/actions/SaveAction.java
r78 r86 14 14 15 15 import org.openstreetmap.josm.Main; 16 import org.openstreetmap.josm.data.osm. LineSegment;16 import org.openstreetmap.josm.data.osm.Segment; 17 17 import org.openstreetmap.josm.io.GpxWriter; 18 18 import org.openstreetmap.josm.io.OsmWriter; … … 41 41 if (isDataSetEmpty() && JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(Main.main, "The document contains no data. Save anyway?", "Empty document", JOptionPane.YES_NO_OPTION)) 42 42 return; 43 if (!Main.main.getMapFrame().conflictDialog.conflicts.isEmpty()) { 44 int answer = JOptionPane.showConfirmDialog(Main.main, 45 "There are unresolved conflicts. Conflicts will not be saved and handled as if you rejected all. Continue?", "Conflicts", JOptionPane.YES_NO_OPTION); 46 if (answer != JOptionPane.YES_OPTION) 47 return; 48 } 43 49 44 50 JFileChooser fc = createAndOpenFileChooser(false, false); … … 60 66 FileWriter fileWriter; 61 67 if (ExtensionFileFilter.filters[ExtensionFileFilter.GPX].acceptName(fn)) { 62 for ( LineSegment ls : Main.main.ds.lineSegments) {68 for (Segment ls : Main.ds.segments) { 63 69 if (ls.incomplete) { 64 70 JOptionPane.showMessageDialog(Main.main, "Export of data containing incomplete ways to GPX is not implemented.\nBe aware, that in future versions of JOSM, GPX support will be kept at a minimum.\nPlease use .osm or .xml as extension for the better OSM support."); … … 66 72 } 67 73 } 68 new GpxWriter(fileWriter = new FileWriter(file), Main. main.ds).output();74 new GpxWriter(fileWriter = new FileWriter(file), Main.ds).output(); 69 75 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) 70 OsmWriter.output(fileWriter = new FileWriter(file), Main. main.ds, false);76 OsmWriter.output(fileWriter = new FileWriter(file), Main.ds, false); 71 77 else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 72 78 JOptionPane.showMessageDialog(Main.main, "CSV output not supported yet."); -
src/org/openstreetmap/josm/actions/UploadAction.java
r81 r86 58 58 final Collection<OsmPrimitive> update = new LinkedList<OsmPrimitive>(); 59 59 final Collection<OsmPrimitive> delete = new LinkedList<OsmPrimitive>(); 60 for (OsmPrimitive osm : Main. main.ds.allPrimitives()) {61 if (osm.id == 0 && !osm. isDeleted())60 for (OsmPrimitive osm : Main.ds.allPrimitives()) { 61 if (osm.id == 0 && !osm.deleted) 62 62 add.add(osm); 63 else if ( (osm.modified || osm.modifiedProperties) && !osm.isDeleted())63 else if (osm.modified && !osm.deleted) 64 64 update.add(osm); 65 else if (osm. isDeleted()&& osm.id != 0)65 else if (osm.deleted && osm.id != 0) 66 66 delete.add(osm); 67 67 } … … 77 77 78 78 PleaseWaitRunnable uploadTask = new PleaseWaitRunnable("Uploading data"){ 79 @Override 80 protected void realRun() throws JDOMException { 79 @Override protected void realRun() throws JDOMException { 81 80 server.uploadOsm(all); 82 81 } 83 @Override 84 protected void finish() { 82 @Override protected void finish() { 85 83 Main.main.getMapFrame().mapView.editLayer().cleanData(server.processed, !add.isEmpty()); 86 84 } -
src/org/openstreetmap/josm/actions/WmsServerAction.java
r79 r86 31 31 if (mv.getAllLayers().size() == 1) { 32 32 Main.main.setMapFrame(null); 33 Main. main.ds = new DataSet();33 Main.ds = new DataSet(); 34 34 } else 35 35 mv.removeLayer(l); -
src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java
r71 r86 27 27 } 28 28 29 @Override 30 public void registerListener() { 29 @Override public void registerListener() { 31 30 super.registerListener(); 32 31 mv.addMouseListener(this); 33 32 } 34 33 35 @Override 36 public void unregisterListener() { 34 @Override public void unregisterListener() { 37 35 super.unregisterListener(); 38 36 mv.removeMouseListener(this); … … 43 41 * position. 44 42 */ 45 @Override 46 public void mouseClicked(MouseEvent e) { 43 @Override public void mouseClicked(MouseEvent e) { 47 44 if (e.getButton() == MouseEvent.BUTTON1) { 48 45 Node node = new Node(mv.getLatLon(e.getX(), e.getY())); … … 51 48 return; 52 49 } 53 mv.editLayer().add(new AddCommand(Main. main.ds, node));50 mv.editLayer().add(new AddCommand(Main.ds, node)); 54 51 mv.repaint(); 55 52 } -
src/org/openstreetmap/josm/actions/mapmode/AddSegmentAction.java
r84 r86 11 11 import org.openstreetmap.josm.Main; 12 12 import org.openstreetmap.josm.command.AddCommand; 13 import org.openstreetmap.josm.data.osm. LineSegment;13 import org.openstreetmap.josm.data.osm.Segment; 14 14 import org.openstreetmap.josm.data.osm.Node; 15 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 17 17 18 18 /** 19 * The user can add a new linesegment between two nodes by pressing on the19 * The user can add a new segment between two nodes by pressing on the 20 20 * starting node and dragging to the ending node. 21 21 * 22 * No line segment can be created if there is already a linesegment containing22 * No segment can be created if there is already a segment containing 23 23 * both nodes. 24 24 * 25 25 * @author imi 26 26 */ 27 public class Add LineSegmentAction extends MapMode implements MouseListener {27 public class AddSegmentAction extends MapMode implements MouseListener { 28 28 29 29 /** … … 42 42 43 43 /** 44 * Create a new Add LineSegmentAction.44 * Create a new AddSegmentAction. 45 45 * @param mapFrame The MapFrame this action belongs to. 46 46 */ 47 public Add LineSegmentAction(MapFrame mapFrame) {48 super("Add Line Segment", "addlinesegment", "Add a linesegment between two nodes.", "G", KeyEvent.VK_G, mapFrame);47 public AddSegmentAction(MapFrame mapFrame) { 48 super("Add segment", "addlinesegment", "Add a segment between two nodes.", "G", KeyEvent.VK_G, mapFrame); 49 49 } 50 50 51 @Override 52 public void registerListener() { 51 @Override public void registerListener() { 53 52 super.registerListener(); 54 53 mv.addMouseListener(this); … … 56 55 } 57 56 58 @Override 59 public void unregisterListener() { 57 @Override public void unregisterListener() { 60 58 super.unregisterListener(); 61 59 mv.removeMouseListener(this); … … 65 63 66 64 67 @Override 68 public void actionPerformed(ActionEvent e) { 65 @Override public void actionPerformed(ActionEvent e) { 69 66 super.actionPerformed(e); 70 make LineSegment();67 makeSegment(); 71 68 } 72 69 … … 74 71 * If user clicked on a node, from the dragging with that node. 75 72 */ 76 @Override 77 public void mousePressed(MouseEvent e) { 73 @Override public void mousePressed(MouseEvent e) { 78 74 if (e.getButton() != MouseEvent.BUTTON1) 79 75 return; … … 91 87 * the mouse button now. 92 88 */ 93 @Override 94 public void mouseDragged(MouseEvent e) { 89 @Override public void mouseDragged(MouseEvent e) { 95 90 if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0) 96 91 return; … … 107 102 108 103 /** 109 * If left button was released, try to create the linesegment.104 * If left button was released, try to create the segment. 110 105 */ 111 @Override 112 public void mouseReleased(MouseEvent e) { 106 @Override public void mouseReleased(MouseEvent e) { 113 107 if (e.getButton() == MouseEvent.BUTTON1) { 114 make LineSegment();115 first = null; // release linesegment drawing108 makeSegment(); 109 first = null; // release segment drawing 116 110 } 117 111 } 118 112 119 113 /** 120 * Create the linesegment if first and second are different and there is121 * not already a linesegment.114 * Create the segment if first and second are different and there is 115 * not already a segment. 122 116 */ 123 private void make LineSegment() {117 private void makeSegment() { 124 118 if (first == null || second == null) { 125 119 first = null; … … 136 130 137 131 if (start != end) { 138 // try to find a linesegment139 for ( LineSegment ls : Main.main.ds.lineSegments)132 // try to find a segment 133 for (Segment ls : Main.ds.segments) 140 134 if ((start == ls.from && end == ls.to) || (end == ls.from && start == ls.to)) 141 return; // already a linesegment here - be happy, do nothing.135 return; // already a segment here - be happy, do nothing. 142 136 143 LineSegment ls = new LineSegment(start, end);144 mv.editLayer().add(new AddCommand(Main. main.ds, ls));137 Segment ls = new Segment(start, end); 138 mv.editLayer().add(new AddCommand(Main.ds, ls)); 145 139 } 146 140 -
src/org/openstreetmap/josm/actions/mapmode/AddWayAction.java
r68 r86 11 11 import org.openstreetmap.josm.Main; 12 12 import org.openstreetmap.josm.command.AddCommand; 13 import org.openstreetmap.josm.data.osm. LineSegment;13 import org.openstreetmap.josm.data.osm.Segment; 14 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 15 import org.openstreetmap.josm.data.osm.Way; … … 17 17 18 18 /** 19 * Add a new way from all selected linesegments.19 * Add a new way from all selected segments. 20 20 * 21 * If there is a selection when the mode is entered, all linesegments in this21 * If there is a selection when the mode is entered, all segments in this 22 22 * selection form a new way, except the user holds down Shift. 23 23 * 24 * The user can click on a linesegment. If he holds down Shift, no way is24 * The user can click on a segment. If he holds down Shift, no way is 25 25 * created yet. If he holds down Alt, the whole way is considered instead of 26 * the clicked linesegment. If the user holds down Ctrl, no way is created27 * and the clicked linesegment get removed from the list.26 * the clicked segment. If the user holds down Ctrl, no way is created 27 * and the clicked segment get removed from the list. 28 28 * 29 29 * Also, the user may select a rectangle as in selection mode. No node, area or … … 47 47 } 48 48 49 @Override 50 public void actionPerformed(ActionEvent e) { 49 @Override public void actionPerformed(ActionEvent e) { 51 50 makeWay(); 52 51 super.actionPerformed(e); … … 58 57 */ 59 58 private void makeWay() { 60 Collection<OsmPrimitive> selection = Main. main.ds.getSelected();59 Collection<OsmPrimitive> selection = Main.ds.getSelected(); 61 60 if (selection.isEmpty()) 62 61 return; 63 62 64 63 // form a new way 65 LinkedList< LineSegment> lineSegments = new LinkedList<LineSegment>();64 LinkedList<Segment> segments = new LinkedList<Segment>(); 66 65 int numberOfSelectedWays = 0; 67 66 for (OsmPrimitive osm : selection) { 68 67 if (osm instanceof Way) 69 68 numberOfSelectedWays++; 70 else if (osm instanceof LineSegment)71 lineSegments.add((LineSegment)osm);69 else if (osm instanceof Segment) 70 segments.add((Segment)osm); 72 71 } 73 72 … … 81 80 for (OsmPrimitive osm : selection) 82 81 if (osm instanceof Way) 83 lineSegments.addAll(((Way)osm).segments);82 segments.addAll(((Way)osm).segments); 84 83 } 85 84 } 86 85 87 // sort the linesegments in best possible order. This is done by:86 // sort the segments in best possible order. This is done by: 88 87 // 0 if no elements in list, quit 89 88 // 1 taking the first ls as pivot, remove it from list … … 91 90 // 3 if found, attach it, remove it from list, goto 2 92 91 // 4 if not found, save the pivot-string and goto 0 93 LinkedList< LineSegment> sortedLineSegments = new LinkedList<LineSegment>();94 while (! lineSegments.isEmpty()) {95 LinkedList< LineSegment> pivotList = new LinkedList<LineSegment>();96 pivotList.add( lineSegments.getFirst());97 lineSegments.removeFirst();92 LinkedList<Segment> sortedSegments = new LinkedList<Segment>(); 93 while (!segments.isEmpty()) { 94 LinkedList<Segment> pivotList = new LinkedList<Segment>(); 95 pivotList.add(segments.getFirst()); 96 segments.removeFirst(); 98 97 for (boolean found = true; found;) { 99 98 found = false; 100 for (Iterator< LineSegment> it = lineSegments.iterator(); it.hasNext();) {101 LineSegment ls = it.next();99 for (Iterator<Segment> it = segments.iterator(); it.hasNext();) { 100 Segment ls = it.next(); 102 101 if (ls.incomplete) 103 102 continue; // incomplete segments are never added to a new way … … 113 112 } 114 113 } 115 sorted LineSegments.addAll(pivotList);114 sortedSegments.addAll(pivotList); 116 115 } 117 116 118 117 Way t = new Way(); 119 t.segments.addAll(sorted LineSegments);120 mv.editLayer().add(new AddCommand(Main. main.ds, t));121 Main. main.ds.clearSelection();118 t.segments.addAll(sortedSegments); 119 mv.editLayer().add(new AddCommand(Main.ds, t)); 120 Main.ds.clearSelection(); 122 121 mv.repaint(); 123 122 } -
src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r71 r86 26 26 * @see #deleteWithReferences(OsmPrimitive) 27 27 * 28 * Pressing Alt will select the way instead of a linesegment, as usual.28 * Pressing Alt will select the way instead of a segment, as usual. 29 29 * 30 30 * If the user did not press Ctrl and the object has any references, the user … … 46 46 } 47 47 48 @Override 49 public void registerListener() { 48 @Override public void registerListener() { 50 49 super.registerListener(); 51 50 mv.addMouseListener(this); 52 51 } 53 52 54 @Override 55 public void unregisterListener() { 53 @Override public void unregisterListener() { 56 54 super.unregisterListener(); 57 55 mv.removeMouseListener(this); … … 59 57 60 58 61 @Override 62 public void actionPerformed(ActionEvent e) { 59 @Override public void actionPerformed(ActionEvent e) { 63 60 super.actionPerformed(e); 64 61 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 65 62 if (ctrl) 66 deleteWithReferences(Main. main.ds.getSelected());63 deleteWithReferences(Main.ds.getSelected()); 67 64 else 68 delete(Main. main.ds.getSelected(), false);65 delete(Main.ds.getSelected(), false); 69 66 mv.repaint(); 70 67 } … … 74 71 * position. 75 72 */ 76 @Override 77 public void mouseClicked(MouseEvent e) { 73 @Override public void mouseClicked(MouseEvent e) { 78 74 if (e.getButton() != MouseEvent.BUTTON1) 79 75 return; … … 94 90 * Delete the primitives and everything they references. 95 91 * 96 * If a node is deleted, the node and all linesegments, ways and areas92 * If a node is deleted, the node and all segments, ways and areas 97 93 * the node is part of are deleted as well. 98 94 * 99 * If a line segment is deleted, all ways the line segment is part of95 * If a segment is deleted, all ways the segment is part of 100 96 * are deleted as well. No nodes are deleted. 101 97 * 102 * If a way is deleted, only the way and no linesegments or nodes are98 * If a way is deleted, only the way and no segments or nodes are 103 99 * deleted. 104 100 * … … 110 106 Collection<Command> deleteCommands = new LinkedList<Command>(); 111 107 for (OsmPrimitive osm : selection) 112 deleteCommands.add(new DeleteCommand( Main.main.ds,osm));108 deleteCommands.add(new DeleteCommand(osm)); 113 109 if (!deleteCommands.isEmpty()) 114 110 mv.editLayer().add(new SequenceCommand(deleteCommands)); … … 126 122 Collection<Command> deleteCommands = new LinkedList<Command>(); 127 123 for (OsmPrimitive osm : selection) { 128 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main. main.ds);124 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.ds); 129 125 osm.visit(v); 130 126 if (!selection.containsAll(v.data)) { … … 132 128 JOptionPane.showMessageDialog(Main.main, "This object is in use."); 133 129 } else 134 deleteCommands.add(new DeleteCommand( Main.main.ds,osm));130 deleteCommands.add(new DeleteCommand(osm)); 135 131 } 136 132 if (!deleteCommands.isEmpty()) -
src/org/openstreetmap/josm/actions/mapmode/MapMode.java
r68 r86 14 14 /** 15 15 * A class implementing MapMode is able to be selected as an mode for map editing. 16 * As example scrolling the map is a MapMode, connecting Nodes to new LineSegments16 * As example scrolling the map is a MapMode, connecting Nodes to new Segments 17 17 * is another. 18 18 * -
src/org/openstreetmap/josm/actions/mapmode/MoveAction.java
r71 r86 5 5 import java.awt.event.KeyEvent; 6 6 import java.awt.event.MouseEvent; 7 import java.util.Arrays; 7 8 import java.util.Collection; 8 9 … … 51 52 } 52 53 53 @Override 54 public void registerListener() { 54 @Override public void registerListener() { 55 55 super.registerListener(); 56 56 mv.addMouseListener(this); … … 58 58 } 59 59 60 @Override 61 public void unregisterListener() { 60 @Override public void unregisterListener() { 62 61 super.unregisterListener(); 63 62 mv.removeMouseListener(this); … … 70 69 * objects. 71 70 */ 72 @Override 73 public void mouseDragged(MouseEvent e) { 71 @Override public void mouseDragged(MouseEvent e) { 74 72 if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == 0) 75 73 return; … … 87 85 return; 88 86 89 Collection<OsmPrimitive> selection = Main. main.ds.getSelected();87 Collection<OsmPrimitive> selection = Main.ds.getSelected(); 90 88 Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection); 91 89 … … 117 115 * cursor to movement. 118 116 */ 119 @Override 120 public void mousePressed(MouseEvent e) { 117 @Override public void mousePressed(MouseEvent e) { 121 118 if (e.getButton() != MouseEvent.BUTTON1) 122 119 return; 123 120 124 if (Main. main.ds.getSelected().size() == 0) {121 if (Main.ds.getSelected().size() == 0) { 125 122 OsmPrimitive osm = mv.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0); 126 123 if (osm != null) 127 osm.setSelected(true);124 Main.ds.setSelected(Arrays.asList(new OsmPrimitive[]{osm})); 128 125 singleOsmPrimitive = osm; 129 126 mv.repaint(); … … 139 136 * Restore the old mouse cursor. 140 137 */ 141 @Override 142 public void mouseReleased(MouseEvent e) { 138 @Override public void mouseReleased(MouseEvent e) { 143 139 mv.setCursor(oldCursor); 144 140 if (singleOsmPrimitive != null) { 145 singleOsmPrimitive.setSelected(false);141 Main.ds.clearSelection(); 146 142 mv.repaint(); 147 143 } -
src/org/openstreetmap/josm/actions/mapmode/SelectionAction.java
r71 r86 4 4 import java.awt.event.KeyEvent; 5 5 import java.util.Collection; 6 import java.util.LinkedList; 6 7 7 8 import org.openstreetmap.josm.Main; … … 43 44 * pixel are considered "only click". If that happens, the nearest Node will 44 45 * be selected if there is any within 10 pixel range. If there is no Node within 45 * 10 pixel, the nearest LineSegment (or Street, if user hold down the Alt-Key)46 * within 10 pixel range is selected. If there is no LineSegment within 10 pixel46 * 10 pixel, the nearest Segment (or Street, if user hold down the Alt-Key) 47 * within 10 pixel range is selected. If there is no Segment within 10 pixel 47 48 * and the user clicked in or 10 pixel away from an area, this area is selected. 48 49 * If there is even no area, nothing is selected. Shift and Ctrl key applies to … … 67 68 } 68 69 69 @Override 70 public void registerListener() { 70 @Override public void registerListener() { 71 71 super.registerListener(); 72 72 selectionManager.register(mv); 73 73 } 74 74 75 @Override 76 public void unregisterListener() { 75 @Override public void unregisterListener() { 77 76 super.unregisterListener(); 78 77 selectionManager.unregister(mv); … … 87 86 return; // not allowed together 88 87 88 Collection<OsmPrimitive> curSel; 89 89 if (!ctrl && !shift) 90 Main.main.ds.clearSelection(); // new selection will replace the old. 90 curSel = new LinkedList<OsmPrimitive>(); // new selection will replace the old. 91 else 92 curSel = Main.ds.getSelected(); 91 93 92 94 Collection<OsmPrimitive> selectionList = selectionManager.getObjectsInRectangle(r,alt); 93 95 for (OsmPrimitive osm : selectionList) 94 osm.setSelected(!ctrl); 96 if (ctrl) 97 curSel.remove(osm); 98 else 99 curSel.add(osm); 100 Main.ds.setSelected(curSel); 95 101 mv.repaint(); 96 102 } -
src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java
r71 r86 57 57 } 58 58 59 @Override 60 public void registerListener() { 59 @Override public void registerListener() { 61 60 super.registerListener(); 62 61 selectionManager.register(mv); 63 62 } 64 63 65 @Override 66 public void unregisterListener() { 64 @Override public void unregisterListener() { 67 65 super.unregisterListener(); 68 66 selectionManager.unregister(mv); -
src/org/openstreetmap/josm/command/AddCommand.java
r40 r86 14 14 * @author imi 15 15 */ 16 public class AddCommand implements Command {16 public class AddCommand extends Command { 17 17 18 18 /** … … 34 34 } 35 35 36 public void executeCommand() {36 @Override public void executeCommand() { 37 37 osm.visit(new AddVisitor(ds)); 38 38 } 39 39 40 public void undoCommand() {40 @Override public void undoCommand() { 41 41 osm.visit(new DeleteVisitor(ds)); 42 42 } 43 43 44 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {44 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 45 45 added.add(osm); 46 46 } -
src/org/openstreetmap/josm/command/ChangePropertyCommand.java
r84 r86 2 2 3 3 import java.util.Collection; 4 import java.util.HashMap;5 import java.util.Iterator;6 4 import java.util.LinkedList; 7 5 import java.util.List; 8 import java.util.Map;9 6 10 7 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 16 13 * @author imi 17 14 */ 18 public class Change KeyValueCommand implements Command {15 public class ChangePropertyCommand extends Command { 19 16 20 17 /** … … 33 30 private final String value; 34 31 35 /** 36 * These are the old values of the objects to do a proper undo. 37 */ 38 private List<Map<String, String>> oldProperties; 39 40 /** 41 * These are the old modified states of the data. 42 */ 43 private List<Boolean> oldModified = new LinkedList<Boolean>(); 44 45 public ChangeKeyValueCommand(Collection<OsmPrimitive> objects, String key, String value) { 32 public ChangePropertyCommand(Collection<OsmPrimitive> objects, String key, String value) { 46 33 this.objects = new LinkedList<OsmPrimitive>(objects); 47 34 this.key = key; … … 49 36 } 50 37 51 public void executeCommand() { 52 // save old 53 oldProperties = new LinkedList<Map<String, String>>(); 54 for (OsmPrimitive osm : objects) { 55 oldProperties.add(osm.keys == null ? null : new HashMap<String, String>(osm.keys)); 56 oldModified.add(osm.modifiedProperties); 57 osm.modifiedProperties = true; 58 } 59 38 @Override public void executeCommand() { 39 super.executeCommand(); // save old 60 40 if (value == null) { 61 41 for (OsmPrimitive osm : objects) … … 67 47 } 68 48 69 public void undoCommand() { 70 Iterator<Map<String, String>> it = oldProperties.iterator(); 71 Iterator<Boolean> itMod = oldModified.iterator(); 72 for (OsmPrimitive osm : objects) { 73 osm.keys = it.next(); 74 osm.modifiedProperties = itMod.next(); 75 } 76 } 77 78 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 49 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 79 50 modified.addAll(objects); 80 51 } -
src/org/openstreetmap/josm/command/Command.java
r31 r86 2 2 3 3 import java.util.Collection; 4 import java.util.HashSet; 5 import java.util.Map.Entry; 4 6 5 7 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 import org.openstreetmap.josm.data.osm.visitor.CloneVisitor; 6 9 7 10 … … 16 19 * @author imi 17 20 */ 18 public interfaceCommand {21 abstract public class Command { 19 22 23 private CloneVisitor orig; 24 20 25 /** 21 * Executes the command on the dataset. 26 * Executes the command on the dataset. This implementation will remember all 27 * primitives returned by fillModifiedData for restoring them on undo. 22 28 */ 23 void executeCommand(); 29 public void executeCommand() { 30 orig = new CloneVisitor(); 31 Collection<OsmPrimitive> all = new HashSet<OsmPrimitive>(); 32 fillModifiedData(all, all, all); 33 for (OsmPrimitive osm : all) 34 osm.visit(orig); 35 } 24 36 25 37 /** … … 27 39 * It can be assumed, that all objects are in the same state they were before. 28 40 * It can also be assumed that executeCommand was called exactly once before. 41 * 42 * This implementation undoes all objects stored by a former call to executeCommand. 29 43 */ 30 void undoCommand(); 31 44 public void undoCommand() { 45 for (Entry<OsmPrimitive, OsmPrimitive> e : orig.orig.entrySet()) 46 e.getKey().cloneFrom(e.getValue()); 47 } 48 32 49 /** 33 50 * Fill in the changed data this command operates on. … … 38 55 * @param added The added primitives 39 56 */ 40 void fillModifiedData(Collection<OsmPrimitive> modified,57 abstract public void fillModifiedData(Collection<OsmPrimitive> modified, 41 58 Collection<OsmPrimitive> deleted, 42 59 Collection<OsmPrimitive> added); -
src/org/openstreetmap/josm/command/DeleteCommand.java
r40 r86 4 4 import java.util.HashSet; 5 5 6 import org.openstreetmap.josm. data.osm.DataSet;6 import org.openstreetmap.josm.Main; 7 7 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 8 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; … … 12 12 * @author imi 13 13 */ 14 public class DeleteCommand implements Command {14 public class DeleteCommand extends Command { 15 15 16 /**17 * The dataset this command operates on.18 */19 final DataSet ds;20 16 /** 21 17 * The primitive that get deleted. … … 23 19 final Collection<OsmPrimitive> data = new HashSet<OsmPrimitive>(); 24 20 25 public DeleteCommand(DataSet ds, OsmPrimitive osm) { 26 this.ds = ds; 27 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(ds); 21 public DeleteCommand(OsmPrimitive osm) { 22 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.ds); 28 23 osm.visit(v); 29 24 data.addAll(v.data); … … 31 26 } 32 27 33 public void executeCommand() { 28 @Override public void executeCommand() { 29 super.executeCommand(); 34 30 for (OsmPrimitive osm : data) 35 osm. setDeleted(true);31 osm.delete(true); 36 32 } 37 33 38 public void undoCommand() { 39 for (OsmPrimitive osm : data) 40 osm.setDeleted(false); 41 } 42 43 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 34 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 44 35 deleted.addAll(data); 45 36 } -
src/org/openstreetmap/josm/command/MoveCommand.java
r73 r86 19 19 * @author imi 20 20 */ 21 public class MoveCommand implements Command {21 public class MoveCommand extends Command { 22 22 23 23 /** … … 84 84 } 85 85 86 public void executeCommand() {86 @Override public void executeCommand() { 87 87 for (Node n : objects) { 88 88 n.eastNorth = new EastNorth(n.eastNorth.east()+x, n.eastNorth.north()+y); … … 92 92 } 93 93 94 public void undoCommand() {94 @Override public void undoCommand() { 95 95 Iterator<OldState> it = oldState.iterator(); 96 96 for (Node n : objects) { … … 102 102 } 103 103 104 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {104 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 105 105 for (OsmPrimitive osm : objects) 106 106 modified.add(osm); -
src/org/openstreetmap/josm/command/SequenceCommand.java
r31 r86 10 10 * @author imi 11 11 */ 12 public class SequenceCommand implements Command {12 public class SequenceCommand extends Command { 13 13 14 14 /** … … 26 26 } 27 27 28 public void executeCommand() {28 @Override public void executeCommand() { 29 29 for (Command c : sequenz) 30 30 c.executeCommand(); 31 31 } 32 32 33 public void undoCommand() {33 @Override public void undoCommand() { 34 34 for (int i = sequenz.length-1; i >= 0; --i) 35 35 sequenz[i].undoCommand(); 36 36 } 37 37 38 public void fillModifiedData(Collection<OsmPrimitive> modified, 39 Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 38 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 40 39 for (Command c : sequenz) 41 40 c.fillModifiedData(modified, deleted, added); -
src/org/openstreetmap/josm/data/Bounds.java
r78 r86 35 35 } 36 36 37 @Override 38 public String toString() { 37 @Override public String toString() { 39 38 return "Bounds["+min.lat()+","+min.lon()+","+max.lat()+","+max.lon()+"]"; 40 39 } -
src/org/openstreetmap/josm/data/coor/Coordinate.java
r78 r86 50 50 } 51 51 52 @Override 53 public boolean equals(Object obj) { 52 @Override public boolean equals(Object obj) { 54 53 return obj instanceof Coordinate ? x == ((Coordinate)obj).x && ((Coordinate)obj).y == y : false; 55 54 } 56 55 57 @Override 58 public int hashCode() { 56 @Override public int hashCode() { 59 57 return (int)(x*65536+y*4096); 60 58 } -
src/org/openstreetmap/josm/data/coor/EastNorth.java
r79 r86 22 22 } 23 23 24 @Override 25 public String toString() { 24 @Override public String toString() { 26 25 return "EastNorth[e="+x+", n="+y+"]"; 27 26 } -
src/org/openstreetmap/josm/data/coor/LatLon.java
r79 r86 42 42 } 43 43 44 @Override 45 public String toString() { 44 @Override public String toString() { 46 45 return "LatLon[lat="+lat()+",lon="+lon()+"]"; 47 46 } -
src/org/openstreetmap/josm/data/osm/DataSet.java
r78 r86 2 2 3 3 import java.util.Collection; 4 import java.util.Collections; 4 5 import java.util.HashSet; 5 6 import java.util.LinkedList; 6 7 7 import org.openstreetmap.josm.data.Selection Tracker;8 import org.openstreetmap.josm.data.SelectionChangedListener; 8 9 9 10 /** … … 17 18 * @author imi 18 19 */ 19 public class DataSet extends SelectionTracker{20 public class DataSet { 20 21 21 22 /** … … 27 28 28 29 /** 29 * All linesegments goes here, even when they are in a way.30 * All segments goes here, even when they are in a way. 30 31 */ 31 public Collection< LineSegment> lineSegments = new LinkedList<LineSegment>();32 public Collection<Segment> segments = new LinkedList<Segment>(); 32 33 33 34 /** … … 41 42 42 43 /** 44 * A list of listeners to selection changed events. 45 */ 46 transient Collection<SelectionChangedListener> listeners = new LinkedList<SelectionChangedListener>(); 47 48 /** 43 49 * @return A collection containing all primitives (except keys) of the 44 50 * dataset. … … 47 53 Collection<OsmPrimitive> o = new LinkedList<OsmPrimitive>(); 48 54 o.addAll(nodes); 49 o.addAll( lineSegments);55 o.addAll(segments); 50 56 o.addAll(ways); 51 57 return o; … … 58 64 Collection<OsmPrimitive> o = new LinkedList<OsmPrimitive>(); 59 65 for (OsmPrimitive osm : allPrimitives()) 60 if (!osm. isDeleted())66 if (!osm.deleted) 61 67 o.add(osm); 62 68 return o; … … 68 74 public void clearSelection() { 69 75 clearSelection(nodes); 70 clearSelection( lineSegments);76 clearSelection(segments); 71 77 clearSelection(ways); 78 Collection<OsmPrimitive> sel = Collections.emptyList(); 79 fireSelectionChanged(sel); 72 80 } 73 81 … … 76 84 * @return List of all selected objects. 77 85 */ 78 @Override79 86 public Collection<OsmPrimitive> getSelected() { 80 87 Collection<OsmPrimitive> sel = getSelected(nodes); 81 sel.addAll(getSelected( lineSegments));88 sel.addAll(getSelected(segments)); 82 89 sel.addAll(getSelected(ways)); 83 90 return sel; 84 91 } 85 92 93 public void setSelected(Collection<OsmPrimitive> selection) { 94 clearSelection(); 95 for (OsmPrimitive osm : selection) 96 osm.selected = true; 97 fireSelectionChanged(selection); 98 } 99 86 100 /** 87 101 * Remove the selection from every value in the collection. … … 92 106 return; 93 107 for (OsmPrimitive osm : list) 94 osm.se tSelected(false);108 osm.selected = false; 95 109 } 96 110 … … 104 118 return sel; 105 119 for (OsmPrimitive osm : list) 106 if (osm. isSelected() && !osm.isDeleted())120 if (osm.selected && !osm.deleted) 107 121 sel.add(osm); 108 122 return sel; 109 123 } 124 125 /** 126 * Remember to fire an selection changed event. A call to this will not fire 127 * the event immediately. For more, @see SelectionChangedListener 128 */ 129 private void fireSelectionChanged(Collection<OsmPrimitive> sel) { 130 for (SelectionChangedListener l : listeners) 131 l.selectionChanged(sel); 132 } 133 134 /** 135 * Add a listener to the selection changed listener list. If <code>null</code> 136 * is passed, nothing happens. 137 * @param listener The listener to add to the list. 138 */ 139 public void addSelectionChangedListener(SelectionChangedListener listener) { 140 if (listener != null) 141 listeners.add(listener); 142 } 143 144 /** 145 * Remove a listener from the selection changed listener list. 146 * If <code>null</code> is passed, nothing happens. 147 * @param listener The listener to remove from the list. 148 */ 149 public void removeSelectionChangedListener(SelectionChangedListener listener) { 150 if (listener != null) 151 listeners.remove(listener); 152 } 110 153 } -
src/org/openstreetmap/josm/data/osm/Node.java
r73 r86 15 15 16 16 public LatLon coor; 17 public EastNorth eastNorth; 17 public volatile EastNorth eastNorth; 18 19 /** 20 * Create an identical clone of the argument (including the id) 21 */ 22 public Node(Node clone) { 23 cloneFrom(clone); 24 } 18 25 19 26 public Node(LatLon latlon) { … … 22 29 } 23 30 24 @Override 25 public void visit(Visitor visitor) { 31 @Override public void visit(Visitor visitor) { 26 32 visitor.visit(this); 27 33 } 28 34 29 @Override 30 public String toString() { 31 return "{Node id="+id+",lat="+coor.lat()+",lon="+coor.lon()+"}"; 32 } 33 34 @Override 35 public void cloneFrom(OsmPrimitive osm) { 35 @Override public void cloneFrom(OsmPrimitive osm) { 36 36 super.cloneFrom(osm); 37 37 coor = ((Node)osm).coor; 38 38 eastNorth = ((Node)osm).eastNorth; 39 39 } 40 41 @Override public String toString() { 42 return "{Node id="+id+",lat="+coor.lat()+",lon="+coor.lon()+"}"; 43 } 44 45 @Override public boolean realEqual(OsmPrimitive osm) { 46 return osm instanceof Node ? super.realEqual(osm) && coor.equals(((Node)osm).coor) : false; 47 } 40 48 } -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r81 r86 8 8 import java.util.Map.Entry; 9 9 10 import org.openstreetmap.josm.Main;11 10 import org.openstreetmap.josm.data.osm.visitor.Visitor; 12 11 … … 38 37 39 38 /** 40 * <code>true</code>, if the objects content (not the properties) has been 41 * modified since it was loaded from the server. In this case, on next upload, 42 * this object will be updated. Deleted objects are deleted from the server. 43 * If the objects are added (id=0), the modified is ignored and the object is 44 * added to the server. 39 * <code>true</code>, if the object has been modified since it was loaded from 40 * the server. In this case, on next upload, this object will be updated. 41 * Deleted objects are deleted from the server. If the objects are added (id=0), 42 * the modified is ignored and the object is added to the server. 45 43 */ 46 44 public boolean modified = false; 47 45 48 46 /** 49 * <code>true</code>, if the object's keys has been changed by JOSM since50 * last update.51 */52 public boolean modifiedProperties = false;53 54 /**55 47 * <code>true</code>, if the object has been deleted. 56 48 */ 57 p rivateboolean deleted = false;49 public boolean deleted = false; 58 50 59 51 /** 60 52 * If set to true, this object is currently selected. 61 53 */ 62 p rivate boolean selected = false;54 public volatile boolean selected = false; 63 55 64 56 /** … … 67 59 * used to check against edit conflicts. 68 60 */ 69 public Date lastModified= null;61 public Date timestamp = null; 70 62 71 63 /** … … 76 68 abstract public void visit(Visitor visitor); 77 69 78 /** 79 * Return <code>true</code>, if either <code>this.keys</code> and 80 * <code>other.keys</code> is <code>null</code> or if they do not share Keys 81 * with different values. 82 * 83 * @param other The second key-set to compare with. 84 * @return True, if the keysets are mergable 85 */ 86 final public boolean keyPropertiesMergable(OsmPrimitive other) { 87 if ((keys == null) != (other.keys == null)) 88 return false; 89 90 if (keys != null) { 91 for (String k : keys.keySet()) 92 if (other.keys.containsKey(k) && !keys.get(k).equals(other.keys.get(k))) 93 return false; 94 for (String k : other.keys.keySet()) 95 if (keys.containsKey(k) && !other.keys.get(k).equals(keys.get(k))) 96 return false; 97 } 98 return true; 99 } 100 101 /** 102 * Mark the primitive as selected or not selected and fires a selection 103 * changed later, if the value actualy changed. 104 * @param selected Whether the primitive should be selected or not. 105 */ 106 final public void setSelected(boolean selected) { 107 if (selected != this.selected) 108 Main.main.ds.fireSelectionChanged(); 109 this.selected = selected; 110 } 111 112 /** 113 * @return Return whether the primitive is selected on screen. 114 */ 115 final public boolean isSelected() { 116 return selected; 117 } 118 119 120 public void setDeleted(boolean deleted) { 70 public final void delete(boolean deleted) { 121 71 this.deleted = deleted; 122 setSelected(false); 123 } 124 125 public boolean isDeleted() { 126 return deleted; 72 selected = false; 73 modified = true; 127 74 } 128 75 … … 133 80 * An primitive is equal to its incomplete counter part. 134 81 */ 135 @Override 136 public boolean equals(Object obj) { 82 @Override public final boolean equals(Object obj) { 137 83 if (obj == null || getClass() != obj.getClass() || id == 0 || ((OsmPrimitive)obj).id == 0) 138 84 return super.equals(obj); … … 145 91 * An primitive has the same hashcode as its incomplete counter part. 146 92 */ 147 @Override 148 public int hashCode() { 93 @Override public final int hashCode() { 149 94 return id == 0 ? super.hashCode() : (int)id; 150 95 } … … 155 100 * @param value The value for the key. 156 101 */ 157 public void put(String key, String value) { 158 if (keys == null) 159 keys = new HashMap<String, String>(); 160 keys.put(key, value); 102 public final void put(String key, String value) { 103 if (value == null) 104 remove(key); 105 else { 106 if (keys == null) 107 keys = new HashMap<String, String>(); 108 keys.put(key, value); 109 } 161 110 } 162 111 /** 163 112 * Remove the given key from the list. 164 113 */ 165 public void remove(String key) {114 public final void remove(String key) { 166 115 if (keys != null) { 167 116 keys.remove(key); … … 171 120 } 172 121 173 public String get(String key) {122 public final String get(String key) { 174 123 return keys == null ? null : keys.get(key); 175 124 } 176 177 public Collection<Entry<String, String>> entrySet() {125 126 public final Collection<Entry<String, String>> entrySet() { 178 127 if (keys == null) 179 128 return Collections.emptyList(); … … 181 130 } 182 131 183 public Collection<String> keySet() {132 public final Collection<String> keySet() { 184 133 if (keys == null) 185 134 return Collections.emptyList(); … … 192 141 */ 193 142 public void cloneFrom(OsmPrimitive osm) { 194 keys = osm.keys ;143 keys = osm.keys == null ? null : new HashMap<String, String>(osm.keys); 195 144 id = osm.id; 196 145 modified = osm.modified; 197 modifiedProperties = osm.modifiedProperties;198 146 deleted = osm.deleted; 199 147 selected = osm.selected; 200 lastModified = osm.lastModified; 148 timestamp = osm.timestamp; 149 } 150 151 /** 152 * Perform an equality compare for all non-volatile fields not only for the id 153 * but for the whole object (for conflict resolving etc) 154 */ 155 public boolean realEqual(OsmPrimitive osm) { 156 return 157 id == osm.id && 158 modified == osm.modified && 159 deleted == osm.deleted && 160 (timestamp == null ? osm.timestamp==null : timestamp.equals(osm.timestamp)) && 161 (keys == null ? osm.keys==null : keys.equals(osm.keys)); 201 162 } 202 163 } -
src/org/openstreetmap/josm/data/osm/Segment.java
r84 r86 5 5 6 6 /** 7 * One way linesegment consisting of a pair of nodes (from/to)7 * One way segment consisting of a pair of nodes (from/to) 8 8 * 9 9 * @author imi 10 10 */ 11 public class LineSegment extends OsmPrimitive {11 public class Segment extends OsmPrimitive { 12 12 13 13 /** 14 * The starting node of the linesegment14 * The starting node of the segment 15 15 */ 16 16 public Node from; 17 17 18 18 /** 19 * The ending node of the linesegment19 * The ending node of the segment 20 20 */ 21 21 public Node to; … … 28 28 29 29 /** 30 * Create an line segment from the given starting and ending node 31 * @param from Starting node of the line segment. 32 * @param to Ending node of the line segment. 30 * Create an identical clone of the argument (including the id) 33 31 */ 34 public LineSegment(Node from, Node to) { 32 public Segment(Segment clone) { 33 cloneFrom(clone); 34 } 35 36 /** 37 * Create an segment from the given starting and ending node 38 * @param from Starting node of the segment. 39 * @param to Ending node of the segment. 40 */ 41 public Segment(Node from, Node to) { 35 42 this.from = from; 36 43 this.to = to; … … 38 45 } 39 46 40 public LineSegment(long id) {47 public Segment(long id) { 41 48 this.id = id; 42 49 incomplete = true; 43 50 } 44 51 45 @Override 46 public void visit(Visitor visitor) { 52 @Override public void visit(Visitor visitor) { 47 53 visitor.visit(this); 48 54 } … … 52 58 * exactly the same place as <code>this</code>. 53 59 */ 54 public boolean equalPlace( LineSegment ls) {60 public boolean equalPlace(Segment ls) { 55 61 if (equals(ls)) 56 62 return true; … … 61 67 } 62 68 63 @Override 64 public String toString() { 65 String s = "{LineSegment id="+id; 66 if (incomplete) 67 return s+",incomplete}"; 68 return s+",from="+from+",to="+to+"}"; 69 } 70 71 @Override 72 public void cloneFrom(OsmPrimitive osm) { 69 @Override public void cloneFrom(OsmPrimitive osm) { 73 70 super.cloneFrom(osm); 74 LineSegment ls = ((LineSegment)osm);71 Segment ls = ((Segment)osm); 75 72 from = ls.from; 76 73 to = ls.to; 77 74 incomplete = ls.incomplete; 78 75 } 76 77 @Override public String toString() { 78 return "{Segment id="+id+" from="+from+" to="+to+"}"; 79 } 80 81 @Override public boolean realEqual(OsmPrimitive osm) { 82 return osm instanceof Segment ? 83 super.realEqual(osm) && 84 from.equals(((Segment)osm).from) && 85 to.equals(((Segment)osm).to) : false; 86 } 79 87 } -
src/org/openstreetmap/josm/data/osm/Way.java
r66 r86 2 2 3 3 import java.util.ArrayList; 4 import java.util.Arrays; 4 5 import java.util.List; 5 6 … … 16 17 * All way segments in this way 17 18 */ 18 public final List< LineSegment> segments = new ArrayList<LineSegment>();19 public final List<Segment> segments = new ArrayList<Segment>(); 19 20 20 @Override 21 public void visit(Visitor visitor) { 21 @Override public void visit(Visitor visitor) { 22 22 visitor.visit(this); 23 23 } 24 24 25 @Override 26 public void cloneFrom(OsmPrimitive osm) { 25 /** 26 * Create an identical clone of the argument (including the id) 27 */ 28 public Way(Way clone) { 29 cloneFrom(clone); 30 } 31 32 public Way() { 33 } 34 35 @Override public void cloneFrom(OsmPrimitive osm) { 27 36 super.cloneFrom(osm); 28 37 segments.clear(); 29 38 segments.addAll(((Way)osm).segments); 30 39 } 40 41 @Override public String toString() { 42 return "{Way id="+id+" segments="+Arrays.toString(segments.toArray())+"}"; 43 } 44 45 @Override public boolean realEqual(OsmPrimitive osm) { 46 return osm instanceof Way ? super.realEqual(osm) && segments.equals(((Way)osm).segments) : false; 47 } 31 48 } -
src/org/openstreetmap/josm/data/osm/visitor/AddVisitor.java
r71 r86 4 4 5 5 import org.openstreetmap.josm.data.osm.DataSet; 6 import org.openstreetmap.josm.data.osm. LineSegment;6 import org.openstreetmap.josm.data.osm.Segment; 7 7 import org.openstreetmap.josm.data.osm.Node; 8 8 import org.openstreetmap.josm.data.osm.Way; … … 26 26 ds.nodes.add(n); 27 27 } 28 public void visit( LineSegment ls) {29 ds. lineSegments.add(ls);28 public void visit(Segment ls) { 29 ds.segments.add(ls); 30 30 } 31 31 public void visit(Way t) { -
src/org/openstreetmap/josm/data/osm/visitor/AllNodesVisitor.java
r71 r86 4 4 import java.util.HashSet; 5 5 6 import org.openstreetmap.josm.data.osm. LineSegment;6 import org.openstreetmap.josm.data.osm.Segment; 7 7 import org.openstreetmap.josm.data.osm.Node; 8 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 31 31 * Line segments have exactly two nodes: from and to. 32 32 */ 33 public void visit( LineSegment ls) {33 public void visit(Segment ls) { 34 34 if (!ls.incomplete) { 35 35 visit(ls.from); … … 39 39 40 40 /** 41 * Ways have all nodes from their linesegments.41 * Ways have all nodes from their segments. 42 42 */ 43 43 public void visit(Way t) { 44 for ( LineSegment ls : t.segments)44 for (Segment ls : t.segments) 45 45 visit(ls); 46 46 } -
src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java
r73 r86 4 4 import org.openstreetmap.josm.data.Bounds; 5 5 import org.openstreetmap.josm.data.coor.EastNorth; 6 import org.openstreetmap.josm.data.osm. LineSegment;6 import org.openstreetmap.josm.data.osm.Segment; 7 7 import org.openstreetmap.josm.data.osm.Node; 8 8 import org.openstreetmap.josm.data.osm.Way; … … 21 21 } 22 22 23 public void visit( LineSegment ls) {23 public void visit(Segment ls) { 24 24 if (!ls.incomplete) { 25 25 visit(ls.from); … … 29 29 30 30 public void visit(Way t) { 31 for ( LineSegment ls : t.segments)31 for (Segment ls : t.segments) 32 32 visit(ls); 33 33 } -
src/org/openstreetmap/josm/data/osm/visitor/CollectBackReferencesVisitor.java
r71 r86 5 5 6 6 import org.openstreetmap.josm.data.osm.DataSet; 7 import org.openstreetmap.josm.data.osm. LineSegment;7 import org.openstreetmap.josm.data.osm.Segment; 8 8 import org.openstreetmap.josm.data.osm.Node; 9 9 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 11 11 12 12 /** 13 * Helper that collect all linesegments a node is part of, all ways14 * a node or linesegment is part of and all areas a node is part of.13 * Helper that collect all segments a node is part of, all ways 14 * a node or segment is part of and all areas a node is part of. 15 15 * 16 16 * Deleted objects are not collected. … … 38 38 public void visit(Node n) { 39 39 for (Way t : ds.ways) { 40 if (t. isDeleted())40 if (t.deleted) 41 41 continue; 42 for ( LineSegment ls : t.segments) {42 for (Segment ls : t.segments) { 43 43 if (ls.incomplete) 44 44 continue; … … 49 49 } 50 50 } 51 for ( LineSegment ls : ds.lineSegments) {52 if (ls. isDeleted()|| ls.incomplete)51 for (Segment ls : ds.segments) { 52 if (ls.deleted || ls.incomplete) 53 53 continue; 54 54 if (ls.from == n || ls.to == n) … … 56 56 } 57 57 } 58 public void visit( LineSegment ls) {58 public void visit(Segment ls) { 59 59 for (Way t : ds.ways) { 60 if (t. isDeleted())60 if (t.deleted) 61 61 continue; 62 62 if (t.segments.contains(ls)) -
src/org/openstreetmap/josm/data/osm/visitor/DeleteVisitor.java
r71 r86 4 4 5 5 import org.openstreetmap.josm.data.osm.DataSet; 6 import org.openstreetmap.josm.data.osm. LineSegment;6 import org.openstreetmap.josm.data.osm.Segment; 7 7 import org.openstreetmap.josm.data.osm.Node; 8 8 import org.openstreetmap.josm.data.osm.Way; … … 26 26 ds.nodes.remove(n); 27 27 } 28 public void visit( LineSegment ls) {29 ds. lineSegments.remove(ls);28 public void visit(Segment ls) { 29 ds.segments.remove(ls); 30 30 } 31 31 public void visit(Way t) { -
src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java
r71 r86 1 1 package org.openstreetmap.josm.data.osm.visitor; 2 2 3 import java.util.Collection; 4 import java.util.Date; 3 5 import java.util.HashMap; 4 6 import java.util.Iterator; … … 7 9 8 10 import org.openstreetmap.josm.data.osm.DataSet; 9 import org.openstreetmap.josm.data.osm. LineSegment;11 import org.openstreetmap.josm.data.osm.Segment; 10 12 import org.openstreetmap.josm.data.osm.Node; 11 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 20 22 public class MergeVisitor implements Visitor { 21 23 24 /** 25 * Map from primitives in the database to visited primitives. (Attention: The other way 26 * round than mergedNodes and mergedSegments) 27 */ 28 public Map<OsmPrimitive, OsmPrimitive> conflicts = new HashMap<OsmPrimitive, OsmPrimitive>(); 29 22 30 private final DataSet ds; 23 31 24 32 /** 25 33 * A list of all nodes that got replaced with other nodes. … … 29 37 private final Map<Node, Node> mergedNodes = new HashMap<Node, Node>(); 30 38 /** 31 * A list of all linesegments that got replaced with others.39 * A list of all segments that got replaced with others. 32 40 * Key is the segment in the other's dataset and the value is the one that is now 33 * in ds. lineSegments.34 */ 35 private final Map< LineSegment, LineSegment> mergedLineSegments = new HashMap<LineSegment, LineSegment>();36 41 * in ds.segments. 42 */ 43 private final Map<Segment, Segment> mergedSegments = new HashMap<Segment, Segment>(); 44 37 45 public MergeVisitor(DataSet ds) { 38 46 this.ds = ds; … … 43 51 * either id is zero, merge if lat/lon matches. 44 52 */ 45 public void visit(Node otherNode) { 46 Node myNode = null; 53 public void visit(Node other) { 54 if (mergeAfterId(mergedNodes, ds.nodes, other)) 55 return; 56 57 Node my = null; 47 58 for (Node n : ds.nodes) { 48 if (match(n, other Node)) {49 my Node= n;59 if (match(n, other)) { 60 my = n; 50 61 break; 51 62 } 52 63 } 53 if (my Node== null)54 ds.nodes.add(other Node);64 if (my == null) 65 ds.nodes.add(other); 55 66 else { 56 mergedNodes.put(other Node, myNode);57 mergeCommon(my Node, otherNode);58 if (my Node.modified && !otherNode.modified)67 mergedNodes.put(other, my); 68 mergeCommon(my, other); 69 if (my.modified && !other.modified) 59 70 return; 60 if (!myNode.coor.equalsEpsilon(otherNode.coor)) { 61 myNode.coor = otherNode.coor; 62 myNode.modified = otherNode.modified; 63 } 64 } 65 } 66 67 /** 68 * Merge the line segment if id matches or if both nodes are the same (and the 71 if (!my.coor.equalsEpsilon(other.coor)) { 72 my.coor = other.coor; 73 my.eastNorth = other.eastNorth; 74 my.modified = other.modified; 75 } 76 } 77 } 78 79 /** 80 * Merge the segment if id matches or if both nodes are the same (and the 69 81 * id is zero of either segment). Nodes are the "same" when they @see match 70 82 */ 71 public void visit(LineSegment otherLs) { 72 LineSegment myLs = null; 73 for (LineSegment ls : ds.lineSegments) { 74 if (match(otherLs, ls)) { 75 myLs = ls; 83 public void visit(Segment other) { 84 if (mergeAfterId(mergedSegments, ds.segments, other)) 85 return; 86 87 Segment my = null; 88 for (Segment ls : ds.segments) { 89 if (match(other, ls)) { 90 my = ls; 76 91 break; 77 92 } 78 93 } 79 if (my Ls== null)80 ds. lineSegments.add(otherLs);81 else if (my Ls.incomplete && !otherLs.incomplete) {82 merged LineSegments.put(otherLs, myLs);83 my Ls.cloneFrom(otherLs);84 } else if (!other Ls.incomplete) {85 merged LineSegments.put(otherLs, myLs);86 mergeCommon(my Ls, otherLs);87 if (my Ls.modified && !otherLs.modified)94 if (my == null) 95 ds.segments.add(other); 96 else if (my.incomplete && !other.incomplete) { 97 mergedSegments.put(other, my); 98 my.cloneFrom(other); 99 } else if (!other.incomplete) { 100 mergedSegments.put(other, my); 101 mergeCommon(my, other); 102 if (my.modified && !other.modified) 88 103 return; 89 if (!match(my Ls.from, otherLs.from)) {90 my Ls.from = otherLs.from;91 my Ls.modified = otherLs.modified;92 } 93 if (!match(my Ls.to, otherLs.to)) {94 my Ls.to = otherLs.to;95 my Ls.modified = otherLs.modified;96 } 97 } 98 } 99 100 /** 101 * Merge the way if id matches or if all linesegments matches and the104 if (!match(my.from, other.from)) { 105 my.from = other.from; 106 my.modified = other.modified; 107 } 108 if (!match(my.to, other.to)) { 109 my.to = other.to; 110 my.modified = other.modified; 111 } 112 } 113 } 114 115 /** 116 * Merge the way if id matches or if all segments matches and the 102 117 * id is zero of either way. 103 118 */ 104 public void visit(Way otherWay) { 105 Way myWay = null; 119 public void visit(Way other) { 120 if (mergeAfterId(null, ds.ways, other)) 121 return; 122 123 Way my = null; 106 124 for (Way t : ds.ways) { 107 if (match(other Way, t)) {108 my Way= t;125 if (match(other, t)) { 126 my = t; 109 127 break; 110 128 } 111 129 } 112 if (my Way== null)113 ds.ways.add(other Way);130 if (my == null) 131 ds.ways.add(other); 114 132 else { 115 mergeCommon(my Way, otherWay);116 if (my Way.modified && !otherWay.modified)133 mergeCommon(my, other); 134 if (my.modified && !other.modified) 117 135 return; 118 136 boolean same = true; 119 Iterator< LineSegment> it = otherWay.segments.iterator();120 for ( LineSegment ls : myWay.segments) {137 Iterator<Segment> it = other.segments.iterator(); 138 for (Segment ls : my.segments) { 121 139 if (!match(ls, it.next())) 122 140 same = false; 123 141 } 124 142 if (!same) { 125 my Way.segments.clear();126 my Way.segments.addAll(otherWay.segments);127 my Way.modified = otherWay.modified;143 my.segments.clear(); 144 my.segments.addAll(other.segments); 145 my.modified = other.modified; 128 146 } 129 147 } … … 135 153 */ 136 154 public void fixReferences() { 137 for (LineSegment ls : ds.lineSegments) { 138 if (mergedNodes.containsKey(ls.from)) 139 ls.from = mergedNodes.get(ls.from); 140 if (mergedNodes.containsKey(ls.to)) 141 ls.to = mergedNodes.get(ls.to); 142 } 143 for (Way t : ds.ways) { 144 boolean replacedSomething = false; 145 LinkedList<LineSegment> newSegments = new LinkedList<LineSegment>(); 146 for (LineSegment ls : t.segments) { 147 LineSegment otherLs = mergedLineSegments.get(ls); 148 newSegments.add(otherLs == null ? ls : otherLs); 149 if (otherLs != null) 150 replacedSomething = true; 151 } 152 if (replacedSomething) { 153 t.segments.clear(); 154 t.segments.addAll(newSegments); 155 } 156 for (LineSegment ls : t.segments) { 157 if (mergedNodes.containsKey(ls.from)) 158 ls.from = mergedNodes.get(ls.from); 159 if (mergedNodes.containsKey(ls.to)) 160 ls.to = mergedNodes.get(ls.to); 161 } 162 } 163 } 164 155 for (Segment s : ds.segments) 156 fixSegment(s); 157 for (OsmPrimitive osm : conflicts.values()) 158 if (osm instanceof Segment) 159 fixSegment((Segment)osm); 160 for (Way w : ds.ways) 161 fixWay(w); 162 for (OsmPrimitive osm : conflicts.values()) 163 if (osm instanceof Way) 164 fixWay((Way)osm); 165 } 166 167 private void fixWay(Way t) { 168 boolean replacedSomething = false; 169 LinkedList<Segment> newSegments = new LinkedList<Segment>(); 170 for (Segment ls : t.segments) { 171 Segment otherLs = mergedSegments.get(ls); 172 newSegments.add(otherLs == null ? ls : otherLs); 173 if (otherLs != null) 174 replacedSomething = true; 175 } 176 if (replacedSomething) { 177 t.segments.clear(); 178 t.segments.addAll(newSegments); 179 } 180 for (Segment ls : t.segments) { 181 fixSegment(ls); 182 } 183 } 184 185 private void fixSegment(Segment ls) { 186 if (mergedNodes.containsKey(ls.from)) 187 ls.from = mergedNodes.get(ls.from); 188 if (mergedNodes.containsKey(ls.to)) 189 ls.to = mergedNodes.get(ls.to); 190 } 191 165 192 /** 166 193 * @return Whether the nodes matches (in sense of "be mergable"). … … 171 198 return n1.id == n2.id; 172 199 } 173 174 /** 175 * @return Whether the linesegments matches (in sense of "be mergable").176 */ 177 private boolean match( LineSegment ls1, LineSegment ls2) {200 201 /** 202 * @return Whether the segments matches (in sense of "be mergable"). 203 */ 204 private boolean match(Segment ls1, Segment ls2) { 178 205 if (ls1.id == ls2.id) 179 206 return true; … … 190 217 if (t1.segments.size() != t2.segments.size()) 191 218 return false; 192 Iterator< LineSegment> it = t1.segments.iterator();193 for ( LineSegment ls : t2.segments)219 Iterator<Segment> it = t1.segments.iterator(); 220 for (Segment ls : t2.segments) 194 221 if (!match(ls, it.next())) 195 222 return false; … … 201 228 /** 202 229 * Merge the common parts of an osm primitive. 203 * @param myOsm The object, the information gets merged into 204 * @param otherOsm The object, the information gets merged from 205 */ 206 private void mergeCommon(OsmPrimitive myOsm, OsmPrimitive otherOsm) { 207 if (otherOsm.isDeleted()) 208 myOsm.setDeleted(true); 209 if (!myOsm.modified || otherOsm.modified) { 210 if (myOsm.id == 0 && otherOsm.id != 0) 211 myOsm.id = otherOsm.id; // means not ncessary the object is now modified 212 else if (myOsm.id != 0 && otherOsm.id != 0 && otherOsm.modified) 213 myOsm.modified = true; 214 } 215 if (myOsm.modifiedProperties && !otherOsm.modifiedProperties) 216 return; 217 if (otherOsm.keys == null) 218 return; 219 if (myOsm.keys != null && myOsm.keys.entrySet().containsAll(otherOsm.keys.entrySet())) 220 return; 221 if (myOsm.keys == null) 222 myOsm.keys = otherOsm.keys; 230 * @param my The object, the information gets merged into 231 * @param other The object, the information gets merged from 232 */ 233 private void mergeCommon(OsmPrimitive my, OsmPrimitive other) { 234 if (other.deleted) 235 my.delete(true); 236 if (my.id == 0 || !my.modified || other.modified) { 237 if (my.id == 0 && other.id != 0) { 238 my.id = other.id; 239 my.modified = other.modified; // match a new node 240 } else if (my.id != 0 && other.id != 0 && other.modified) 241 my.modified = true; 242 } 243 if (other.keys == null) 244 return; 245 if (my.keySet().containsAll(other.keys.entrySet())) 246 return; 247 if (my.keys == null) 248 my.keys = other.keys; 223 249 else 224 myOsm.keys.putAll(otherOsm.keys); 225 myOsm.modifiedProperties = true; 250 my.keys.putAll(other.keys); 251 my.modified = true; 252 } 253 254 private <P extends OsmPrimitive> boolean mergeAfterId(Map<P,P> merged, Collection<P> primitives, P other) { 255 for (P my : primitives) { 256 if (my.realEqual(other)) 257 return true; // no merge needed. 258 if (my.id == other.id) { 259 Date d1 = my.timestamp == null ? new Date(0) : my.timestamp; 260 Date d2 = other.timestamp == null ? new Date(0) : other.timestamp; 261 if (my.modified && other.modified) { 262 conflicts.put(my, other); 263 if (merged != null) 264 merged.put(other, my); 265 } else if (!my.modified && !other.modified) { 266 if (d1.before(d2)) { 267 my.cloneFrom(other); 268 if (merged != null) 269 merged.put(other, my); 270 } 271 } else if (other.modified) { 272 if (d1.after(d2)) { 273 conflicts.put(my, other); 274 if (merged != null) 275 merged.put(other, my); 276 } else { 277 my.cloneFrom(other); 278 if (merged != null) 279 merged.put(other, my); 280 } 281 } else if (my.modified) { 282 if (d2.after(d1)) { 283 conflicts.put(my, other); 284 if (merged != null) 285 merged.put(other, my); 286 } 287 } 288 return true; 289 } 290 } 291 return false; 226 292 } 227 293 } -
src/org/openstreetmap/josm/data/osm/visitor/SelectionComponentVisitor.java
r79 r86 7 7 import javax.swing.Icon; 8 8 9 import org.openstreetmap.josm.data.osm. LineSegment;9 import org.openstreetmap.josm.data.osm.Segment; 10 10 import org.openstreetmap.josm.data.osm.Node; 11 11 import org.openstreetmap.josm.data.osm.Way; … … 30 30 31 31 /** 32 * If the linesegment has a key named "name", its value is displayed.32 * If the segment has a key named "name", its value is displayed. 33 33 * Otherwise, if it has "id", this is used. If none of these available, 34 34 * "(x1,y1) -> (x2,y2)" is displayed with the nodes coordinates. 35 35 */ 36 public void visit( LineSegment ls) {36 public void visit(Segment ls) { 37 37 name = ls.get("name"); 38 38 if (name == null) { … … 65 65 AllNodesVisitor.getAllNodes(w.segments); 66 66 Set<Node> nodes = new HashSet<Node>(); 67 for ( LineSegment ls : w.segments) {67 for (Segment ls : w.segments) { 68 68 if (!ls.incomplete) { 69 69 nodes.add(ls.from); -
src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
r75 r86 6 6 7 7 import org.openstreetmap.josm.Main; 8 import org.openstreetmap.josm.data.osm. LineSegment;8 import org.openstreetmap.josm.data.osm.Segment; 9 9 import org.openstreetmap.josm.data.osm.Node; 10 10 import org.openstreetmap.josm.data.osm.Way; … … 32 32 */ 33 33 private final NavigatableComponent nc; 34 34 35 35 /** 36 36 * Construct the painter visitor. … … 42 42 this.nc = mv; 43 43 } 44 44 45 45 /** 46 46 * Draw a small rectangle. … … 50 50 */ 51 51 public void visit(Node n) { 52 drawNode(n, n. isSelected()? getPreferencesColor("selected", Color.WHITE)52 drawNode(n, n.selected ? getPreferencesColor("selected", Color.WHITE) 53 53 : getPreferencesColor("node", Color.RED)); 54 54 } … … 58 58 * White if selected (as always) or green otherwise. 59 59 */ 60 public void visit( LineSegment ls) {61 draw LineSegment(ls, getPreferencesColor("segment", darkgreen));60 public void visit(Segment ls) { 61 drawSegment(ls, getPreferencesColor("segment", darkgreen)); 62 62 } 63 63 64 64 /** 65 * Draw a darkblue line for all linesegments.66 * @param tThe way to draw.65 * Draw a darkblue line for all segments. 66 * @param w The way to draw. 67 67 */ 68 public void visit(Way t) {68 public void visit(Way w) { 69 69 // only to overwrite with blue 70 70 Color wayColor = getPreferencesColor("way", darkblue); 71 for ( LineSegment ls : t.segments) {71 for (Segment ls : w.segments) { 72 72 if (ls.incomplete) { 73 73 wayColor = getPreferencesColor("incomplete way", darkerblue); … … 75 75 } 76 76 } 77 for ( LineSegment ls : t.segments)78 if (!ls. isSelected()) // selected already in good color79 draw LineSegment(ls, t.isSelected()? getPreferencesColor("selected", Color.WHITE) : wayColor);77 for (Segment ls : w.segments) 78 if (!ls.selected) // selected already in good color 79 drawSegment(ls, w.selected ? getPreferencesColor("selected", Color.WHITE) : wayColor); 80 80 } 81 81 … … 95 95 * Draw a line with the given color. 96 96 */ 97 private void draw LineSegment(LineSegment ls, Color col) {97 private void drawSegment(Segment ls, Color col) { 98 98 if (ls.incomplete) 99 99 return; 100 if (ls. isSelected())100 if (ls.selected) 101 101 col = getPreferencesColor("selected", Color.WHITE); 102 102 g.setColor(col); … … 105 105 g.drawLine(p1.x, p1.y, p2.x, p2.y); 106 106 } 107 108 p rivateColor getPreferencesColor(String colName, Color def) {107 108 public static Color getPreferencesColor(String colName, Color def) { 109 109 String colStr = Main.pref.get("color."+colName); 110 110 if (colStr.equals("")) -
src/org/openstreetmap/josm/data/osm/visitor/Visitor.java
r66 r86 1 1 package org.openstreetmap.josm.data.osm.visitor; 2 2 3 import org.openstreetmap.josm.data.osm. LineSegment;3 import org.openstreetmap.josm.data.osm.Segment; 4 4 import org.openstreetmap.josm.data.osm.Node; 5 5 import org.openstreetmap.josm.data.osm.Way; … … 13 13 public interface Visitor { 14 14 void visit(Node n); 15 void visit( LineSegment ls);15 void visit(Segment s); 16 16 void visit(Way w); 17 17 } -
src/org/openstreetmap/josm/data/projection/Epsg4326.java
r79 r86 19 19 } 20 20 21 @Override 22 public String toString() { 21 @Override public String toString() { 23 22 return "EPSG:4326"; 24 23 } -
src/org/openstreetmap/josm/data/projection/Mercator.java
r79 r86 27 27 } 28 28 29 @Override 30 public String toString() { 29 @Override public String toString() { 31 30 return "Mercator"; 32 31 } -
src/org/openstreetmap/josm/gui/BookmarkList.java
r73 r86 47 47 setVisibleRowCount(7); 48 48 setCellRenderer(new DefaultListCellRenderer(){ 49 @Override 50 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 49 @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 51 50 Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 52 51 if (c instanceof JLabel) { -
src/org/openstreetmap/josm/gui/MapFrame.java
r79 r86 15 15 16 16 import org.openstreetmap.josm.actions.AutoScaleAction; 17 import org.openstreetmap.josm.actions.mapmode.Add LineSegmentAction;17 import org.openstreetmap.josm.actions.mapmode.AddSegmentAction; 18 18 import org.openstreetmap.josm.actions.mapmode.AddNodeAction; 19 19 import org.openstreetmap.josm.actions.mapmode.AddWayAction; … … 23 23 import org.openstreetmap.josm.actions.mapmode.SelectionAction; 24 24 import org.openstreetmap.josm.actions.mapmode.ZoomAction; 25 import org.openstreetmap.josm.gui.dialogs.ConflictDialog; 25 26 import org.openstreetmap.josm.gui.dialogs.LayerList; 26 27 import org.openstreetmap.josm.gui.dialogs.PropertiesDialog; … … 53 54 */ 54 55 public MapStatus statusLine; 56 57 public ConflictDialog conflictDialog; 58 55 59 /** 56 60 * Construct a map with a given DataSet. The set cannot be replaced after … … 73 77 toolBarActions.add(new IconToggleButton(new MoveAction(this))); 74 78 toolBarActions.add(new IconToggleButton(new AddNodeAction(this))); 75 toolBarActions.add(new IconToggleButton(new Add LineSegmentAction(this)));79 toolBarActions.add(new IconToggleButton(new AddSegmentAction(this))); 76 80 toolBarActions.add(new IconToggleButton(new AddWayAction(this, selectionAction))); 77 81 toolBarActions.add(new IconToggleButton(new DeleteAction(this))); … … 104 108 addIconToggle(toggleDialogs, new PropertiesDialog(this)); 105 109 addIconToggle(toggleDialogs, new SelectionListDialog(this)); 110 addIconToggle(toggleDialogs, conflictDialog = new ConflictDialog()); 106 111 107 112 // status line below the map … … 119 124 * Fires an property changed event "visible". 120 125 */ 121 @Override 122 public void setVisible(boolean aFlag) { 126 @Override public void setVisible(boolean aFlag) { 123 127 boolean old = isVisible(); 124 128 super.setVisible(aFlag); -
src/org/openstreetmap/josm/gui/MapMover.java
r71 r86 64 64 * Start the movement, if it was the 3rd button (right button). 65 65 */ 66 @Override 67 public void mousePressed(MouseEvent e) { 66 @Override public void mousePressed(MouseEvent e) { 68 67 int offMask = MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON2_DOWN_MASK; 69 68 if (e.getButton() == MouseEvent.BUTTON3 && (e.getModifiersEx() & offMask) == 0) … … 74 73 * Change the cursor back to it's pre-move cursor. 75 74 */ 76 @Override 77 public void mouseReleased(MouseEvent e) { 75 @Override public void mouseReleased(MouseEvent e) { 78 76 if (e.getButton() == MouseEvent.BUTTON3) 79 77 endMovement(); -
src/org/openstreetmap/josm/gui/MapStatus.java
r71 r86 14 14 import java.beans.PropertyChangeEvent; 15 15 import java.beans.PropertyChangeListener; 16 import java.util.Arrays; 16 17 import java.util.Collection; 17 18 import java.util.ConcurrentModificationException; … … 135 136 osm.visit(visitor); 136 137 final StringBuilder text = new StringBuilder(); 137 if (osm.id == 0 || osm.modified || osm.modifiedProperties)138 if (osm.id == 0 || osm.modified) 138 139 visitor.name = "<i><b>"+visitor.name+"*</b></i>"; 139 140 text.append(visitor.name); … … 147 148 l.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 148 149 l.addMouseListener(new MouseAdapter(){ 149 @Override 150 public void mouseEntered(MouseEvent e) { 150 @Override public void mouseEntered(MouseEvent e) { 151 151 l.setText("<html><u color='blue'>"+text.toString()+"</u></html>"); 152 152 } 153 @Override 154 public void mouseExited(MouseEvent e) { 153 @Override public void mouseExited(MouseEvent e) { 155 154 l.setText("<html>"+text.toString()+"</html>"); 156 155 } 157 @Override 158 public void mouseClicked(MouseEvent e) { 159 Main.main.ds.clearSelection(); 160 osm.setSelected(true); 156 @Override public void mouseClicked(MouseEvent e) { 157 Main.ds.setSelected(Arrays.asList(new OsmPrimitive[]{osm})); 161 158 mv.repaint(); 162 159 } -
src/org/openstreetmap/josm/gui/MapView.java
r79 r86 13 13 import org.openstreetmap.josm.Main; 14 14 import org.openstreetmap.josm.data.Bounds; 15 import org.openstreetmap.josm.data.SelectionChangedListener; 15 16 import org.openstreetmap.josm.data.coor.EastNorth; 16 17 import org.openstreetmap.josm.data.coor.LatLon; 17 18 import org.openstreetmap.josm.data.osm.DataSet; 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 20 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 19 21 import org.openstreetmap.josm.data.projection.Projection; … … 76 78 public MapView(Layer layer) { 77 79 addComponentListener(new ComponentAdapter(){ 78 @Override 79 public void componentResized(ComponentEvent e) { 80 @Override public void componentResized(ComponentEvent e) { 80 81 recalculateCenterScale(); 81 82 } … … 83 84 new MapMover(this); 84 85 addLayer(layer); 86 87 // listend to selection changes to redraw the map 88 Main.ds.addSelectionChangedListener(new SelectionChangedListener(){ 89 public void selectionChanged(Collection<OsmPrimitive> newSelection) { 90 repaint(); 91 } 92 }); 85 93 } 86 94 … … 155 163 * Draw the component. 156 164 */ 157 @Override 158 public void paint(Graphics g) { 165 @Override public void paint(Graphics g) { 159 166 g.setColor(Color.BLACK); 160 167 g.fillRect(0, 0, getWidth(), getHeight()); … … 218 225 double oldScale = this.scale; 219 226 220 if (v.min == null || v.max == null ) {227 if (v.min == null || v.max == null || v.min.equals(v.max)) { 221 228 // no bounds means whole world 222 229 center = getProjection().latlon2eastNorth(new LatLon(0,0)); … … 225 232 double scaleY = world.north()*2/h; 226 233 scale = Math.max(scaleX, scaleY); // minimum scale to see all of the screen 227 228 234 } else { 229 235 center = new EastNorth(v.min.east()/2+v.max.east()/2, v.min.north()/2+v.max.north()/2); … … 277 283 activeLayer = layer; 278 284 if (layer instanceof OsmDataLayer) 279 Main. main.ds = ((OsmDataLayer)layer).data;285 Main.ds = ((OsmDataLayer)layer).data; 280 286 if (old != layer) { 281 287 for (LayerChangeListener l : listeners) … … 306 312 * feature. 307 313 */ 308 @Override 309 public void zoomTo(EastNorth newCenter, double scale) { 314 @Override public void zoomTo(EastNorth newCenter, double scale) { 310 315 boolean oldAutoScale = autoScale; 311 316 EastNorth oldCenter = center; -
src/org/openstreetmap/josm/gui/NavigatableComponent.java
r73 r86 10 10 import org.openstreetmap.josm.data.coor.LatLon; 11 11 import org.openstreetmap.josm.data.coor.EastNorth; 12 import org.openstreetmap.josm.data.osm. LineSegment;12 import org.openstreetmap.josm.data.osm.Segment; 13 13 import org.openstreetmap.josm.data.osm.Node; 14 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 109 109 * nearest node is returned. 110 110 * 111 * If no node is found, search for pending linesegments.112 * 113 * If no such line segment is found, and a non-pending linesegment is111 * If no node is found, search for pending segments. 112 * 113 * If no such segment is found, and a non-pending segment is 114 114 * within 10 pixel to p, this segment is returned, except when 115 115 * <code>wholeWay</code> is <code>true</code>, in which case the 116 116 * corresponding Way is returned. 117 117 * 118 * If no linesegment is found and the point is within an area, return that118 * If no segment is found and the point is within an area, return that 119 119 * area. 120 120 * … … 122 122 * 123 123 * @param p The point on screen. 124 * @param segmentInsteadWay Whether the linesegment (true) or only the whole124 * @param segmentInsteadWay Whether the segment (true) or only the whole 125 125 * way should be returned. 126 126 * @return The primitive, that is nearest to the point p. … … 131 131 132 132 // nodes 133 for (Node n : Main. main.ds.nodes) {134 if (n. isDeleted())133 for (Node n : Main.ds.nodes) { 134 if (n.deleted) 135 135 continue; 136 136 Point sp = getPoint(n.eastNorth); … … 147 147 minDistanceSq = Double.MAX_VALUE; 148 148 if (!segmentInsteadWay) { 149 for (Way w : Main. main.ds.ways) {150 if (w. isDeleted())149 for (Way w : Main.ds.ways) { 150 if (w.deleted) 151 151 continue; 152 for ( LineSegment ls : w.segments) {153 if (ls. isDeleted()|| ls.incomplete)152 for (Segment ls : w.segments) { 153 if (ls.deleted || ls.incomplete) 154 154 continue; 155 155 Point A = getPoint(ls.from.eastNorth); … … 170 170 171 171 minDistanceSq = Double.MAX_VALUE; 172 // linesegments173 for ( LineSegment ls : Main.main.ds.lineSegments) {174 if (ls. isDeleted()|| ls.incomplete)172 // segments 173 for (Segment ls : Main.ds.segments) { 174 if (ls.deleted || ls.incomplete) 175 175 continue; 176 176 Point A = getPoint(ls.from.eastNorth); … … 194 194 * determined. 195 195 * 196 * If its a node, return all linesegments and196 * If its a node, return all segments and 197 197 * streets the node is part of, as well as all nodes 198 * (with their linesegments and ways) with the same198 * (with their segments and ways) with the same 199 199 * location. 200 200 * 201 * If its a linesegment, return all ways this segment202 * belongs to as well as all linesegments that are between201 * If its a segment, return all ways this segment 202 * belongs to as well as all segments that are between 203 203 * the same nodes (in both direction) with all their ways. 204 204 * … … 215 215 if (osm instanceof Node) { 216 216 Node node = (Node)osm; 217 for (Node n : Main. main.ds.nodes)218 if (!n. isDeleted()&& n.coor.equals(node.coor))217 for (Node n : Main.ds.nodes) 218 if (!n.deleted && n.coor.equals(node.coor)) 219 219 c.add(n); 220 for ( LineSegment ls : Main.main.ds.lineSegments)221 // linesegments never match nodes, so they are skipped by contains222 if (!ls. isDeleted()&& !ls.incomplete && (c.contains(ls.from) || c.contains(ls.to)))220 for (Segment ls : Main.ds.segments) 221 // segments never match nodes, so they are skipped by contains 222 if (!ls.deleted && !ls.incomplete && (c.contains(ls.from) || c.contains(ls.to))) 223 223 c.add(ls); 224 224 } 225 if (osm instanceof LineSegment) {226 LineSegment line = (LineSegment)osm;227 for ( LineSegment ls : Main.main.ds.lineSegments)228 if (!ls. isDeleted()&& ls.equalPlace(line))225 if (osm instanceof Segment) { 226 Segment line = (Segment)osm; 227 for (Segment ls : Main.ds.segments) 228 if (!ls.deleted && ls.equalPlace(line)) 229 229 c.add(ls); 230 230 } 231 if (osm instanceof Node || osm instanceof LineSegment) {232 for (Way t : Main. main.ds.ways) {233 if (t. isDeleted())231 if (osm instanceof Node || osm instanceof Segment) { 232 for (Way t : Main.ds.ways) { 233 if (t.deleted) 234 234 continue; 235 for ( LineSegment ls : t.segments) {236 if (!ls. isDeleted()&& !ls.incomplete && c.contains(ls)) {235 for (Segment ls : t.segments) { 236 if (!ls.deleted && !ls.incomplete && c.contains(ls)) { 237 237 c.add(t); 238 238 break; -
src/org/openstreetmap/josm/gui/OsmPrimitivRenderer.java
r33 r86 18 18 private SelectionComponentVisitor visitor = new SelectionComponentVisitor(); 19 19 20 @Override 21 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 20 @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 22 21 Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 23 22 if (c instanceof JLabel && value != null) { -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r85 r86 153 153 * The checkbox stating whether raw gps lines should be forced. 154 154 */ 155 private JCheckBox forceRawGpsLines = new JCheckBox("Force lines if no linesegments imported.");155 private JCheckBox forceRawGpsLines = new JCheckBox("Force lines if no segments imported."); 156 156 157 157 private JTable colors; -
src/org/openstreetmap/josm/gui/SelectionManager.java
r71 r86 16 16 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.osm. LineSegment;18 import org.openstreetmap.josm.data.osm.Segment; 19 19 import org.openstreetmap.josm.data.osm.Node; 20 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 257 257 * @param alt Whether the alt key was pressed, which means select all objects 258 258 * that are touched, instead those which are completly covered. Also 259 * select whole ways instead of linesegments.259 * select whole ways instead of segments. 260 260 */ 261 261 public Collection<OsmPrimitive> getObjectsInRectangle(Rectangle r, boolean alt) { … … 272 272 } else { 273 273 // nodes 274 for (Node n : Main. main.ds.nodes) {274 for (Node n : Main.ds.nodes) { 275 275 if (r.contains(nc.getPoint(n.eastNorth))) 276 276 selection.add(n); 277 277 } 278 278 279 // pending linesegments280 for ( LineSegment ls : Main.main.ds.lineSegments)281 if (rectangleContain LineSegment(r, alt, ls))279 // pending segments 280 for (Segment ls : Main.ds.segments) 281 if (rectangleContainSegment(r, alt, ls)) 282 282 selection.add(ls); 283 283 284 284 // ways 285 for (Way t : Main. main.ds.ways) {285 for (Way t : Main.ds.ways) { 286 286 boolean wholeWaySelected = !t.segments.isEmpty(); 287 for ( LineSegment ls : t.segments)288 if (rectangleContain LineSegment(r, alt, ls))287 for (Segment ls : t.segments) 288 if (rectangleContainSegment(r, alt, ls)) 289 289 selection.add(ls); 290 290 else … … 300 300 301 301 /** 302 * Decide whether the linesegment is in the rectangle Return302 * Decide whether the segment is in the rectangle Return 303 303 * <code>true</code>, if it is in or false if not. 304 304 * 305 * @param r The rectangle, in which the linesegment has to be.305 * @param r The rectangle, in which the segment has to be. 306 306 * @param alt Whether user pressed the Alt key 307 * @param ls The linesegment.308 * @return <code>true</code>, if the LineSegment was added to the selection.309 */ 310 private boolean rectangleContain LineSegment(Rectangle r, boolean alt, LineSegment ls) {307 * @param ls The segment. 308 * @return <code>true</code>, if the Segment was added to the selection. 309 */ 310 private boolean rectangleContainSegment(Rectangle r, boolean alt, Segment ls) { 311 311 if (ls.incomplete) 312 312 return false; -
src/org/openstreetmap/josm/gui/ShowModifiers.java
r46 r86 131 131 } 132 132 133 @Override 134 public void paint(Graphics g) { 133 @Override public void paint(Graphics g) { 135 134 super.paint(g); 136 135 paintMouse(g); -
src/org/openstreetmap/josm/gui/WorldChooser.java
r79 r86 72 72 p.east()*360/world.getIconWidth() - 180); 73 73 } 74 @Override 75 public String toString() { 74 @Override public String toString() { 76 75 return "WorldChooser"; 77 76 } … … 87 86 * Set the scale as well as the preferred size. 88 87 */ 89 @Override 90 public void setPreferredSize(Dimension preferredSize) { 88 @Override public void setPreferredSize(Dimension preferredSize) { 91 89 super.setPreferredSize(preferredSize); 92 90 scale = world.getIconWidth()/preferredSize.getWidth(); … … 98 96 * Draw the current selected region. 99 97 */ 100 @Override 101 public void paint(Graphics g) { 98 @Override public void paint(Graphics g) { 102 99 EastNorth tl = getEastNorth(0,0); 103 100 EastNorth br = getEastNorth(getWidth(),getHeight()); … … 122 119 123 120 124 @Override 125 public void zoomTo(EastNorth newCenter, double scale) { 121 @Override public void zoomTo(EastNorth newCenter, double scale) { 126 122 if (getWidth() != 0 && scale > scaleMax) { 127 123 scale = scaleMax; … … 158 154 // messages are dispatched and so text fields are updated. 159 155 KeyListener listener = new KeyAdapter(){ 160 @Override 161 public void keyTyped(KeyEvent e) { 156 @Override public void keyTyped(KeyEvent e) { 162 157 SwingUtilities.invokeLater(new Runnable(){ 163 158 public void run() { … … 216 211 * Always use our image projection mode. 217 212 */ 218 @Override 219 protected Projection getProjection() { 213 @Override protected Projection getProjection() { 220 214 return projection; 221 215 } -
src/org/openstreetmap/josm/gui/dialogs/LayerList.java
r79 r86 59 59 if (layers.getModel().getSize() == 1) { 60 60 Main.main.setMapFrame(null); 61 Main. main.ds = new DataSet();61 Main.ds = new DataSet(); 62 62 } else { 63 63 int sel = layers.getSelectedIndex(); … … 133 133 layers.setBackground(UIManager.getColor("Button.background")); 134 134 layers.setCellRenderer(new DefaultListCellRenderer(){ 135 @Override 136 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 135 @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 137 136 Layer layer = (Layer)value; 138 137 JLabel label = (JLabel)super.getListCellRendererComponent(list, -
src/org/openstreetmap/josm/gui/dialogs/LayerListPopup.java
r79 r86 1 1 package org.openstreetmap.josm.gui.dialogs; 2 2 3 import java.awt.Color;4 3 import java.awt.event.ActionEvent; 5 import java.awt.event.ActionListener;6 4 7 import javax.swing. JColorChooser;5 import javax.swing.AbstractAction; 8 6 import javax.swing.JList; 9 import javax.swing.JMenuItem;10 7 import javax.swing.JOptionPane; 11 8 import javax.swing.JPopupMenu; 12 9 13 10 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm.actions.GpxExportAction;15 import org.openstreetmap.josm.actions.SaveAction;16 11 import org.openstreetmap.josm.gui.layer.Layer; 17 import org.openstreetmap.josm.gui.layer.OsmDataLayer;18 import org.openstreetmap.josm.gui.layer.RawGpsDataLayer;19 import org.openstreetmap.josm.gui.layer.WmsServerLayer;20 import org.openstreetmap.josm.tools.ColorHelper;21 12 import org.openstreetmap.josm.tools.ImageProvider; 22 13 … … 26 17 public class LayerListPopup extends JPopupMenu { 27 18 19 public final static class InfoAction extends AbstractAction { 20 private final Layer layer; 21 public InfoAction(Layer layer) { 22 super("Info", ImageProvider.get("info")); 23 this.layer = layer; 24 } 25 public void actionPerformed(ActionEvent e) { 26 JOptionPane.showMessageDialog(Main.main, layer.getInfoComponent()); 27 } 28 } 29 28 30 public LayerListPopup(final JList layers, final Layer layer) { 29 add(new LayerList.ShowHideLayerAction(layers, layer)); 30 add(new LayerList.DeleteLayerAction(layers, layer)); 31 addSeparator(); 32 33 if (layer instanceof OsmDataLayer) 34 add(new JMenuItem(new SaveAction())); 31 add(new LayerList.ShowHideLayerAction(layers, layer)); 32 add(new LayerList.DeleteLayerAction(layers, layer)); 33 addSeparator(); 35 34 36 if (!(layer instanceof WmsServerLayer)) 37 add(new JMenuItem(new GpxExportAction(layer))); 38 39 if (layer instanceof RawGpsDataLayer) { 40 JMenuItem color = new JMenuItem("Customize Color", ImageProvider.get("colorchooser")); 41 color.addActionListener(new ActionListener(){ 42 public void actionPerformed(ActionEvent e) { 43 String col = Main.pref.get("color.layer "+layer.name, Main.pref.get("color.gps point", ColorHelper.color2html(Color.gray))); 44 JColorChooser c = new JColorChooser(ColorHelper.html2color(col)); 45 Object[] options = new Object[]{"OK", "Cancel", "Default"}; 46 int answer = JOptionPane.showOptionDialog(Main.main, c, "Choose a color", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); 47 switch (answer) { 48 case 0: 49 Main.pref.put("color.layer "+layer.name, ColorHelper.color2html(c.getColor())); 50 break; 51 case 1: 52 return; 53 case 2: 54 Main.pref.put("color.layer "+layer.name, null); 55 break; 56 } 57 Main.main.repaint(); 58 } 59 }); 60 add(color); 61 } 62 63 if (!(layer instanceof WmsServerLayer)) 64 addSeparator(); 65 66 JMenuItem info = new JMenuItem("Info", ImageProvider.get("info")); 67 info.addActionListener(new ActionListener(){ 68 public void actionPerformed(ActionEvent e) { 69 JOptionPane.showMessageDialog(Main.main, layer.getInfoComponent()); 70 } 71 }); 72 add(info); 35 layer.addMenuEntries(this); 73 36 } 74 37 } -
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r79 r86 36 36 37 37 import org.openstreetmap.josm.Main; 38 import org.openstreetmap.josm.command.Change KeyValueCommand;38 import org.openstreetmap.josm.command.ChangePropertyCommand; 39 39 import org.openstreetmap.josm.data.SelectionChangedListener; 40 40 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 68 68 */ 69 69 public class DblClickWatch extends MouseAdapter { 70 @Override 71 public void mouseClicked(MouseEvent e) { 70 @Override public void mouseClicked(MouseEvent e) { 72 71 if (e.getClickCount() < 2) 73 72 return; … … 87 86 void edit(int row) { 88 87 String key = data.getValueAt(row, 0).toString(); 89 Collection<OsmPrimitive> sel = Main. main.ds.getSelected();88 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 90 89 String msg = "<html>This will change "+sel.size()+" object"+(sel.size()==1?"":"s")+".<br><br>"+ 91 90 "Please select a new value for '"+key+"'.<br>(Empty string deletes the key.)"; … … 125 124 if (value.equals("")) 126 125 value = null; // delete the key 127 mv.editLayer().add(new Change KeyValueCommand(sel, key, value));126 mv.editLayer().add(new ChangePropertyCommand(sel, key, value)); 128 127 129 128 if (value == null) … … 138 137 */ 139 138 void add() { 140 Collection<OsmPrimitive> sel = Main. main.ds.getSelected();139 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 141 140 142 141 JPanel p = new JPanel(new BorderLayout()); … … 144 143 "Please select a key"), BorderLayout.NORTH); 145 144 Vector<String> allKeys = new Vector<String>(); 146 for (OsmPrimitive osm : Main. main.ds.allNonDeletedPrimitives())145 for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) 147 146 allKeys.addAll(osm.keySet()); 148 147 for (Iterator<String> it = allKeys.iterator(); it.hasNext();) { … … 172 171 if (value.equals("")) 173 172 return; 174 mv.editLayer().add(new Change KeyValueCommand(sel, key, value));173 mv.editLayer().add(new ChangePropertyCommand(sel, key, value)); 175 174 selectionChanged(sel); // update table 176 175 } … … 182 181 private void delete(int row) { 183 182 String key = data.getValueAt(row, 0).toString(); 184 Collection<OsmPrimitive> sel = Main. main.ds.getSelected();185 mv.editLayer().add(new Change KeyValueCommand(sel, key, null));183 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 184 mv.editLayer().add(new ChangePropertyCommand(sel, key, null)); 186 185 selectionChanged(sel); // update table 187 186 } … … 191 190 */ 192 191 private final DefaultTableModel data = new DefaultTableModel(){ 193 @Override 194 public boolean isCellEditable(int row, int column) { 192 @Override public boolean isCellEditable(int row, int column) { 195 193 return false; 196 194 } 197 @Override 198 public Class<?> getColumnClass(int columnIndex) { 195 @Override public Class<?> getColumnClass(int columnIndex) { 199 196 return columnIndex == 1 ? JComboBox.class : String.class; 200 197 } … … 221 218 propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 222 219 propertyTable.setDefaultRenderer(JComboBox.class, new DefaultTableCellRenderer(){ 223 @Override 224 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 220 @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 225 221 Component c = super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 226 222 if (c instanceof JLabel) { … … 234 230 }); 235 231 propertyTable.setDefaultRenderer(String.class, new DefaultTableCellRenderer(){ 236 @Override 237 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 232 @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 238 233 return super.getTableCellRendererComponent(table, value, isSelected, false, row, column); 239 234 } … … 279 274 } 280 275 281 @Override 282 public void setVisible(boolean b) { 276 @Override public void setVisible(boolean b) { 283 277 if (b) { 284 Main. main.ds.addSelectionChangedListener(this);285 selectionChanged(Main. main.ds.getSelected());278 Main.ds.addSelectionChangedListener(this); 279 selectionChanged(Main.ds.getSelected()); 286 280 } else { 287 Main. main.ds.removeSelectionChangedListener(this);281 Main.ds.removeSelectionChangedListener(this); 288 282 } 289 283 super.setVisible(b); … … 291 285 292 286 public void selectionChanged(Collection<OsmPrimitive> newSelection) { 287 if (propertyTable == null) 288 return; // selection changed may be received in base class constructor before init 293 289 if (propertyTable.getCellEditor() != null) 294 290 propertyTable.getCellEditor().cancelCellEditing(); -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r81 r86 11 11 import java.awt.event.MouseEvent; 12 12 import java.util.Collection; 13 import java.util.LinkedList; 13 14 14 15 import javax.swing.ButtonGroup; … … 61 62 displaylist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 62 63 displaylist.addMouseListener(new MouseAdapter(){ 63 @Override 64 public void mouseClicked(MouseEvent e) { 64 @Override public void mouseClicked(MouseEvent e) { 65 65 if (e.getClickCount() < 2) 66 66 return; … … 122 122 lastSearch = input.getText(); 123 123 SearchCompiler.Match matcher = SearchCompiler.compile(lastSearch); 124 for (OsmPrimitive osm : Main.main.ds.allNonDeletedPrimitives()) { 125 if (replace.isSelected()) 126 osm.setSelected(matcher.match(osm)); 127 else if (add.isSelected() && !osm.isSelected() && matcher.match(osm)) 128 osm.setSelected(true); 129 else if (remove.isSelected() && osm.isSelected() && matcher.match(osm)) 130 osm.setSelected(false); 124 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 125 for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) { 126 if (replace.isSelected()) { 127 if (matcher.match(osm)) 128 sel.add(osm); 129 else 130 sel.remove(osm); 131 } else if (add.isSelected() && !osm.selected && matcher.match(osm)) 132 sel.add(osm); 133 else if (remove.isSelected() && osm.selected && matcher.match(osm)) 134 sel.remove(osm); 131 135 } 132 selectionChanged(Main.main.ds.getSelected()); 133 Main.main.getMapFrame().repaint(); 136 Main.ds.setSelected(sel); 134 137 } 135 138 }); … … 137 140 138 141 add(buttonPanel, BorderLayout.SOUTH); 139 selectionChanged(Main. main.ds.getSelected());142 selectionChanged(Main.ds.getSelected()); 140 143 } 141 144 142 @Override 143 public void setVisible(boolean b) { 145 @Override public void setVisible(boolean b) { 144 146 if (b) { 145 Main. main.ds.addSelectionChangedListener(this);146 selectionChanged(Main. main.ds.getSelected());147 Main.ds.addSelectionChangedListener(this); 148 selectionChanged(Main.ds.getSelected()); 147 149 } else { 148 Main. main.ds.removeSelectionChangedListener(this);150 Main.ds.removeSelectionChangedListener(this); 149 151 } 150 152 super.setVisible(b); … … 158 160 */ 159 161 public void selectionChanged(Collection<OsmPrimitive> newSelection) { 162 if (list == null) 163 return; // selection changed may be received in base class constructor before init 160 164 list.removeAllElements(); 161 165 list.setSize(newSelection.size()); … … 169 173 */ 170 174 public void updateMap() { 171 Main.main.ds.clearSelection();175 Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>(); 172 176 for (int i = 0; i < list.getSize(); ++i) 173 177 if (displaylist.isSelectedIndex(i)) 174 ((OsmPrimitive)list.get(i)).setSelected(true);175 Main. main.getMapFrame().repaint();178 sel.add((OsmPrimitive)list.get(i)); 179 Main.ds.setSelected(sel); 176 180 } 177 181 } -
src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r81 r86 32 32 * @param title The title of the dialog. 33 33 * @param prefName Name of the base preference setting string (prefix) 34 * with the final . (e.g.: "layerlist.")35 34 */ 36 35 public ToggleDialog(String title, String name, String iconName, String tooltip, String shortCutName, int shortCut, final String prefName) { … … 41 40 show = ((AbstractButton)e.getSource()).isSelected(); 42 41 setVisible(show); 43 Main.pref.put(prefName+" visible", show);42 Main.pref.put(prefName+".visible", show); 44 43 } 45 44 }; … … 48 47 setVisible(false); 49 48 setBorder(BorderFactory.createEtchedBorder()); 50 if (Main.pref.getBoolean(prefName+" visible")) {49 if (Main.pref.getBoolean(prefName+".visible")) { 51 50 EventQueue.invokeLater(new Runnable(){ 52 51 public void run() { -
src/org/openstreetmap/josm/gui/layer/Layer.java
r78 r86 4 4 5 5 import javax.swing.Icon; 6 import javax.swing.JPopupMenu; 6 7 7 8 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; … … 80 81 81 82 abstract public Object getInfoComponent(); 83 84 abstract public void addMenuEntries(JPopupMenu menu); 82 85 } -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r78 r86 12 12 import javax.swing.Icon; 13 13 import javax.swing.JLabel; 14 import javax.swing.JMenuItem; 14 15 import javax.swing.JPanel; 16 import javax.swing.JPopupMenu; 15 17 16 18 import org.openstreetmap.josm.Main; 19 import org.openstreetmap.josm.actions.GpxExportAction; 20 import org.openstreetmap.josm.actions.SaveAction; 17 21 import org.openstreetmap.josm.command.Command; 18 22 import org.openstreetmap.josm.data.osm.DataSet; 19 import org.openstreetmap.josm.data.osm. LineSegment;23 import org.openstreetmap.josm.data.osm.Segment; 20 24 import org.openstreetmap.josm.data.osm.Node; 21 25 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 26 30 import org.openstreetmap.josm.data.osm.visitor.Visitor; 27 31 import org.openstreetmap.josm.gui.MapView; 32 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 28 33 import org.openstreetmap.josm.tools.GBC; 29 34 import org.openstreetmap.josm.tools.ImageProvider; … … 37 42 public class OsmDataLayer extends Layer { 38 43 44 public final static class DataCountVisitor implements Visitor { 45 public final int[] normal = new int[3]; 46 public final int[] deleted = new int[3]; 47 public final String[] names = {"node", "segment", "way"}; 48 49 private void inc(OsmPrimitive osm, int i) { 50 normal[i]++; 51 if (osm.deleted) 52 deleted[i]++; 53 } 54 55 public void visit(Node n) { 56 inc(n, 0); 57 } 58 59 public void visit(Segment ls) { 60 inc(ls, 1); 61 } 62 63 public void visit(Way w) { 64 inc(w, 2); 65 } 66 } 67 39 68 public interface ModifiedChangedListener { 40 69 void modifiedChanged(boolean value, OsmDataLayer source); 41 70 } 42 71 43 72 private static Icon icon; 44 73 … … 75 104 LinkedList<ModifiedChangedListener> listener; 76 105 77 106 78 107 /** 79 108 * Construct a OsmDataLayer. … … 89 118 * updated by a background thread to not disturb the running programm. 90 119 */ 91 @Override 92 public Icon getIcon() { 120 @Override public Icon getIcon() { 93 121 if (icon == null) 94 122 icon = ImageProvider.get("layer", "osmdata"); … … 99 127 * Draw all primitives in this layer but do not draw modified ones (they 100 128 * are drawn by the edit layer). 101 * Draw nodes last to overlap the line segments they belong to. 102 */ 103 @Override 104 public void paint(Graphics g, MapView mv) { 129 * Draw nodes last to overlap the segments they belong to. 130 */ 131 @Override public void paint(Graphics g, MapView mv) { 105 132 SimplePaintVisitor visitor = new SimplePaintVisitor(g, mv); 106 for (OsmPrimitive osm : data. lineSegments)107 if (!osm. isDeleted())133 for (OsmPrimitive osm : data.segments) 134 if (!osm.deleted) 108 135 osm.visit(visitor); 109 136 for (OsmPrimitive osm : data.ways) 110 if (!osm. isDeleted())137 if (!osm.deleted) 111 138 osm.visit(visitor); 112 139 for (OsmPrimitive osm : data.nodes) 113 if (!osm. isDeleted())140 if (!osm.deleted) 114 141 osm.visit(visitor); 115 142 for (OsmPrimitive osm : data.getSelected()) 116 if (!osm. isDeleted())143 if (!osm.deleted) 117 144 osm.visit(visitor); 118 }119 120 @Override 121 public String getToolTipText() {145 Main.main.getMapFrame().conflictDialog.paintConflicts(g, mv); 146 } 147 148 @Override public String getToolTipText() { 122 149 return undeletedSize(data.nodes)+" nodes, "+ 123 undeletedSize(data.lineSegments)+" segments, "+ 124 undeletedSize(data.ways)+" streets."; 125 } 126 127 @Override 128 public void mergeFrom(Layer from) { 129 MergeVisitor visitor = new MergeVisitor(data); 150 undeletedSize(data.segments)+" segments, "+ 151 undeletedSize(data.ways)+" streets."; 152 } 153 154 @Override public void mergeFrom(Layer from) { 155 final MergeVisitor visitor = new MergeVisitor(data); 130 156 for (OsmPrimitive osm : ((OsmDataLayer)from).data.allPrimitives()) 131 157 osm.visit(visitor); 132 158 visitor.fixReferences(); 133 } 134 135 @Override 136 public boolean isMergable(Layer other) { 159 if (visitor.conflicts.isEmpty()) 160 return; 161 Main.main.getMapFrame().conflictDialog.add(visitor.conflicts); 162 } 163 164 @Override public boolean isMergable(Layer other) { 137 165 return other instanceof OsmDataLayer; 138 166 } 139 167 140 @Override 141 public void visitBoundingBox(BoundingXYVisitor v) { 168 @Override public void visitBoundingBox(BoundingXYVisitor v) { 142 169 for (Node n : data.nodes) 143 170 v.visit(n); … … 150 177 return commands.isEmpty() ? null : commands.getLast(); 151 178 } 152 179 153 180 /** 154 181 * Execute the command and add it to the intern command queue. Also mark all … … 214 241 for (Iterator<Node> it = data.nodes.iterator(); it.hasNext();) 215 242 cleanIterator(it, processedSet); 216 for (Iterator< LineSegment> it = data.lineSegments.iterator(); it.hasNext();)243 for (Iterator<Segment> it = data.segments.iterator(); it.hasNext();) 217 244 cleanIterator(it, processedSet); 218 245 for (Iterator<Way> it = data.ways.iterator(); it.hasNext();) … … 221 248 222 249 // update the modified flag 223 250 224 251 if (fromDisk && processed != null && !dataAdded) 225 252 return; // do nothing when uploading non-harmful changes. 226 253 227 254 // modified if server changed the data (esp. the id). 228 255 uploadedModified = fromDisk && processed != null && dataAdded; … … 246 273 return; 247 274 osm.modified = false; 248 osm.modifiedProperties = false; 249 if (osm.isDeleted()) 275 if (osm.deleted) 250 276 it.remove(); 251 277 } … … 280 306 int size = 0; 281 307 for (OsmPrimitive osm : list) 282 if (!osm. isDeleted())308 if (!osm.deleted) 283 309 size++; 284 310 return size; 285 311 } 286 312 287 @Override 288 public Object getInfoComponent() { 289 final int[] normal = new int[3]; 290 final int[] deleted = new int[3]; 291 final String[] names = {"node", "segment", "way"}; 292 Visitor counter = new Visitor(){ 293 private void inc(OsmPrimitive osm, int i) { 294 normal[i]++; 295 if (osm.isDeleted()) 296 deleted[i]++; 297 } 298 public void visit(Node n) { 299 inc(n, 0); 300 } 301 public void visit(LineSegment ls) { 302 inc(ls, 1); 303 } 304 public void visit(Way w) { 305 inc(w, 2); 306 } 307 }; 313 @Override public Object getInfoComponent() { 314 DataCountVisitor counter = new DataCountVisitor(); 308 315 for (OsmPrimitive osm : data.allPrimitives()) 309 316 osm.visit(counter); 310 311 317 JPanel p = new JPanel(new GridBagLayout()); 312 318 p.add(new JLabel(name+" consists of:"), GBC.eol()); 313 for (int i = 0; i < normal.length; ++i) {314 String s = normal[i]+" "+names[i]+(normal[i] != 1 ?"s":"");315 if ( deleted[i] > 0)316 s += " ("+ deleted[i]+" deleted)";317 p.add(new JLabel(s, ImageProvider.get("data", names[i]), JLabel.HORIZONTAL), GBC.eol().insets(15,0,0,0));319 for (int i = 0; i < counter.normal.length; ++i) { 320 String s = counter.normal[i]+" "+counter.names[i]+(counter.normal[i] != 1 ?"s":""); 321 if (counter.deleted[i] > 0) 322 s += " ("+counter.deleted[i]+" deleted)"; 323 p.add(new JLabel(s, ImageProvider.get("data", counter.names[i]), JLabel.HORIZONTAL), GBC.eol().insets(15,0,0,0)); 318 324 } 319 325 return p; 320 326 } 327 328 @Override public void addMenuEntries(JPopupMenu menu) { 329 menu.add(new JMenuItem(new SaveAction())); 330 menu.add(new JMenuItem(new GpxExportAction(this))); 331 menu.addSeparator(); 332 menu.add(new LayerListPopup.InfoAction(this)); 333 } 321 334 } -
src/org/openstreetmap/josm/gui/layer/RawGpsDataLayer.java
r78 r86 4 4 import java.awt.Graphics; 5 5 import java.awt.Point; 6 import java.awt.event.ActionEvent; 7 import java.awt.event.ActionListener; 6 8 import java.util.Collection; 7 9 8 10 import javax.swing.Icon; 11 import javax.swing.JColorChooser; 12 import javax.swing.JMenuItem; 13 import javax.swing.JOptionPane; 14 import javax.swing.JPopupMenu; 9 15 10 16 import org.openstreetmap.josm.Main; 17 import org.openstreetmap.josm.actions.GpxExportAction; 11 18 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 12 19 import org.openstreetmap.josm.data.coor.EastNorth; … … 14 21 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 15 22 import org.openstreetmap.josm.gui.MapView; 23 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 16 24 import org.openstreetmap.josm.tools.ColorHelper; 17 25 import org.openstreetmap.josm.tools.ImageProvider; … … 57 65 * Return a static icon. 58 66 */ 59 @Override 60 public Icon getIcon() { 67 @Override public Icon getIcon() { 61 68 if (icon == null) 62 69 icon = ImageProvider.get("layer", "rawgps"); … … 64 71 } 65 72 66 @Override 67 public void paint(Graphics g, MapView mv) { 73 @Override public void paint(Graphics g, MapView mv) { 68 74 String gpsCol = Main.pref.get("color.gps point"); 69 75 String gpsColSpecial = Main.pref.get("color.layer "+name); … … 89 95 } 90 96 91 @Override 92 public String getToolTipText() { 97 @Override public String getToolTipText() { 93 98 int points = 0; 94 99 for (Collection<GpsPoint> c : data) … … 97 102 } 98 103 99 @Override 100 public void mergeFrom(Layer from) { 104 @Override public void mergeFrom(Layer from) { 101 105 RawGpsDataLayer layer = (RawGpsDataLayer)from; 102 106 data.addAll(layer.data); 103 107 } 104 108 105 @Override 106 public boolean isMergable(Layer other) { 109 @Override public boolean isMergable(Layer other) { 107 110 return other instanceof RawGpsDataLayer; 108 111 } 109 112 110 @Override 111 public void visitBoundingBox(BoundingXYVisitor v) { 113 @Override public void visitBoundingBox(BoundingXYVisitor v) { 112 114 for (Collection<GpsPoint> c : data) 113 115 for (GpsPoint p : c) … … 115 117 } 116 118 117 @Override 118 public Object getInfoComponent() { 119 @Override public Object getInfoComponent() { 119 120 StringBuilder b = new StringBuilder(); 120 121 int points = 0; … … 126 127 return "<html>"+name+" consists of "+data.size()+" tracks ("+points+" points)<br>"+b.toString(); 127 128 } 129 130 @Override public void addMenuEntries(JPopupMenu menu) { 131 menu.add(new JMenuItem(new GpxExportAction(this))); 132 133 JMenuItem color = new JMenuItem("Customize Color", ImageProvider.get("colorchooser")); 134 color.addActionListener(new ActionListener(){ 135 public void actionPerformed(ActionEvent e) { 136 String col = Main.pref.get("color.layer "+name, Main.pref.get("color.gps point", ColorHelper.color2html(Color.gray))); 137 JColorChooser c = new JColorChooser(ColorHelper.html2color(col)); 138 Object[] options = new Object[]{"OK", "Cancel", "Default"}; 139 int answer = JOptionPane.showOptionDialog(Main.main, c, "Choose a color", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); 140 switch (answer) { 141 case 0: 142 Main.pref.put("color.layer "+name, ColorHelper.color2html(c.getColor())); 143 break; 144 case 1: 145 return; 146 case 2: 147 Main.pref.put("color.layer "+name, null); 148 break; 149 } 150 Main.main.repaint(); 151 } 152 }); 153 menu.add(color); 154 155 menu.addSeparator(); 156 menu.add(new LayerListPopup.InfoAction(this)); 157 } 128 158 } -
src/org/openstreetmap/josm/gui/layer/WmsServerLayer.java
r79 r86 6 6 7 7 import javax.swing.Icon; 8 import javax.swing.JPopupMenu; 8 9 9 10 import org.openstreetmap.josm.Main; … … 13 14 import org.openstreetmap.josm.data.projection.Projection; 14 15 import org.openstreetmap.josm.gui.MapView; 16 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 15 17 import org.openstreetmap.josm.tools.ImageProvider; 16 18 import org.openstreetmap.josm.tools.TileCache; … … 43 45 } 44 46 45 @Override 46 public Icon getIcon() { 47 @Override public Icon getIcon() { 47 48 return icon; 48 49 } 49 50 50 @Override 51 public String getToolTipText() { 51 @Override public String getToolTipText() { 52 52 return "WMS layer: "+url; 53 53 } 54 54 55 @Override 56 public boolean isMergable(Layer other) { 55 @Override public boolean isMergable(Layer other) { 57 56 return false; 58 57 } 59 58 60 @Override 61 public void mergeFrom(Layer from) { 59 @Override public void mergeFrom(Layer from) { 62 60 } 63 61 64 @Override 65 public void paint(Graphics g, final MapView mv) { 62 @Override public void paint(Graphics g, final MapView mv) { 66 63 // EastNorth max = mv.getEastNorth(mv.getWidth(),0); 67 64 // EastNorth min = mv.getEastNorth(0,mv.getHeight()); … … 90 87 } 91 88 92 @Override 93 public void visitBoundingBox(BoundingXYVisitor v) { 89 @Override public void visitBoundingBox(BoundingXYVisitor v) { 94 90 // doesn't have a bounding box 95 91 } 96 92 97 @Override 98 public Object getInfoComponent() { 93 @Override public Object getInfoComponent() { 99 94 return getToolTipText(); 100 95 } 96 97 @Override public void addMenuEntries(JPopupMenu menu) { 98 menu.addSeparator(); 99 menu.add(new LayerListPopup.InfoAction(this)); 100 } 101 101 } -
src/org/openstreetmap/josm/io/GpxReader.java
r80 r86 15 15 import org.openstreetmap.josm.data.coor.LatLon; 16 16 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.data.osm. LineSegment;17 import org.openstreetmap.josm.data.osm.Segment; 18 18 import org.openstreetmap.josm.data.osm.Node; 19 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 104 104 } 105 105 106 // read ways (and linesegments)106 // read ways (and segments) 107 107 for (Object wayElement : e.getChildren("trk", GPX)) 108 108 parseWay((Element)wayElement, data); … … 114 114 115 115 // clean up the data a bit (remove broken stuff) 116 // remove linesegments with from==to117 for (Iterator< LineSegment> it = data.lineSegments.iterator(); it.hasNext();) {118 LineSegment ls = it.next();116 // remove segments with from==to 117 for (Iterator<Segment> it = data.segments.iterator(); it.hasNext();) { 118 Segment ls = it.next(); 119 119 if (ls.from.equals(ls.to)) { 120 120 it.remove(); … … 123 123 } 124 124 } 125 // remove double linesegments (remove only subsequent doubles yet)125 // remove double segments (remove only subsequent doubles yet) 126 126 for (Iterator<Way> it = data.ways.iterator(); it.hasNext();) { 127 LineSegment ls = null;128 for (Iterator< LineSegment> its = it.next().segments.iterator(); its.hasNext();) {129 LineSegment cur = its.next();127 Segment ls = null; 128 for (Iterator<Segment> its = it.next().segments.iterator(); its.hasNext();) { 129 Segment cur = its.next(); 130 130 if (ls != null && ls.equals(cur)) 131 131 its.remove(); … … 150 150 private void parseWay(Element e, DataSet ds) { 151 151 Way way = new Way(); 152 boolean real LineSegment = false; // is this way just a fake?152 boolean realSegment = false; // is this way just a fake? 153 153 154 154 for (Object o : e.getChildren()) { … … 162 162 start = node; 163 163 else { 164 LineSegment lineSegment = new LineSegment(start, node);165 parseKeyValueExtensions( lineSegment, child.getChild("extensions", GPX));166 lineSegment = (LineSegment)getNewIfSeenBefore(lineSegment);167 way.segments.add( lineSegment);164 Segment segment = new Segment(start, node); 165 parseKeyValueExtensions(segment, child.getChild("extensions", GPX)); 166 segment = (Segment)getNewIfSeenBefore(segment); 167 way.segments.add(segment); 168 168 start = node; 169 169 } … … 172 172 parseKeyValueExtensions(way, child); 173 173 if (child.getChild("segment", JOSM) != null) 174 real LineSegment = true;174 realSegment = true; 175 175 } else if (child.getName().equals("link")) 176 176 parseKeyValueLink(way, child); … … 179 179 } 180 180 way = (Way)getNewIfSeenBefore(way); 181 ds. lineSegments.addAll(way.segments);182 if (!real LineSegment)181 ds.segments.addAll(way.segments); 182 if (!realSegment) 183 183 ds.ways.add(way); 184 184 } … … 240 240 newCreatedPrimitives.put(osm.id, osm); 241 241 osm.modified = e.getChild("modified", JOSM) != null; 242 osm.setDeleted(e.getChild("deleted", JOSM) != null); 243 osm.modifiedProperties = e.getChild("modifiedProperties", JOSM) != null; 242 osm.delete(e.getChild("deleted", JOSM) != null); 244 243 } 245 244 } -
src/org/openstreetmap/josm/io/GpxWriter.java
r79 r86 19 19 import org.openstreetmap.josm.data.coor.LatLon; 20 20 import org.openstreetmap.josm.data.osm.DataSet; 21 import org.openstreetmap.josm.data.osm. LineSegment;21 import org.openstreetmap.josm.data.osm.Segment; 22 22 import org.openstreetmap.josm.data.osm.Node; 23 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 108 108 // for getting all unreferenced waypoints in the wpt-list 109 109 LinkedList<Node> unrefNodes = new LinkedList<Node>(ds.nodes); 110 // for getting all unreferenced linesegments111 LinkedList< LineSegment> unrefLs = new LinkedList<LineSegment>(ds.lineSegments);110 // for getting all unreferenced segments 111 LinkedList<Segment> unrefLs = new LinkedList<Segment>(ds.segments); 112 112 113 113 // ways 114 114 for (Way t : ds.ways) { 115 if (t. isDeleted()&& t.id == 0)115 if (t.deleted && t.id == 0) 116 116 continue; 117 117 Element tElem = new Element("trk", GPX); … … 129 129 addPropertyExtensions(tElem, keys, t); 130 130 131 // linesegments132 for ( LineSegment ls : t.segments) {133 tElem.getChildren().add(parse LineSegment(ls));131 // segments 132 for (Segment ls : t.segments) { 133 tElem.getChildren().add(parseSegment(ls)); 134 134 unrefNodes.remove(ls.from); 135 135 unrefNodes.remove(ls.to); … … 140 140 } 141 141 142 // encode pending linesegments as ways143 for ( LineSegment ls : unrefLs) {144 if (ls. isDeleted()&& ls.id == 0)142 // encode pending segments as ways 143 for (Segment ls : unrefLs) { 144 if (ls.deleted && ls.id == 0) 145 145 continue; 146 146 Element t = new Element("trk", GPX); 147 t.getChildren().add(parse LineSegment(ls));147 t.getChildren().add(parseSegment(ls)); 148 148 unrefNodes.remove(ls.from); 149 149 unrefNodes.remove(ls.to); … … 156 156 // waypoints (missing nodes) 157 157 for (Node n : unrefNodes) { 158 if (n. isDeleted()&& n.id == 0)158 if (n.deleted && n.id == 0) 159 159 continue; 160 160 e.getChildren().add(parseWaypoint(n, "wpt")); … … 179 179 180 180 /** 181 * Parse a linesegment and store it into a JDOM-Element. Return that element.181 * Parse a segment and store it into a JDOM-Element. Return that element. 182 182 */ 183 183 @SuppressWarnings("unchecked") 184 private Element parse LineSegment(LineSegment ls) {184 private Element parseSegment(Segment ls) { 185 185 Element lsElem = new Element("trkseg", GPX); 186 186 addPropertyExtensions(lsElem, ls.keys, ls); … … 306 306 extensions.add(modElement); 307 307 } 308 if (osm. isDeleted()) {308 if (osm.deleted) { 309 309 Element modElement = new Element("deleted", JOSM); 310 extensions.add(modElement);311 }312 if (osm.modifiedProperties) {313 Element modElement = new Element("modifiedProperties", JOSM);314 310 extensions.add(modElement); 315 311 } … … 355 351 356 352 /** 357 * Export the dataset to gpx. Only the physical linesegment structure is353 * Export the dataset to gpx. Only the physical segment structure is 358 354 * exported. To do this, the list of ways is processed. If a way span a 359 * sequence of linesegments, this is added as one trkseg.360 * Then, all remaining linesegments are added in one extra trk. Finally,355 * sequence of segments, this is added as one trkseg. 356 * Then, all remaining segments are added in one extra trk. Finally, 361 357 * all remaining nodes are added as wpt. 362 358 */ … … 371 367 Bounds b = new Bounds(new LatLon(Double.MAX_VALUE, Double.MAX_VALUE), new LatLon(Double.MIN_VALUE, Double.MIN_VALUE)); 372 368 for (Node n : data.nodes) 373 if (!n. isDeleted())369 if (!n.deleted) 374 370 b.extend(n.coor); 375 371 out.println(" <bounds minlat='"+b.min.lat()+"' minlon='"+b.min.lon()+"' maxlat='"+b.max.lat()+"' maxlon='"+b.max.lon()+"' />"); … … 378 374 // add ways 379 375 for (Way w : data.ways) { 380 if (w. isDeleted())376 if (w.deleted) 381 377 continue; 382 378 out.println(" <trk>"); 383 LineSegment oldLs = null;384 for ( LineSegment ls : w.segments) {379 Segment oldLs = null; 380 for (Segment ls : w.segments) { 385 381 // end old segemnt, if no longer match a chain 386 382 if (oldLs != null && !oldLs.to.coor.equals(ls.from.coor)) { … … 408 404 } 409 405 410 // add remaining linesegments411 Collection< LineSegment> lineSegments = new LinkedList<LineSegment>();406 // add remaining segments 407 Collection<Segment> segments = new LinkedList<Segment>(); 412 408 for (OsmPrimitive osm : all) 413 if (osm instanceof LineSegment)414 lineSegments.add((LineSegment)osm);415 if (! lineSegments.isEmpty()) {409 if (osm instanceof Segment) 410 segments.add((Segment)osm); 411 if (!segments.isEmpty()) { 416 412 out.println(" <trk>"); 417 for ( LineSegment ls : lineSegments) {413 for (Segment ls : segments) { 418 414 out.println(" <trkseg>"); 419 415 outputNode(ls.from, false); -
src/org/openstreetmap/josm/io/OsmConnection.java
r75 r86 37 37 boolean cancelled = false; 38 38 39 @Override 40 protected PasswordAuthentication getPasswordAuthentication() { 39 @Override protected PasswordAuthentication getPasswordAuthentication() { 41 40 String username = Main.pref.get("osm-server.username"); 42 41 String password = Main.pref.get("osm-server.password"); -
src/org/openstreetmap/josm/io/OsmReader.java
r82 r86 11 11 import org.openstreetmap.josm.data.coor.LatLon; 12 12 import org.openstreetmap.josm.data.osm.DataSet; 13 import org.openstreetmap.josm.data.osm. LineSegment;13 import org.openstreetmap.josm.data.osm.Segment; 14 14 import org.openstreetmap.josm.data.osm.Node; 15 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 50 50 * All read segents so far. 51 51 */ 52 private Map<Long, LineSegment> lineSegments = new HashMap<Long, LineSegment>();52 private Map<Long, Segment> segments = new HashMap<Long, Segment>(); 53 53 54 54 /** … … 70 70 } 71 71 72 @Override 73 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 72 @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 74 73 try { 75 74 if (qName.equals("osm")) { … … 89 88 if (from == null || to == null) 90 89 throw new SAXException("Segment "+atts.getValue("id")+" is missing its nodes."); 91 current = new LineSegment(from, to);90 current = new Segment(from, to); 92 91 readCommon(atts); 93 lineSegments.put(current.id, (LineSegment)current);92 segments.put(current.id, (Segment)current); 94 93 } else if (qName.equals("way")) { 95 94 current = new Way(); … … 99 98 long id = getLong(atts, "id"); 100 99 if (id == 0) 101 throw new SAXException("Incomplete linesegment with id=0");102 LineSegment ls = lineSegments.get(id);100 throw new SAXException("Incomplete segment with id=0"); 101 Segment ls = segments.get(id); 103 102 if (ls == null) { 104 ls = new LineSegment(id); // incomplete line segment105 lineSegments.put(id, ls);103 ls = new Segment(id); // incomplete segment 104 segments.put(id, ls); 106 105 adder.visit(ls); 107 106 } … … 119 118 120 119 121 @Override 122 public void endElement(String namespaceURI, String localName, String qName) { 120 @Override public void endElement(String namespaceURI, String localName, String qName) { 123 121 if (qName.equals("node") || qName.equals("segment") || qName.equals("way") || qName.equals("area")) { 124 122 current.visit(adder); … … 138 136 try { 139 137 DateFormat df = new SimpleDateFormat("y-M-d H:m:s"); 140 current. lastModified= df.parse(time);138 current.timestamp = df.parse(time); 141 139 } catch (ParseException e) { 142 140 e.printStackTrace(); … … 146 144 147 145 String action = atts.getValue("action"); 148 if ("delete".equals(action)) 149 current.setDeleted(true); 150 else if ("modify".equals(action)) { 146 if (action == null) 147 return; 148 if (action.equals("delete")) 149 current.delete(true); 150 else if (action.startsWith("modify")) 151 151 current.modified = true; 152 current.modifiedProperties = true;153 } else if ("modify/object".equals(action))154 current.modified = true;155 else if ("modify/property".equals(action))156 current.modifiedProperties = true;157 152 } 158 153 -
src/org/openstreetmap/josm/io/OsmReaderOld.java
r71 r86 11 11 import org.openstreetmap.josm.data.coor.LatLon; 12 12 import org.openstreetmap.josm.data.osm.DataSet; 13 import org.openstreetmap.josm.data.osm. LineSegment;13 import org.openstreetmap.josm.data.osm.Segment; 14 14 import org.openstreetmap.josm.data.osm.Node; 15 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 80 80 return parseNode(e); 81 81 else if (e.getName().equals("segment")) 82 return parse LineSegment(e, data);82 return parseSegment(e, data); 83 83 else if (e.getName().equals("way")) 84 84 return parseWay(e, data); … … 115 115 116 116 /** 117 * Parse and return an linesegment. The node information of the "from" and117 * Parse and return an segment. The node information of the "from" and 118 118 * "to" attributes must already be in the dataset. 119 * @param e The linesegment element to parse.119 * @param e The segment element to parse. 120 120 * @param data The dataset to obtain the node information from. 121 * @return The parsed linesegment.121 * @return The parsed segment. 122 122 * @throws JDOMException In case of parsing errors. 123 123 */ 124 private LineSegment parseLineSegment(Element e, DataSet data) throws JDOMException {124 private Segment parseSegment(Element e, DataSet data) throws JDOMException { 125 125 long startId = Long.parseLong(e.getAttributeValue("from")); 126 126 long endId = Long.parseLong(e.getAttributeValue("to")); … … 135 135 if (start == null || end == null) 136 136 throw new JDOMException("The 'from' or 'to' object has not been transfered before."); 137 LineSegment ls = new LineSegment(start, end);137 Segment ls = new Segment(start, end); 138 138 parseCommon(ls, e); 139 139 return ls; … … 154 154 Element child = (Element)o; 155 155 long id = Long.parseLong(child.getAttributeValue("uid")); 156 LineSegment ls = findLineSegment(data.lineSegments, id);156 Segment ls = findSegment(data.segments, id); 157 157 way.segments.add(ls); 158 158 } … … 189 189 190 190 String action = e.getAttributeValue("action"); 191 if ("delete".equals(action)) 192 data.setDeleted(true); 193 else if ("modify".equals(action)) 194 data.modified = data.modifiedProperties = true; 195 else if ("modify/property".equals(action)) 196 data.modifiedProperties = true; 197 else if ("modify/object".equals(action)) 191 if (action == null) 192 return; 193 if (action.equals("delete")) 194 data.delete(true); 195 else if (action.startsWith("modify")) 198 196 data.modified = true; 199 197 } … … 218 216 if (osm.id == id) 219 217 return osm; 220 for (OsmPrimitive osm : data. lineSegments)218 for (OsmPrimitive osm : data.segments) 221 219 if (osm.id == id) 222 220 return osm; … … 230 228 * Search for a segment in a collection by comparing the id. 231 229 */ 232 private LineSegment findLineSegment(Collection<LineSegment> segments, long id) throws JDOMException {233 for ( LineSegment ls : segments)230 private Segment findSegment(Collection<Segment> segments, long id) throws JDOMException { 231 for (Segment ls : segments) 234 232 if (ls.id == id) 235 233 return ls; 236 throw new JDOMException("Unknown linesegment reference: "+id);234 throw new JDOMException("Unknown segment reference: "+id); 237 235 } 238 236 } -
src/org/openstreetmap/josm/io/OsmServerWriter.java
r84 r86 16 16 import org.jdom.JDOMException; 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.osm. LineSegment;18 import org.openstreetmap.josm.data.osm.Segment; 19 19 import org.openstreetmap.josm.data.osm.Node; 20 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 65 65 */ 66 66 public void visit(Node n) { 67 if (n.id == 0 && !n. isDeleted()&& n.get("created_by") == null) {67 if (n.id == 0 && !n.deleted && n.get("created_by") == null) { 68 68 n.put("created_by", "JOSM"); 69 69 sendRequest("PUT", "node", n, true); 70 } else if (n. isDeleted()) {70 } else if (n.deleted) { 71 71 sendRequest("DELETE", "node", n, false); 72 72 } else { … … 77 77 78 78 /** 79 * Upload a linesegment (without the nodes).79 * Upload a segment (without the nodes). 80 80 */ 81 public void visit( LineSegment ls) {82 if (ls.id == 0 && !ls. isDeleted()&& ls.get("created_by") == null) {81 public void visit(Segment ls) { 82 if (ls.id == 0 && !ls.deleted && ls.get("created_by") == null) { 83 83 ls.put("created_by", "JOSM"); 84 84 sendRequest("PUT", "segment", ls, true); 85 } else if (ls. isDeleted()) {85 } else if (ls.deleted) { 86 86 sendRequest("DELETE", "segment", ls, false); 87 87 } else { … … 92 92 93 93 /** 94 * Upload a whole way with the complete linesegment id list.94 * Upload a whole way with the complete segment id list. 95 95 */ 96 96 public void visit(Way w) { 97 if (w.id == 0 && !w. isDeleted()&& w.get("created_by") == null) {97 if (w.id == 0 && !w.deleted && w.get("created_by") == null) { 98 98 w.put("created_by", "JOSM"); 99 99 sendRequest("PUT", "way", w, true); 100 } else if (w. isDeleted()) {100 } else if (w.deleted) { 101 101 sendRequest("DELETE", "way", w, false); 102 102 } else { -
src/org/openstreetmap/josm/io/OsmWriter.java
r82 r86 8 8 9 9 import org.openstreetmap.josm.data.osm.DataSet; 10 import org.openstreetmap.josm.data.osm. LineSegment;10 import org.openstreetmap.josm.data.osm.Segment; 11 11 import org.openstreetmap.josm.data.osm.Node; 12 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 51 51 for (Node n : ds.nodes) 52 52 writer.visit(n); 53 for ( LineSegment ls : ds.lineSegments)53 for (Segment ls : ds.segments) 54 54 writer.visit(ls); 55 55 for (Way w : ds.ways) … … 80 80 } 81 81 82 public void visit( LineSegment ls) {82 public void visit(Segment ls) { 83 83 if (ls.incomplete) 84 return; // Do not write an incomplete linesegment84 return; // Do not write an incomplete segment 85 85 addCommon(ls, "segment"); 86 86 out.print(" from='"+getUsedId(ls.from)+"' to='"+getUsedId(ls.to)+"'"); … … 91 91 addCommon(w, "way"); 92 92 out.println(">"); 93 for ( LineSegment ls : w.segments)93 for (Segment ls : w.segments) 94 94 out.println(" <seg id='"+getUsedId(ls)+"' />"); 95 95 addTags(w, "way", false); … … 130 130 if (!osmConform) { 131 131 String action = null; 132 if (osm. isDeleted())132 if (osm.deleted) 133 133 action = "delete"; 134 else if (osm.modified && osm.modifiedProperties)134 else if (osm.modified) 135 135 action = "modify"; 136 else if (osm.modified && !osm.modifiedProperties)137 action = "modify/object";138 else if (!osm.modified && osm.modifiedProperties)139 action = "modify/property";140 136 if (action != null) 141 137 out.print(" action='"+action+"'"); 142 138 } 143 if (osm. lastModified!= null) {144 String time = new SimpleDateFormat("y-M-d H:m:s").format(osm. lastModified);139 if (osm.timestamp != null) { 140 String time = new SimpleDateFormat("y-M-d H:m:s").format(osm.timestamp); 145 141 out.print(" timestamp='"+time+"'"); 146 142 } -
src/org/openstreetmap/josm/test/GpxWriterTest.java
r71 r86 31 31 @Bug(47) 32 32 public void testDeleteNewDoesReallyRemove() throws JDOMException, IOException { 33 ds.ways.iterator().next(). setDeleted(true);33 ds.ways.iterator().next().delete(true); 34 34 root = reparse(); 35 35 assertEquals("way has vanished and 3 trk (segments) left", 3, root.getChildren("trk", GPX).size()); … … 77 77 78 78 79 @Override 80 protected void setUp() throws Exception { 79 @Override protected void setUp() throws Exception { 81 80 super.setUp(); 82 81 ds = DataSetTestCaseHelper.createCommon(); -
src/org/openstreetmap/josm/test/MergeVisitorTest.java
r71 r86 1 1 package org.openstreetmap.josm.test; 2 3 import java.util.Date; 2 4 3 5 import junit.framework.TestCase; … … 5 7 import org.openstreetmap.josm.data.coor.LatLon; 6 8 import org.openstreetmap.josm.data.osm.DataSet; 7 import org.openstreetmap.josm.data.osm.LineSegment;8 9 import org.openstreetmap.josm.data.osm.Node; 9 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 import org.openstreetmap.josm.data.osm.Segment; 10 12 import org.openstreetmap.josm.data.osm.visitor.MergeVisitor; 11 13 import org.openstreetmap.josm.test.framework.Bug; … … 15 17 16 18 19 private DataSet ds; 20 private Node dsNode; 21 private Node n; 22 private MergeVisitor v; 23 24 @Override protected void setUp() throws Exception { 25 ds = new DataSet(); 26 dsNode = DataSetTestCaseHelper.createNode(ds); 27 v = new MergeVisitor(ds); 28 n = DataSetTestCaseHelper.createNode(null); 29 } 30 31 32 public void testNodesMergeUpdate() { 33 dsNode.id = 1; 34 n.id = 1; 35 n.timestamp = new Date(); 36 v.visit(n); 37 assertEquals(dsNode, n); 38 } 39 public void testNodesMergeModified() { 40 dsNode.id = 1; 41 n.id = 1; 42 n.modified = true; 43 v.visit(n); 44 assertEquals(dsNode, n); 45 } 46 public void testNodesConflictBothModified() { 47 n.modified = true; 48 dsNode.modified = true; 49 v.visit(n); 50 assertEquals(1, v.conflicts.size()); 51 assertFalse(n.equals(dsNode)); 52 } 53 public void testNodesConflict() { 54 dsNode.id = 1; 55 dsNode.timestamp = new Date(); 56 n.id = 1; 57 n.modified = true; 58 n.timestamp = new Date(dsNode.timestamp.getTime()-1); 59 v.visit(n); 60 assertEquals(1, v.conflicts.size()); 61 assertSame(dsNode, v.conflicts.keySet().iterator().next()); 62 assertSame(n, v.conflicts.values().iterator().next()); 63 } 64 public void testNodesConflict2() { 65 dsNode.id = 1; 66 dsNode.timestamp = new Date(); 67 dsNode.modified = true; 68 n.id = 1; 69 n.timestamp = new Date(dsNode.timestamp.getTime()+1); 70 v.visit(n); 71 assertEquals(1, v.conflicts.size()); 72 } 73 public void testNodesConflictModifyDelete() { 74 dsNode.id = 1; 75 dsNode.modified = true; 76 n.id = 1; 77 n.delete(true); 78 v.visit(n); 79 assertEquals(1, v.conflicts.size()); 80 } 81 public void testNodesMergeSamePosition() { 82 n.id = 1; // new node comes from server 83 dsNode.modified = true; // our node is modified 84 dsNode.coor = new LatLon(n.coor.lat(), n.coor.lon()); 85 v.visit(n); 86 v.fixReferences(); 87 assertEquals(0, v.conflicts.size()); 88 assertEquals(1, dsNode.id); 89 assertFalse("updating a new node clear the modified state", dsNode.modified); 90 } 91 92 public void testFixReferencesConflicts() { 93 // make two nodes mergable 94 dsNode.id = 1; 95 n.id = 1; 96 n.timestamp = new Date(); 97 // have an old segment with the old node 98 Segment sold = new Segment(dsNode, dsNode); 99 sold.id = 23; 100 sold.modified = true; 101 ds.segments.add(sold); 102 // have a conflicting segment point to the new node 103 Segment s = new Segment(n,n); 104 s.id = 23; 105 s.modified = true; 106 107 v.visit(n); // merge 108 assertEquals(n.timestamp, dsNode.timestamp); 109 v.visit(s); 110 v.fixReferences(); 111 assertSame(s.from, dsNode); 112 assertSame(s.to, dsNode); 113 } 114 115 public void testNoConflictForSame() { 116 dsNode.id = 1; 117 dsNode.modified = true; 118 n.cloneFrom(dsNode); 119 v.visit(n); 120 assertEquals(0, v.conflicts.size()); 121 } 122 17 123 /** 18 * Merge of an old linesegment with a new one. This should124 * Merge of an old segment with a new one. This should 19 125 * be mergable (if the nodes matches). 20 126 */ 21 public void testMergeOldLineSegmentsWithNew() { 22 DataSet ds = new DataSet(); 127 public void testMergeOldSegmentsWithNew() { 23 128 Node[] n = createNodes(ds, 2); 24 LineSegment ls1 = DataSetTestCaseHelper.createLineSegment(ds, n[0], n[1]);129 Segment ls1 = DataSetTestCaseHelper.createSegment(ds, n[0], n[1]); 25 130 ls1.id = 3; 26 131 27 132 Node newnode = new Node(new LatLon(n[1].coor.lat(), n[1].coor.lon())); 28 LineSegment newls = new LineSegment(n[0], newnode);133 Segment newls = new Segment(n[0], newnode); 29 134 30 MergeVisitor v = new MergeVisitor(ds);31 135 v.visit(newls); 32 assertEquals(" line segment should have been merged.", 1, ds.lineSegments.size());136 assertEquals("segment should have been merged.", 1, ds.segments.size()); 33 137 } 34 138 35 139 /** 36 * Nodes beeing merged are equal but notthe same.140 * Nodes beeing merged are equal but should be the same. 37 141 */ 38 142 @Bug(54) 39 143 public void testEqualNotSame() { 40 // create a dataset with line segment a-b41 DataSet ds = new DataSet();144 ds = new DataSet(); 145 // create a dataset with segment a-b 42 146 Node n[] = createNodes(ds, 2); 43 LineSegment ls1 = DataSetTestCaseHelper.createLineSegment(ds, n[0], n[1]);147 Segment ls1 = DataSetTestCaseHelper.createSegment(ds, n[0], n[1]); 44 148 ls1.id = 1; 45 46 // create an other dataset with linesegment a'-c (a' is equal, but not same to a)149 150 // create an other dataset with segment a'-c (a' is equal, but not same to a) 47 151 DataSet ds2 = new DataSet(); 48 152 Node n2[] = createNodes(ds2, 2); 49 153 n2[0].coor = new LatLon(n[0].coor.lat(), n[0].coor.lon()); 154 n2[0].id = 0; 50 155 n2[1].id = 42; 51 LineSegment ls2 = DataSetTestCaseHelper.createLineSegment(ds, n2[0], n2[1]); 52 53 MergeVisitorv = new MergeVisitor(ds);156 157 Segment ls2 = DataSetTestCaseHelper.createSegment(ds, n2[0], n2[1]); 158 v = new MergeVisitor(ds); 54 159 for (OsmPrimitive osm : ds2.allPrimitives()) 55 160 osm.visit(v); 56 161 v.fixReferences(); 57 162 58 163 assertSame(ls1.from, ls2.from); 59 164 } -
src/org/openstreetmap/josm/test/OsmWriterTest.java
r71 r86 14 14 import org.jdom.JDOMException; 15 15 import org.jdom.input.SAXBuilder; 16 import org.openstreetmap.josm.Main; 16 17 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.data.osm. LineSegment;18 import org.openstreetmap.josm.data.osm.Segment; 18 19 import org.openstreetmap.josm.data.osm.Node; 19 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 20 import org.openstreetmap.josm.data. osm.Way;21 import org.openstreetmap.josm.data.projection.Mercator; 21 22 import org.openstreetmap.josm.io.OsmWriter; 22 23 import org.openstreetmap.josm.test.framework.Bug; … … 34 35 private Node n4; 35 36 private Node n5; 36 private LineSegment ls1; 37 private LineSegment ls2; 38 private LineSegment ls3; 39 private Way w; 37 private Segment ls1; 38 private Segment ls2; 39 private Segment ls3; 40 40 41 41 private DataSet ds; 42 42 private Element osm; 43 43 private List<Element> nodes; 44 private List<Element> lineSegments;44 private List<Element> segments; 45 45 private List<Element> ways; 46 46 private StringWriter out; 47 47 48 public OsmWriterTest() { 49 Main.proj = new Mercator(); 50 } 48 51 49 52 public void testNode() throws Exception { … … 72 75 } 73 76 74 public void test LineSegment() throws Exception {77 public void testSegment() throws Exception { 75 78 ds = new DataSet(); 76 LineSegment ls = DataSetTestCaseHelper.createLineSegment(ds, DataSetTestCaseHelper.createNode(ds), DataSetTestCaseHelper.createNode(ds));79 Segment ls = DataSetTestCaseHelper.createSegment(ds, DataSetTestCaseHelper.createNode(ds), DataSetTestCaseHelper.createNode(ds)); 77 80 ls.put("foo", "bar"); 78 81 reparse(); 79 assertEquals(1, lineSegments.size());82 assertEquals(1, segments.size()); 80 83 assertEquals("foo", getAttr(osm.getChild("segment"), "tag", 0, "k")); 81 84 assertEquals("bar", getAttr(osm.getChild("segment"), "tag", 0, "v")); … … 94 97 ids.add(id); 95 98 } 96 assertEquals(nodes.size()+ lineSegments.size()+ways.size(), ids.size());99 assertEquals(nodes.size()+segments.size()+ways.size(), ids.size()); 97 100 } 98 101 … … 125 128 @Bug(47) 126 129 public void testDeleteNewDoesReallyRemove() throws Exception { 127 ds.ways.iterator().next(). setDeleted(true);130 ds.ways.iterator().next().delete(true); 128 131 reparse(); 129 132 //assertEquals(0, deleted.size()); … … 138 141 for (OsmPrimitive osm : ds.allPrimitives()) 139 142 osm.id = id++; // make all objects "old". 140 n1. setDeleted(true);143 n1.delete(true); 141 144 ls1.modified = true; 142 ls1.modifiedProperties = true;143 145 ls3.modified = true; 144 w.modifiedProperties = true;145 146 reparse(); 146 147 … … 156 157 boolean foundLs1 = false; 157 158 boolean foundLs3 = false; 158 for (Element lsElem : lineSegments) {159 for (Element lsElem : segments) { 159 160 String idStr = lsElem.getAttributeValue("id"); 160 161 String action = lsElem.getAttributeValue("action"); … … 163 164 foundLs1 = true; 164 165 } else if (idStr.equals(""+ls3.id)) { 165 assertEquals("Attribute action on modified/object data is ok", "modify /object", action);166 assertEquals("Attribute action on modified/object data is ok", "modify", action); 166 167 foundLs3 = true; 167 168 } 168 169 } 169 assertTrue("LineSegments found in output", foundLs1 && foundLs3); 170 170 assertTrue("Segments found in output", foundLs1 && foundLs3); 171 171 assertEquals("Way found in output", 1, ways.size()); 172 assertEquals("Attribute action on modifiedProperty data is ok", "modify/property", ways.get(0).getAttributeValue("action")); 173 } 174 175 @Override 176 protected void setUp() throws Exception { 172 } 173 174 @Override protected void setUp() throws Exception { 177 175 super.setUp(); 178 176 … … 184 182 n4 = DataSetTestCaseHelper.createNode(ds); 185 183 n5 = DataSetTestCaseHelper.createNode(ds); 186 ls1 = DataSetTestCaseHelper.create LineSegment(ds, n1, n2);187 ls2 = DataSetTestCaseHelper.create LineSegment(ds, n2, n3);188 ls3 = DataSetTestCaseHelper.create LineSegment(ds, n4, n5);189 w =DataSetTestCaseHelper.createWay(ds, ls1, ls2);184 ls1 = DataSetTestCaseHelper.createSegment(ds, n1, n2); 185 ls2 = DataSetTestCaseHelper.createSegment(ds, n2, n3); 186 ls3 = DataSetTestCaseHelper.createSegment(ds, n4, n5); 187 DataSetTestCaseHelper.createWay(ds, ls1, ls2); 190 188 191 189 reparse(); … … 211 209 osm = new SAXBuilder().build(new StringReader(out.toString())).getRootElement(); 212 210 nodes = osm.getChildren("node"); 213 lineSegments = osm.getChildren("segment");211 segments = osm.getChildren("segment"); 214 212 ways = osm.getChildren("way"); 215 213 } -
src/org/openstreetmap/josm/test/framework/DataSetTestCaseHelper.java
r71 r86 3 3 import java.util.Arrays; 4 4 5 import org.openstreetmap.josm.Main; 5 6 import org.openstreetmap.josm.data.coor.LatLon; 6 7 import org.openstreetmap.josm.data.osm.DataSet; 7 import org.openstreetmap.josm.data.osm. LineSegment;8 import org.openstreetmap.josm.data.osm.Segment; 8 9 import org.openstreetmap.josm.data.osm.Node; 9 10 import org.openstreetmap.josm.data.osm.Way; 11 import org.openstreetmap.josm.data.projection.Mercator; 10 12 11 13 … … 32 34 Node n4 = createNode(ds); 33 35 Node n5 = createNode(ds); 34 LineSegment ls1 = createLineSegment(ds, n1, n2);35 LineSegment ls2 = createLineSegment(ds, n2, n3);36 create LineSegment(ds, n4, n5);36 Segment ls1 = createSegment(ds, n1, n2); 37 Segment ls2 = createSegment(ds, n2, n3); 38 createSegment(ds, n4, n5); 37 39 createWay(ds, ls1, ls2); 38 40 return ds; 39 41 } 40 42 41 public static Way createWay(DataSet ds, LineSegment... lineSegments) {43 public static Way createWay(DataSet ds, Segment... segments) { 42 44 Way t = new Way(); 43 t.segments.addAll(Arrays.asList( lineSegments));45 t.segments.addAll(Arrays.asList(segments)); 44 46 ds.ways.add(t); 45 47 return t; … … 47 49 48 50 /** 49 * Create a linesegment with out of the given nodes.51 * Create a segment with out of the given nodes. 50 52 */ 51 public static LineSegment createLineSegment(DataSet ds, Node n1, Node n2) {52 LineSegment ls = new LineSegment(n1, n2);53 ds. lineSegments.add(ls);53 public static Segment createSegment(DataSet ds, Node n1, Node n2) { 54 Segment ls = new Segment(n1, n2); 55 ds.segments.add(ls); 54 56 return ls; 55 57 } … … 59 61 */ 60 62 public static Node createNode(DataSet ds) { 63 if (Main.proj == null) 64 Main.proj = new Mercator(); 61 65 Node node = new Node(new LatLon(Math.random(), Math.random())); 62 ds.nodes.add(node); 66 if (ds != null) 67 ds.nodes.add(node); 63 68 return node; 64 69 } -
src/org/openstreetmap/josm/tools/SearchCompiler.java
r70 r86 6 6 import java.util.Map.Entry; 7 7 8 import org.openstreetmap.josm.data.osm. LineSegment;8 import org.openstreetmap.josm.data.osm.Segment; 9 9 import org.openstreetmap.josm.data.osm.Node; 10 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 99 99 if (osm instanceof Node) 100 100 return type.equals("node"); 101 if (osm instanceof LineSegment)101 if (osm instanceof Segment) 102 102 return type.equals("segment"); 103 103 if (osm instanceof Way)
Note:
See TracChangeset
for help on using the changeset viewer.