- Timestamp:
- 2006-04-23T19:51:19+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 2 added
- 38 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r93 r94 110 110 getContentPane().add(panel, BorderLayout.CENTER); 111 111 setSize(1000,740); // some strange default size 112 setVisible(true);113 112 114 113 downloadAction = new DownloadAction(); -
src/org/openstreetmap/josm/actions/AutoScaleAction.java
r93 r94 51 51 this.mapFrame = mapFrame; 52 52 Main.ds.addSelectionChangedListener(new SelectionChangedListener(){ 53 public void selectionChanged(Collection< OsmPrimitive> newSelection) {53 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 54 54 if (mode == AutoScaleMode.selection) 55 55 mapFrame.mapView.recalculateCenterScale(); -
src/org/openstreetmap/josm/actions/DownloadAction.java
r92 r94 101 101 super("Downloading GPS data"); 102 102 this.reader = reader; 103 reader.setProgressInformation(currentAction, progress); 103 104 } 104 105 -
src/org/openstreetmap/josm/actions/GroupAction.java
r93 r94 3 3 import java.awt.event.ActionEvent; 4 4 import java.awt.event.ActionListener; 5 import java.awt.event.KeyEvent;6 5 import java.beans.PropertyChangeEvent; 7 6 import java.beans.PropertyChangeListener; … … 17 16 import org.openstreetmap.josm.gui.IconToggleButton; 18 17 import org.openstreetmap.josm.tools.ImageProvider; 18 import org.openstreetmap.josm.tools.ShortCutLabel; 19 19 import org.openstreetmap.josm.tools.ImageProvider.OverlayPosition; 20 20 … … 50 50 public GroupAction(int shortCut, int modifiers) { 51 51 registerShortCut(getClass().getName(), KeyStroke.getKeyStroke(shortCut, modifiers)); 52 if ((modifiers & KeyEvent.CTRL_DOWN_MASK) != 0) 53 shortCutName += "Ctrl-"; 54 if ((modifiers & KeyEvent.ALT_DOWN_MASK) != 0) 55 shortCutName += "Alt-"; 56 if ((modifiers & KeyEvent.ALT_GRAPH_DOWN_MASK) != 0) 57 shortCutName += "AltGr-"; 58 if ((modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0) 59 shortCutName += "Shift-"; 60 shortCutName += Character.toUpperCase((char)shortCut); 52 shortCutName = ShortCutLabel.name(shortCut, modifiers); 61 53 addPropertyChangeListener(new PropertyChangeListener(){ 62 54 public void propertyChange(PropertyChangeEvent evt) { -
src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java
r93 r94 49 49 } 50 50 51 @Override public void registerListener() {52 super. registerListener();51 @Override public void enterMode() { 52 super.enterMode(); 53 53 mv.addMouseListener(this); 54 54 } 55 55 56 @Override public void unregisterListener() {57 super. unregisterListener();56 @Override public void exitMode() { 57 super.exitMode(); 58 58 mv.removeMouseListener(this); 59 59 } -
src/org/openstreetmap/josm/actions/mapmode/AddSegmentAction.java
r93 r94 49 49 } 50 50 51 @Override public void registerListener() {52 super. registerListener();51 @Override public void enterMode() { 52 super.enterMode(); 53 53 mv.addMouseListener(this); 54 54 mv.addMouseMotionListener(this); 55 55 } 56 56 57 @Override public void unregisterListener() {58 super. unregisterListener();57 @Override public void exitMode() { 58 super.exitMode(); 59 59 mv.removeMouseListener(this); 60 60 mv.removeMouseMotionListener(this); -
src/org/openstreetmap/josm/actions/mapmode/AddWayAction.java
r93 r94 1 1 package org.openstreetmap.josm.actions.mapmode; 2 2 3 import java.awt.event.ActionEvent;4 3 import java.awt.event.KeyEvent; 4 import java.awt.event.MouseEvent; 5 import java.util.Arrays; 5 6 import java.util.Collection; 7 import java.util.HashSet; 6 8 import java.util.Iterator; 7 9 import java.util.LinkedList; … … 11 13 import org.openstreetmap.josm.Main; 12 14 import org.openstreetmap.josm.command.AddCommand; 15 import org.openstreetmap.josm.command.ChangeCommand; 16 import org.openstreetmap.josm.command.Command; 17 import org.openstreetmap.josm.command.DeleteCommand; 18 import org.openstreetmap.josm.data.SelectionChangedListener; 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 20 import org.openstreetmap.josm.data.osm.Segment; 14 import org.openstreetmap.josm.data.osm.OsmPrimitive;15 21 import org.openstreetmap.josm.data.osm.Way; 16 22 import org.openstreetmap.josm.gui.MapFrame; 17 23 18 24 /** 19 * Add a new way from all selected segments. 25 * Add a new way. The action is split into the first phase, where a new way get 26 * created or selected and the second, where this way is modified. 20 27 * 28 * Way creation mode: 21 29 * If there is a selection when the mode is entered, all segments in this 22 * selection form a new way, except the user holds down Shift. 30 * selection form a new way. All non-segment objects are deselected. If there 31 * were ways selected, the user is asked whether to select all segments of these 32 * ways or not, except there is exactly one way selected, which enter the 33 * edit ways mode for this way immediatly. 34 * 35 * If there is no selection on entering, and the user clicks on an segment, 36 * the way editing starts the with a new way and this segment. If the user click 37 * on a way (not holding Alt down), then this way is edited in the way edit mode. 23 38 * 24 * The user can click on a segment. If he holds down Shift, no way is25 * created yet. If he holds down Alt, the whole way is considered instead of26 * the clicked segment. If the user holds down Ctrl, no way is created27 * and the clicked segment get removed from the list.28 * 29 * Also, the user may select a rectangle as in selection mode. No node, area or30 * way can be selected this way.39 * Way editing mode: 40 * The user can click on subsequent segments. If the segment belonged to the way 41 * it get removed from the way. Elsewhere it get added to the way. JOSM try to add 42 * the segment in the correct position. This is done by searching for connections 43 * to the segment at its 'to' node which are also in the way. The segemnt is 44 * inserted in the way as predecessor of the found segment (or at last segment, if 45 * nothing found). 31 46 * 32 47 * @author imi 33 *34 48 */ 35 public class AddWayAction extends MapMode {36 37 private MapMode followMode;38 49 public class AddWayAction extends MapMode implements SelectionChangedListener { 50 51 private Way way; 52 39 53 /** 40 54 * Create a new AddWayAction. … … 42 56 * @param followMode The mode to go into when finished creating a way. 43 57 */ 44 public AddWayAction(MapFrame mapFrame, MapMode followMode) { 45 super("Add Way", "addway", "Combine selected segments to a new way.", "W", KeyEvent.VK_W, mapFrame); 46 this.followMode = followMode; 47 } 48 49 @Override public void actionPerformed(ActionEvent e) { 50 makeWay(); 51 super.actionPerformed(e); 52 mapFrame.selectMapMode(followMode); 58 public AddWayAction(MapFrame mapFrame) { 59 super("Add Way", "addway", "Add a new way to the data.", "W", KeyEvent.VK_W, mapFrame); 60 61 Main.ds.addSelectionChangedListener(this); 62 } 63 64 @Override public void enterMode() { 65 super.enterMode(); 66 Command c = null; 67 way = makeWay(); 68 if (way != null) { 69 c = new AddCommand(way); 70 Main.ds.setSelected(way); 71 mv.editLayer().add(c); 72 } else 73 Main.ds.clearSelection(); 74 mv.addMouseListener(this); 75 } 76 77 @Override public void exitMode() { 78 super.exitMode(); 79 way = null; 80 mv.removeMouseListener(this); 81 } 82 83 @Override public void mouseClicked(MouseEvent e) { 84 if (e.getButton() != MouseEvent.BUTTON1) 85 return; 86 87 Segment s = mv.getNearestSegment(e.getPoint()); 88 if (s == null) 89 return; 90 91 // special case for initial selecting one way 92 if (way == null && (e.getModifiers() & MouseEvent.ALT_DOWN_MASK) == 0) { 93 Way w = mv.getNearestWay(e.getPoint()); 94 if (w != null) { 95 way = w; 96 Main.ds.setSelected(way); 97 return; 98 } 99 } 100 101 if (way != null && way.segments.contains(s)) { 102 Way copy = new Way(way); 103 104 copy.segments.remove(s); 105 if (copy.segments.isEmpty()) { 106 mv.editLayer().add(new DeleteCommand(Arrays.asList(new OsmPrimitive[]{way}))); 107 way = null; 108 } else 109 mv.editLayer().add(new ChangeCommand(way, copy)); 110 } else { 111 if (way == null) { 112 way = new Way(); 113 way.segments.add(s); 114 mv.editLayer().add(new AddCommand(way)); 115 } else { 116 Way copy = new Way(way); 117 int i; 118 for (i = 0; i < way.segments.size(); ++i) 119 if (way.segments.get(i).from == s.to) 120 break; 121 copy.segments.add(i, s); 122 mv.editLayer().add(new ChangeCommand(way, copy)); 123 } 124 } 125 Main.ds.setSelected(way); 53 126 } 54 127 55 128 /** 56 * Just make a way of all selected items. 129 * Form a way, either out of the (one) selected way or by creating a way over the selected 130 * line segments. 57 131 */ 58 private voidmakeWay() {132 private Way makeWay() { 59 133 Collection<OsmPrimitive> selection = Main.ds.getSelected(); 60 134 if (selection.isEmpty()) 61 return; 62 63 // form a new way 64 LinkedList<Segment> segments = new LinkedList<Segment>(); 135 return null; 136 137 if (selection.size() == 1 && selection.iterator().next() instanceof Way) 138 return (Way)selection.iterator().next(); 139 140 HashSet<Segment> segmentSet = new HashSet<Segment>(); 65 141 int numberOfSelectedWays = 0; 66 142 for (OsmPrimitive osm : selection) { … … 68 144 numberOfSelectedWays++; 69 145 else if (osm instanceof Segment) 70 segment s.add((Segment)osm);71 } 72 146 segmentSet.add((Segment)osm); 147 } 148 73 149 if (numberOfSelectedWays > 0) { 74 150 String ways = "way" + (numberOfSelectedWays==1?" has":"s have"); 75 151 int answer = JOptionPane.showConfirmDialog(Main.main, numberOfSelectedWays+" "+ways+" been selected.\n" + 76 "Do you wish to select all segments belonging to the "+ways+" instead?"); 77 if (answer == JOptionPane.CANCEL_OPTION) 78 return; 152 "Do you wish to select all segments belonging to the "+ways+" instead?", "Add segments from ways", JOptionPane.YES_NO_OPTION); 79 153 if (answer == JOptionPane.YES_OPTION) { 80 154 for (OsmPrimitive osm : selection) 81 155 if (osm instanceof Way) 82 segment s.addAll(((Way)osm).segments);83 } 84 } 85 86 if (segment s.isEmpty())87 return ;88 156 segmentSet.addAll(((Way)osm).segments); 157 } 158 } 159 160 if (segmentSet.isEmpty()) 161 return null; 162 89 163 // sort the segments in best possible order. This is done by: 90 164 // 0 if no elements in list, quit … … 94 168 // 4 if not found, save the pivot-string and goto 0 95 169 LinkedList<Segment> sortedSegments = new LinkedList<Segment>(); 170 LinkedList<Segment> segments = new LinkedList<Segment>(segmentSet); 96 171 while (!segments.isEmpty()) { 97 172 LinkedList<Segment> pivotList = new LinkedList<Segment>(); … … 117 192 sortedSegments.addAll(pivotList); 118 193 } 119 194 195 if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(Main.main, "Create a new way out of "+sortedSegments.size()+" segments?", "Create new way", JOptionPane.YES_NO_OPTION)) 196 return null; 197 120 198 Way w = new Way(); 121 199 w.segments.addAll(sortedSegments); 122 mv.editLayer().add(new AddCommand(w)); 123 Main.ds.clearSelection(); 124 mv.repaint(); 125 } 200 return w; 201 } 202 203 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 204 if (newSelection.size() == 1) { 205 OsmPrimitive osm = newSelection.iterator().next(); 206 way = osm instanceof Way ? (Way)osm : null; 207 } else 208 way = null; 209 } 126 210 } -
src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r86 r94 6 6 import java.util.Collection; 7 7 import java.util.Collections; 8 import java.util. LinkedList;8 import java.util.HashSet; 9 9 10 10 import javax.swing.JOptionPane; 11 11 12 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.command.Command;14 13 import org.openstreetmap.josm.command.DeleteCommand; 15 import org.openstreetmap.josm.command.SequenceCommand;16 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 15 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; … … 46 44 } 47 45 48 @Override public void registerListener() {49 super. registerListener();46 @Override public void enterMode() { 47 super.enterMode(); 50 48 mv.addMouseListener(this); 51 49 } 52 50 53 @Override public void unregisterListener() {54 super. unregisterListener();51 @Override public void exitMode() { 52 super.exitMode(); 55 53 mv.removeMouseListener(this); 56 54 } … … 104 102 */ 105 103 private void deleteWithReferences(Collection<OsmPrimitive> selection) { 106 Collect ion<Command> deleteCommands = new LinkedList<Command>();104 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.ds); 107 105 for (OsmPrimitive osm : selection) 108 deleteCommands.add(new DeleteCommand(osm)); 109 if (!deleteCommands.isEmpty()) 110 mv.editLayer().add(new SequenceCommand(deleteCommands)); 106 osm.visit(v); 107 v.data.addAll(selection); 108 if (!v.data.isEmpty()) 109 mv.editLayer().add(new DeleteCommand(v.data)); 111 110 } 112 111 … … 120 119 */ 121 120 private void delete(Collection<OsmPrimitive> selection, boolean msgBox) { 122 Collection< Command> deleteCommands = new LinkedList<Command>();121 Collection<OsmPrimitive> del = new HashSet<OsmPrimitive>(); 123 122 for (OsmPrimitive osm : selection) { 124 123 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.ds); 125 124 osm.visit(v); 126 125 if (!selection.containsAll(v.data)) { 127 if (msgBox) 126 if (msgBox) { 128 127 JOptionPane.showMessageDialog(Main.main, "This object is in use."); 129 } else 130 deleteCommands.add(new DeleteCommand(osm)); 128 return; 129 } 130 } else { 131 del.addAll(v.data); 132 del.add(osm); 133 } 131 134 } 132 if (!del eteCommands.isEmpty())133 mv.editLayer().add(new SequenceCommand(deleteCommands));135 if (!del.isEmpty()) 136 mv.editLayer().add(new DeleteCommand(del)); 134 137 } 135 138 } -
src/org/openstreetmap/josm/actions/mapmode/MapMode.java
r93 r94 39 39 this.mapFrame = mapFrame; 40 40 mv = mapFrame.mapView; 41 putValue("active", false); 41 42 } 42 43 … … 52 53 } 53 54 54 /** 55 * Register all listener to the mapView 56 * @param mapView The view, where the listener should be registered. 57 */ 58 public void registerListener() { 55 public void enterMode() { 59 56 putValue("active", true); 60 57 } 61 62 /** 63 * Unregister all listener previously registered. 64 * @param mapView The view from which the listener should be deregistered. 65 */ 66 public void unregisterListener() { 58 public void exitMode() { 67 59 putValue("active", false); 68 60 } -
src/org/openstreetmap/josm/actions/mapmode/MoveAction.java
r86 r94 5 5 import java.awt.event.KeyEvent; 6 6 import java.awt.event.MouseEvent; 7 import java.util.Arrays;8 7 import java.util.Collection; 9 8 … … 52 51 } 53 52 54 @Override public void registerListener() {55 super. registerListener();53 @Override public void enterMode() { 54 super.enterMode(); 56 55 mv.addMouseListener(this); 57 56 mv.addMouseMotionListener(this); 58 57 } 59 58 60 @Override public void unregisterListener() {61 super. unregisterListener();59 @Override public void exitMode() { 60 super.exitMode(); 62 61 mv.removeMouseListener(this); 63 62 mv.removeMouseMotionListener(this); … … 96 95 } 97 96 98 Command c = mv.editLayer(). lastCommand();97 Command c = mv.editLayer().commands.getLast(); 99 98 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand)c).objects)) 100 99 ((MoveCommand)c).moveAgain(dx,dy); … … 122 121 OsmPrimitive osm = mv.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0); 123 122 if (osm != null) 124 Main.ds.setSelected( Arrays.asList(new OsmPrimitive[]{osm}));123 Main.ds.setSelected(osm); 125 124 singleOsmPrimitive = osm; 126 125 mv.repaint(); -
src/org/openstreetmap/josm/actions/mapmode/SelectionAction.java
r86 r94 68 68 } 69 69 70 @Override public void registerListener() {71 super. registerListener();70 @Override public void enterMode() { 71 super.enterMode(); 72 72 selectionManager.register(mv); 73 73 } 74 74 75 @Override public void unregisterListener() {76 super. unregisterListener();75 @Override public void exitMode() { 76 super.exitMode(); 77 77 selectionManager.unregister(mv); 78 78 } -
src/org/openstreetmap/josm/actions/mapmode/ZoomAction.java
r86 r94 57 57 } 58 58 59 @Override public void registerListener() {60 super. registerListener();59 @Override public void enterMode() { 60 super.enterMode(); 61 61 selectionManager.register(mv); 62 62 } 63 63 64 @Override public void unregisterListener() {65 super. unregisterListener();64 @Override public void exitMode() { 65 super.exitMode(); 66 66 selectionManager.unregister(mv); 67 67 } -
src/org/openstreetmap/josm/command/AddCommand.java
r93 r94 2 2 3 3 import java.util.Collection; 4 5 import javax.swing.JLabel; 6 import javax.swing.tree.DefaultMutableTreeNode; 7 import javax.swing.tree.MutableTreeNode; 4 8 5 9 import org.openstreetmap.josm.Main; … … 7 11 import org.openstreetmap.josm.data.osm.visitor.AddVisitor; 8 12 import org.openstreetmap.josm.data.osm.visitor.DeleteVisitor; 13 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 9 14 10 15 /** … … 39 44 added.add(osm); 40 45 } 46 47 @Override public MutableTreeNode description() { 48 NameVisitor v = new NameVisitor(); 49 osm.visit(v); 50 return new DefaultMutableTreeNode(new JLabel("Add "+v.className+" "+v.name, v.icon, JLabel.HORIZONTAL)); 51 } 41 52 } -
src/org/openstreetmap/josm/command/ChangeCommand.java
r93 r94 3 3 import java.util.Collection; 4 4 5 import javax.swing.JLabel; 6 import javax.swing.tree.DefaultMutableTreeNode; 7 import javax.swing.tree.MutableTreeNode; 8 5 9 import org.openstreetmap.josm.data.osm.OsmPrimitive; 10 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 6 11 7 12 public class ChangeCommand extends Command { … … 18 23 super.executeCommand(); 19 24 osm.cloneFrom(newOsm); 25 osm.modified = true; 20 26 } 21 27 … … 23 29 modified.add(osm); 24 30 } 31 32 @Override public MutableTreeNode description() { 33 NameVisitor v = new NameVisitor(); 34 osm.visit(v); 35 return new DefaultMutableTreeNode(new JLabel("Change "+v.className+" "+v.name, v.icon, JLabel.HORIZONTAL)); 36 } 25 37 } -
src/org/openstreetmap/josm/command/ChangePropertyCommand.java
r90 r94 5 5 import java.util.List; 6 6 7 import javax.swing.JLabel; 8 import javax.swing.tree.DefaultMutableTreeNode; 9 import javax.swing.tree.MutableTreeNode; 10 7 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 13 import org.openstreetmap.josm.tools.ImageProvider; 8 14 9 15 /** … … 55 61 } 56 62 63 @Override public MutableTreeNode description() { 64 String text = value == null ? "Remove '"+key+"'" : "Set '"+key+"="+value+"'"; 65 text += " for "; 66 if (objects.size() == 1) { 67 NameVisitor v = new NameVisitor(); 68 objects.iterator().next().visit(v); 69 text += v.className+" "+v.name; 70 } else 71 text += objects.size()+" objects"; 72 DefaultMutableTreeNode root = new DefaultMutableTreeNode(new JLabel(text, ImageProvider.get("data", "key"), JLabel.HORIZONTAL)); 73 if (objects.size() == 1) 74 return root; 75 NameVisitor v = new NameVisitor(); 76 for (OsmPrimitive osm : objects) { 77 osm.visit(v); 78 root.add(new DefaultMutableTreeNode(v.toLabel())); 79 } 80 return root; 81 } 57 82 } -
src/org/openstreetmap/josm/command/Command.java
r86 r94 4 4 import java.util.HashSet; 5 5 import java.util.Map.Entry; 6 7 import javax.swing.tree.MutableTreeNode; 6 8 7 9 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 58 60 Collection<OsmPrimitive> deleted, 59 61 Collection<OsmPrimitive> added); 62 63 abstract public MutableTreeNode description(); 60 64 } -
src/org/openstreetmap/josm/command/ConflictResolveCommand.java
r91 r94 9 9 import java.util.Map.Entry; 10 10 11 import javax.swing.JLabel; 12 import javax.swing.tree.DefaultMutableTreeNode; 13 import javax.swing.tree.MutableTreeNode; 14 11 15 import org.openstreetmap.josm.Main; 12 16 import org.openstreetmap.josm.data.conflict.ConflictItem; … … 14 18 import org.openstreetmap.josm.gui.ConflictResolver; 15 19 import org.openstreetmap.josm.gui.dialogs.ConflictDialog; 20 import org.openstreetmap.josm.tools.ImageProvider; 16 21 17 22 public class ConflictResolveCommand extends Command { … … 62 67 modified.addAll(resolved.keySet()); 63 68 } 69 70 @Override public MutableTreeNode description() { 71 int i = 0; 72 for (ConflictItem c : conflicts) 73 if (c.resolution != null) 74 i++; 75 return new DefaultMutableTreeNode(new JLabel("Resolve "+i+" conflicts in "+resolved.size()+" objects", ImageProvider.get("data", "primitive"), JLabel.HORIZONTAL)); 76 } 64 77 } -
src/org/openstreetmap/josm/command/DeleteCommand.java
r86 r94 2 2 3 3 import java.util.Collection; 4 import java.util.HashSet;5 4 6 import org.openstreetmap.josm.Main; 5 import javax.swing.JLabel; 6 import javax.swing.tree.DefaultMutableTreeNode; 7 import javax.swing.tree.MutableTreeNode; 8 7 9 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; 10 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 11 import org.openstreetmap.josm.tools.ImageProvider; 9 12 10 13 /** … … 17 20 * The primitive that get deleted. 18 21 */ 19 final Collection<OsmPrimitive> data = new HashSet<OsmPrimitive>();22 private final Collection<OsmPrimitive> data; 20 23 21 public DeleteCommand(OsmPrimitive osm) { 22 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.ds); 23 osm.visit(v); 24 data.addAll(v.data); 25 data.add(osm); 24 public DeleteCommand(Collection<OsmPrimitive> data) { 25 this.data = data; 26 26 } 27 27 28 28 @Override public void executeCommand() { 29 29 super.executeCommand(); … … 35 35 deleted.addAll(data); 36 36 } 37 38 @Override public MutableTreeNode description() { 39 NameVisitor v = new NameVisitor(); 40 41 if (data.size() == 1) { 42 data.iterator().next().visit(v); 43 return new DefaultMutableTreeNode(new JLabel("Delete "+v.className+" "+v.name, v.icon, JLabel.HORIZONTAL)); 44 } 45 46 String cname = null; 47 for (OsmPrimitive osm : data) { 48 osm.visit(v); 49 if (cname == null) 50 cname = v.className; 51 else if (!cname.equals(v.className)) 52 cname = "primitive"; 53 } 54 DefaultMutableTreeNode root = new DefaultMutableTreeNode(new JLabel("Delete "+data.size()+" "+cname+(data.size()==1?"":"s"), ImageProvider.get("data", cname), JLabel.HORIZONTAL)); 55 for (OsmPrimitive osm : data) { 56 osm.visit(v); 57 root.add(new DefaultMutableTreeNode(v.toLabel())); 58 } 59 return root; 60 } 37 61 } -
src/org/openstreetmap/josm/command/MoveCommand.java
r86 r94 6 6 import java.util.List; 7 7 8 import javax.swing.JLabel; 9 import javax.swing.tree.DefaultMutableTreeNode; 10 import javax.swing.tree.MutableTreeNode; 11 8 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.data.coor.EastNorth; 9 14 import org.openstreetmap.josm.data.coor.LatLon; 10 import org.openstreetmap.josm.data.coor.EastNorth;11 15 import org.openstreetmap.josm.data.osm.Node; 12 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 17 import org.openstreetmap.josm.data.osm.visitor.AllNodesVisitor; 18 import org.openstreetmap.josm.tools.ImageProvider; 14 19 15 20 /** … … 106 111 modified.add(osm); 107 112 } 113 114 @Override public MutableTreeNode description() { 115 return new DefaultMutableTreeNode(new JLabel("Move "+objects.size()+" Node"+(objects.size()==1?"":"s"), ImageProvider.get("data", "node"), JLabel.HORIZONTAL)); 116 } 108 117 } -
src/org/openstreetmap/josm/command/SequenceCommand.java
r86 r94 2 2 3 3 import java.util.Collection; 4 5 import javax.swing.tree.DefaultMutableTreeNode; 6 import javax.swing.tree.MutableTreeNode; 4 7 5 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 15 18 * The command sequenz to be executed. 16 19 */ 17 private Command[] sequen z;20 private Command[] sequence; 18 21 19 22 /** … … 22 25 */ 23 26 public SequenceCommand(Collection<Command> sequenz) { 24 this.sequen z= new Command[sequenz.size()];25 this.sequen z = sequenz.toArray(this.sequenz);27 this.sequence = new Command[sequenz.size()]; 28 this.sequence = sequenz.toArray(this.sequence); 26 29 } 27 30 28 31 @Override public void executeCommand() { 29 for (Command c : sequen z)32 for (Command c : sequence) 30 33 c.executeCommand(); 31 34 } 32 35 33 36 @Override public void undoCommand() { 34 for (int i = sequen z.length-1; i >= 0; --i)35 sequen z[i].undoCommand();37 for (int i = sequence.length-1; i >= 0; --i) 38 sequence[i].undoCommand(); 36 39 } 37 40 38 41 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 39 for (Command c : sequen z)42 for (Command c : sequence) 40 43 c.fillModifiedData(modified, deleted, added); 41 44 } 42 45 46 @Override public MutableTreeNode description() { 47 DefaultMutableTreeNode root = new DefaultMutableTreeNode("Sequence"); 48 for (Command c : sequence) 49 root.add(c.description()); 50 return root; 51 } 43 52 } -
src/org/openstreetmap/josm/data/SelectionChangedListener.java
r8 r94 22 22 * @param newSelection The new selection. 23 23 */ 24 public void selectionChanged(Collection< OsmPrimitive> newSelection);24 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection); 25 25 } -
src/org/openstreetmap/josm/data/osm/DataSet.java
r91 r94 1 1 package org.openstreetmap.josm.data.osm; 2 2 3 import java.util.Arrays; 3 4 import java.util.Collection; 4 5 import java.util.Collections; … … 91 92 } 92 93 93 public void setSelected(Collection< OsmPrimitive> selection) {94 public void setSelected(Collection<? extends OsmPrimitive> selection) { 94 95 clearSelection(); 95 96 for (OsmPrimitive osm : selection) 96 97 osm.selected = true; 97 98 fireSelectionChanged(selection); 99 } 100 101 public void setSelected(OsmPrimitive osm) { 102 clearSelection(); 103 if (osm == null) 104 return; 105 osm.selected = true; 106 fireSelectionChanged(Arrays.asList(new OsmPrimitive[]{osm})); 98 107 } 99 108 … … 127 136 * the event immediately. For more, @see SelectionChangedListener 128 137 */ 129 p rivate void fireSelectionChanged(Collection<OsmPrimitive> sel) {138 public void fireSelectionChanged(Collection<? extends OsmPrimitive> sel) { 130 139 for (SelectionChangedListener l : listeners) 131 140 l.selectionChanged(sel); -
src/org/openstreetmap/josm/data/osm/Node.java
r86 r94 46 46 return osm instanceof Node ? super.realEqual(osm) && coor.equals(((Node)osm).coor) : false; 47 47 } 48 49 public int compareTo(OsmPrimitive o) { 50 return o instanceof Node ? Long.valueOf(id).compareTo(o.id) : -1; 51 } 48 52 } -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r90 r94 23 23 * @author imi 24 24 */ 25 abstract public class OsmPrimitive {25 abstract public class OsmPrimitive implements Comparable<OsmPrimitive> { 26 26 27 27 /** -
src/org/openstreetmap/josm/data/osm/Segment.java
r86 r94 85 85 to.equals(((Segment)osm).to) : false; 86 86 } 87 } 87 88 public int compareTo(OsmPrimitive o) { 89 return o instanceof Segment ? Long.valueOf(id).compareTo(o.id) : (o instanceof Node ? 1 : -1); 90 } 91 } -
src/org/openstreetmap/josm/data/osm/Way.java
r86 r94 46 46 return osm instanceof Way ? super.realEqual(osm) && segments.equals(((Way)osm).segments) : false; 47 47 } 48 49 public int compareTo(OsmPrimitive o) { 50 return o instanceof Way ? Long.valueOf(id).compareTo(o.id) : 1; 51 } 48 52 } -
src/org/openstreetmap/josm/data/osm/visitor/NameVisitor.java
r92 r94 6 6 7 7 import javax.swing.Icon; 8 import javax.swing.JLabel; 8 9 9 10 import org.openstreetmap.josm.data.osm.Segment; … … 82 83 className = "way"; 83 84 } 85 86 public JLabel toLabel() { 87 return new JLabel(name, icon, JLabel.HORIZONTAL); 88 } 84 89 } -
src/org/openstreetmap/josm/gui/MapFrame.java
r93 r94 25 25 import org.openstreetmap.josm.actions.mapmode.ZoomAction; 26 26 import org.openstreetmap.josm.actions.mapmode.AddNodeAction.AddNodeGroup; 27 import org.openstreetmap.josm.gui.dialogs.CommandStackDialog; 27 28 import org.openstreetmap.josm.gui.dialogs.ConflictDialog; 28 29 import org.openstreetmap.josm.gui.dialogs.LayerList; … … 82 83 toolBarActions.add(new IconToggleButton(new AddNodeGroup(this))); 83 84 toolBarActions.add(new IconToggleButton(new AddSegmentAction(this))); 84 toolBarActions.add(new IconToggleButton(new AddWayAction(this , selectionAction)));85 toolBarActions.add(new IconToggleButton(new AddWayAction(this))); 85 86 toolBarActions.add(new IconToggleButton(new DeleteAction(this))); 86 87 … … 122 123 addIconToggle(toggleDialogs, new SelectionListDialog(this)); 123 124 addIconToggle(toggleDialogs, conflictDialog = new ConflictDialog()); 125 addIconToggle(toggleDialogs, new CommandStackDialog(this)); 124 126 125 127 // status line below the map … … 159 161 return; 160 162 if (this.mapMode != null) 161 this.mapMode. unregisterListener();163 this.mapMode.exitMode(); 162 164 this.mapMode = mapMode; 163 mapMode. registerListener();165 mapMode.enterMode(); 164 166 } 165 167 -
src/org/openstreetmap/josm/gui/MapStatus.java
r92 r94 14 14 import java.beans.PropertyChangeEvent; 15 15 import java.beans.PropertyChangeListener; 16 import java.util.Arrays;17 16 import java.util.Collection; 18 17 import java.util.ConcurrentModificationException; … … 155 154 } 156 155 @Override public void mouseClicked(MouseEvent e) { 157 Main.ds.setSelected( Arrays.asList(new OsmPrimitive[]{osm}));156 Main.ds.setSelected(osm); 158 157 mv.repaint(); 159 158 } -
src/org/openstreetmap/josm/gui/MapView.java
r93 r94 85 85 // listend to selection changes to redraw the map 86 86 Main.ds.addSelectionChangedListener(new SelectionChangedListener(){ 87 public void selectionChanged(Collection< OsmPrimitive> newSelection) {87 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 88 88 repaint(); 89 89 } … … 106 106 dataLayer.data.addAllSelectionListener(Main.ds); 107 107 Main.ds = dataLayer.data; 108 dataLayer. addModifiedListener(new ModifiedChangedListener(){109 110 111 112 108 dataLayer.listenerModified.add(new ModifiedChangedListener(){ 109 public void modifiedChanged(boolean value, OsmDataLayer source) { 110 Main.main.setTitle((value?"*":"")+"Java Open Street Map - Editor"); 111 } 112 }); 113 113 } 114 114 -
src/org/openstreetmap/josm/gui/OsmPrimitivRenderer.java
r92 r94 4 4 5 5 import javax.swing.DefaultListCellRenderer; 6 import javax.swing.JLabel;7 6 import javax.swing.JList; 8 7 … … 19 18 20 19 @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 21 Component c =super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);22 if ( c instanceof JLabel &&value != null) {20 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 21 if (value != null) { 23 22 ((OsmPrimitive)value).visit(visitor); 24 ((JLabel)c).setText(visitor.name);25 ((JLabel)c).setIcon(visitor.icon);23 setText(visitor.name); 24 setIcon(visitor.icon); 26 25 } 27 return c;26 return this; 28 27 } 29 28 } -
src/org/openstreetmap/josm/gui/SelectionManager.java
r86 r94 273 273 // nodes 274 274 for (Node n : Main.ds.nodes) { 275 if ( r.contains(nc.getPoint(n.eastNorth)))275 if (!n.deleted && r.contains(nc.getPoint(n.eastNorth))) 276 276 selection.add(n); 277 277 } 278 278 279 279 // pending segments 280 for (Segment ls : Main.ds.segments)281 if ( rectangleContainSegment(r, alt, ls))282 selection.add( ls);280 for (Segment s : Main.ds.segments) 281 if (!s.deleted && rectangleContainSegment(r, alt, s)) 282 selection.add(s); 283 283 284 284 // ways 285 for (Way t : Main.ds.ways) { 286 boolean wholeWaySelected = !t.segments.isEmpty(); 287 for (Segment ls : t.segments) 288 if (rectangleContainSegment(r, alt, ls)) 289 selection.add(ls); 290 else 285 for (Way w : Main.ds.ways) { 286 if (w.deleted) 287 continue; 288 boolean wholeWaySelected = !w.segments.isEmpty(); 289 for (Segment s : w.segments) { 290 if (s.incomplete) 291 continue; 292 if (!rectangleContainSegment(r, alt, s)) { 291 293 wholeWaySelected = false; 294 break; 295 } 296 } 292 297 if (wholeWaySelected) 293 selection.add( t);298 selection.add(w); 294 299 } 295 296 // TODO areas297 300 } 298 301 return selection; -
src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
r90 r94 48 48 49 49 public ConflictDialog() { 50 super("Conflict", " Conflict Dialog", "merge", "Merging conflicts.", "C", KeyEvent.VK_C, "conflict");50 super("Conflict", "conflict", "Merging conflicts.", KeyEvent.VK_C); 51 51 displaylist.setCellRenderer(new OsmPrimitivRenderer()); 52 52 displaylist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); … … 60 60 61 61 JPanel buttonPanel = new JPanel(new GridLayout(1,2)); 62 JButton button = new JButton("Resolve", ImageProvider.get("dialogs", " merge"));62 JButton button = new JButton("Resolve", ImageProvider.get("dialogs", "conflict")); 63 63 button.setToolTipText("Open a merge dialog of all selected items in the list above."); 64 64 button.addActionListener(new ActionListener(){ … … 84 84 85 85 Main.ds.addSelectionChangedListener(new SelectionChangedListener(){ 86 public void selectionChanged(Collection< OsmPrimitive> newSelection) {86 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 87 87 displaylist.clearSelection(); 88 88 for (OsmPrimitive osm : newSelection) { -
src/org/openstreetmap/josm/gui/dialogs/LayerList.java
r91 r94 123 123 */ 124 124 public LayerList(MapFrame mapFrame) { 125 super("Layers", " List of all layers", "layerlist", "Open a list of all loaded layers.", "L", KeyEvent.VK_L, "layerlist");125 super("Layers", "layerlist", "Open a list of all loaded layers.", KeyEvent.VK_L); 126 126 setPreferredSize(new Dimension(320,100)); 127 127 add(new JScrollPane(layers), BorderLayout.CENTER); -
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r92 r94 210 210 */ 211 211 public PropertiesDialog(MapFrame mapFrame) { 212 super("Properties", " Properties Dialog", "properties", "Property for selected objects.", "P", KeyEvent.VK_P, "propertiesdialog");212 super("Properties", "propertiesdialog", "Property for selected objects.", KeyEvent.VK_P); 213 213 mv = mapFrame.mapView; 214 214 … … 284 284 } 285 285 286 public void selectionChanged(Collection< OsmPrimitive> newSelection) {286 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 287 287 if (propertyTable == null) 288 288 return; // selection changed may be received in base class constructor before init -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r93 r94 18 18 import java.util.LinkedList; 19 19 import java.util.Map; 20 import java.util.TreeSet; 20 21 21 22 import javax.swing.ButtonGroup; … … 116 117 */ 117 118 public SelectionListDialog(MapFrame mapFrame) { 118 super("Current Selection", " Selection List", "selectionlist", "Open a selection list window.", "E", KeyEvent.VK_E, "selectionlist");119 super("Current Selection", "selectionlist", "Open a selection list window.", KeyEvent.VK_E); 119 120 setPreferredSize(new Dimension(320,150)); 120 121 displaylist.setCellRenderer(new OsmPrimitivRenderer()); … … 141 142 buttonPanel.add(button); 142 143 144 button = new JButton("Reload", ImageProvider.get("dialogs", "refresh")); 145 button.setToolTipText("Refresh the selection list."); 146 button.addActionListener(new ActionListener(){ 147 public void actionPerformed(ActionEvent e) { 148 selectionChanged(Main.ds.getSelected()); 149 } 150 }); 151 buttonPanel.add(button); 152 143 153 button = new JButton("Search", ImageProvider.get("dialogs", "search")); 144 154 button.setToolTipText("Search for objects."); … … 205 215 * @param newSelection The new selection array. 206 216 */ 207 public void selectionChanged(Collection<OsmPrimitive> newSelection) { 217 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 218 TreeSet<OsmPrimitive> sortedSel = new TreeSet<OsmPrimitive>(newSelection); 208 219 if (list == null) 209 220 return; // selection changed may be received in base class constructor before init 210 list.removeAllElements(); 211 list.setSize(newSelection.size()); 221 list.setSize(sortedSel.size()); 212 222 int i = 0; 213 for (OsmPrimitive osm : newSelection)223 for (OsmPrimitive osm : sortedSel) 214 224 list.setElementAt(osm, i++); 215 225 } -
src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r90 r94 13 13 import org.openstreetmap.josm.Main; 14 14 import org.openstreetmap.josm.actions.JosmAction; 15 import org.openstreetmap.josm.tools.ShortCutLabel; 15 16 16 17 /** … … 44 45 public ToggleDialogAction action; 45 46 46 /** 47 * Create a new ToggleDialog. 48 * @param title The title of the dialog. 49 * @param prefName Name of the base preference setting string (prefix) 50 */ 51 public ToggleDialog(String title, String name, String iconName, String tooltip, String shortCutName, int shortCut, final String prefName) { 52 action = new ToggleDialogAction(name, "dialogs/"+iconName, tooltip, "Alt-"+shortCutName, KeyStroke.getKeyStroke(shortCut, KeyEvent.ALT_MASK), prefName); 47 public ToggleDialog(String name, String iconName, String tooltip, int shortCut) { 48 action = new ToggleDialogAction(name, "dialogs/"+iconName, tooltip, ShortCutLabel.name(shortCut, KeyEvent.ALT_MASK), KeyStroke.getKeyStroke(shortCut, KeyEvent.ALT_MASK), iconName); 53 49 setLayout(new BorderLayout()); 54 add(new JLabel( title), BorderLayout.NORTH);50 add(new JLabel(name), BorderLayout.NORTH); 55 51 setVisible(false); 56 52 setBorder(BorderFactory.createEtchedBorder()); -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r90 r94 23 23 import org.openstreetmap.josm.command.Command; 24 24 import org.openstreetmap.josm.data.osm.DataSet; 25 import org.openstreetmap.josm.data.osm.Segment;26 25 import org.openstreetmap.josm.data.osm.Node; 27 26 import org.openstreetmap.josm.data.osm.OsmPrimitive; 27 import org.openstreetmap.josm.data.osm.Segment; 28 28 import org.openstreetmap.josm.data.osm.Way; 29 29 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; … … 72 72 void modifiedChanged(boolean value, OsmDataLayer source); 73 73 } 74 public interface CommandQueueListener { 75 void commandChanged(); 76 } 74 77 75 78 private static Icon icon; … … 94 97 private boolean fromDisk = false; 95 98 /** 96 * All commands that were made on the dataset. 97 */ 98 p rivateLinkedList<Command> commands = new LinkedList<Command>();99 * All commands that were made on the dataset. Don't write from outside! 100 */ 101 public final LinkedList<Command> commands = new LinkedList<Command>(); 99 102 /** 100 103 * The stack for redoing commands … … 102 105 private Stack<Command> redoCommands = new Stack<Command>(); 103 106 104 /** 105 * List of all listeners for changes of modified flag. 106 */ 107 LinkedList<ModifiedChangedListener> listener; 107 public final LinkedList<ModifiedChangedListener> listenerModified = new LinkedList<ModifiedChangedListener>(); 108 public final LinkedList<CommandQueueListener> listenerCommands = new LinkedList<CommandQueueListener>(); 108 109 109 110 … … 175 176 @Override public void visitBoundingBox(BoundingXYVisitor v) { 176 177 for (Node n : data.nodes) 177 v.visit(n); 178 } 179 180 /** 181 * @return the last command added or <code>null</code> if no command in queue. 182 */ 183 public Command lastCommand() { 184 return commands.isEmpty() ? null : commands.getLast(); 178 if (!n.deleted) 179 v.visit(n); 185 180 } 186 181 … … 197 192 Main.main.redoAction.setEnabled(false); 198 193 setModified(true); 194 for (CommandQueueListener l : listenerCommands) 195 l.commandChanged(); 199 196 } 200 197 … … 213 210 if (commands.isEmpty()) 214 211 setModified(uploadedModified); 212 Main.ds.clearSelection(); 213 for (CommandQueueListener l : listenerCommands) 214 l.commandChanged(); 215 215 } 216 216 /** … … 227 227 Main.main.redoAction.setEnabled(!redoCommands.isEmpty()); 228 228 setModified(true); 229 for (CommandQueueListener l : listenerCommands) 230 l.commandChanged(); 229 231 } 230 232 … … 234 236 * after a successfull upload. 235 237 * 236 * @param uploaded <code>true</code>, if the data was uploaded, false if saved to disk237 238 * @param processed A list of all objects, that were actually uploaded. 238 239 * May be <code>null</code>, which means nothing has been uploaded but … … 292 293 return; 293 294 this.modified = modified; 294 if (listener != null) 295 for (ModifiedChangedListener l : listener) 296 l.modifiedChanged(modified, this); 297 } 298 299 /** 300 * Add the parameter to the intern list of listener for modified state. 301 * @param l Listener to add to the list. Must not be null. 302 */ 303 public void addModifiedListener(ModifiedChangedListener l) { 304 if (listener == null) 305 listener = new LinkedList<ModifiedChangedListener>(); 306 listener.add(l); 295 for (ModifiedChangedListener l : listenerModified) 296 l.modifiedChanged(modified, this); 307 297 } 308 298 … … 328 318 if (counter.deleted[i] > 0) 329 319 s += " ("+counter.deleted[i]+" deleted)"; 330 p.add(new JLabel(s, ImageProvider.get("data", counter.names[i]), JLabel.HORIZONTAL), GBC.eo l().insets(15,0,0,0));320 p.add(new JLabel(s, ImageProvider.get("data", counter.names[i]), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0)); 331 321 } 332 322 return p;
Note:
See TracChangeset
for help on using the changeset viewer.