- Timestamp:
- 2006-04-28T01:32:03+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 31 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r99 r100 98 98 Main.main.editLayer().listenerCommands.add(redoUndoListener); 99 99 } 100 public void layerRemoved(final Layer oldLayer) {} 100 public void layerRemoved(final Layer oldLayer) { 101 if (oldLayer instanceof OsmDataLayer) 102 Main.main.editLayer().listenerCommands.add(redoUndoListener); 103 } 101 104 }); 102 105 if (map.mapView.editLayer != null) … … 110 113 */ 111 114 public final void removeLayer(final Layer layer) { 112 final Collection<Layer> allLayers = map.mapView.getAllLayers(); 113 if (allLayers.size() == 1 && allLayers.iterator().next() == layer) { 114 Main.map.setVisible(false); 115 map.mapView.removeLayer(layer); 116 if (layer instanceof OsmDataLayer) 117 ds = new DataSet(); 118 if (map.mapView.getAllLayers().isEmpty()) 115 119 setMapFrame(null); 116 ds = new DataSet();117 } else {118 map.mapView.removeLayer(layer);119 if (layer instanceof OsmDataLayer)120 ds = new DataSet();121 }122 120 } 123 121 public Main() { -
src/org/openstreetmap/josm/actions/DownloadAction.java
r99 r100 10 10 import java.awt.event.KeyEvent; 11 11 import java.awt.event.KeyListener; 12 import java.awt.event.MouseAdapter; 13 import java.awt.event.MouseEvent; 12 14 import java.io.IOException; 13 15 import java.util.Collection; … … 17 19 import javax.swing.JButton; 18 20 import javax.swing.JCheckBox; 21 import javax.swing.JDialog; 19 22 import javax.swing.JLabel; 20 23 import javax.swing.JOptionPane; … … 283 286 Bookmark b; 284 287 do { 285 int r = JOptionPane.showConfirmDialog(Main.parent, dlg, "Choose an area", 286 JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); 287 if (r != JOptionPane.OK_OPTION) 288 final JOptionPane pane = new JOptionPane(dlg, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 289 final JDialog panedlg = pane.createDialog(Main.parent, "Choose an area"); 290 bookmarks.addMouseListener(new MouseAdapter(){ 291 @Override public void mouseClicked(MouseEvent e) { 292 if (e.getClickCount() >= 2) { 293 pane.setValue(JOptionPane.OK_OPTION); 294 panedlg.setVisible(false); 295 } 296 } 297 }); 298 panedlg.setVisible(true); 299 Object answer = pane.getValue(); 300 if (answer == null || answer == JOptionPane.UNINITIALIZED_VALUE || (answer instanceof Integer && (Integer)answer != JOptionPane.OK_OPTION)) 288 301 return; 289 302 b = readBookmark(); -
src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java
r99 r100 114 114 } 115 115 116 c = new SequenceCommand( cmds);116 c = new SequenceCommand("Add Node into Segment", cmds); 117 117 } 118 118 Main.main.editLayer().add(c); -
src/org/openstreetmap/josm/actions/mapmode/AddWayAction.java
r99 r100 88 88 way = w; 89 89 Main.ds.setSelected(way); 90 for (Segment seg : way.segments) { 91 if (seg.incomplete) { 92 JOptionPane.showMessageDialog(Main.parent, "Warning: This way is incomplete. Try to download it, before adding segments."); 93 return; 94 } 95 } 90 96 return; 91 97 } … … 128 134 return null; 129 135 130 if (selection.size() == 1 && selection.iterator().next() instanceof Way) 131 return (Way)selection.iterator().next(); 136 if (selection.size() == 1 && selection.iterator().next() instanceof Way) { 137 Way way = (Way)selection.iterator().next(); 138 for (Segment seg : way.segments) { 139 if (seg.incomplete) { 140 JOptionPane.showMessageDialog(Main.parent, "Warning: This way is incomplete. Try to download it, before adding segments."); 141 break; 142 } 143 } 144 return way; 145 } 132 146 133 147 HashSet<Segment> segmentSet = new HashSet<Segment>(); … … 220 234 Way w = new Way(); 221 235 w.segments.addAll(sortedSegments); 222 223 if (way != null) 224 Main.main.editLayer().add(new AddCommand(way)); 236 Main.main.editLayer().add(new AddCommand(w)); 225 237 return w; 226 238 } -
src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r98 r100 4 4 import java.awt.event.KeyEvent; 5 5 import java.awt.event.MouseEvent; 6 import java.util.ArrayList; 7 import java.util.Arrays; 6 8 import java.util.Collection; 7 9 import java.util.Collections; 8 10 import java.util.HashSet; 11 import java.util.Map.Entry; 9 12 10 13 import javax.swing.JOptionPane; 11 14 12 15 import org.openstreetmap.josm.Main; 16 import org.openstreetmap.josm.command.ChangeCommand; 17 import org.openstreetmap.josm.command.Command; 13 18 import org.openstreetmap.josm.command.DeleteCommand; 19 import org.openstreetmap.josm.command.SequenceCommand; 20 import org.openstreetmap.josm.data.osm.Node; 14 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 import org.openstreetmap.josm.data.osm.Segment; 23 import org.openstreetmap.josm.data.osm.Way; 15 24 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; 16 25 import org.openstreetmap.josm.gui.MapFrame; … … 115 124 * inform the user and do not delete. 116 125 * 126 * If deleting a node which is part of exactly two segments, and both segments 127 * have no conflicting keys, join them and remove the node. 128 * 117 129 * @param selection The objects to delete. 118 130 * @param msgBox Whether a message box for errors should be shown … … 124 136 osm.visit(v); 125 137 if (!selection.containsAll(v.data)) { 126 if (msgBox) { 138 if (osm instanceof Node) { 139 String reason = deleteNodeAndJoinSegment((Node)osm); 140 if (reason != null && msgBox) { 141 JOptionPane.showMessageDialog(Main.parent, "Cannot delete node. "+reason); 142 return; 143 } 144 } else if (msgBox) { 127 145 JOptionPane.showMessageDialog(Main.parent, "This object is in use."); 128 146 return; … … 136 154 Main.main.editLayer().add(new DeleteCommand(del)); 137 155 } 156 157 private String deleteNodeAndJoinSegment(Node n) { 158 ArrayList<Segment> segs = new ArrayList<Segment>(2); 159 for (Segment s : Main.ds.segments) { 160 if (!s.deleted && (s.from == n || s.to == n)) { 161 if (segs.size() > 1) 162 return "Used by more than two segments."; 163 segs.add(s); 164 } 165 } 166 if (segs.size() != 2) 167 return "Used by only one segment."; 168 Segment seg1 = segs.get(0); 169 Segment seg2 = segs.get(1); 170 if (seg1.from == seg2.to) { 171 Segment s = seg1; 172 seg1 = seg2; 173 seg2 = s; 174 } 175 for (Way w : Main.ds.ways) 176 if (!w.deleted && (w.segments.contains(seg1) || w.segments.contains(seg2))) 177 return "Used in a way."; 178 if (seg1.from == seg2.from || seg1.to == seg2.to) 179 return "Wrong direction of segments."; 180 for (Entry<String, String> e : seg1.entrySet()) 181 if (seg2.keySet().contains(e.getKey()) && !seg2.get(e.getKey()).equals(e.getValue())) 182 return "Conflicting keys"; 183 Segment s = new Segment(seg1); 184 s.to = seg2.to; 185 if (s.keys == null) 186 s.keys = seg2.keys; 187 else if (seg2.keys != null) 188 s.keys.putAll(seg2.keys); 189 Command[] cmds = new Command[]{ 190 new ChangeCommand(seg1, s), 191 new DeleteCommand(Arrays.asList(new OsmPrimitive[]{n, seg2}))}; 192 Main.main.editLayer().add(new SequenceCommand("Delete Node", Arrays.asList(cmds))); 193 return null; 194 } 138 195 } -
src/org/openstreetmap/josm/command/SequenceCommand.java
r94 r100 19 19 */ 20 20 private Command[] sequence; 21 private final String name; 21 22 22 23 /** … … 24 25 * @param sequenz The sequenz that should be executed. 25 26 */ 26 public SequenceCommand(Collection<Command> sequenz) { 27 public SequenceCommand(String name, Collection<Command> sequenz) { 28 this.name = name; 27 29 this.sequence = new Command[sequenz.size()]; 28 30 this.sequence = sequenz.toArray(this.sequence); … … 45 47 46 48 @Override public MutableTreeNode description() { 47 DefaultMutableTreeNode root = new DefaultMutableTreeNode("Sequence ");49 DefaultMutableTreeNode root = new DefaultMutableTreeNode("Sequence: "+name); 48 50 for (Command c : sequence) 49 51 root.add(c.description()); -
src/org/openstreetmap/josm/data/Preferences.java
r98 r100 128 128 properties.put("projection", "org.openstreetmap.josm.data.projection.Epsg4326"); 129 129 properties.put("osm-server.url", "http://www.openstreetmap.org/api"); 130 properties.put("color.background", ColorHelper.color2html(Color.black)); 130 131 properties.put("color.node", ColorHelper.color2html(Color.red)); 131 132 properties.put("color.segment", ColorHelper.color2html(SimplePaintVisitor.darkgreen)); … … 134 135 properties.put("color.selected", ColorHelper.color2html(Color.white)); 135 136 properties.put("color.gps point", ColorHelper.color2html(Color.gray)); 137 properties.put("color.conflict", ColorHelper.color2html(Color.gray)); 136 138 save(); 137 139 } -
src/org/openstreetmap/josm/data/osm/Node.java
r94 r100 48 48 49 49 public int compareTo(OsmPrimitive o) { 50 return o instanceof Node ? Long.valueOf(id).compareTo(o.id) : -1;50 return o instanceof Node ? Long.valueOf(id).compareTo(o.id) : 1; 51 51 } 52 52 } -
src/org/openstreetmap/josm/data/osm/Segment.java
r97 r100 88 88 89 89 public int compareTo(OsmPrimitive o) { 90 return o instanceof Segment ? Long.valueOf(id).compareTo(o.id) : (o instanceof Node ? 1 : -1);90 return o instanceof Segment ? Long.valueOf(id).compareTo(o.id) : (o instanceof Node ? -1 : 1); 91 91 } 92 92 } -
src/org/openstreetmap/josm/data/osm/Way.java
r94 r100 48 48 49 49 public int compareTo(OsmPrimitive o) { 50 return o instanceof Way ? Long.valueOf(id).compareTo(o.id) : 1;50 return o instanceof Way ? Long.valueOf(id).compareTo(o.id) : -1; 51 51 } 52 52 } -
src/org/openstreetmap/josm/data/osm/visitor/CollectBackReferencesVisitor.java
r86 r100 21 21 22 22 private final DataSet ds; 23 23 24 24 /** 25 25 * The result list of primitives stored here. … … 35 35 this.ds = ds; 36 36 } 37 37 38 38 public void visit(Node n) { 39 for (Way t: ds.ways) {40 if ( t.deleted)39 for (Way w : ds.ways) { 40 if (w.deleted) 41 41 continue; 42 for (Segment ls : t.segments) {42 for (Segment ls : w.segments) { 43 43 if (ls.incomplete) 44 44 continue; 45 45 if (ls.from == n || ls.to == n) { 46 data.add( t);46 data.add(w); 47 47 break; 48 48 } -
src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java
r97 r100 9 9 10 10 import org.openstreetmap.josm.data.osm.DataSet; 11 import org.openstreetmap.josm.data.osm.Segment;12 11 import org.openstreetmap.josm.data.osm.Node; 13 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 import org.openstreetmap.josm.data.osm.Segment; 14 14 import org.openstreetmap.josm.data.osm.Way; 15 15 … … 116 116 } 117 117 118 private <T extends OsmPrimitive> void cloneFromExceptIncomplete(T myOsm, T otherOsm) { 119 if (!(myOsm instanceof Way)) 120 myOsm.cloneFrom(otherOsm); 121 else { 122 Way my = (Way)myOsm; 123 Way other = (Way)otherOsm; 124 HashMap<Long, Segment> copy = new HashMap<Long, Segment>(); 125 for (Segment s : my.segments) 126 copy.put(s.id, s); 127 my.cloneFrom(other); 128 my.segments.clear(); 129 for (Segment s : other.segments) { 130 Segment myS = copy.get(s.id); 131 if (s.incomplete && myS != null && !myS.incomplete) { 132 mergedSegments.put(s, myS); 133 my.segments.add(myS); 134 } else 135 my.segments.add(s); 136 } 137 } 138 } 139 118 140 /** 119 141 * Merge the way if id matches or if all segments matches and the … … 144 166 } 145 167 if (!same) { 168 HashMap<Long, Segment> copy = new HashMap<Long, Segment>(); 169 for (Segment s : my.segments) 170 copy.put(s.id, s); 146 171 my.segments.clear(); 147 my.segments.addAll(other.segments); 172 for (Segment s : other.segments) { 173 Segment myS = copy.get(s.id); 174 if (s.incomplete && myS != null && !myS.incomplete) { 175 mergedSegments.put(s, myS); 176 my.segments.add(myS); 177 } else 178 my.segments.add(s); 179 } 148 180 my.modified = other.modified; 149 181 } … … 273 305 } else if (!my.modified && !other.modified) { 274 306 if (d1.before(d2)) { 275 my.cloneFrom(other);307 cloneFromExceptIncomplete(my, other); 276 308 if (merged != null) 277 309 merged.put(other, my); … … 283 315 merged.put(other, my); 284 316 } else { 285 my.cloneFrom(other);317 cloneFromExceptIncomplete(my, other); 286 318 if (merged != null) 287 319 merged.put(other, my); -
src/org/openstreetmap/josm/data/osm/visitor/NameVisitor.java
r94 r100 43 43 if (name == null) { 44 44 if (ls.incomplete) 45 name = ls.id == 0 ? "new" : ""+ls.id ;45 name = ls.id == 0 ? "new" : ""+ls.id+" (unknown)"; 46 46 else 47 47 name = (ls.id==0?"":ls.id+" ")+"("+ls.from.coor.lat()+","+ls.from.coor.lon()+") -> ("+ls.to.coor.lat()+","+ls.to.coor.lon()+")"; … … 71 71 if (name == null) { 72 72 AllNodesVisitor.getAllNodes(w.segments); 73 boolean incomplete = false; 73 74 Set<Node> nodes = new HashSet<Node>(); 74 75 for (Segment ls : w.segments) { … … 76 77 nodes.add(ls.from); 77 78 nodes.add(ls.to); 78 } 79 } else 80 incomplete = true; 79 81 } 80 name = "("+nodes.size()+" nodes)"; 82 name = nodes.size()+" nodes"; 83 if (incomplete) 84 name += " (incomplete)"; 81 85 } 82 86 icon = ImageProvider.get("data", "way"); -
src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
r99 r100 116 116 public static Color getPreferencesColor(String colName, Color def) { 117 117 String colStr = Main.pref.get("color."+colName); 118 if (colStr.equals("")) 118 if (colStr.equals("")) { 119 Main.pref.put("color."+colName, ColorHelper.color2html(def)); 119 120 return def; 121 } 120 122 return ColorHelper.html2color(colStr); 121 123 } -
src/org/openstreetmap/josm/gui/MapMover.java
r86 r100 32 32 private Cursor oldCursor; 33 33 34 private boolean movementInPlace = false; 34 35 35 36 /** … … 84 85 */ 85 86 private void startMovement(MouseEvent e) { 87 if (movementInPlace) 88 return; 89 movementInPlace = true; 86 90 mousePosMove = nc.getEastNorth(e.getX(), e.getY()); 87 91 oldCursor = nc.getCursor(); … … 93 97 */ 94 98 private void endMovement() { 99 if (!movementInPlace) 100 return; 101 movementInPlace = false; 95 102 if (oldCursor != null) 96 103 nc.setCursor(oldCursor); -
src/org/openstreetmap/josm/gui/MapStatus.java
r94 r100 12 12 import java.awt.event.MouseEvent; 13 13 import java.awt.event.MouseMotionListener; 14 import java.beans.PropertyChangeEvent;15 import java.beans.PropertyChangeListener;16 14 import java.util.Collection; 17 15 import java.util.ConcurrentModificationException; … … 79 77 */ 80 78 private Popup popup; 81 /** 82 * Signals the collector to shut down on next event. 83 */ 84 boolean exitCollector = false; 79 80 private MapFrame parent; 81 82 public Collector(MapFrame parent) { 83 this.parent = parent; 84 } 85 85 86 86 /** … … 95 95 ms.mousePos = mouseState.mousePos; 96 96 } 97 if ( exitCollector)98 return; 97 if (parent != Main.map) 98 return; // exit, if new parent. 99 99 if ((ms.modifiers & MouseEvent.CTRL_DOWN_MASK) != 0 || ms.mousePos == null) 100 100 continue; // freeze display when holding down ctrl … … 218 218 219 219 // The background thread 220 final Collector collector = new Collector( );220 final Collector collector = new Collector(mapFrame); 221 221 new Thread(collector).start(); 222 222 … … 233 233 } 234 234 }, AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK); 235 236 // listen for shutdowns to cancel the background thread237 mapFrame.addPropertyChangeListener("visible", new PropertyChangeListener(){238 public void propertyChange(PropertyChangeEvent evt) {239 if (evt.getNewValue() == Boolean.FALSE) {240 collector.exitCollector = true;241 synchronized (collector) {242 collector.notify();243 }244 }245 }246 });247 235 } 248 236 } -
src/org/openstreetmap/josm/gui/MapView.java
r99 r100 28 28 import org.openstreetmap.josm.data.osm.OsmPrimitive; 29 29 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 30 import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor; 30 31 import org.openstreetmap.josm.data.projection.Projection; 31 32 import org.openstreetmap.josm.gui.layer.Layer; … … 85 86 86 87 private final class Scaler extends JSlider implements PropertyChangeListener, ChangeListener { 87 boolean hovered = false;88 boolean clicked = false; 88 89 public Scaler() { 89 90 super(0, 20); 90 91 addMouseListener(new MouseAdapter(){ 91 @Override public void mouse Entered(MouseEvent e) {92 hovered = true;92 @Override public void mousePressed(MouseEvent e) { 93 clicked = true; 93 94 } 94 @Override public void mouse Exited(MouseEvent e) {95 hovered = false;95 @Override public void mouseReleased(MouseEvent e) { 96 clicked = false; 96 97 } 97 98 }); … … 104 105 } 105 106 public void stateChanged(ChangeEvent e) { 106 if (! hovered)107 if (!clicked) 107 108 return; 108 109 EastNorth pos = world; … … 206 207 */ 207 208 @Override public void paint(Graphics g) { 208 g.setColor( Color.BLACK);209 g.setColor(SimplePaintVisitor.getPreferencesColor("background", Color.BLACK)); 209 210 g.fillRect(0, 0, getWidth(), getHeight()); 210 211 -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r98 r100 315 315 warning.setFont(warning.getFont().deriveFont(Font.ITALIC)); 316 316 con.add(warning, GBC.eop().fill(GBC.HORIZONTAL)); 317 con.add(new JLabel("WMS server base url (everything except bbox-parameter)"), GBC.eol());318 con.add(wmsServerBaseUrl, GBC.eop().fill(GBC.HORIZONTAL));319 con.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));317 //con.add(new JLabel("WMS server base url (everything except bbox-parameter)"), GBC.eol()); 318 //con.add(wmsServerBaseUrl, GBC.eop().fill(GBC.HORIZONTAL)); 319 //con.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); 320 320 con.add(new JLabel("CSV import specification (empty: read from first line in data)"), GBC.eol()); 321 321 con.add(csvImportString, GBC.eop().fill(GBC.HORIZONTAL)); -
src/org/openstreetmap/josm/gui/SelectionManager.java
r99 r100 123 123 * @param eventSource The emitter of the mouse events. 124 124 */ 125 public void register( Component eventSource) {125 public void register(NavigatableComponent eventSource) { 126 126 eventSource.addMouseListener(this); 127 127 eventSource.addMouseMotionListener(this); … … 134 134 mousePosStart = null; 135 135 mousePos = null; 136 } 137 }); 138 eventSource.addPropertyChangeListener("scale", new PropertyChangeListener(){ 139 public void propertyChange(PropertyChangeEvent evt) { 140 if (mousePosStart != null) { 141 paintRect(); 142 mousePos = mousePosStart = null; 143 } 136 144 } 137 145 }); -
src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java
r99 r100 36 36 Main.main.editLayer().listenerCommands.add(CommandStackDialog.this); 37 37 } 38 public void layerRemoved(Layer oldLayer) {} 38 public void layerRemoved(Layer oldLayer) { 39 if (oldLayer instanceof OsmDataLayer) 40 Main.main.editLayer().listenerCommands.remove(CommandStackDialog.this); 41 } 39 42 }); 40 43 if (mapFrame.mapView.editLayer != null) … … 69 72 70 73 private void buildList() { 74 if (Main.map == null || Main.map.mapView == null || Main.map.mapView.editLayer == null) 75 return; 71 76 Collection<Command> commands = Main.main.editLayer().commands; 72 77 DefaultMutableTreeNode root = new DefaultMutableTreeNode(); … … 74 79 root.add(c.description()); 75 80 treeModel.setRoot(root); 81 tree.scrollRowToVisible(treeModel.getChildCount(root)-1); 76 82 } 77 83 -
src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
r98 r100 140 140 */ 141 141 public void paintConflicts(final Graphics g, final NavigatableComponent nc) { 142 Color preferencesColor = SimplePaintVisitor.getPreferencesColor("conflict", Color. GRAY);142 Color preferencesColor = SimplePaintVisitor.getPreferencesColor("conflict", Color.gray); 143 143 if (preferencesColor.equals(Color.BLACK)) 144 144 return; -
src/org/openstreetmap/josm/gui/dialogs/LayerList.java
r98 r100 145 145 layers.addListSelectionListener(new ListSelectionListener(){ 146 146 public void valueChanged(ListSelectionEvent e) { 147 if (layers.getModel().getSize() == 0) 148 return; 147 149 if (layers.getSelectedIndex() == -1) 148 150 layers.setSelectedIndex(e.getFirstIndex()); -
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r98 r100 11 11 import java.awt.event.MouseAdapter; 12 12 import java.awt.event.MouseEvent; 13 import java.awt.event.WindowEvent;14 import java.awt.event.WindowFocusListener;15 13 import java.util.Collection; 16 14 import java.util.HashMap; 17 import java.util.Iterator;18 15 import java.util.Map; 19 16 import java.util.TreeMap; … … 93 90 p.add(combo, BorderLayout.CENTER); 94 91 95 final JOptionPane optionPane = new JOptionPane(p, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 92 final JOptionPane optionPane = new JOptionPane(p, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION){ 93 @Override public void selectInitialValue() { 94 combo.requestFocusInWindow(); 95 combo.getEditor().selectAll(); 96 } 97 }; 96 98 final JDialog dlg = optionPane.createDialog(Main.parent, "Change values?"); 97 dlg.addWindowFocusListener(new WindowFocusListener(){98 public void windowGainedFocus(WindowEvent e) {99 combo.requestFocusInWindow();100 }101 public void windowLostFocus(WindowEvent e) {102 }103 });104 99 combo.getEditor().addActionListener(new ActionListener(){ 105 100 public void actionPerformed(ActionEvent e) { … … 130 125 PropertiesDialog.this.repaint(); // repaint is enough 131 126 } 132 127 133 128 /** 134 129 * Open the add selection dialog and add a new key/value to the table (and to the … … 137 132 void add() { 138 133 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 139 134 140 135 JPanel p = new JPanel(new BorderLayout()); 141 136 p.add(new JLabel("<html>This will change "+sel.size()+" object"+(sel.size()==1?"":"s")+".<br><br>"+ 142 137 "Please select a key"), BorderLayout.NORTH); 143 Vector<String> allKeys = new Vector<String>();138 TreeSet<String> allKeys = new TreeSet<String>(); 144 139 for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) 145 140 allKeys.addAll(osm.keySet()); 146 for (Iterator<String> it = allKeys.iterator(); it.hasNext();) { 147 String s = it.next(); 148 for (int i = 0; i < data.getRowCount(); ++i) { 149 if (s.equals(data.getValueAt(i, 0))) { 150 it.remove(); 151 break; 152 } 153 } 154 } 155 JComboBox keys = new JComboBox(allKeys); 141 for (int i = 0; i < data.getRowCount(); ++i) 142 allKeys.remove(data.getValueAt(i, 0)); 143 final JComboBox keys = new JComboBox(new Vector<String>(allKeys)); 156 144 keys.setEditable(true); 157 145 p.add(keys, BorderLayout.CENTER); 158 146 159 147 JPanel p2 = new JPanel(new BorderLayout()); 160 148 p.add(p2, BorderLayout.SOUTH); 161 149 p2.add(new JLabel("Please select a value"), BorderLayout.NORTH); 162 JTextField values = new JTextField();150 final JTextField values = new JTextField(); 163 151 p2.add(values, BorderLayout.CENTER); 164 int answer = JOptionPane.showConfirmDialog(Main.parent, p, 165 "Change values?", JOptionPane.OK_CANCEL_OPTION); 166 if (answer != JOptionPane.OK_OPTION) 152 JOptionPane pane = new JOptionPane(p, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION){ 153 @Override public void selectInitialValue() { 154 keys.requestFocusInWindow(); 155 keys.getEditor().selectAll(); 156 } 157 }; 158 pane.createDialog(Main.parent, "Change values?").setVisible(true); 159 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) 167 160 return; 168 161 String key = keys.getEditor().getItem().toString(); … … 184 177 selectionChanged(sel); // update table 185 178 } 186 179 187 180 /** 188 181 * The property data. … … 200 193 */ 201 194 private final JTable propertyTable = new JTable(data); 202 195 203 196 /** 204 197 * Create a new PropertiesDialog … … 208 201 209 202 setPreferredSize(new Dimension(320,150)); 210 203 211 204 data.setColumnIdentifiers(new String[]{"Key", "Value"}); 212 205 propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); … … 228 221 } 229 222 }); 230 //propertyTable.addMouseListener(new DblClickWatch());231 223 DblClickWatch dblClickWatch = new DblClickWatch(); 224 propertyTable.addMouseListener(dblClickWatch); 232 225 JScrollPane scrollPane = new JScrollPane(propertyTable); 233 scrollPane.addMouseListener( new DblClickWatch());226 scrollPane.addMouseListener(dblClickWatch); 234 227 add(scrollPane, BorderLayout.CENTER); 235 228 236 229 JPanel buttonPanel = new JPanel(new GridLayout(1,3)); 237 230 ActionListener buttonAction = new ActionListener(){ … … 258 251 add(buttonPanel, BorderLayout.SOUTH); 259 252 } 260 253 261 254 private JButton createButton(String name, String tooltip, int mnemonic, ActionListener actionListener) { 262 255 JButton b = new JButton(name, ImageProvider.get("dialogs", name.toLowerCase())); … … 284 277 propertyTable.getCellEditor().cancelCellEditing(); 285 278 data.setRowCount(0); 286 279 287 280 Map<String, Integer> valueCount = new HashMap<String, Integer>(); 288 281 TreeMap<String, Collection<String>> props = new TreeMap<String, Collection<String>>(); -
src/org/openstreetmap/josm/gui/layer/GeoImageLayer.java
r99 r100 5 5 import java.awt.Component; 6 6 import java.awt.Cursor; 7 import java.awt.Dimension;8 7 import java.awt.Graphics; 9 8 import java.awt.GridBagLayout; … … 24 23 import java.util.Date; 25 24 import java.util.LinkedList; 26 import java.util.List;27 25 import java.util.regex.Matcher; 28 26 import java.util.regex.Pattern; … … 82 80 private final RawGpsLayer gpsLayer; 83 81 public Loader(Collection<File> files, RawGpsLayer gpsLayer) { 84 85 82 super("Images"); 83 this.files = files; 86 84 this.gpsLayer = gpsLayer; 87 85 } 88 86 @Override protected void realRun() throws SAXException, JDOMException, IOException { 89 87 currentAction.setText("Read GPS..."); 90 layer = new GeoImageLayer();88 LinkedList<TimedPoint> gps = new LinkedList<TimedPoint>(); 91 89 92 90 // check the gps layer for time loops (and process it on the way) … … 102 100 throw new IOException("Cannot read time from point "+p.latlon.lat()+","+p.latlon.lon()); 103 101 Date d = dateFormat.parse(m.group(1)+" "+m.group(2)); 104 layer.gps.add(new TimedPoint(d, p.eastNorth));102 gps.add(new TimedPoint(d, p.eastNorth)); 105 103 if (last != null && last.after(d)) 106 104 throw new IOException("Time loop in gps data."); … … 112 110 } 113 111 114 if ( layer.gps.isEmpty()) {115 layer.data = new ArrayList<ImageEntry>();112 if (gps.isEmpty()) { 113 errorMessage = "No images with readable timestamps found."; 116 114 return; 117 115 } 118 116 119 117 // read the image files 120 layer.data = new ArrayList<ImageEntry>(files.size());118 ArrayList<ImageEntry> data = new ArrayList<ImageEntry>(files.size()); 121 119 int i = 0; 122 120 progress.setMaximum(files.size()); … … 134 132 e.icon = loadScaledImage(f, 16); 135 133 136 layer.data.add(e); 137 } 134 data.add(e); 135 } 136 layer = new GeoImageLayer(data, gps); 138 137 layer.calculatePosition(); 139 138 } 140 139 @Override protected void finish() { 141 140 if (layer != null) … … 144 143 @Override protected void cancel() {cancelled = true;} 145 144 } 146 147 public List<ImageEntry> data;145 146 public ArrayList<ImageEntry> data; 148 147 private LinkedList<TimedPoint> gps = new LinkedList<TimedPoint>(); 149 148 150 149 /** 151 150 * The delta added to all timestamps in files from the camera … … 156 155 private boolean mousePressed = false; 157 156 private static final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); 157 private MouseAdapter mouseAdapter; 158 158 159 159 public static final class GpsTimeIncorrect extends Exception { … … 180 180 loader.pleaseWaitDlg.setVisible(true); 181 181 } 182 183 private GeoImageLayer( ) {182 183 private GeoImageLayer(final ArrayList<ImageEntry> data, LinkedList<TimedPoint> gps) { 184 184 super("Geotagged Images"); 185 Main.map.mapView.addMouseListener(new MouseAdapter(){ 185 this.data = data; 186 this.gps = gps; 187 mouseAdapter = new MouseAdapter(){ 186 188 @Override public void mousePressed(MouseEvent e) { 187 189 if (e.getButton() != MouseEvent.BUTTON1) … … 190 192 if (visible) 191 193 Main.map.mapView.repaint(); 192 194 } 193 195 @Override public void mouseReleased(MouseEvent ev) { 194 196 if (ev.getButton() != MouseEvent.BUTTON1) … … 197 199 if (!visible) 198 200 return; 199 for (ImageEntry e : data) { 201 for (int i = data.size(); i > 0; --i) { 202 ImageEntry e = data.get(i-1); 200 203 if (e.pos == null) 201 204 continue; … … 208 211 } 209 212 Main.map.mapView.repaint(); 210 } 211 }); 213 } 214 }; 215 Main.map.mapView.addMouseListener(mouseAdapter); 212 216 } 213 217 214 218 private void showImage(final ImageEntry e) { 215 219 final JPanel p = new JPanel(new BorderLayout()); 216 final JScrollPane scroll = new JScrollPane(new JLabel(new ImageIcon(e.image.getPath()))); 217 scroll.setPreferredSize(new Dimension(800,600)); 220 final JScrollPane scroll = new JScrollPane(new JLabel(loadScaledImage(e.image, 580))); 221 //scroll.setPreferredSize(new Dimension(800,600)); 222 final JViewport vp = scroll.getViewport(); 218 223 p.add(scroll, BorderLayout.CENTER); 219 224 220 225 final JToggleButton scale = new JToggleButton(ImageProvider.get("misc", "rectangle")); 221 226 JPanel p2 = new JPanel(); … … 224 229 scale.addActionListener(new ActionListener(){ 225 230 public void actionPerformed(ActionEvent ev) { 226 JViewport vp = scroll.getViewport();227 231 p.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 228 232 if (scale.getModel().isSelected()) 229 vp.setView(new JLabel(loadScaledImage(e.image, Math.max(vp.getWidth(), vp.getHeight()))));233 ((JLabel)vp.getView()).setIcon(loadScaledImage(e.image, Math.max(vp.getWidth(), vp.getHeight()))); 230 234 else 231 vp.setView(new JLabel(new ImageIcon(e.image.getPath())));235 ((JLabel)vp.getView()).setIcon(new ImageIcon(e.image.getPath())); 232 236 p.setCursor(Cursor.getDefaultCursor()); 233 237 } 234 238 }); 239 scale.setSelected(true); 235 240 JOptionPane.showMessageDialog(Main.parent, p, e.image+" ("+e.coor.lat()+","+e.coor.lon()+")", JOptionPane.PLAIN_MESSAGE); 236 241 } 237 242 238 243 @Override public Icon getIcon() { … … 246 251 p.add(new JLabel("GPS start: "+dateFormat.format(gps.getFirst().time)), GBC.eol()); 247 252 p.add(new JLabel("GPS end: "+dateFormat.format(gps.getLast().time)), GBC.eop()); 248 253 249 254 p.add(new JLabel("current delta: "+(delta/1000.0)+"s"), GBC.eol()); 250 255 p.add(new JLabel("timezone difference: "+(gpstimezone>0?"+":"")+(gpstimezone/1000/60/60)), GBC.eop()); 251 256 252 257 JList img = new JList(data.toArray()); 253 258 img.setCellRenderer(new DefaultListCellRenderer(){ … … 291 296 Rectangle r = new Rectangle(p.x-e.icon.getIconWidth()/2, p.y-e.icon.getIconHeight()/2, e.icon.getIconWidth(), e.icon.getIconHeight()); 292 297 e.icon.paintIcon(mv, g, r.x, r.y); 293 Border b = BorderFactory.createBevelBorder(!clickedFound && mousePressed && r.contains(mv.getMousePosition()) ? BevelBorder.LOWERED : BevelBorder.RAISED); 294 Insets i = b.getBorderInsets(mv); 295 r.grow((i.top+i.bottom)/2, (i.left+i.right)/2); 298 Border b = null; 299 if (!clickedFound && mousePressed && r.contains(mv.getMousePosition())) { 300 b = BorderFactory.createBevelBorder(BevelBorder.LOWERED); 301 clickedFound = true; 302 } else 303 b = BorderFactory.createBevelBorder(BevelBorder.RAISED); 304 Insets inset = b.getBorderInsets(mv); 305 r.grow((inset.top+inset.bottom)/2, (inset.left+inset.right)/2); 296 306 b.paintBorder(mv, g, r.x, r.y, r.width, r.height); 297 307 } … … 402 412 return new ImageIcon(img.getScaledInstance(w, h, Image.SCALE_SMOOTH)); 403 413 } 414 415 @Override public void layerRemoved() { 416 Main.map.mapView.removeMouseListener(mouseAdapter); 417 } 404 418 } -
src/org/openstreetmap/josm/gui/layer/Layer.java
r86 r100 83 83 84 84 abstract public void addMenuEntries(JPopupMenu menu); 85 86 /** 87 * Called, when the layer is removed from the list. (See it as an destructor) 88 */ 89 public void layerRemoved() {} 85 90 } -
src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r98 r100 76 76 } 77 77 78 private static Icon icon;79 80 78 /** 81 79 * The data behind this layer. … … 107 105 public final LinkedList<ModifiedChangedListener> listenerModified = new LinkedList<ModifiedChangedListener>(); 108 106 public final LinkedList<CommandQueueListener> listenerCommands = new LinkedList<CommandQueueListener>(); 109 110 107 111 108 /** … … 123 120 */ 124 121 @Override public Icon getIcon() { 125 if (icon == null) 126 icon = ImageProvider.get("layer", "osmdata"); 127 return icon; 122 return ImageProvider.get("layer", "osmdata"); 128 123 } 129 124 … … 202 197 redoCommands.push(c); 203 198 //TODO: Replace with listener scheme 204 199 setModified(uploadedModified); 205 200 Main.ds.clearSelection(); 206 201 fireCommandsChanged(); … … 255 250 256 251 public void fireCommandsChanged() { 257 252 for (final CommandQueueListener l : listenerCommands) 258 253 l.commandChanged(commands.size(), redoCommands.size()); 259 254 } 260 255 261 256 /** -
src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java
r99 r100 35 35 * @author imi 36 36 */ 37 public class RawGpsLayer extends Layer {37 public class RawGpsLayer extends Layer implements PreferenceChangedListener { 38 38 39 private static Icon icon;40 41 39 public static class GpsPoint { 42 40 public final LatLon latlon; … … 58 56 super(name); 59 57 this.data = data; 60 Main.pref.listener.add(new PreferenceChangedListener(){ 61 public void preferenceChanged(String key, String newValue) { 62 if (Main.map != null && (key.equals("drawRawGpsLines") || key.equals("forceRawGpsLines"))) 63 Main.map.repaint(); 64 } 65 }); 58 Main.pref.listener.add(this); 66 59 } 67 60 … … 70 63 */ 71 64 @Override public Icon getIcon() { 72 if (icon == null) 73 icon = ImageProvider.get("layer", "rawgps"); 74 return icon; 65 return ImageProvider.get("layer", "rawgps"); 75 66 } 76 67 … … 86 77 Point old = null; 87 78 for (Collection<GpsPoint> c : data) { 88 if (!Main.pref.getBoolean(" forceRawGpsLines"))79 if (!Main.pref.getBoolean("draw.rawgps.lines.force")) 89 80 old = null; 90 81 for (GpsPoint p : c) { 91 82 Point screen = mv.getPoint(p.eastNorth); 92 if (Main.pref.getBoolean("draw RawGpsLines") && old != null)83 if (Main.pref.getBoolean("draw.rawgps.lines") && old != null) 93 84 g.drawLine(old.x, old.y, screen.x, screen.y); 94 85 else … … 196 187 menu.add(new LayerListPopup.InfoAction(this)); 197 188 } 189 190 public void preferenceChanged(String key, String newValue) { 191 if (Main.map != null && (key.equals("draw.rawgps.lines") || key.equals("draw.rawgps.lines.force"))) 192 Main.map.repaint(); 193 } 194 195 @Override public void layerRemoved() { 196 Main.pref.listener.remove(this); 197 } 198 198 } -
src/org/openstreetmap/josm/io/GpxReader.java
r86 r100 1 1 package org.openstreetmap.josm.io; 2 2 3 import static org.openstreetmap.josm.io.GpxWriter.GPX;4 3 import static org.openstreetmap.josm.io.GpxWriter.JOSM; 5 4 import static org.openstreetmap.josm.io.GpxWriter.OSM; … … 12 11 import org.jdom.Element; 13 12 import org.jdom.JDOMException; 13 import org.jdom.Namespace; 14 14 import org.jdom.input.SAXBuilder; 15 15 import org.openstreetmap.josm.data.coor.LatLon; 16 16 import org.openstreetmap.josm.data.osm.DataSet; 17 import org.openstreetmap.josm.data.osm.Segment;18 17 import org.openstreetmap.josm.data.osm.Node; 19 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 import org.openstreetmap.josm.data.osm.Segment; 20 20 import org.openstreetmap.josm.data.osm.Way; 21 21 … … 43 43 private boolean mergeNodes = false; 44 44 45 private Namespace gpx; 46 45 47 /** 46 48 * Construct a parser from a specific data source. … … 50 52 this.source = source; 51 53 } 52 54 53 55 /** 54 56 * Read the input stream and return a DataSet from the stream. … … 58 60 final SAXBuilder builder = new SAXBuilder(); 59 61 Element root = builder.build(source).getRootElement(); 62 gpx = root.getNamespace(); 60 63 mergeNodes = !root.getAdditionalNamespaces().contains(JOSM); 61 64 return parseDataSet(root); … … 75 78 private Node parseWaypoint(Element e) { 76 79 Node data = new Node(new LatLon( 77 Double.parseDouble(e.getAttributeValue("lat")),78 Double.parseDouble(e.getAttributeValue("lon"))));79 80 Double.parseDouble(e.getAttributeValue("lat")), 81 Double.parseDouble(e.getAttributeValue("lon")))); 82 80 83 for (Object o : e.getChildren()) { 81 84 Element child = (Element)o; … … 99 102 DataSet data = new DataSet(); 100 103 // read waypoints not contained in ways or areas 101 for (Object o : e.getChildren("wpt", GPX)) {104 for (Object o : e.getChildren("wpt", gpx)) { 102 105 Node node = parseWaypoint((Element)o); 103 106 addNode(data, node); … … 105 108 106 109 // read ways (and segments) 107 for (Object wayElement : e.getChildren("trk", GPX))110 for (Object wayElement : e.getChildren("trk", gpx)) 108 111 parseWay((Element)wayElement, data); 109 112 … … 112 115 if (osm.id < 0) 113 116 osm.id = 0; 114 117 115 118 // clean up the data a bit (remove broken stuff) 116 119 // remove segments with from==to … … 157 160 if (child.getName().equals("trkseg")) { 158 161 Node start = null; 159 for (Object w : child.getChildren("trkpt", GPX)) {162 for (Object w : child.getChildren("trkpt", gpx)) { 160 163 Node node = addNode(ds, parseWaypoint((Element)w)); 161 164 if (start == null) … … 163 166 else { 164 167 Segment segment = new Segment(start, node); 165 parseKeyValueExtensions(segment, child.getChild("extensions", GPX));168 parseKeyValueExtensions(segment, child.getChild("extensions", gpx)); 166 169 segment = (Segment)getNewIfSeenBefore(segment); 167 170 way.segments.add(segment); … … 201 204 return node; 202 205 } 203 206 204 207 205 208 /** -
src/org/openstreetmap/josm/io/GpxWriter.java
r99 r100 112 112 113 113 // ways 114 for (Way t: ds.ways) {115 if ( t.deleted && t.id == 0)114 for (Way w : ds.ways) { 115 if (w.deleted && w.id == 0) 116 116 continue; 117 117 Element tElem = new Element("trk", GPX); 118 118 HashMap<String, String> keys = null; 119 if ( t.keys != null) {120 keys = new HashMap<String, String>( t.keys);119 if (w.keys != null) { 120 keys = new HashMap<String, String>(w.keys); 121 121 addAndRemovePropertyTag("name", tElem, keys); 122 122 addAndRemovePropertyTag("cmt", tElem, keys); … … 127 127 addAndRemovePropertyTag("type", tElem, keys); 128 128 } 129 addPropertyExtensions(tElem, keys, t);129 addPropertyExtensions(tElem, keys, w); 130 130 131 131 // segments 132 for (Segment ls : t.segments) { 132 for (Segment ls : w.segments) { 133 if (ls.incomplete) 134 continue; 133 135 tElem.getChildren().add(parseSegment(ls)); 134 136 unrefNodes.remove(ls.from); … … 379 381 Segment oldLs = null; 380 382 for (Segment ls : w.segments) { 383 if (ls.incomplete) 384 continue; 381 385 // end old segemnt, if no longer match a chain 382 386 if (oldLs != null && !oldLs.to.coor.equals(ls.from.coor)) { … … 407 411 Collection<Segment> segments = new LinkedList<Segment>(); 408 412 for (OsmPrimitive osm : all) 409 if (osm instanceof Segment )413 if (osm instanceof Segment && !((Segment)osm).incomplete) 410 414 segments.add((Segment)osm); 411 415 if (!segments.isEmpty()) { … … 424 428 425 429 // finally add the remaining nodes 426 for (OsmPrimitive osm : all) {427 outputNode((Node)osm, true);428 }430 for (OsmPrimitive osm : all) 431 if (osm instanceof Node) 432 outputNode((Node)osm, true); 429 433 430 434 out.println("</gpx>"); -
src/org/openstreetmap/josm/io/OsmServerWriter.java
r92 r100 68 68 return; 69 69 osm.visit(v); 70 currentAction.setText("Upload "+v.className+" "+ osm.id+"...");70 currentAction.setText("Upload "+v.className+" "+v.name+" ("+osm.id+")..."); 71 71 osm.visit(this); 72 72 progress.setValue(progress.getValue()+1); … … 184 184 throw new RuntimeException("Unknown host: "+e.getMessage(), e); 185 185 } catch (Exception e) { 186 if (cancel) 187 return; // assume cancel 186 188 if (e instanceof RuntimeException) 187 189 throw (RuntimeException)e; 188 if (!cancel) 189 throw new RuntimeException(e.getMessage(), e); 190 throw new RuntimeException(e.getMessage(), e); 190 191 } 191 192 } -
src/org/openstreetmap/josm/test/MergeVisitorTest.java
r97 r100 10 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 11 import org.openstreetmap.josm.data.osm.Segment; 12 import org.openstreetmap.josm.data.osm.Way; 12 13 import org.openstreetmap.josm.data.osm.visitor.MergeVisitor; 13 14 import org.openstreetmap.josm.test.framework.Bug; … … 178 179 179 180 181 public void testCloneWayNotIncomplete() { 182 DataSet ds = new DataSet(); 183 Node[] n = createNodes(ds, 2); 184 Segment s = DataSetTestCaseHelper.createSegment(ds, n[0], n[1]); 185 Way w = DataSetTestCaseHelper.createWay(ds, s); 186 MergeVisitor v = new MergeVisitor(ds); 187 v.visit(n[0]); 188 v.visit(n[1]); 189 v.visit(s); 190 v.visit(w); 191 Way w2 = new Way(w); 192 w2.timestamp = new Date(); 193 Segment s2 = new Segment(s); 194 s2.incomplete = true; 195 w2.segments.clear(); 196 w2.segments.add(s2); 197 v.visit(w2); 198 assertSame("Do not import incomplete segments when merging ways.", s, w.segments.iterator().next()); 199 } 200 180 201 /** 181 202 * Create that amount of nodes and add them to the dataset. The id will be 1,2,3,4...
Note:
See TracChangeset
for help on using the changeset viewer.