Changeset 30 in josm
- Timestamp:
- 2005-12-03T14:14:35+01:00 (19 years ago)
- Files:
-
- 2 added
- 9 deleted
- 38 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r29 r30 20 20 import org.openstreetmap.josm.actions.PreferencesAction; 21 21 import org.openstreetmap.josm.actions.SaveAction; 22 import org.openstreetmap.josm.actions.SaveGpxAction;23 22 import org.openstreetmap.josm.actions.UndoAction; 24 23 import org.openstreetmap.josm.data.Preferences; … … 79 78 OpenAction openAction = new OpenAction(); 80 79 SaveAction saveAction = new SaveAction(); 81 SaveGpxAction saveGpxAction = new SaveGpxAction();82 80 ExitAction exitAction = new ExitAction(); 83 81 UndoAction undoAction = new UndoAction(); … … 93 91 fileMenu.add(openAction); 94 92 fileMenu.add(saveAction); 95 fileMenu.add(saveGpxAction);96 93 fileMenu.addSeparator(); 97 94 fileMenu.add(exitAction); … … 106 103 JMenu editMenu = new JMenu("Edit"); 107 104 editMenu.setMnemonic('E'); 108 //editMenu.add(undoAction);105 editMenu.add(undoAction); 109 106 editMenu.addSeparator(); 110 107 editMenu.add(preferencesAction); … … 123 120 toolBar.add(openAction); 124 121 toolBar.add(saveAction); 125 toolBar.add(saveGpxAction);126 122 toolBar.addSeparator(); 127 //toolBar.add(undoAction);123 toolBar.add(undoAction); 128 124 toolBar.addSeparator(); 129 125 toolBar.add(preferencesAction); -
src/org/openstreetmap/josm/actions/AboutAction.java
r27 r30 13 13 import java.util.regex.Pattern; 14 14 15 import javax.swing.AbstractAction;16 15 import javax.swing.JEditorPane; 17 16 import javax.swing.JLabel; … … 36 35 * @author imi 37 36 */ 38 public class AboutAction extends AbstractAction {37 public class AboutAction extends JosmAction { 39 38 40 39 public AboutAction() { 41 super("About", ImageProvider.get("about")); 42 putValue(MNEMONIC_KEY, KeyEvent.VK_A); 43 putValue(SHORT_DESCRIPTION, "Display the about screen."); 40 super("About", "about", "Display the about screen.", KeyEvent.VK_A, null); 44 41 } 45 42 -
src/org/openstreetmap/josm/actions/AutoScaleAction.java
r17 r30 4 4 import java.awt.event.KeyEvent; 5 5 6 import javax.swing.AbstractAction;7 import javax.swing.JComponent;8 import javax.swing.KeyStroke;9 10 import org.openstreetmap.josm.gui.ImageProvider;11 6 import org.openstreetmap.josm.gui.MapFrame; 12 7 import org.openstreetmap.josm.gui.MapView; … … 16 11 * @author imi 17 12 */ 18 public class AutoScaleAction extends AbstractAction {13 public class AutoScaleAction extends JosmAction { 19 14 /** 20 15 * The mapView this action operates on. … … 23 18 24 19 public AutoScaleAction(MapFrame mapFrame) { 25 super("Auto Scale", ImageProvider.get("autoscale")); 20 super("Auto Scale", "autoscale", "Zoom the view to show the whole layer. Disabled if the view is moved.", 21 KeyEvent.VK_A, null); 26 22 mapView = mapFrame.mapView; 27 putValue(MNEMONIC_KEY, KeyEvent.VK_A);28 putValue(SHORT_DESCRIPTION, "Zoom the view to show the whole layer. Disabled if the view is moved.");29 KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_A, 0);30 putValue(ACCELERATOR_KEY, ks);31 mapFrame.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ks, this);32 mapFrame.getActionMap().put(this, this);33 23 } 34 24 -
src/org/openstreetmap/josm/actions/ExitAction.java
r17 r30 3 3 import java.awt.event.ActionEvent; 4 4 import java.awt.event.KeyEvent; 5 6 import javax.swing.AbstractAction;7 8 import org.openstreetmap.josm.gui.ImageProvider;9 5 10 6 /** … … 13 9 * @author imi 14 10 */ 15 public class ExitAction extends AbstractAction {11 public class ExitAction extends JosmAction { 16 12 17 13 /** … … 19 15 */ 20 16 public ExitAction() { 21 super("Exit", ImageProvider.get("exit")); 22 putValue(MNEMONIC_KEY, KeyEvent.VK_X); 23 putValue(SHORT_DESCRIPTION, "Exit the application."); 17 super("Exit", "exit", "Exit the application.", KeyEvent.VK_X, null); 24 18 } 25 19 -
src/org/openstreetmap/josm/actions/OpenAction.java
r29 r30 10 10 import java.util.Collection; 11 11 12 import javax.swing.AbstractAction;13 12 import javax.swing.Box; 14 13 import javax.swing.JCheckBox; … … 24 23 import org.openstreetmap.josm.data.GeoPoint; 25 24 import org.openstreetmap.josm.data.osm.DataSet; 26 import org.openstreetmap.josm.data.osm.OsmPrimitive;27 25 import org.openstreetmap.josm.gui.GBC; 28 import org.openstreetmap.josm.gui.ImageProvider;29 26 import org.openstreetmap.josm.gui.MapFrame; 30 27 import org.openstreetmap.josm.gui.layer.Layer; … … 41 38 * @author imi 42 39 */ 43 public class OpenAction extends AbstractAction {40 public class OpenAction extends JosmAction { 44 41 45 42 /** … … 47 44 */ 48 45 public OpenAction() { 49 super("Open", ImageProvider.get("open")); 50 putValue(ACCELERATOR_KEY, KeyStroke.getAWTKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK)); 51 putValue(MNEMONIC_KEY, KeyEvent.VK_O); 52 putValue(SHORT_DESCRIPTION, "Open a file."); 46 super("Open", "open", "Open a file.", null, KeyStroke.getAWTKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK)); 53 47 } 54 48 … … 96 90 layer = new RawGpsDataLayer(data, filename.getName()); 97 91 } else { 98 DataSet dataSet = filename.getName().toLowerCase().endsWith(" gpx") ?92 DataSet dataSet = filename.getName().toLowerCase().endsWith(".gpx") ? 99 93 new GpxReader(new FileReader(filename)).parse() : 100 94 new OsmReader(new FileReader(filename)).parse(); 101 Collection<OsmPrimitive> l = Main.main.ds.mergeFrom(dataSet); 102 layer = new OsmDataLayer(l, filename.getName()); 95 layer = new OsmDataLayer(dataSet, filename.getName()); 103 96 } 104 97 -
src/org/openstreetmap/josm/actions/OpenOsmServerAction.java
r24 r30 5 5 import java.awt.event.ActionEvent; 6 6 import java.awt.event.ActionListener; 7 import java.awt.event.InputEvent; 7 8 import java.awt.event.KeyEvent; 8 9 import java.io.IOException; 9 import java.util.Collection;10 10 11 import javax.swing.AbstractAction;12 11 import javax.swing.DefaultListModel; 13 12 import javax.swing.JButton; … … 18 17 import javax.swing.JScrollPane; 19 18 import javax.swing.JTextField; 19 import javax.swing.KeyStroke; 20 20 import javax.swing.event.ListSelectionEvent; 21 21 import javax.swing.event.ListSelectionListener; … … 25 25 import org.openstreetmap.josm.data.GeoPoint; 26 26 import org.openstreetmap.josm.data.osm.DataSet; 27 import org.openstreetmap.josm.data.osm.OsmPrimitive;28 27 import org.openstreetmap.josm.gui.BookmarkList; 29 28 import org.openstreetmap.josm.gui.GBC; 30 import org.openstreetmap.josm.gui.ImageProvider;31 29 import org.openstreetmap.josm.gui.MapFrame; 32 30 import org.openstreetmap.josm.gui.MapView; … … 45 43 * @author imi 46 44 */ 47 public class OpenOsmServerAction extends AbstractAction {45 public class OpenOsmServerAction extends JosmAction { 48 46 49 47 JTextField[] latlon = new JTextField[]{ … … 55 53 56 54 public OpenOsmServerAction() { 57 super("Connect to OSM", ImageProvider.get("connectosm")); 58 putValue(MNEMONIC_KEY, KeyEvent.VK_C); 59 putValue(SHORT_DESCRIPTION, "Open a connection to the OSM server."); 55 super("Connect to OSM", "connectosm", "Open a connection to the OSM server.", KeyEvent.VK_C, 56 KeyStroke.getAWTKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); 60 57 } 61 58 … … 163 160 JOptionPane.showMessageDialog(Main.main, "No data imported."); 164 161 165 Collection<OsmPrimitive> data = Main.main.ds.mergeFrom(dataSet); 166 layer = new OsmDataLayer(data, name); 162 layer = new OsmDataLayer(dataSet, name); 167 163 } 168 164 -
src/org/openstreetmap/josm/actions/PreferencesAction.java
r24 r30 2 2 3 3 import java.awt.event.ActionEvent; 4 import java.awt.event.InputEvent;5 4 import java.awt.event.KeyEvent; 6 5 7 import javax.swing.AbstractAction;8 import javax.swing.KeyStroke;9 10 import org.openstreetmap.josm.gui.ImageProvider;11 6 import org.openstreetmap.josm.gui.PreferenceDialog; 12 7 … … 16 11 * @author imi 17 12 */ 18 public class PreferencesAction extends AbstractAction {13 public class PreferencesAction extends JosmAction { 19 14 20 15 /** … … 22 17 */ 23 18 public PreferencesAction() { 24 super("Preferences", ImageProvider.get("preference")); 25 putValue(ACCELERATOR_KEY, KeyStroke.getAWTKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_DOWN_MASK)); 26 putValue(MNEMONIC_KEY, KeyEvent.VK_P); 27 putValue(SHORT_DESCRIPTION, "Open a preferences page for global settings."); 19 super("Preferences", "preference", "Open a preferences page for global settings.", 20 KeyEvent.VK_P, null); 28 21 } 29 22 -
src/org/openstreetmap/josm/actions/SaveAction.java
r24 r30 8 8 import java.io.IOException; 9 9 10 import javax.swing.AbstractAction;11 10 import javax.swing.JFileChooser; 12 11 import javax.swing.JOptionPane; … … 15 14 16 15 import org.openstreetmap.josm.Main; 17 import org.openstreetmap.josm. gui.ImageProvider;16 import org.openstreetmap.josm.io.GpxWriter; 18 17 import org.openstreetmap.josm.io.OsmWriter; 19 18 … … 25 24 * @author imi 26 25 */ 27 public class SaveAction extends AbstractAction {26 public class SaveAction extends JosmAction { 28 27 29 28 /** … … 31 30 */ 32 31 public SaveAction() { 33 super("Save", ImageProvider.get("save")); 34 putValue(ACCELERATOR_KEY, KeyStroke.getAWTKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK)); 35 putValue(SHORT_DESCRIPTION, "Save the current data."); 32 super("Save", "save", "Save the current data.", null, KeyStroke.getAWTKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK)); 36 33 } 37 34 … … 46 43 public boolean accept(File f) { 47 44 String name = f.getName().toLowerCase(); 48 return f.isDirectory() || name.endsWith(".xml") ;45 return f.isDirectory() || name.endsWith(".xml") || name.endsWith(".gpx"); 49 46 } 50 47 @Override 51 48 public String getDescription() { 52 return " XML Files";49 return "GPX or XML Files"; 53 50 } 54 51 }); … … 60 57 try { 61 58 FileWriter fileWriter = new FileWriter(file); 62 OsmWriter out = new OsmWriter(fileWriter, Main.main.ds); 63 out.output(); 59 if (file.getName().endsWith(".gpx")) 60 new GpxWriter(fileWriter).output(); 61 else 62 new OsmWriter(fileWriter, Main.main.ds).output(); 64 63 fileWriter.close(); 65 64 } catch (IOException e) { -
src/org/openstreetmap/josm/actions/UndoAction.java
r29 r30 4 4 import java.awt.event.InputEvent; 5 5 import java.awt.event.KeyEvent; 6 import java.util.LinkedList;7 6 8 import javax.swing.AbstractAction;9 7 import javax.swing.KeyStroke; 10 8 11 9 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.command.Command;13 import org.openstreetmap.josm.gui.ImageProvider;14 10 15 11 … … 19 15 * @author imi 20 16 */ 21 public class UndoAction extends AbstractAction {17 public class UndoAction extends JosmAction { 22 18 23 19 /** … … 25 21 */ 26 22 public UndoAction() { 27 super("Undo", ImageProvider.get("undo")); 28 putValue(ACCELERATOR_KEY, KeyStroke.getAWTKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_DOWN_MASK)); 29 putValue(SHORT_DESCRIPTION, "Undo the last action."); 23 super("Undo", "undo", "Undo the last action.", null, KeyStroke.getAWTKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_DOWN_MASK)); 30 24 } 31 25 … … 33 27 if (Main.main.getMapFrame() == null) 34 28 return; 35 LinkedList<Command> commands = Main.main.getMapFrame().mapView.editLayer().commands;36 if (commands.isEmpty())37 return;38 Command c = commands.getLast();39 //c.undoCommand();40 commands.removeLast();41 29 Main.main.getMapFrame().repaint(); 30 Main.main.getMapFrame().mapView.editLayer().undo(); 42 31 } 43 32 } -
src/org/openstreetmap/josm/actions/mapmode/AddLineSegmentAction.java
r24 r30 4 4 import java.awt.Graphics; 5 5 import java.awt.Point; 6 import java.awt.event.ActionEvent; 6 7 import java.awt.event.KeyEvent; 7 8 import java.awt.event.MouseEvent; 8 9 import java.awt.event.MouseListener; 9 10 import javax.swing.JOptionPane;11 10 12 11 import org.openstreetmap.josm.Main; … … 15 14 import org.openstreetmap.josm.data.osm.Node; 16 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 import org.openstreetmap.josm.data.osm.Track;18 16 import org.openstreetmap.josm.gui.MapFrame; 19 17 … … 22 20 * starting node and dragging to the ending node. 23 21 * 24 * If the Alt key was pressed when releasing the mouse, this action tries to25 * add the line segment to a track. The new line segment gets added to all tracks26 * of the first node that end in the first node. If no tracks are found, the27 * line segment gets added to all tracks in the second node that start with28 * the second node.29 *30 22 * No line segment can be created if there is already a line segment containing 31 * both nodes in the same order.23 * both nodes. 32 24 * 33 25 * @author imi … … 72 64 } 73 65 66 67 @Override 68 public void actionPerformed(ActionEvent e) { 69 super.actionPerformed(e); 70 makeLineSegment(); 71 } 72 74 73 /** 75 74 * If user clicked on a node, start the dragging with that node. … … 108 107 109 108 /** 109 * If left button was released, try to create the line segment. 110 */ 111 @Override 112 public void mouseReleased(MouseEvent e) { 113 if (e.getButton() == MouseEvent.BUTTON1) { 114 makeLineSegment(); 115 first = null; // release line segment drawing 116 } 117 } 118 119 /** 110 120 * Create the line segment if first and second are different and there is 111 121 * not already a line segment. 112 122 */ 113 @Override 114 public void mouseReleased(MouseEvent e) { 115 if (e.getButton() != MouseEvent.BUTTON1) 116 return; 117 123 private void makeLineSegment() { 118 124 if (first == null || second == null) { 119 125 first = null; … … 126 132 Node start = first; 127 133 Node end = second; 128 first = null;134 first = second; 129 135 second = null; 130 136 131 137 if (start != end) { 132 138 // try to find a line segment 133 for (Track t : Main.main.ds.tracks) 134 for (LineSegment ls : t.segments) 135 if (start == ls.start && end == ls.end) { 136 JOptionPane.showMessageDialog(Main.main, "There is already an line segment with the same direction between the selected nodes."); 137 return; 138 } 139 for (LineSegment ls : Main.main.ds.lineSegments) 140 if ((start == ls.start && end == ls.end) || (end == ls.start && start == ls.end)) 141 return; // already a line segment here - be happy, do nothing. 139 142 140 143 LineSegment ls = new LineSegment(start, end); 141 mv.editLayer().add(new AddCommand( ls));144 mv.editLayer().add(new AddCommand(Main.main.ds, ls)); 142 145 } 143 146 144 147 mv.repaint(); 145 148 } -
src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java
r23 r30 4 4 import java.awt.event.MouseEvent; 5 5 6 import org.openstreetmap.josm.Main; 6 7 import org.openstreetmap.josm.command.AddCommand; 7 8 import org.openstreetmap.josm.data.osm.Node; … … 49 50 Node node = new Node(); 50 51 node.coor = mv.getPoint(e.getX(), e.getY(), true); 51 mv.editLayer().add(new AddCommand( node));52 mv.editLayer().add(new AddCommand(Main.main.ds, node)); 52 53 mv.repaint(); 53 54 } -
src/org/openstreetmap/josm/actions/mapmode/AddTrackAction.java
r23 r30 2 2 3 3 import java.awt.Rectangle; 4 import java.awt.event.ActionEvent; 4 5 import java.awt.event.KeyEvent; 5 6 import java.util.Collection; … … 61 62 } 62 63 64 65 @Override 66 public void actionPerformed(ActionEvent e) { 67 makeTrack(); 68 super.actionPerformed(e); 69 } 70 63 71 /** 64 72 * If Shift is pressed, only add the selected line segments to the selection. … … 90 98 return; // no new track yet. 91 99 100 makeTrack(); 101 } 102 103 /** 104 * Just make a track of all selected items. 105 */ 106 private void makeTrack() { 92 107 Collection<OsmPrimitive> selection = Main.main.ds.getSelected(); 93 108 if (selection.isEmpty()) … … 135 150 for (LineSegment ls : sortedLineSegments) 136 151 t.add(ls); 137 mv.editLayer().add(new AddCommand( t));152 mv.editLayer().add(new AddCommand(Main.main.ds, t)); 138 153 Main.main.ds.clearSelection(); 154 mv.repaint(); 139 155 } 140 156 } -
src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r23 r30 1 1 package org.openstreetmap.josm.actions.mapmode; 2 2 3 import java.awt.event.ActionEvent; 3 4 import java.awt.event.KeyEvent; 4 5 import java.awt.event.MouseEvent; 5 6 import java.util.ArrayList; 6 7 import java.util.Collection; 8 import java.util.HashSet; 9 import java.util.Iterator; 7 10 import java.util.LinkedList; 8 11 … … 12 15 import org.openstreetmap.josm.command.CombineAndDeleteCommand; 13 16 import org.openstreetmap.josm.command.DeleteCommand; 14 import org.openstreetmap.josm. command.CombineAndDeleteCommand.LineSegmentCombineEntry;17 import org.openstreetmap.josm.data.osm.DataSet; 15 18 import org.openstreetmap.josm.data.osm.LineSegment; 16 19 import org.openstreetmap.josm.data.osm.Node; … … 32 35 * tries to combine the referencing objects as follows: 33 36 * 34 * If a node is part of exactly two line segments from a track, the two line 35 * segments are combined into one. The first line segment spans now to the end 36 * of the second and the second line segment gets deleted. This is checked for 37 * every track. 38 * 39 * If a node is the end of the ending line segment of one track and the start of 40 * exactly one other tracks start segment, the tracks are combined into one track, 41 * deleting the second track and keeping the first one. The ending line segment 42 * of the fist track is combined with the starting line segment of the second 43 * track. 37 * If a node is part of exactly two line segments, the two line segments are 38 * combined into one. The first line segment spans now to the end of the 39 * second and the second line segment gets deleted. 44 40 * 45 41 * Combining is only possible, if both objects that should be combined have no … … 55 51 * 56 52 * If the user enters the mapmode and any object is selected, all selected 57 * objects get deleted. Combining applies to the selected objects.53 * objects that can be deleted will. Combining applies to the selected objects. 58 54 * 59 55 * @author imi … … 66 62 */ 67 63 public DeleteAction(MapFrame mapFrame) { 68 super("Delete", "delete", "Delete nodes, streets or areas.", KeyEvent.VK_D ELETE, mapFrame);64 super("Delete", "delete", "Delete nodes, streets or areas.", KeyEvent.VK_D, mapFrame); 69 65 } 70 66 … … 81 77 } 82 78 79 80 @Override 81 public void actionPerformed(ActionEvent e) { 82 super.actionPerformed(e); 83 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 84 Collection<OsmPrimitive> selection = Main.main.ds.getSelected(); 85 86 int selSize = 0; 87 // loop as long as the selection size changes 88 while(selSize != selection.size()) { 89 selSize = selection.size(); 90 91 for (Iterator<OsmPrimitive> it = selection.iterator(); it.hasNext();) { 92 OsmPrimitive osm = it.next(); 93 if (ctrl) { 94 deleteWithReferences(osm); 95 it.remove(); 96 } else { 97 if (delete(osm, false)) 98 it.remove(); 99 } 100 } 101 } 102 mv.repaint(); 103 } 104 83 105 /** 84 106 * If user clicked with the left button, delete the nearest object. … … 97 119 deleteWithReferences(sel); 98 120 else 99 delete(sel );121 delete(sel, true); 100 122 101 123 mv.repaint(); … … 124 146 * TODO If you delete x, then a,B,C and x gets deleted. A now consist of b only. 125 147 * If you delete a or b, then A, a, b and z gets deleted. 126 * 148 * 127 149 * @param osm The object to delete. 128 150 */ 129 151 private void deleteWithReferences(OsmPrimitive osm) { 130 // collect all tracks, areas and pendingline segments that should be deleted152 // collect all tracks, areas and line segments that should be deleted 131 153 ArrayList<Track> tracksToDelete = new ArrayList<Track>(); 132 154 ArrayList<LineSegment> lineSegmentsToDelete = new ArrayList<LineSegment>(); … … 138 160 if (ls.start == osm || ls.end == osm) 139 161 tracksToDelete.add(t); 140 for (LineSegment ls : Main.main.ds. pendingLineSegments)162 for (LineSegment ls : Main.main.ds.lineSegments) 141 163 if (ls.start == osm || ls.end == osm) 142 164 lineSegmentsToDelete.add(ls); … … 164 186 checkUnreferencing.add(ls.end); 165 187 } 166 188 167 189 Collection<OsmPrimitive> deleteData = new LinkedList<OsmPrimitive>(); 168 190 deleteData.addAll(tracksToDelete); … … 175 197 if (osm instanceof Node) 176 198 deleteData.add(osm); 177 178 mv.editLayer().add(new DeleteCommand( deleteData));199 200 mv.editLayer().add(new DeleteCommand(Main.main.ds, deleteData)); 179 201 } 180 202 … … 185 207 * 186 208 * @param osm The object to delete. 187 * /188 private void delete(OsmPrimitive osm) {189 if (osm instanceof Node && isReferenced((Node)osm)) {190 combineAndDelete((Node)osm);191 return;192 }209 * @param msgBox Whether a message box for errors should be shown 210 * @return <code>true</code> if the object could be deleted 211 */ 212 private boolean delete(OsmPrimitive osm, boolean msgBox) { 213 if (osm instanceof Node && isReferenced((Node)osm)) 214 return combineAndDelete((Node)osm, msgBox); 193 215 Collection<OsmPrimitive> c = new LinkedList<OsmPrimitive>(); 194 216 c.add(osm); 195 mv.editLayer().add(new DeleteCommand(c)); 217 mv.editLayer().add(new DeleteCommand(Main.main.ds, c)); 218 return true; 196 219 } 197 220 … … 203 226 */ 204 227 private boolean isReferenced(Node n) { 205 for (Track t : Main.main.ds.tracks) 206 for (LineSegment ls : t.segments) 207 if (ls.start == n || ls.end == n) 208 return true; 209 for (LineSegment ls : Main.main.ds.pendingLineSegments) 228 for (LineSegment ls : Main.main.ds.lineSegments) 210 229 if (ls.start == n || ls.end == n) 211 230 return true; … … 220 239 * 221 240 * @param n The node that is going to be deleted. 222 * @return <code>null</code> if combining suceded or an error string if there 223 * are problems combining the node. 224 */ 225 private void combineAndDelete(Node n) { 226 // first, check for pending line segments 227 for (LineSegment ls : Main.main.ds.pendingLineSegments) 228 if (n == ls.start || n == ls.end) { 229 JOptionPane.showMessageDialog(Main.main, "Node used by a line segment which is not part of any track. Remove this first."); 230 return; 231 } 232 233 // These line segments must be combined within the track combining 234 ArrayList<LineSegment> pendingLineSegmentsForTrack = new ArrayList<LineSegment>(); 235 236 // try to combine line segments 237 238 // These line segments are combinable. The inner arraylist has always 239 // two elements. The keys maps to the track, the line segments are in. 240 Collection<LineSegmentCombineEntry> lineSegments = new ArrayList<LineSegmentCombineEntry>(); 241 242 for (Track t : Main.main.ds.tracks) { 243 ArrayList<LineSegment> current = new ArrayList<LineSegment>(); 244 for (LineSegment ls : t.segments) 245 if (ls.start == n || ls.end == n) 246 current.add(ls); 247 if (!current.isEmpty()) { 248 if (current.size() > 2) { 249 JOptionPane.showMessageDialog(Main.main, "Node used by more than two line segments."); 250 return; 251 } 252 if (current.size() == 1 && 253 (current.get(0) == t.getStartingSegment() || current.get(0) == t.getEndingSegment())) 254 pendingLineSegmentsForTrack.add(current.get(0)); 255 else if (current.get(0).end != current.get(1).start && 256 current.get(1).end != current.get(0).start) { 257 JOptionPane.showMessageDialog(Main.main, "Node used by line segments that points together."); 258 return; 259 } else if (!current.get(0).keyPropertiesMergable(current.get(1))) { 260 JOptionPane.showMessageDialog(Main.main, "Node used by line segments with different properties."); 261 return; 262 } else { 263 LineSegmentCombineEntry e = new LineSegmentCombineEntry(); 264 e.first = current.get(0); 265 e.second = current.get(1); 266 e.track = t; 267 lineSegments.add(e); 268 } 269 } 270 } 271 272 // try to combine tracks 273 ArrayList<Track> tracks = new ArrayList<Track>(); 274 for (Track t : Main.main.ds.tracks) 275 if (t.getStartingNode() == n || t.getEndingNode() == n) 276 tracks.add(t); 277 if (!tracks.isEmpty()) { 278 if (tracks.size() > 2) { 279 JOptionPane.showMessageDialog(Main.main, "Node used by more than two tracks."); 280 return; 281 } 282 if (tracks.size() == 1) { 283 JOptionPane.showMessageDialog(Main.main, "Node used by a track."); 284 return; 285 } 286 Track t1 = tracks.get(0); 287 Track t2 = tracks.get(1); 288 if (t1.getStartingNode() != t2.getEndingNode() && 289 t2.getStartingNode() != t1.getEndingNode()) { 290 if (t1.getStartingNode() == t2.getStartingNode() || 291 t1.getEndingNode() == t2.getEndingNode()) { 292 JOptionPane.showMessageDialog(Main.main, "Node used by tracks that point together."); 293 return; 294 } 295 JOptionPane.showMessageDialog(Main.main, "Node used by tracks that cannot be combined."); 296 return; 297 } 298 if (!t1.keyPropertiesMergable(t2)) { 299 JOptionPane.showMessageDialog(Main.main, "Node used by tracks with different properties."); 300 return; 301 } 302 } 303 304 // try to match the pending line segments 305 if (pendingLineSegmentsForTrack.size() == 2) { 306 LineSegment l1 = pendingLineSegmentsForTrack.get(0); 307 LineSegment l2 = pendingLineSegmentsForTrack.get(1); 308 if (l1.start == l2.start || l1.end == l2.end) { 309 JOptionPane.showMessageDialog(Main.main, "Node used by line segments that points together."); 310 return; 311 } 312 if (l1.start == l2.end || l2.start == l1.end) 313 pendingLineSegmentsForTrack.clear(); // resolved. 314 } 315 316 // still pending line segments? 317 if (!pendingLineSegmentsForTrack.isEmpty()) { 318 JOptionPane.showMessageDialog(Main.main, "Node used by tracks that cannot be combined."); 319 return; 241 * @param msgBox Whether a message box should be displayed in case of problems 242 * @return <code>true</code> if combining suceded. 243 */ 244 private boolean combineAndDelete(Node n, boolean msgBox) { 245 DataSet ds = Main.main.ds; 246 Collection<LineSegment> lineSegmentsUsed = new HashSet<LineSegment>(); 247 for (LineSegment ls : ds.lineSegments) 248 if (ls.start == n || ls.end == n) 249 lineSegmentsUsed.add(ls); 250 251 if (lineSegmentsUsed.isEmpty()) 252 // should not be called 253 throw new IllegalStateException(); 254 255 if (lineSegmentsUsed.size() == 1) { 256 if (msgBox) 257 JOptionPane.showMessageDialog(Main.main, "Node used by a line segment. Delete this first."); 258 return false; 259 } 260 261 if (lineSegmentsUsed.size() > 2) { 262 if (msgBox) 263 JOptionPane.showMessageDialog(Main.main, "Node used by more than two line segments. Delete them first."); 264 return false; 265 } 266 267 Iterator<LineSegment> it = lineSegmentsUsed.iterator(); 268 LineSegment first = it.next(); 269 LineSegment second = it.next(); 270 271 // wrong direction? 272 if (first.start == second.end) { 273 LineSegment t = first; 274 first = second; 275 second = t; 276 } 277 278 // combinable? 279 if (first.end != second.start || !first.end.keyPropertiesMergable(second.start)) { 280 if (msgBox) 281 JOptionPane.showMessageDialog(Main.main, "Node used by line segments that cannot be combined."); 282 return false; 320 283 } 321 284 322 285 // Ok, we can combine. Do it. 323 Track firstTrack = tracks.isEmpty() ? null : tracks.get(0); 324 Track secondTrack = tracks.isEmpty() ? null : tracks.get(1); 325 mv.editLayer().add(new CombineAndDeleteCommand(n, lineSegments, firstTrack, secondTrack)); 286 mv.editLayer().add(new CombineAndDeleteCommand(ds, first, second)); 287 return true; 326 288 } 327 289 } -
src/org/openstreetmap/josm/actions/mapmode/MapMode.java
r23 r30 6 6 import java.awt.event.MouseMotionListener; 7 7 8 import javax.swing.AbstractAction; 9 import javax.swing.JComponent; 10 import javax.swing.KeyStroke; 11 12 import org.openstreetmap.josm.gui.ImageProvider; 8 import org.openstreetmap.josm.actions.JosmAction; 13 9 import org.openstreetmap.josm.gui.MapFrame; 14 10 import org.openstreetmap.josm.gui.MapView; … … 22 18 * control. 23 19 */ 24 abstract public class MapMode extends AbstractAction implements MouseListener, MouseMotionListener {20 abstract public class MapMode extends JosmAction implements MouseListener, MouseMotionListener { 25 21 26 22 /** … … 40 36 */ 41 37 public MapMode(String name, String iconName, String tooltip, int mnemonic, MapFrame mapFrame) { 42 super(name, ImageProvider.get("mapmode", iconName)); 43 putValue(MNEMONIC_KEY, mnemonic); 44 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(mnemonic,0)); 45 putValue(LONG_DESCRIPTION, tooltip); 46 mapFrame.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(mnemonic,0), this); 47 mapFrame.getActionMap().put(this, this); 38 super(name, "mapmode/"+iconName, tooltip, mnemonic, null); 48 39 this.mapFrame = mapFrame; 49 40 mv = mapFrame.mapView; -
src/org/openstreetmap/josm/command/AddCommand.java
r23 r30 3 3 import java.awt.Component; 4 4 import java.util.Collection; 5 import java.util.Iterator;6 5 7 6 import javax.swing.JLabel; 8 7 9 import org.openstreetmap.josm. Main;8 import org.openstreetmap.josm.data.osm.DataSet; 10 9 import org.openstreetmap.josm.data.osm.Key; 11 10 import org.openstreetmap.josm.data.osm.LineSegment; … … 22 21 * @author imi 23 22 */ 24 public class AddCommand implements Command , Visitor{23 public class AddCommand implements Command { 25 24 25 /** 26 * The dataset this command operates on. 27 */ 28 DataSet ds; 29 30 /** 31 * Helper that adds the object 32 * @author imi 33 */ 34 private final class AddVisitor implements Visitor { 35 public void visit(Node n) {ds.nodes.add(n);} 36 public void visit(LineSegment ls) {ds.lineSegments.add(ls);} 37 public void visit(Track t) {ds.tracks.add(t);} 38 public void visit(Key k) {throw new IllegalStateException("Keys are added by using ChangeKeyValueCommand");} 39 } 40 41 /** 42 * Helper that deletes the object (for undo) 43 * @author imi 44 */ 45 private final class RemoveVisitor implements Visitor { 46 public void visit(Node n) {ds.nodes.remove(n);} 47 public void visit(LineSegment ls) {ds.lineSegments.remove(ls);} 48 public void visit(Track t) {ds.tracks.remove(t);} 49 public void visit(Key k) {throw new IllegalStateException("Keys are added by using ChangeKeyValueCommand");} 50 } 51 26 52 /** 27 53 * The primitive to add to the dataset. … … 32 58 * Create the command and specify the element to add. 33 59 */ 34 public AddCommand(OsmPrimitive osm) { 60 public AddCommand(DataSet ds, OsmPrimitive osm) { 61 this.ds = ds; 35 62 this.osm = osm; 36 63 } 37 64 38 65 public void executeCommand() { 39 osm.visit( this);66 osm.visit(new AddVisitor()); 40 67 } 41 68 69 public void undoCommand() { 70 osm.visit(new RemoveVisitor()); 71 } 72 42 73 public Component commandDescription() { 43 74 SelectionComponentVisitor v = new SelectionComponentVisitor(); … … 47 78 48 79 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 49 if (added != null && !added.contains(osm)) 50 added.add(osm); 51 } 52 53 /** 54 * Add the node to the nodes - list only. 55 * @param n The node to add. 56 */ 57 public void visit(Node n) { 58 Main.main.ds.nodes.add(n); 59 } 60 61 /** 62 * Add the line segment to the list of pending line segments. 63 * @param ls The line segment to add. 64 */ 65 public void visit(LineSegment ls) { 66 Main.main.ds.pendingLineSegments.add(ls); 67 Main.main.ds.addBackReference(ls.start, ls); 68 Main.main.ds.addBackReference(ls.end, ls); 69 } 70 71 /** 72 * Add the track to the dataset. Remove all line segments that were pending 73 * from the dataset. 74 */ 75 public void visit(Track t) { 76 Main.main.ds.tracks.add(t); 77 for (Iterator<LineSegment> it = Main.main.ds.pendingLineSegments.iterator(); it.hasNext();) 78 if (t.segments.contains(it.next())) 79 it.remove(); 80 for (LineSegment ls : t.segments) { 81 Main.main.ds.addBackReference(ls, t); 82 Main.main.ds.addBackReference(ls.start, t); 83 Main.main.ds.addBackReference(ls.end, t); 84 } 85 } 86 87 /** 88 * Add the key to the parent specified by the constructor 89 */ 90 public void visit(Key k) { 91 throw new IllegalStateException("Keys are added by using ChangeKeyValueCommand"); 80 added.add(osm); 92 81 } 93 82 } -
src/org/openstreetmap/josm/command/ChangeKeyValueCommand.java
r24 r30 4 4 import java.util.Collection; 5 5 import java.util.HashMap; 6 import java.util.Iterator; 7 import java.util.LinkedList; 8 import java.util.List; 9 import java.util.Map; 6 10 7 11 import javax.swing.JLabel; … … 21 25 * All primitives, that are affected with this command. 22 26 */ 23 private final Collection<OsmPrimitive> objects;27 private final List<OsmPrimitive> objects; 24 28 /** 25 29 * The key that is subject to change. … … 32 36 */ 33 37 private final String value; 38 39 /** 40 * These are the old values of the objects to do a proper undo. 41 */ 42 private List<Map<Key, String>> oldProperties; 34 43 35 44 public ChangeKeyValueCommand(Collection<OsmPrimitive> objects, Key key, String value) { 36 this.objects = objects;45 this.objects = new LinkedList<OsmPrimitive>(objects); 37 46 this.key = key; 38 47 this.value = value; … … 40 49 41 50 public void executeCommand() { 51 // save old 52 oldProperties = new LinkedList<Map<Key, String>>(); 53 for (OsmPrimitive osm : objects) 54 oldProperties.add(osm.keys == null ? null : new HashMap<Key, String>(osm.keys)); 55 42 56 if (value == null) { 43 57 for (OsmPrimitive osm : objects) { … … 57 71 } 58 72 73 public void undoCommand() { 74 Iterator<Map<Key, String>> it = oldProperties.iterator(); 75 for (OsmPrimitive osm : objects) 76 osm.keys = it.next(); 77 } 78 59 79 public Component commandDescription() { 60 80 String objStr = objects.size()+" object" + (objects.size()==1?"":"s"); -
src/org/openstreetmap/josm/command/CombineAndDeleteCommand.java
r23 r30 3 3 import java.awt.Component; 4 4 import java.util.Collection; 5 import java.util.HashMap; 6 import java.util.Iterator; 7 import java.util.LinkedList; 8 import java.util.List; 5 9 import java.util.Map; 6 10 7 11 import javax.swing.JLabel; 8 12 9 import org.openstreetmap.josm.Main;10 13 import org.openstreetmap.josm.data.osm.DataSet; 11 14 import org.openstreetmap.josm.data.osm.Key; 12 15 import org.openstreetmap.josm.data.osm.LineSegment; 13 import org.openstreetmap.josm.data.osm.Node;14 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 17 import org.openstreetmap.josm.data.osm.Track; … … 19 21 * This is a combination of first combining objects to get a node free of 20 22 * references and then delete that node. It is used by the delete action. 23 * 24 * The rules is as follow: 25 * If the node to delete is between exact two line segments, which are 26 * in a straight (not pointing together), the second line segment is deleted 27 * and the first now spans to the last node of the second line segment. 28 * 21 29 * @author imi 22 30 */ … … 24 32 25 33 /** 26 * This class is used as one line segment pair that needs to get combined 27 * for the node to be deleted. 28 * @author imi 34 * The dataset, this command operates on. 29 35 */ 30 public static class LineSegmentCombineEntry { 31 public LineSegment first, second; 32 public Track track; 33 } 36 private DataSet ds; 37 /** 38 * This line segment is combined with the second line segment. 39 * The node that get deleted is the end of this segment. 40 */ 41 private LineSegment first; 42 /** 43 * This line segment is deleted by the combining. 44 * The node that get deleted is the start of this segment. 45 */ 46 private LineSegment second; 47 48 /** 49 * The tracks (if any) the line segments are part of. 50 */ 51 private List<Track> track; 52 53 54 // stuff for undo 55 56 /** 57 * The old properties of the first line segment (for undo) 58 */ 59 private Map<Key, String> oldProperties; 60 /** 61 * The positions of the second line segment in the tracks (if any track) 62 */ 63 private List<Integer> lineSegmentTrackPos; 34 64 35 65 /** 36 * The node that get deleted 66 * Create the command and assign the data entries. 67 * @param ds The dataset this command operates on. 68 * @param first The line segment that remain alive 69 * @param second The line segment that get deleted 37 70 */ 38 private Node node; 39 /** 40 * These line segments are 41 */ 42 private Collection<LineSegmentCombineEntry> combineLineSegments; 43 /** 44 * These tracks are combined 45 */ 46 private Track firstTrack, secondTrack; 47 /** 48 * This line segment is deleted together with the second track. It was the 49 * first segment of the second track (the other line segments were integrated 50 * into the first track). 51 */ 52 private LineSegment firstOfSecond; 53 54 /** 55 * Create the command and assign the data entries. 56 */ 57 public CombineAndDeleteCommand(Node nodeToDelete, 58 Collection<LineSegmentCombineEntry> combineLineSegments, 59 Track firstTrack, Track secondTrack) { 60 node = nodeToDelete; 61 this.combineLineSegments = combineLineSegments; 62 this.firstTrack = firstTrack; 63 this.secondTrack = secondTrack; 71 public CombineAndDeleteCommand(DataSet ds, LineSegment first, LineSegment second) { 72 this.ds = ds; 73 this.first = first; 74 this.second = second; 75 if (first.end != second.start) 76 throw new IllegalArgumentException(); 64 77 } 65 78 66 79 public void executeCommand() { 67 // line segments 68 DataSet ds = Main.main.ds; 69 for (LineSegmentCombineEntry e : combineLineSegments) { 70 if (e.first.start == e.second.end) { 71 LineSegment tmp = e.first; 72 e.first = e.second; 73 e.second = tmp; 80 first.end = second.end; 81 oldProperties = new HashMap<Key, String>(first.keys); 82 first.keys = mergeKeys(first.keys, second.keys); 83 84 // delete second line segment 85 for (Track t : ds.tracks) { 86 if (t.segments.contains(second)) { 87 if (track == null) 88 track = new LinkedList<Track>(); 89 track.add(t); 74 90 } 75 e.first.end = e.second.end;76 e.first.keys = mergeKeys(e.first.keys, e.second.keys);77 e.track.segments.remove(e.second);78 91 } 92 if (track != null) { 93 lineSegmentTrackPos = new LinkedList<Integer>(); 94 for (Track t : track) { 95 int i = t.segments.indexOf(second); 96 if (i != -1) 97 t.segments.remove(second); 98 lineSegmentTrackPos.add(i); 99 } 100 } 101 ds.lineSegments.remove(second); 79 102 80 // tracks 81 if (firstTrack != null && secondTrack != null) { 82 if (firstTrack.getStartingNode() == secondTrack.getEndingNode()) { 83 Track t = firstTrack; 84 firstTrack = secondTrack; 85 secondTrack = t; 103 // delete node 104 ds.nodes.remove(second.start); 105 } 106 107 public void undoCommand() { 108 ds.nodes.add(second.start); 109 ds.lineSegments.add(second); 110 111 if (track != null) { 112 Iterator<Track> it = track.iterator(); 113 for (int i : lineSegmentTrackPos) { 114 Track t = it.next(); 115 if (i != -1) 116 t.segments.add(i, second); 86 117 } 87 // concatenate the line segments.88 LineSegment lastOfFirst = firstTrack.getEndingSegment();89 firstOfSecond = secondTrack.getStartingSegment();90 lastOfFirst.end = firstOfSecond.end;91 lastOfFirst.keys = mergeKeys(lastOfFirst.keys, firstOfSecond.keys);92 secondTrack.segments.remove(firstOfSecond);93 // move the remaining line segments to first track.94 firstTrack.segments.addAll(secondTrack.segments);95 ds.tracks.remove(secondTrack);96 118 } 97 ds.nodes.remove(node);98 ds.rebuildBackReferences();119 first.keys = oldProperties; 120 first.end = second.start; 99 121 } 100 122 … … 115 137 public Component commandDescription() { 116 138 SelectionComponentVisitor v = new SelectionComponentVisitor(); 117 v.visit( node);139 v.visit(second.start); 118 140 return new JLabel("Remove "+v.name, v.icon, JLabel.LEADING); 119 141 } 120 142 121 143 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 122 deleted.add(node); 123 if (firstTrack != null) 124 modified.add(firstTrack); 125 if (secondTrack != null) 126 deleted.add(secondTrack); 127 if (firstOfSecond != null) 128 deleted.add(firstOfSecond); 129 for (LineSegmentCombineEntry e : combineLineSegments) { 130 modified.add(e.first); 131 deleted.add(e.second); 132 modified.add(e.track); 133 } 144 deleted.add(second); 145 deleted.add(second.start); 146 modified.add(first); 147 if (track != null) 148 modified.addAll(track); 134 149 } 135 150 -
src/org/openstreetmap/josm/command/Command.java
r23 r30 11 11 * one atomic action on a specific dataset, such as move or delete. 12 12 * 13 * Remember, that the command must be executable and undoable, even if the 14 * Main.main.ds has changed, so the command must save the dataset it operates on 15 * if necessary. 16 * 13 17 * @author imi 14 18 */ … … 21 25 22 26 /** 27 * Undoes the command. 28 * It can be assumed, that all objects are in the same state they were before. 29 * It can also be assumed that executeCommand was called exactly once before. 30 */ 31 void undoCommand(); 32 33 /** 23 34 * Give a description of the command as component to draw 24 35 */ … … 26 37 27 38 /** 28 * Fill in the changed data this command operates on (for sending to the server). 29 * Add to the lists, don't clear them. The lists can be <code>null</code> 30 * in which case they are ignored. 39 * Fill in the changed data this command operates on. 40 * Add to the lists, don't clear them. 31 41 * 32 * @param modified The modified primitives or <code>null</code>33 * @param deleted The deleted primitives or <code>null</code>34 * @param added The added primitives or <code>null</code>42 * @param modified The modified primitives 43 * @param deleted The deleted primitives 44 * @param added The added primitives 35 45 */ 36 46 void fillModifiedData(Collection<OsmPrimitive> modified, -
src/org/openstreetmap/josm/command/DeleteCommand.java
r23 r30 3 3 import java.awt.Component; 4 4 import java.util.Collection; 5 import java.util.LinkedList;6 5 7 6 import javax.swing.JLabel; 8 7 9 import org.openstreetmap.josm. Main;8 import org.openstreetmap.josm.data.osm.DataSet; 10 9 import org.openstreetmap.josm.data.osm.Key; 11 10 import org.openstreetmap.josm.data.osm.LineSegment; … … 19 18 * @author imi 20 19 */ 21 public class DeleteCommand implements Command , Visitor{20 public class DeleteCommand implements Command { 22 21 22 /** 23 * The dataset this command operates on. 24 */ 25 DataSet ds; 26 27 /** 28 * Helper that adds the object. 29 * @author imi 30 */ 31 private final class AddVisitor implements Visitor { 32 public void visit(Node n) {ds.nodes.add(n);} 33 public void visit(LineSegment ls) {ds.lineSegments.add(ls);} 34 public void visit(Track t) {ds.tracks.add(t);} 35 public void visit(Key k) {throw new IllegalStateException("Keys are added by using ChangeKeyValueCommand");} 36 } 37 38 /** 39 * Helper that deletes the object. Does not respect back reference cache. 40 * @author imi 41 */ 42 private final class DeleteVisitor implements Visitor { 43 public void visit(Node n) {ds.nodes.remove(n);} 44 public void visit(LineSegment ls) {ds.lineSegments.remove(ls);} 45 public void visit(Track t) {ds.tracks.remove(t);} 46 public void visit(Key k) {throw new IllegalStateException("Keys are added by using ChangeKeyValueCommand");} 47 } 48 49 50 23 51 /** 24 52 * The primitives that are going to deleted. … … 26 54 private final Collection<OsmPrimitive> data; 27 55 28 public DeleteCommand(Collection<OsmPrimitive> data) { 56 public DeleteCommand(DataSet ds, Collection<OsmPrimitive> data) { 57 this.ds = ds; 29 58 this.data = data; 30 59 } 31 60 32 61 public void executeCommand() { 62 Visitor v = new DeleteVisitor(); 33 63 for (OsmPrimitive osm : data) 34 osm.visit(this); 64 osm.visit(v); 65 } 66 67 public void undoCommand() { 68 Visitor v = new AddVisitor(); 69 for (OsmPrimitive osm : data) 70 osm.visit(v); 35 71 } 36 72 … … 39 75 } 40 76 41 public void fillModifiedData(Collection<OsmPrimitive> modified, 42 Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 43 if (deleted != null) 44 deleted.addAll(data); 77 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 78 deleted.addAll(data); 45 79 } 46 47 48 public void visit(Node n) {49 Main.main.ds.nodes.remove(n);50 Main.main.ds.removeBackReference(n);51 }52 53 public void visit(LineSegment ls) {54 Main.main.ds.pendingLineSegments.remove(ls);55 LinkedList<Track> tracksToDelete = new LinkedList<Track>();56 for (Track t : Main.main.ds.tracks) {57 t.segments.remove(ls);58 if (t.segments.isEmpty())59 tracksToDelete.add(t);60 }61 for (Track t : tracksToDelete) {62 Main.main.ds.tracks.remove(t);63 Main.main.ds.removeBackReference(t);64 }65 Main.main.ds.removeBackReference(ls);66 }67 68 public void visit(Track t) {69 Main.main.ds.tracks.remove(t);70 for (LineSegment ls : t.segments)71 Main.main.ds.pendingLineSegments.add(ls);72 Main.main.ds.removeBackReference(t);73 }74 75 public void visit(Key k) {76 // TODO77 }78 79 80 } -
src/org/openstreetmap/josm/command/MoveCommand.java
r23 r30 2 2 3 3 import java.awt.Component; 4 import java.awt.geom.Point2D; 4 5 import java.util.Collection; 6 import java.util.Iterator; 7 import java.util.LinkedList; 8 import java.util.List; 5 9 6 10 import javax.swing.JLabel; … … 21 25 * The objects that should be moved. 22 26 */ 23 private Collection<OsmPrimitive> objects;27 private List<OsmPrimitive> objects; 24 28 /** 25 29 * x difference movement. Coordinates are in northern/eastern … … 32 36 33 37 /** 38 * x/y List of all old positions of the objects. 39 */ 40 private List<Point2D.Double> oldPositions; 41 42 /** 34 43 * Create a MoveCommand and assign the initial object set and movement vector. 35 44 */ 36 45 public MoveCommand(Collection<OsmPrimitive> objects, double x, double y) { 37 this.objects = objects;46 this.objects = new LinkedList<OsmPrimitive>(objects); 38 47 this.x = x; 39 48 this.y = y; 40 }41 42 /**43 * Move the objects additional to the current movement.44 */45 public void move(double x, double y) {46 this.x += x;47 this.y += y;48 49 } 49 50 … … 58 59 } 59 60 61 public void undoCommand() { 62 AllNodesVisitor visitor = new AllNodesVisitor(); 63 for (OsmPrimitive osm : objects) 64 osm.visit(visitor); 65 Iterator<Point2D.Double> it = oldPositions.iterator(); 66 for (Node n : visitor.nodes) { 67 Point2D.Double p = it.next(); 68 n.coor.x = p.x; 69 n.coor.y = p.y; 70 } 71 } 72 60 73 public Component commandDescription() { 61 74 String xstr = Math.abs(x) + (x < 0 ? "W" : "E"); … … 65 78 66 79 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 67 if (modified != null) 68 for (OsmPrimitive osm : objects) 69 if (!modified.contains(osm)) 70 modified.add(osm); 80 for (OsmPrimitive osm : objects) 81 if (!modified.contains(osm)) 82 modified.add(osm); 71 83 } 72 84 } -
src/org/openstreetmap/josm/data/Preferences.java
r23 r30 45 45 */ 46 46 private boolean drawRawGpsLines = false; 47 /**48 * Whether deleted objects should be drawn in a dark color.49 */50 private boolean drawDeleted = false;51 47 /** 52 48 * Force the drawing of lines between raw gps points if there are no … … 139 135 drawRawGpsLines = root.getChild("drawRawGpsLines") != null; 140 136 forceRawGpsLines = root.getChild("forceRawGpsLines") != null; 141 drawDeleted = root.getChild("drawDeleted") != null;142 137 } catch (Exception e) { 143 138 if (e instanceof PreferencesException) … … 162 157 if (drawRawGpsLines) 163 158 children.add(new Element("drawRawGpsLines")); 164 if (drawDeleted)165 children.add(new Element("drawDeleted"));166 159 if (forceRawGpsLines) 167 160 children.add(new Element("forceRawGpsLines")); … … 256 249 return forceRawGpsLines; 257 250 } 258 public boolean isDrawDeleted() {259 return drawDeleted;260 }261 public void setDrawDeleted(boolean drawDeleted) {262 boolean old = this.drawDeleted;263 this.drawDeleted = drawDeleted;264 firePropertyChanged("drawDeleted", old, drawDeleted);265 }266 251 } -
src/org/openstreetmap/josm/data/osm/DataSet.java
r28 r30 6 6 import java.util.LinkedList; 7 7 import java.util.Map; 8 import java.util.Set;9 8 10 9 import org.openstreetmap.josm.data.Bounds; 11 10 import org.openstreetmap.josm.data.SelectionTracker; 12 import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor;13 11 14 12 /** 15 * DataSet is the data behind one window inthe application. It can consist of only a few16 * points up to the whole osm database. DataSet's can be merged together, split up into17 * s everal different ones, saved, (up/down/disk)loaded etc.13 * DataSet is the data behind the application. It can consist of only a few 14 * points up to the whole osm database. DataSet's can be merged together, 15 * saved, (up/down/disk)loaded etc. 18 16 * 19 * Note, that DataSet is not an osm-primitive, it is not within 20 * org.openstreetmap.josm.data.osm and has no key association but a few 21 * members to store some information. 17 * Note, that DataSet is not an osm-primitive and so has no key association 18 * but a few members to store some information. 22 19 * 23 20 * @author imi 24 21 */ 25 public class DataSet extends SelectionTracker implements Cloneable{22 public class DataSet extends SelectionTracker { 26 23 27 24 /** … … 33 30 34 31 /** 35 * All pending line segments goes here. Pending line segments are those, that 36 * are in this list but are in no track. 37 */ 38 public Collection<LineSegment> pendingLineSegments = new LinkedList<LineSegment>(); 32 * All line segments goes here, even when they are in a track. 33 */ 34 public Collection<LineSegment> lineSegments = new LinkedList<LineSegment>(); 39 35 40 36 /** … … 47 43 public Collection<Track> tracks = new LinkedList<Track>(); 48 44 49 50 /**51 * This is a list of all back references of nodes to their track usage.52 */53 public Map<Node, Set<Track>> nodeTrackRef = new HashMap<Node, Set<Track>>();54 /**55 * This is a list of all back references of nodes to their line segments.56 */57 public Map<Node, Set<LineSegment>> nodeLsRef = new HashMap<Node, Set<LineSegment>>();58 /**59 * This is a list of all back references of lines to their tracks.60 */61 public Map<LineSegment, Set<Track>> lsTrackRef = new HashMap<LineSegment, Set<Track>>();62 63 /**64 * Add a back reference from the node to the line segment.65 */66 public void addBackReference(Node from, LineSegment to) {67 Set<LineSegment> references = nodeLsRef.get(from);68 if (references == null)69 references = new HashSet<LineSegment>();70 references.add(to);71 nodeLsRef.put(from, references);72 }73 /**74 * Add a back reference from the node to the track.75 */76 public void addBackReference(Node from, Track to) {77 Set<Track> references = nodeTrackRef.get(from);78 if (references == null)79 references = new HashSet<Track>();80 references.add(to);81 nodeTrackRef.put(from, references);82 }83 /**84 * Add a back reference from the line segment to the track.85 */86 public void addBackReference(LineSegment from, Track to) {87 Set<Track> references = lsTrackRef.get(from);88 if (references == null)89 references = new HashSet<Track>();90 references.add(to);91 lsTrackRef.put(from, references);92 }93 94 /**95 * Removes all references to and from this line segment.96 */97 public void removeBackReference(LineSegment ls) {98 Set<LineSegment> s = nodeLsRef.get(ls.start);99 if (s != null)100 s.remove(ls);101 s = nodeLsRef.get(ls.end);102 if (s != null)103 s.remove(ls);104 lsTrackRef.remove(ls);105 }106 /**107 * Removes all references to and from the node.108 */109 public void removeBackReference(Node n) {110 nodeLsRef.remove(n);111 nodeTrackRef.remove(n);112 }113 /**114 * Removes all references to and from the track.115 */116 public void removeBackReference(Track t) {117 Collection<Node> nodes = AllNodesVisitor.getAllNodes(t);118 for (Node n : nodes) {119 Set<Track> s = nodeTrackRef.get(n);120 if (s != null)121 s.remove(t);122 }123 for (LineSegment ls : t.segments) {124 Set<Track> s = lsTrackRef.get(ls);125 if (s != null)126 s.remove(t);127 }128 }129 130 /**131 * Rebuild the caches of back references.132 */133 public void rebuildBackReferences() {134 nodeTrackRef.clear();135 nodeLsRef.clear();136 lsTrackRef.clear();137 for (Track t : tracks) {138 for (LineSegment ls : t.segments) {139 addBackReference(ls.start, ls);140 addBackReference(ls.end, ls);141 addBackReference(ls.start, t);142 addBackReference(ls.end, t);143 addBackReference(ls, t);144 }145 }146 for (LineSegment ls : pendingLineSegments) {147 addBackReference(ls.start, ls);148 addBackReference(ls.end, ls);149 }150 }151 152 45 /** 153 46 * Return the bounds of this DataSet, depending on X/Y values. … … 218 111 public void clearSelection() { 219 112 clearSelection(nodes); 220 clearSelection( pendingLineSegments);113 clearSelection(lineSegments); 221 114 clearSelection(tracks); 222 for (Track t : tracks)223 clearSelection(t.segments);224 115 } 225 116 … … 231 122 public Collection<OsmPrimitive> getSelected() { 232 123 Collection<OsmPrimitive> sel = getSelected(nodes); 233 sel.addAll(getSelected( pendingLineSegments));124 sel.addAll(getSelected(lineSegments)); 234 125 sel.addAll(getSelected(tracks)); 235 for (Track t : tracks)236 sel.addAll(getSelected(t.segments));237 126 return sel; 238 127 } … … 249 138 * Tracks are merged, if they consist of the same line segments. 250 139 * 251 * Additional to that, every two objects with the same id are merged.140 * TODO Additional to that, every two objects with the same id are merged. 252 141 * 253 142 * @param ds The DataSet to merge into this one. 254 * @return A list of all primitives that were used in the conjunction. That 255 * is all used primitives (the merged primitives and all added ones). 256 */ 257 public Collection<OsmPrimitive> mergeFrom(DataSet ds) { 258 Collection<OsmPrimitive> data = new LinkedList<OsmPrimitive>(); 259 260 Set<LineSegment> myLineSegments = new HashSet<LineSegment>(); 261 myLineSegments.addAll(pendingLineSegments); 262 for (Track t : tracks) 263 myLineSegments.addAll(t.segments); 143 */ 144 public void mergeFrom(DataSet ds) { 145 // merge nodes 264 146 265 Set<LineSegment> otherLineSegments = new HashSet<LineSegment>();266 otherLineSegments.addAll(ds.pendingLineSegments);267 for (Track t : ds.tracks)268 otherLineSegments.addAll(t.segments);269 270 271 // merge nodes272 273 147 Map<Node, Node> nodeMap = new HashMap<Node, Node>(); 148 274 149 // find mergable 275 150 for (Node otherNode : ds.nodes) … … 278 153 nodeMap.put(otherNode, myNode); 279 154 // add 280 data.addAll(new HashSet<Node>(nodeMap.values())); 281 for (Node n : ds.nodes) { 282 if (!nodeMap.containsKey(n)) { 155 for (Node n : ds.nodes) 156 if (!nodeMap.containsKey(n)) 283 157 nodes.add(n); 284 data.add(n);285 }286 }287 158 // reassign 288 for (LineSegment ls : otherLineSegments) {159 for (LineSegment ls : ds.lineSegments) { 289 160 Node n = nodeMap.get(ls.start); 290 161 if (n != null) … … 300 171 Map<LineSegment, LineSegment> lsMap = new HashMap<LineSegment, LineSegment>(); 301 172 // find mergable 302 for (LineSegment otherLS : otherLineSegments)303 for (LineSegment myLS : myLineSegments)173 for (LineSegment otherLS : ds.lineSegments) 174 for (LineSegment myLS : lineSegments) 304 175 if (otherLS.start == myLS.start && otherLS.end == myLS.end) 305 176 lsMap.put(otherLS, myLS); 306 // add pendings (ls from track are added later 307 data.addAll(new HashSet<LineSegment>(lsMap.values())); 308 for (LineSegment ls : ds.pendingLineSegments) { 309 if (!lsMap.containsKey(ls)) { 310 pendingLineSegments.add(ls); 311 data.add(ls); 312 } 313 } 177 // add ls 178 for (LineSegment ls : ds.lineSegments) 179 if (!lsMap.containsKey(ls)) 180 lineSegments.add(ls); 314 181 // reassign 315 182 for (Track t : ds.tracks) { … … 323 190 324 191 // merge tracks 192 325 193 LinkedList<Track> trackToAdd = new LinkedList<Track>(); 326 194 for (Track otherTrack : ds.tracks) { … … 329 197 if (myTrack.segments.equals(otherTrack.segments)) { 330 198 found = true; 331 data.add(myTrack);332 199 break; 333 200 } … … 336 203 trackToAdd.add(otherTrack); 337 204 } 338 data.addAll(trackToAdd);339 205 tracks.addAll(trackToAdd); 340 341 rebuildBackReferences();342 return data;343 206 } 344 207 … … 373 236 return sel; 374 237 } 375 376 377 @Override378 public DataSet clone() {379 try {return (DataSet)super.clone();} catch (CloneNotSupportedException e) {}380 return null;381 }382 238 } -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r28 r30 27 27 public long id = 0; 28 28 29 /**30 * If set to true, this object has been modified in the current session.31 */32 transient public boolean modified = false;33 34 29 /** 35 30 * If set to true, this object is currently selected. -
src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
r23 r30 4 4 import java.awt.Graphics; 5 5 import java.awt.Point; 6 import java.util.Collection;7 6 8 import org.openstreetmap.josm.Main;9 7 import org.openstreetmap.josm.data.osm.Key; 10 8 import org.openstreetmap.josm.data.osm.LineSegment; … … 51 49 /** 52 50 * Draw a small rectangle. 53 * 54 * - White if selected (as always) 55 * - Yellow, if not used by any tracks or areas. 56 * - Green, if only used by pending line segments. 57 * - Darkblue, if used in tracks but are only as inbound node. Inbound are 58 * all nodes, that have only line segments of the same track and 59 * at least two different line segments attached. 60 * - Red otherwise (means, this is a dead end or is part of more than 61 * one track). 51 * White if selected (as always) or red otherwise. 62 52 * 63 53 * @param n The node to draw. 64 54 */ 65 55 public void visit(Node n) { 66 if (n.isSelected()) { 67 drawNode(n, Color.WHITE); // selected 68 return; 69 } 70 71 Collection<LineSegment> lineSegments = Main.main.ds.nodeLsRef.get(n); 72 if (lineSegments == null || lineSegments.isEmpty()) { 73 drawNode(n, Color.YELLOW); // single waypoint only 74 return; 75 } 76 77 Collection<Track> tracks = Main.main.ds.nodeTrackRef.get(n); 78 if (tracks == null || tracks.isEmpty()) { 79 drawNode(n, Color.GREEN); // pending line 80 return; 81 } 82 if (tracks.size() > 1) { 83 drawNode(n, Color.RED); // more than one track 84 return; 85 } 86 int segmentUsed = 0; 87 for (LineSegment ls : tracks.iterator().next().segments) 88 if (n == ls.start || n == ls.end) 89 ++segmentUsed; 90 drawNode(n, segmentUsed > 1 ? darkblue : Color.RED); 56 drawNode(n, n.isSelected() ? Color.WHITE : Color.RED); 91 57 } 92 58 59 /** 60 * Draw just a line between the points. 61 * White if selected (as always) or green otherwise. 62 */ 93 63 public void visit(LineSegment ls) { 94 if (forceColor != null) 95 g.setColor(forceColor); 96 else if (ls.isSelected()) 97 g.setColor(Color.WHITE); 98 else if (Main.main.ds.pendingLineSegments.contains(ls)) 99 g.setColor(darkgreen); 100 else 101 g.setColor(darkblue); 102 Point p1 = mv.getScreenPoint(ls.start.coor); 103 Point p2 = mv.getScreenPoint(ls.end.coor); 104 g.drawLine(p1.x, p1.y, p2.x, p2.y); 64 drawLineSegment(ls, darkgreen); 105 65 } 106 66 … … 111 71 public void visit(Track t) { 112 72 for (LineSegment ls : t.segments) 113 visit(ls);73 drawLineSegment(ls, darkblue); 114 74 } 115 75 76 /** 77 * Do not draw a key. 78 */ 116 79 public void visit(Key k) { 117 80 } … … 128 91 g.drawRect(p.x-1, p.y-1, 2, 2); 129 92 } 93 94 /** 95 * Draw a line with the given color. 96 */ 97 private void drawLineSegment(LineSegment ls, Color col) { 98 if (forceColor != null) 99 col = forceColor; 100 else if (ls.isSelected()) 101 col = Color.WHITE; 102 g.setColor(col); 103 Point p1 = mv.getScreenPoint(ls.start.coor); 104 Point p2 = mv.getScreenPoint(ls.end.coor); 105 g.drawLine(p1.x, p1.y, p2.x, p2.y); 106 } 130 107 } -
src/org/openstreetmap/josm/gui/IconToggleButton.java
r8 r30 25 25 // Tooltip 26 26 String toolTipText = ""; 27 Object o = action.getValue(Action. LONG_DESCRIPTION);27 Object o = action.getValue(Action.SHORT_DESCRIPTION); 28 28 if (o != null) 29 toolTipText += o.toString(); 30 o = action.getValue(Action.ACCELERATOR_KEY); 31 if (o != null) { 32 String ksName = o.toString(); 33 if (ksName.startsWith("pressed ")) 34 ksName = ksName.substring("pressed ".length()); 35 else if (ksName.startsWith("released ")) 36 ksName = ksName.substring("released ".length()); 37 toolTipText += " Shortcut: "+ksName; 38 } 29 toolTipText = o.toString(); 39 30 setToolTipText(toolTipText); 40 31 -
src/org/openstreetmap/josm/gui/MapFrame.java
r17 r30 4 4 import java.awt.Component; 5 5 import java.awt.Container; 6 import java.awt.event.WindowAdapter;7 import java.awt.event.WindowEvent;8 6 import java.beans.PropertyChangeEvent; 9 7 import java.beans.PropertyChangeListener; 10 8 11 9 import javax.swing.AbstractButton; 10 import javax.swing.BoxLayout; 12 11 import javax.swing.ButtonGroup; 13 12 import javax.swing.JPanel; … … 19 18 import org.openstreetmap.josm.actions.mapmode.AddNodeAction; 20 19 import org.openstreetmap.josm.actions.mapmode.AddTrackAction; 21 import org.openstreetmap.josm.actions.mapmode.CombineAction;22 20 import org.openstreetmap.josm.actions.mapmode.DeleteAction; 23 21 import org.openstreetmap.josm.actions.mapmode.MapMode; … … 54 52 */ 55 53 public MapStatus statusLine; 54 /** 55 * The action to open the layer list 56 */ 57 private LayerList layerList; 58 /** 59 * Action to open the properties panel for the selected objects 60 */ 61 private PropertiesDialog propertiesDialog; 62 /** 63 * Action to open a list of all selected objects 64 */ 65 private SelectionListDialog selectionListDialog; 56 66 57 67 /** … … 76 86 toolBarActions.add(new IconToggleButton(this, new AddLineSegmentAction(this))); 77 87 toolBarActions.add(new IconToggleButton(this, new AddTrackAction(this))); 78 toolBarActions.add(new IconToggleButton(this, new CombineAction(this)));79 88 toolBarActions.add(new IconToggleButton(this, new DeleteAction(this))); 80 89 … … 99 108 }); 100 109 101 // layer list 102 toolBarActions.add(new IconToggleButton(this, new LayerList(this))); 110 JPanel toggleDialogs = new JPanel(); 111 add(toggleDialogs, BorderLayout.EAST); 112 113 toggleDialogs.setLayout(new BoxLayout(toggleDialogs, BoxLayout.Y_AXIS)); 114 toolBarActions.add(new IconToggleButton(this, layerList = new LayerList(this))); 115 toggleDialogs.add(layerList); 116 toolBarActions.add(new IconToggleButton(this, propertiesDialog = new PropertiesDialog(this))); 117 toggleDialogs.add(propertiesDialog); 118 toolBarActions.add(new IconToggleButton(this, selectionListDialog = new SelectionListDialog(this))); 119 toggleDialogs.add(selectionListDialog); 103 120 104 // properties105 toolBarActions.add(new IconToggleButton(this, new PropertiesDialog(this)));106 107 // selection dialog108 SelectionListDialog selectionList = new SelectionListDialog(this);109 final IconToggleButton buttonSelection = new IconToggleButton(this, selectionList);110 selectionList.addWindowListener(new WindowAdapter(){111 @Override112 public void windowClosing(WindowEvent e) {113 buttonSelection.setSelected(false);114 }115 });116 toolBarActions.add(buttonSelection);117 121 118 122 // status line below the map -
src/org/openstreetmap/josm/gui/MapView.java
r29 r30 20 20 import org.openstreetmap.josm.data.Bounds; 21 21 import org.openstreetmap.josm.data.GeoPoint; 22 import org.openstreetmap.josm.data.osm.DataSet; 22 23 import org.openstreetmap.josm.data.osm.LineSegment; 23 24 import org.openstreetmap.josm.data.osm.Node; … … 25 26 import org.openstreetmap.josm.data.osm.Track; 26 27 import org.openstreetmap.josm.data.projection.Projection; 27 import org.openstreetmap.josm.gui.layer.EditLayer;28 28 import org.openstreetmap.josm.gui.layer.Layer; 29 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 29 30 30 31 /** … … 74 75 * Direct link to the edit layer (if any) in the layers list. 75 76 */ 76 private EditLayer editLayer;77 private OsmDataLayer editLayer; 77 78 /** 78 79 * The layer from the layers list that is currently active. … … 109 110 */ 110 111 public void addLayer(Layer layer) { 111 if (layer instanceof EditLayer) { 112 // initialize the projection if it is the first layer 113 if (layers.isEmpty()) 114 Main.pref.getProjection().init(layer.getBoundsLatLon()); 115 116 // reinitialize layer's data 117 layer.init(Main.pref.getProjection()); 118 119 if (layer instanceof OsmDataLayer) { 112 120 if (editLayer != null) { 113 // there can only be one EditLayer 121 // merge the layer into the existing one 122 if (!editLayer.isMergable(layer)) 123 throw new IllegalArgumentException("Cannot merge argument"); 114 124 editLayer.mergeFrom(layer); 125 repaint(); 115 126 return; 116 127 } 117 editLayer = (EditLayer)layer; 118 } 119 128 editLayer = (OsmDataLayer)layer; 129 } 130 131 // add as a new layer 120 132 layers.add(0,layer); 121 122 // initialize the projection if it is the first layer123 if (layers.size() == 1)124 Main.pref.getProjection().init(layer.getBoundsLatLon());125 126 // reinitialize layer's data127 layer.init(Main.pref.getProjection());128 133 129 134 for (LayerChangeListener l : listeners) 130 135 l.layerAdded(layer); 131 136 137 // autoselect the new layer 132 138 setActiveLayer(layer); 133 139 } … … 248 254 249 255 // pending line segments 250 for (LineSegment ls : Main.main.ds. pendingLineSegments) {256 for (LineSegment ls : Main.main.ds.lineSegments) { 251 257 Point A = getScreenPoint(ls.start.coor); 252 258 Point B = getScreenPoint(ls.end.coor); … … 467 473 /** 468 474 * Set the active selection to the given value and raise an layerchange event. 475 * Also, swap the active dataset in Main.main if it is a datalayer. 469 476 */ 470 477 public void setActiveLayer(Layer layer) { … … 473 480 Layer old = activeLayer; 474 481 activeLayer = layer; 482 if (layer instanceof OsmDataLayer) 483 Main.main.ds = ((OsmDataLayer)layer).data; 475 484 if (old != layer) { 476 485 for (LayerChangeListener l : listeners) … … 491 500 * So editLayer does never return <code>null</code>. 492 501 */ 493 public EditLayer editLayer() {502 public OsmDataLayer editLayer() { 494 503 if (editLayer == null) 495 addLayer(new EditLayer(this));504 addLayer(new OsmDataLayer(new DataSet(), "unnamed")); 496 505 return editLayer; 497 506 } -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r23 r30 62 62 Main.pref.setDrawRawGpsLines(drawRawGpsLines.isSelected()); 63 63 Main.pref.setForceRawGpsLines(forceRawGpsLines.isSelected()); 64 Main.pref.setDrawDeleted(drawDeleted.isSelected());65 64 try { 66 65 Main.pref.save(); … … 126 125 */ 127 126 JCheckBox forceRawGpsLines = new JCheckBox("Force lines if no line segments imported."); 128 /**129 * The checkbox stating whether deleted nodes should be drawn.130 */131 JCheckBox drawDeleted = new JCheckBox("Draw deleted lines.");132 127 /** 133 128 * The checkbox stating whether nodes should be merged together. … … 203 198 forceRawGpsLines.setSelected(Main.pref.isForceRawGpsLines()); 204 199 forceRawGpsLines.setEnabled(drawRawGpsLines.isSelected()); 205 drawDeleted.setToolTipText("Draw dark hints where objects were deleted.");206 drawDeleted.setSelected(Main.pref.isDrawDeleted());207 200 mergeNodes.setToolTipText("When importing GPX data, all nodes with exact the same lat/lon are merged."); 208 201 mergeNodes.setSelected(Main.pref.mergeNodes); … … 219 212 display.add(drawRawGpsLines, GBC.eol().insets(20,0,0,0)); 220 213 display.add(forceRawGpsLines, GBC.eol().insets(40,0,0,0)); 221 display.add(drawDeleted, GBC.eol().insets(20,0,0,0));222 214 display.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); 223 215 -
src/org/openstreetmap/josm/gui/SelectionManager.java
r23 r30 278 278 279 279 // pending line segments 280 for (LineSegment ls : Main.main.ds. pendingLineSegments)280 for (LineSegment ls : Main.main.ds.lineSegments) 281 281 if (rectangleContainLineSegment(r, alt, ls)) 282 282 selection.add(ls); -
src/org/openstreetmap/josm/gui/dialogs/LayerList.java
r29 r30 74 74 */ 75 75 public LayerList(MapFrame mapFrame) { 76 super(mapFrame, "Layers", "List of all layers", "layerlist", KeyEvent.VK_L, "Open a list of all loaded layers."); 77 setSize(250,256); 78 setMinimumSize(new Dimension(70,70)); 76 super("Layers", "List of all layers", "layerlist", KeyEvent.VK_L, "Open a list of all loaded layers."); 77 setPreferredSize(new Dimension(320,100)); 79 78 add(new JScrollPane(layers), BorderLayout.CENTER); 80 79 layers.setBackground(UIManager.getColor("Button.background")); -
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r29 r30 3 3 import java.awt.BorderLayout; 4 4 import java.awt.Component; 5 import java.awt.Dimension; 5 6 import java.awt.Font; 6 7 import java.awt.GridLayout; … … 210 211 */ 211 212 public PropertiesDialog(MapFrame mapFrame) { 212 super( mapFrame,"Properties", "Properties Dialog", "properties", KeyEvent.VK_P, "Property for selected objects.");213 super("Properties", "Properties Dialog", "properties", KeyEvent.VK_P, "Property for selected objects."); 213 214 mv = mapFrame.mapView; 214 215 215 setLayout(new BorderLayout()); 216 setSize(350,450); 216 setPreferredSize(new Dimension(320,150)); 217 217 218 218 data.setColumnIdentifiers(new String[]{"Key", "Value"}); … … 241 241 JScrollPane scrollPane = new JScrollPane(propertyTable); 242 242 scrollPane.addMouseListener(new DblClickWatch()); 243 getContentPane().add(scrollPane, BorderLayout.CENTER);243 add(scrollPane, BorderLayout.CENTER); 244 244 245 245 JPanel buttonPanel = new JPanel(new GridLayout(1,3)); … … 264 264 buttonPanel.add(createButton("Add", "Add a new key/value pair to all objects", KeyEvent.VK_A, buttonAction)); 265 265 buttonPanel.add(createButton("Edit", "Edit the value of the selected key for all objects", KeyEvent.VK_E, buttonAction)); 266 buttonPanel.add(createButton("Delete", "Delete the selected key in all objects", KeyEvent.VK_D ELETE, buttonAction));267 getContentPane().add(buttonPanel, BorderLayout.SOUTH);266 buttonPanel.add(createButton("Delete", "Delete the selected key in all objects", KeyEvent.VK_D, buttonAction)); 267 add(buttonPanel, BorderLayout.SOUTH); 268 268 } 269 269 -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r22 r30 3 3 import java.awt.BorderLayout; 4 4 import java.awt.Component; 5 import java.awt.Dimension; 5 6 import java.awt.event.ActionEvent; 6 7 import java.awt.event.ActionListener; … … 46 47 */ 47 48 public SelectionListDialog(MapFrame mapFrame) { 48 super(mapFrame, "Current Selection", "Selection List", "selectionlist", KeyEvent.VK_E, "Open a selection list window."); 49 setLayout(new BorderLayout()); 50 setSize(300,400); 49 super("Current Selection", "Selection List", "selectionlist", KeyEvent.VK_E, "Open a selection list window."); 50 setPreferredSize(new Dimension(320,150)); 51 51 displaylist.setCellRenderer(new DefaultListCellRenderer(){ 52 52 private SelectionComponentVisitor visitor = new SelectionComponentVisitor(); … … 64 64 displaylist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 65 65 66 getContentPane().add(new JScrollPane(displaylist), BorderLayout.CENTER);66 add(new JScrollPane(displaylist), BorderLayout.CENTER); 67 67 68 68 JButton button = new JButton("Select", ImageProvider.get("mapmode", "selection")); … … 73 73 } 74 74 }); 75 getContentPane().add(button, BorderLayout.SOUTH);75 add(button, BorderLayout.SOUTH); 76 76 77 77 selectionChanged(Main.main.ds.getSelected()); -
src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r21 r30 1 1 package org.openstreetmap.josm.gui.dialogs; 2 2 3 import java.awt.BorderLayout; 3 4 import java.awt.event.ActionEvent; 4 import java.beans.PropertyChangeEvent;5 import java.beans.PropertyChangeListener;6 5 import java.util.HashMap; 7 6 import java.util.Map; … … 9 8 import javax.swing.AbstractButton; 10 9 import javax.swing.Action; 11 import javax.swing. JComponent;12 import javax.swing.J Dialog;13 import javax.swing. KeyStroke;10 import javax.swing.BorderFactory; 11 import javax.swing.JLabel; 12 import javax.swing.JPanel; 14 13 15 import org.openstreetmap.josm.Main;16 14 import org.openstreetmap.josm.gui.ImageProvider; 17 import org.openstreetmap.josm.gui.MapFrame;18 15 19 16 /** … … 23 20 * @author imi 24 21 */ 25 public class ToggleDialog extends J Dialogimplements Action {22 public class ToggleDialog extends JPanel implements Action { 26 23 27 24 /** … … 29 26 * @param title The title of the dialog. 30 27 */ 31 public ToggleDialog(MapFrame mapFrame, String title, String name, String iconName, int mnemonic, String tooltip) { 32 super(Main.main, title, false); 28 public ToggleDialog(String title, String name, String iconName, int mnemonic, String tooltip) { 33 29 putValue(SMALL_ICON, ImageProvider.get("dialogs", iconName)); 34 30 putValue(NAME, name); 35 31 putValue(MNEMONIC_KEY, mnemonic); 36 KeyStroke ks = KeyStroke.getKeyStroke(mnemonic,0); 37 putValue(ACCELERATOR_KEY, ks); 38 mapFrame.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ks, this); 39 mapFrame.getActionMap().put(this, this); 40 putValue(LONG_DESCRIPTION, tooltip); 41 mapFrame.addPropertyChangeListener("visible", new PropertyChangeListener(){ 42 public void propertyChange(PropertyChangeEvent evt) { 43 if (evt.getNewValue() == Boolean.FALSE) 44 setVisible(false); 45 } 46 }); 32 putValue(SHORT_DESCRIPTION, tooltip); 33 34 setLayout(new BorderLayout()); 35 add(new JLabel(title), BorderLayout.NORTH); 36 setVisible(false); 37 setBorder(BorderFactory.createEtchedBorder()); 47 38 } 48 39 -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r23 r30 2 2 3 3 import java.awt.Graphics; 4 import java.util.Collection; 4 import java.io.FileWriter; 5 import java.io.StringWriter; 6 import java.util.LinkedList; 5 7 6 8 import javax.swing.Icon; 7 9 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.command.Command; 8 12 import org.openstreetmap.josm.data.Bounds; 13 import org.openstreetmap.josm.data.osm.DataSet; 14 import org.openstreetmap.josm.data.osm.LineSegment; 9 15 import org.openstreetmap.josm.data.osm.Node; 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor; 16 import org.openstreetmap.josm.data.osm.Track; 12 17 import org.openstreetmap.josm.data.osm.visitor.BoundingVisitor; 18 import org.openstreetmap.josm.data.osm.visitor.CsvVisitor; 13 19 import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor; 14 20 import org.openstreetmap.josm.data.projection.Projection; … … 17 23 18 24 /** 19 * A layer holding data imported from the osm server. 20 * 25 * A layer holding data from a specific dataset. 21 26 * The data can be fully edited. 22 27 * … … 28 33 29 34 /** 30 * The data behind this layer. A list of primitives which are also in Main.main.ds.35 * The data behind this layer. 31 36 */ 32 private final Collection<OsmPrimitive> data; 37 public final DataSet data; 38 39 /** 40 * All commands that were made on the dataset. 41 */ 42 private LinkedList<Command> commands = new LinkedList<Command>(); 43 private LinkedList<String> debugDsBefore = new LinkedList<String>(); 33 44 34 45 /** 35 46 * Construct a OsmDataLayer. 36 47 */ 37 public OsmDataLayer( Collection<OsmPrimitive>data, String name) {48 public OsmDataLayer(DataSet data, String name) { 38 49 super(name); 39 50 this.data = data; … … 59 70 public void paint(Graphics g, MapView mv) { 60 71 SimplePaintVisitor visitor = new SimplePaintVisitor(g, mv, null); 61 // first draw the tracks (and line segments) 62 for ( OsmPrimitive osm : data)63 if (!osm.modified && !(osm instanceof Node))64 osm.visit(visitor);65 for (OsmPrimitive osm : data)66 if (!osm.modified && osm instanceof Node)67 osm.visit(visitor);72 73 for (Track t : data.tracks) 74 visitor.visit(t); 75 for (LineSegment ls : data.lineSegments) 76 visitor.visit(ls); 77 for (Node n : data.nodes) 78 visitor.visit(n); 68 79 } 69 80 70 81 @Override 71 82 public String getToolTipText() { 72 return data. size()+" primitives.";83 return data.nodes.size()+" nodes, "+data.tracks.size()+" streets."; 73 84 } 74 85 75 86 @Override 76 87 public void mergeFrom(Layer from) { 77 OsmDataLayer layer = (OsmDataLayer)from; 78 data.addAll(layer.data); 88 data.mergeFrom(((OsmDataLayer)from).data); 79 89 } 80 90 … … 87 97 public Bounds getBoundsLatLon() { 88 98 BoundingVisitor b = new BoundingVisitor(BoundingVisitor.Type.LATLON); 89 for ( OsmPrimitive osm : data)90 osm.visit(b);99 for (Node n : data.nodes) 100 b.visit(n); 91 101 return b.bounds; 92 102 } … … 95 105 public Bounds getBoundsXY() { 96 106 BoundingVisitor b = new BoundingVisitor(BoundingVisitor.Type.XY); 97 for ( OsmPrimitive osm : data)98 osm.visit(b);107 for (Node n : data.nodes) 108 b.visit(n); 99 109 return b.bounds; 100 110 } … … 102 112 @Override 103 113 public void init(Projection projection) { 104 for (OsmPrimitive osm : data) 105 for (Node n : AllNodesVisitor.getAllNodes(osm)) 106 projection.latlon2xy(n.coor); 114 for (Node n : data.nodes) 115 projection.latlon2xy(n.coor); 116 } 117 118 /** 119 * Execute the command and add it to the intern command queue. Also mark all 120 * primitives in the command as modified. 121 */ 122 public void add(Command c) { 123 StringWriter sw = new StringWriter(); 124 CsvVisitor v = new CsvVisitor(sw); 125 for (Node n : Main.main.ds.nodes) { 126 v.visit(n); 127 sw.append('\n'); 128 } 129 for (LineSegment ls : Main.main.ds.lineSegments) { 130 v.visit(ls); 131 sw.append('\n'); 132 } 133 for (Track t : Main.main.ds.tracks) { 134 v.visit(t); 135 sw.append('\n'); 136 } 137 debugDsBefore.add(sw.getBuffer().toString()); 138 139 c.executeCommand(); 140 commands.add(c); 141 } 142 143 /** 144 * Undoes the last added command. 145 */ 146 public void undo() { 147 if (commands.isEmpty()) 148 return; 149 Command c = commands.removeLast(); 150 c.undoCommand(); 151 152 //DEBUG 153 StringWriter sw = new StringWriter(); 154 CsvVisitor v = new CsvVisitor(sw); 155 for (Node n : Main.main.ds.nodes) { 156 v.visit(n); 157 sw.append('\n'); 158 } 159 for (LineSegment ls : Main.main.ds.lineSegments) { 160 v.visit(ls); 161 sw.append('\n'); 162 } 163 for (Track t : Main.main.ds.tracks) { 164 v.visit(t); 165 sw.append('\n'); 166 } 167 String s = Main.main.getMapFrame().mapView.editLayer().debugDsBefore.removeLast(); 168 if (!s.equals(sw.getBuffer().toString())) { 169 try { 170 FileWriter fw = new FileWriter("/home/imi/richtig"); 171 fw.append(sw.getBuffer().toString()); 172 fw.close(); 173 fw = new FileWriter("/home/imi/falsch"); 174 fw.append(s); 175 fw.close(); 176 } catch (Exception x) { 177 x.printStackTrace(); 178 } 179 } 107 180 } 108 181 } -
src/org/openstreetmap/josm/io/GpxReader.java
r29 r30 115 115 private void parseTrack(Element e, DataSet ds) { 116 116 Track track = new Track(); 117 boolean pendingLS= false; // is this track just a fake?117 boolean realLineSegment = false; // is this track just a fake? 118 118 119 119 for (Object o : e.getChildren()) { … … 137 137 parseKeyValueExtensions(track, child); 138 138 if (child.getChild("segment", OSM) != null) 139 pendingLS= true;139 realLineSegment = true; 140 140 } else if (child.getName().equals("link")) 141 141 parseKeyValueLink(track, child); … … 143 143 parseKeyValueTag(track, child); 144 144 } 145 if ( pendingLS&& track.segments.size() == 1)146 ds. pendingLineSegments.add(track.segments.get(0));147 else 145 if (realLineSegment && track.segments.size() == 1) 146 ds.lineSegments.add(track.segments.get(0)); 147 else { 148 148 ds.tracks.add(track); 149 ds.lineSegments.addAll(track.segments); 150 } 149 151 } 150 152 -
src/org/openstreetmap/josm/io/GpxWriter.java
r29 r30 109 109 110 110 // encode pending line segments as tracks 111 for (LineSegment ls : Main.main.ds. pendingLineSegments) {111 for (LineSegment ls : Main.main.ds.lineSegments) { 112 112 Element t = new Element("trk", GPX); 113 113 t.getChildren().add(parseLineSegment(ls)); -
src/org/openstreetmap/josm/io/OsmReader.java
r29 r30 118 118 else if (child.getName().equals("segment")) { 119 119 LineSegment ls = parseLineSegment(child, data); 120 if (data. pendingLineSegments.contains(ls))120 if (data.lineSegments.contains(ls)) 121 121 throw new JDOMException("Double segment definition "+ls.id); 122 122 for (Track t : data.tracks) 123 123 if (t.segments.contains(ls)) 124 124 throw new JDOMException("Double segment definition "+ls.id); 125 data. pendingLineSegments.add(ls);125 data.lineSegments.add(ls); 126 126 } else if (child.getName().equals("track")) { 127 127 Track track = parseTrack(child, data); … … 175 175 Element child = (Element)o; 176 176 long id = Long.parseLong(child.getAttributeValue("uid")); 177 LineSegment ls = findLineSegment(data. pendingLineSegments, id);177 LineSegment ls = findLineSegment(data.lineSegments, id); 178 178 if (ls != null) { 179 179 track.segments.add(ls); 180 data. pendingLineSegments.remove(ls);180 data.lineSegments.remove(ls); 181 181 continue; 182 182 } -
src/org/openstreetmap/josm/io/OsmWriter.java
r27 r30 62 62 for (Node n : ds.nodes) 63 63 list.add(parseNode(n, properties)); 64 for (LineSegment ls : ds. pendingLineSegments)64 for (LineSegment ls : ds.lineSegments) 65 65 list.add(parseLineSegment(ls, properties)); 66 66 // all other line segments … … 159 159 for (OsmPrimitive osm : ds.nodes) 160 160 addIdAndKeyIds(osm, ids); 161 for (OsmPrimitive osm : ds. pendingLineSegments)161 for (OsmPrimitive osm : ds.lineSegments) 162 162 addIdAndKeyIds(osm, ids); 163 163 for (Track t : ds.tracks) {
Note:
See TracChangeset
for help on using the changeset viewer.