- Timestamp:
- 2006-04-23T00:41:38+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 1 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r92 r93 322 322 } else if (s.startsWith("--selection=")) { 323 323 SelectionListDialog.search(s.substring(12), SelectionListDialog.SearchMode.add); 324 } else if (s.startsWith("http:") || s.startsWith("ftp:") || s.startsWith("https:")) {324 } else if (s.startsWith("http:")) { 325 325 Bounds b = DownloadAction.osmurl2bounds(s); 326 326 if (b == null) 327 System.out.println("Ignoring malformed url: "+s);327 JOptionPane.showMessageDialog(main, "Ignoring malformed url: "+s); 328 328 else 329 Main.main.downloadAction.download(false, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon());329 main.downloadAction.download(false, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon()); 330 330 } else { 331 331 main.openAction.openFile(new File(s)); … … 344 344 private static void downloadFromParamString(boolean rawGps, String s) { 345 345 s = s.replaceAll("^(osm:/?/?)|(--download(gps)?=)", ""); 346 System.out.println(s);347 System.exit(1);348 346 StringTokenizer st = new StringTokenizer(s, ","); 349 347 if (st.countTokens() != 4) { … … 355 353 main.downloadAction.download(rawGps, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken())); 356 354 } catch (NumberFormatException e) { 357 JOptionPane.showMessageDialog(main, "Could not parse the Coordinates .");355 JOptionPane.showMessageDialog(main, "Could not parse the Coordinates: "+s); 358 356 } 359 357 } -
src/org/openstreetmap/josm/actions/AutoScaleAction.java
r91 r93 5 5 import java.util.Collection; 6 6 7 import javax.swing.KeyStroke; 8 import javax.swing.MenuElement; 7 import javax.swing.AbstractAction; 9 8 10 9 import org.openstreetmap.josm.Main; … … 16 15 import org.openstreetmap.josm.gui.MapFrame; 17 16 import org.openstreetmap.josm.gui.layer.Layer; 17 import org.openstreetmap.josm.tools.ImageProvider; 18 18 19 19 /** … … 27 27 private final MapFrame mapFrame; 28 28 29 private class Action extends JosmAction {29 private class Action extends AbstractAction { 30 30 private final AutoScaleMode mode; 31 31 public Action(AutoScaleMode mode) { 32 super("Auto Scale: "+mode, "dialogs/autoscale/"+mode, "Auto zoom the view to "+mode+". Disabled if the view is moved.", "Alt-A", KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.ALT_MASK)); 32 super("Auto Scale: "+mode, ImageProvider.get("dialogs/autoscale/"+mode)); 33 putValue(SHORT_DESCRIPTION, "Auto zoom the view to "+mode+". Disabled if the view is moved."); 33 34 this.mode = mode; 34 35 } 35 36 public void actionPerformed(ActionEvent e) { 36 37 AutoScaleAction.this.mode = mode; 37 if (e.getSource() instanceof MenuElement) 38 setAutoScaleOnMapView(); 39 else 40 mapFrame.mapView.setAutoScale(!mapFrame.mapView.isAutoScale()); 41 } 38 if (mapFrame.mapView.isAutoScale()) 39 mapFrame.mapView.recalculateCenterScale(); 40 else 41 mapFrame.mapView.setAutoScale(true); 42 putValue("active", true); 43 } 42 44 } 43 45 44 46 public AutoScaleAction(final MapFrame mapFrame) { 47 super(KeyEvent.VK_A, 0); 45 48 for (AutoScaleMode mode : AutoScaleMode.values()) 46 49 actions.add(new Action(mode)); … … 51 54 if (mode == AutoScaleMode.selection) 52 55 mapFrame.mapView.recalculateCenterScale(); 53 56 } 54 57 }); 55 58 } … … 79 82 } 80 83 return v; 81 } 82 83 private void setAutoScaleOnMapView() { 84 if (mapFrame.mapView.isAutoScale()) 85 mapFrame.mapView.recalculateCenterScale(); 86 else 87 mapFrame.mapView.setAutoScale(true); 88 } 84 } 89 85 } -
src/org/openstreetmap/josm/actions/GroupAction.java
r91 r93 3 3 import java.awt.event.ActionEvent; 4 4 import java.awt.event.ActionListener; 5 import java.awt.event.KeyEvent; 6 import java.beans.PropertyChangeEvent; 7 import java.beans.PropertyChangeListener; 5 8 import java.util.ArrayList; 6 9 import java.util.List; 7 10 8 import javax.swing.AbstractAction;9 11 import javax.swing.Action; 10 12 import javax.swing.Icon; 11 13 import javax.swing.JMenuItem; 12 14 import javax.swing.JPopupMenu; 15 import javax.swing.KeyStroke; 13 16 14 17 import org.openstreetmap.josm.gui.IconToggleButton; … … 17 20 18 21 19 public class GroupAction extends AbstractAction {22 public class GroupAction extends JosmAction { 20 23 21 24 protected final List<Action> actions = new ArrayList<Action>(); 22 private int current; 25 private int current = -1; 26 private String shortCutName = ""; 27 28 private PropertyChangeListener forwardActiveListener = new PropertyChangeListener(){ 29 public void propertyChange(PropertyChangeEvent evt) { 30 if (evt.getPropertyName().equals("active")) { 31 putValue("active", evt.getNewValue()); 32 if (evt.getNewValue() == Boolean.FALSE) 33 cycle = false; 34 } 35 } 36 }; 37 public boolean cycle; 23 38 24 39 protected void setCurrent(int current) { 40 if (this.current != -1) 41 actions.get(this.current).removePropertyChangeListener(forwardActiveListener); 42 actions.get(current).addPropertyChangeListener(forwardActiveListener); 43 25 44 this.current = current; 26 45 putValue(SMALL_ICON, ImageProvider.overlay((Icon)actions.get(current).getValue(SMALL_ICON), "right", OverlayPosition.SOUTHEAST)); 27 putValue(SHORT_DESCRIPTION, actions.get(current).getValue(SHORT_DESCRIPTION)); 28 } 46 Object tooltip = actions.get(current).getValue(SHORT_DESCRIPTION); 47 putValue(SHORT_DESCRIPTION, "<html>"+tooltip+" <font size='-2'>"+shortCutName+"</font> </html>"); 48 } 49 50 public GroupAction(int shortCut, int modifiers) { 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); 61 addPropertyChangeListener(new PropertyChangeListener(){ 62 public void propertyChange(PropertyChangeEvent evt) { 63 if (evt.getPropertyName().equals("active") && evt.getNewValue() == Boolean.FALSE) 64 cycle = false; 65 } 66 }); 67 } 29 68 30 69 public void actionPerformed(ActionEvent e) { … … 33 72 b.setSelected(!b.isSelected()); 34 73 openPopup(b); 35 } else 74 } else { 75 if (cycle) 76 setCurrent((current+1)%actions.size()); 77 else 78 cycle = true; 36 79 actions.get(current).actionPerformed(e); 37 } 80 } 81 } 38 82 39 83 private void openPopup(IconToggleButton b) { … … 45 89 public void actionPerformed(ActionEvent e) { 46 90 setCurrent(j); 47 91 } 48 92 }); 49 93 popup.add(item); 50 94 } 51 95 popup.show(b, b.getWidth(), 0); 52 96 } 53 97 } -
src/org/openstreetmap/josm/actions/JosmAction.java
r92 r93 33 33 super(name, ImageProvider.get(iconName)); 34 34 putValue(SHORT_DESCRIPTION, "<html>"+tooltip+" <font size='-2'>"+shortCutName+"</font> </html>"); 35 Main.main.panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(shortCut, name); 36 Main.main.panel.getActionMap().put(name, this); 35 registerShortCut(name, shortCut); 36 } 37 38 public JosmAction() { 39 } 40 41 public void registerShortCut(String idName, KeyStroke shortCut) { 42 Main.main.panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(shortCut, idName); 43 Main.main.panel.getActionMap().put(idName, this); 37 44 } 38 45 } -
src/org/openstreetmap/josm/actions/WmsServerAction.java
r86 r93 39 39 } 40 40 } else { 41 WmsServerLayer layer = new WmsServerLayer(Main.pref.get("wms ServerBaseUrl", "http://wms.jpl.nasa.gov/wms.cgi?request=GetMap&width=512&height=512&layers=global_mosaic&styles=&srs=EPSG:4326&format=image/jpeg&"));41 WmsServerLayer layer = new WmsServerLayer(Main.pref.get("wms.baseurl", "http://wms.jpl.nasa.gov/wms.cgi?request=GetMap&width=512&height=512&layers=global_mosaic&styles=&srs=EPSG:4326&format=image/jpeg&")); 42 42 if (mapFrame == null) 43 43 Main.main.setMapFrame(new MapFrame(layer)); -
src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java
r86 r93 3 3 import java.awt.event.KeyEvent; 4 4 import java.awt.event.MouseEvent; 5 import java.util.ArrayList; 6 import java.util.Collection; 7 import java.util.LinkedList; 5 8 6 9 import javax.swing.JOptionPane; 7 10 8 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.actions.GroupAction; 9 13 import org.openstreetmap.josm.command.AddCommand; 14 import org.openstreetmap.josm.command.ChangeCommand; 15 import org.openstreetmap.josm.command.Command; 16 import org.openstreetmap.josm.command.SequenceCommand; 10 17 import org.openstreetmap.josm.data.osm.Node; 18 import org.openstreetmap.josm.data.osm.Segment; 19 import org.openstreetmap.josm.data.osm.Way; 11 20 import org.openstreetmap.josm.gui.MapFrame; 12 21 … … 23 32 public class AddNodeAction extends MapMode { 24 33 25 public AddNodeAction(MapFrame mapFrame) { 26 super("Add nodes", "addnode", "Add nodes to the map.", "N", KeyEvent.VK_N, mapFrame); 34 enum Mode {node, nodesegment} 35 private final Mode mode; 36 37 public static class AddNodeGroup extends GroupAction { 38 public AddNodeGroup(MapFrame mf) { 39 super(KeyEvent.VK_N,0); 40 actions.add(new AddNodeAction(mf, "Add node", Mode.node, "Add a new node to the map")); 41 actions.add(new AddNodeAction(mf, "Add node into segment", Mode.nodesegment, "Add a node into an existing segment")); 42 setCurrent(0); 43 } 44 } 45 46 public AddNodeAction(MapFrame mapFrame, String name, Mode mode, String desc) { 47 super(name, "node/"+mode, desc, mapFrame); 48 this.mode = mode; 27 49 } 28 50 … … 40 62 * If user clicked with the left button, add a node at the current mouse 41 63 * position. 64 * 65 * If in nodesegment mode, add the node to the line segment by splitting the 66 * segment. The new created segment will be inserted in every way the segment 67 * was part of. 42 68 */ 43 69 @Override public void mouseClicked(MouseEvent e) { 44 if (e.getButton() == MouseEvent.BUTTON1) { 45 Node node = new Node(mv.getLatLon(e.getX(), e.getY())); 46 if (node.coor.isOutSideWorld()) { 47 JOptionPane.showMessageDialog(Main.main, "Can not add a node outside of the world."); 70 if (e.getButton() != MouseEvent.BUTTON1) 71 return; 72 73 Node n = new Node(mv.getLatLon(e.getX(), e.getY())); 74 if (n.coor.isOutSideWorld()) { 75 JOptionPane.showMessageDialog(Main.main, "Can not add a node outside of the world."); 76 return; 77 } 78 79 Command c = new AddCommand(n); 80 if (mode == Mode.nodesegment) { 81 Segment s = mv.getNearestSegment(e.getPoint()); 82 if (s == null) 48 83 return; 84 85 Collection<Command> cmds = new LinkedList<Command>(); 86 cmds.add(c); 87 Segment s1 = new Segment(s); 88 s1.to = n; 89 Segment s2 = new Segment(s.from, s.to); 90 s2.from = n; 91 92 cmds.add(new ChangeCommand(s, s1)); 93 cmds.add(new AddCommand(s2)); 94 95 // Add the segment to every way 96 for (Way wold : Main.ds.ways) { 97 if (wold.segments.contains(s)) { 98 Way wnew = new Way(wold); 99 Collection<Segment> segs = new ArrayList<Segment>(wnew.segments); 100 wnew.segments.clear(); 101 for (Segment waySeg : segs) { 102 wnew.segments.add(waySeg); 103 if (waySeg == s) 104 wnew.segments.add(s2); 105 } 106 cmds.add(new ChangeCommand(wold, wnew)); 107 } 49 108 } 50 mv.editLayer().add(new AddCommand(Main.ds, node)); 51 mv.repaint();109 110 c = new SequenceCommand(cmds); 52 111 } 112 mv.editLayer().add(c); 113 mv.repaint(); 53 114 } 54 115 } -
src/org/openstreetmap/josm/actions/mapmode/AddSegmentAction.java
r87 r93 136 136 137 137 Segment ls = new Segment(start, end); 138 mv.editLayer().add(new AddCommand( Main.ds,ls));138 mv.editLayer().add(new AddCommand(ls)); 139 139 } 140 140 -
src/org/openstreetmap/josm/actions/mapmode/AddWayAction.java
r90 r93 118 118 } 119 119 120 Way t= new Way();121 t.segments.addAll(sortedSegments);122 mv.editLayer().add(new AddCommand( Main.ds, t));120 Way w = new Way(); 121 w.segments.addAll(sortedSegments); 122 mv.editLayer().add(new AddCommand(w)); 123 123 Main.ds.clearSelection(); 124 124 mv.repaint(); -
src/org/openstreetmap/josm/actions/mapmode/MapMode.java
r91 r93 11 11 import org.openstreetmap.josm.gui.MapFrame; 12 12 import org.openstreetmap.josm.gui.MapView; 13 import org.openstreetmap.josm.tools.ImageProvider; 13 14 14 15 /** … … 32 33 33 34 /** 34 * Construct a mapMode with the given icon and the given MapFrame35 * Constructor for mapmodes without an menu 35 36 */ 36 37 public MapMode(String name, String iconName, String tooltip, String keyname, int keystroke, MapFrame mapFrame) { 37 38 super(name, "mapmode/"+iconName, tooltip, keyname, KeyStroke.getKeyStroke(keystroke, 0)); 39 this.mapFrame = mapFrame; 40 mv = mapFrame.mapView; 41 } 42 43 /** 44 * Constructor for mapmodes with an menu (no shortcut will be registered) 45 */ 46 public MapMode(String name, String iconName, String tooltip, MapFrame mapFrame) { 47 putValue(NAME, name); 48 putValue(SMALL_ICON, ImageProvider.get("mapmode", iconName)); 49 putValue(SHORT_DESCRIPTION, tooltip); 38 50 this.mapFrame = mapFrame; 39 51 mv = mapFrame.mapView; … … 45 57 */ 46 58 public void registerListener() { 47 firePropertyChange("active", false, true);59 putValue("active", true); 48 60 } 49 61 50 62 /** 51 63 * Unregister all listener previously registered. … … 53 65 */ 54 66 public void unregisterListener() { 55 firePropertyChange("active", true, false);67 putValue("active", false); 56 68 } 57 69 -
src/org/openstreetmap/josm/command/AddCommand.java
r86 r93 3 3 import java.util.Collection; 4 4 5 import org.openstreetmap.josm. data.osm.DataSet;5 import org.openstreetmap.josm.Main; 6 6 import org.openstreetmap.josm.data.osm.OsmPrimitive; 7 7 import org.openstreetmap.josm.data.osm.visitor.AddVisitor; … … 17 17 18 18 /** 19 * The dataset this command operates on.20 */21 private DataSet ds;22 23 /**24 19 * The primitive to add to the dataset. 25 20 */ … … 29 24 * Create the command and specify the element to add. 30 25 */ 31 public AddCommand(DataSet ds, OsmPrimitive osm) { 32 this.ds = ds; 26 public AddCommand(OsmPrimitive osm) { 33 27 this.osm = osm; 34 28 } 35 29 36 30 @Override public void executeCommand() { 37 osm.visit(new AddVisitor( ds));31 osm.visit(new AddVisitor(Main.ds)); 38 32 } 39 33 40 34 @Override public void undoCommand() { 41 osm.visit(new DeleteVisitor( ds));35 osm.visit(new DeleteVisitor(Main.ds)); 42 36 } 43 37 -
src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java
r86 r93 6 6 7 7 import org.openstreetmap.josm.Main; 8 import org.openstreetmap.josm.data.osm.Node; 8 9 import org.openstreetmap.josm.data.osm.Segment; 9 import org.openstreetmap.josm.data.osm.Node;10 10 import org.openstreetmap.josm.data.osm.Way; 11 11 import org.openstreetmap.josm.gui.NavigatableComponent; … … 32 32 */ 33 33 private final NavigatableComponent nc; 34 private static final double PHI = Math.toRadians(20); 34 35 35 36 /** … … 75 76 } 76 77 } 78 77 79 for (Segment ls : w.segments) 78 80 if (!ls.selected) // selected already in good color … … 104 106 Point p2 = nc.getPoint(ls.to.eastNorth); 105 107 g.drawLine(p1.x, p1.y, p2.x, p2.y); 108 109 if (Main.pref.getBoolean("draw.segment.direction")) { 110 double t = Math.atan2(p2.y-p1.y, p2.x-p1.x) + Math.PI; 111 g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI))); 112 g.drawLine(p2.x,p2.y, (int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI))); 113 } 106 114 } 107 115 -
src/org/openstreetmap/josm/gui/IconToggleButton.java
r91 r93 34 34 addMouseListener(new MouseAdapter(){ 35 35 @Override public void mousePressed(MouseEvent e) { 36 groupbutton = e.getX() > getWidth()/ 3 && e.getY() > getHeight()/3;36 groupbutton = e.getX() > getWidth()/2 && e.getY() > getHeight()/2; 37 37 } 38 38 }); -
src/org/openstreetmap/josm/gui/MapFrame.java
r91 r93 5 5 import java.awt.Container; 6 6 import java.awt.event.ActionEvent; 7 import java.awt.event.ActionListener; 7 8 import java.beans.PropertyChangeEvent; 8 9 import java.beans.PropertyChangeListener; … … 16 17 import org.openstreetmap.josm.Main; 17 18 import org.openstreetmap.josm.actions.AutoScaleAction; 18 import org.openstreetmap.josm.actions.mapmode.AddNodeAction;19 19 import org.openstreetmap.josm.actions.mapmode.AddSegmentAction; 20 20 import org.openstreetmap.josm.actions.mapmode.AddWayAction; … … 24 24 import org.openstreetmap.josm.actions.mapmode.SelectionAction; 25 25 import org.openstreetmap.josm.actions.mapmode.ZoomAction; 26 import org.openstreetmap.josm.actions.mapmode.AddNodeAction.AddNodeGroup; 26 27 import org.openstreetmap.josm.gui.dialogs.ConflictDialog; 27 28 import org.openstreetmap.josm.gui.dialogs.LayerList; … … 69 70 setLayout(new BorderLayout()); 70 71 71 AutoScaleAction autoScaleAction = new AutoScaleAction(this);72 final AutoScaleAction autoScaleAction = new AutoScaleAction(this); 72 73 add(mapView = new MapView(autoScaleAction), BorderLayout.CENTER); 73 74 mapView.addLayer(layer); … … 79 80 toolBarActions.add(new IconToggleButton(selectionAction)); 80 81 toolBarActions.add(new IconToggleButton(new MoveAction(this))); 81 toolBarActions.add(new IconToggleButton(new AddNode Action(this)));82 toolBarActions.add(new IconToggleButton(new AddNodeGroup(this))); 82 83 toolBarActions.add(new IconToggleButton(new AddSegmentAction(this))); 83 84 toolBarActions.add(new IconToggleButton(new AddWayAction(this, selectionAction))); … … 97 98 autoScaleButton.setText(null); 98 99 autoScaleButton.setSelected(mapView.isAutoScale()); 100 autoScaleAction.putValue("active", true); 99 101 mapView.addPropertyChangeListener(new PropertyChangeListener(){ 100 102 public void propertyChange(PropertyChangeEvent evt) { 101 if (evt.getPropertyName().equals("autoScale")) 102 autoScaleButton.setSelected(mapView.isAutoScale()); 103 if (evt.getPropertyName().equals("autoScale")) { 104 autoScaleAction.putValue("active", evt.getNewValue()); 105 autoScaleButton.setSelected((Boolean)evt.getNewValue()); 106 } 103 107 } 108 }); 109 autoScaleButton.addActionListener(new ActionListener(){ 110 public void actionPerformed(ActionEvent e) { 111 if (!autoScaleButton.groupbutton) 112 autoScaleButton.setSelected(true); 113 } 104 114 }); 105 115 … … 146 156 */ 147 157 public void selectMapMode(MapMode mapMode) { 158 if (mapMode == this.mapMode) 159 return; 148 160 if (this.mapMode != null) 149 161 this.mapMode.unregisterListener(); -
src/org/openstreetmap/josm/gui/MapView.java
r91 r93 53 53 * Whether to adjust the scale property on every resize. 54 54 */ 55 boolean autoScale = true;55 private boolean autoScale = true; 56 56 57 57 /** -
src/org/openstreetmap/josm/gui/NavigatableComponent.java
r86 r93 104 104 105 105 /** 106 * Return the object, that is nearest to the given screen point. 107 * 108 * First, a node will be searched. If a node within 10 pixel is found, the 109 * nearest node is returned. 110 * 111 * If no node is found, search for pending segments. 112 * 113 * If no such segment is found, and a non-pending segment is 114 * within 10 pixel to p, this segment is returned, except when 115 * <code>wholeWay</code> is <code>true</code>, in which case the 116 * corresponding Way is returned. 117 * 118 * If no segment is found and the point is within an area, return that 119 * area. 120 * 121 * If no area is found, return <code>null</code>. 122 * 123 * @param p The point on screen. 124 * @param segmentInsteadWay Whether the segment (true) or only the whole 125 * way should be returned. 126 * @return The primitive, that is nearest to the point p. 127 */ 128 public OsmPrimitive getNearest(Point p, boolean segmentInsteadWay) { 106 * Return the nearest point to the screen point given. 107 * If a node within 10 pixel is found, the nearest node is returned. 108 */ 109 public final Node getNearestNode(Point p) { 129 110 double minDistanceSq = Double.MAX_VALUE; 130 OsmPrimitive minPrimitive = null; 131 132 // nodes 111 Node minPrimitive = null; 133 112 for (Node n : Main.ds.nodes) { 134 113 if (n.deleted) … … 141 120 } 142 121 } 143 if (minPrimitive != null) 144 return minPrimitive; 145 146 // for whole ways, try the ways first 147 minDistanceSq = Double.MAX_VALUE; 148 if (!segmentInsteadWay) { 149 for (Way w : Main.ds.ways) { 150 if (w.deleted) 122 return minPrimitive; 123 } 124 125 /** 126 * @return the nearest way to the screen point given. 127 */ 128 public final Way getNearestWay(Point p) { 129 Way minPrimitive = null; 130 double minDistanceSq = Double.MAX_VALUE; 131 for (Way w : Main.ds.ways) { 132 if (w.deleted) 133 continue; 134 for (Segment ls : w.segments) { 135 if (ls.deleted || ls.incomplete) 151 136 continue; 152 for (Segment ls : w.segments) { 153 if (ls.deleted || ls.incomplete) 154 continue; 155 Point A = getPoint(ls.from.eastNorth); 156 Point B = getPoint(ls.to.eastNorth); 157 double c = A.distanceSq(B); 158 double a = p.distanceSq(B); 159 double b = p.distanceSq(A); 160 double perDist = a-(a-b+c)*(a-b+c)/4/c; // perpendicular distance squared 161 if (perDist < 100 && minDistanceSq > perDist && a < c+100 && b < c+100) { 162 minDistanceSq = perDist; 163 minPrimitive = w; 164 } 165 } 166 } 167 if (minPrimitive != null) 168 return minPrimitive; 169 } 170 171 minDistanceSq = Double.MAX_VALUE; 137 Point A = getPoint(ls.from.eastNorth); 138 Point B = getPoint(ls.to.eastNorth); 139 double c = A.distanceSq(B); 140 double a = p.distanceSq(B); 141 double b = p.distanceSq(A); 142 double perDist = a-(a-b+c)*(a-b+c)/4/c; // perpendicular distance squared 143 if (perDist < 100 && minDistanceSq > perDist && a < c+100 && b < c+100) { 144 minDistanceSq = perDist; 145 minPrimitive = w; 146 } 147 } 148 } 149 return minPrimitive; 150 } 151 152 /** 153 * @return the nearest segment to the screen point given. 154 */ 155 public final Segment getNearestSegment(Point p) { 156 Segment minPrimitive = null; 157 double minDistanceSq = Double.MAX_VALUE; 172 158 // segments 173 159 for (Segment ls : Main.ds.segments) { … … 185 171 } 186 172 } 187 188 173 return minPrimitive; 174 } 175 176 /** 177 * Return the object, that is nearest to the given screen point. 178 * 179 * First, a node will be searched. If a node within 10 pixel is found, the 180 * nearest node is returned. 181 * 182 * If no node is found, search for pending segments. 183 * 184 * If no such segment is found, and a non-pending segment is 185 * within 10 pixel to p, this segment is returned, except when 186 * <code>wholeWay</code> is <code>true</code>, in which case the 187 * corresponding Way is returned. 188 * 189 * If no segment is found and the point is within an area, return that 190 * area. 191 * 192 * If no area is found, return <code>null</code>. 193 * 194 * @param p The point on screen. 195 * @param segmentInsteadWay Whether the segment (true) or only the whole 196 * way should be returned. 197 * @return The primitive, that is nearest to the point p. 198 */ 199 public OsmPrimitive getNearest(Point p, boolean segmentInsteadWay) { 200 OsmPrimitive osm = getNearestNode(p); 201 if (osm == null && !segmentInsteadWay) 202 osm = getNearestWay(p); 203 if (osm == null) 204 osm = getNearestSegment(p); 205 return osm; 189 206 } 190 207 … … 243 260 return c; 244 261 } 245 262 246 263 /** 247 264 * @return The projection to be used in calculating stuff. -
src/org/openstreetmap/josm/gui/PreferenceDialog.java
r86 r93 72 72 pwd = null; 73 73 Main.pref.put("osm-server.password", pwd); 74 Main.pref.put("wmsServerBaseUrl", wmsServerBaseUrl.getText()); 75 Main.pref.put("csvImportString", csvImportString.getText()); 76 Main.pref.put("drawRawGpsLines", drawRawGpsLines.isSelected()); 77 Main.pref.put("forceRawGpsLines", forceRawGpsLines.isSelected()); 74 Main.pref.put("wms.baseurl", wmsServerBaseUrl.getText()); 75 Main.pref.put("csv.importstring", csvImportString.getText()); 76 Main.pref.put("draw.rawgps.lines", drawRawGpsLines.isSelected()); 77 Main.pref.put("draw.rawgps.lines.force", forceRawGpsLines.isSelected()); 78 Main.pref.put("draw.segment.direction", directionHint.isSelected()); 78 79 79 80 for (int i = 0; i < colors.getRowCount(); ++i) { … … 154 155 */ 155 156 private JCheckBox forceRawGpsLines = new JCheckBox("Force lines if no segments imported."); 156 157 private JCheckBox directionHint = new JCheckBox("Draw Direction Arrows"); 157 158 private JTable colors; 158 159 … … 200 201 }); 201 202 202 // drawRawGpsLines203 203 drawRawGpsLines.addActionListener(new ActionListener(){ 204 204 public void actionPerformed(ActionEvent e) { … … 212 212 osmDataUsername.setText(Main.pref.get("osm-server.username")); 213 213 osmDataPassword.setText(Main.pref.get("osm-server.password")); 214 wmsServerBaseUrl.setText(Main.pref.get("wms ServerBaseUrl", "http://wms.jpl.nasa.gov/wms.cgi?request=GetMap&width=512&height=512&layers=global_mosaic&styles=&srs=EPSG:4326&format=image/jpeg&"));215 csvImportString.setText(Main.pref.get("csv ImportString"));216 drawRawGpsLines.setSelected(Main.pref.getBoolean("draw RawGpsLines"));214 wmsServerBaseUrl.setText(Main.pref.get("wms.baseurl", "http://wms.jpl.nasa.gov/wms.cgi?request=GetMap&width=512&height=512&layers=global_mosaic&styles=&srs=EPSG:4326&format=image/jpeg&")); 215 csvImportString.setText(Main.pref.get("csv.importstring")); 216 drawRawGpsLines.setSelected(Main.pref.getBoolean("draw.rawgps.lines")); 217 217 forceRawGpsLines.setToolTipText("Force drawing of lines if the imported data contain no line information."); 218 forceRawGpsLines.setSelected(Main.pref.getBoolean(" forceRawGpsLines"));218 forceRawGpsLines.setSelected(Main.pref.getBoolean("draw.rawgps.lines.force")); 219 219 forceRawGpsLines.setEnabled(drawRawGpsLines.isSelected()); 220 directionHint.setToolTipText("Draw direction hints for all segments."); 221 directionHint.setSelected(Main.pref.getBoolean("draw.segment.direction")); 220 222 221 223 … … 292 294 display.add(drawRawGpsLines, GBC.eol().insets(20,0,0,0)); 293 295 display.add(forceRawGpsLines, GBC.eop().insets(40,0,0,0)); 296 display.add(directionHint, GBC.eop().insets(20,0,0,0)); 294 297 display.add(new JLabel("Colors"), GBC.eol()); 295 298 colors.setPreferredScrollableViewportSize(new Dimension(100,112)); -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r92 r93 12 12 import java.io.IOException; 13 13 import java.io.Reader; 14 import java.net.HttpURLConnection;15 14 import java.net.MalformedURLException; 16 15 import java.net.URL; 16 import java.net.URLConnection; 17 17 import java.util.Collection; 18 18 import java.util.LinkedList; … … 72 72 sel = mode != SearchMode.remove ? new LinkedList<OsmPrimitive>() : Main.ds.allNonDeletedPrimitives(); 73 73 try { 74 HttpURLConnection con = (HttpURLConnection)url.openConnection();74 URLConnection con = url.openConnection(); 75 75 Reader in = new ProgressReader(con, progress); 76 76 currentAction.setText("Downloading..."); … … 227 227 228 228 public static void search(String search, SearchMode mode) { 229 if (search.startsWith("http://")) {230 229 if (search.startsWith("http://") || search.startsWith("ftp://") || search.startsWith("https://") || search.startsWith("file:/")) { 230 SelectionWebsiteLoader loader = new SelectionWebsiteLoader(search, mode); 231 231 if (loader.url != null) { 232 232 Main.worker.execute(loader); -
src/org/openstreetmap/josm/io/ProgressReader.java
r92 r93 4 4 import java.io.InputStreamReader; 5 5 import java.io.Reader; 6 import java.net. HttpURLConnection;6 import java.net.URLConnection; 7 7 8 8 import javax.swing.BoundedRangeModel; … … 17 17 private final BoundedRangeModel progress; 18 18 19 public ProgressReader( HttpURLConnection con, BoundedRangeModel progress) throws IOException {19 public ProgressReader(URLConnection con, BoundedRangeModel progress) throws IOException { 20 20 this.in = new InputStreamReader(con.getInputStream()); 21 21 this.progress = progress; -
src/org/openstreetmap/josm/io/RawCsvReader.java
r78 r93 31 31 public Collection<GpsPoint> parse() throws JDOMException, IOException { 32 32 Collection<GpsPoint> data = new LinkedList<GpsPoint>(); 33 String formatStr = Main.pref.get("csv ImportString");33 String formatStr = Main.pref.get("csv.importstring"); 34 34 if (formatStr == null) 35 35 formatStr = in.readLine(); … … 53 53 // test for completness 54 54 if (!format.contains("lat") || !format.contains("lon")) { 55 if (Main.pref.get("csv ImportString").equals(""))55 if (Main.pref.get("csv.importstring").equals("")) 56 56 throw new JDOMException("Format string in data is incomplete or not found. Try setting an manual format string in Preferences."); 57 57 throw new JDOMException("Format string is incomplete. Need at least 'lat' and 'lon' specification"); … … 75 75 st.nextToken(); 76 76 else 77 throw new JDOMException("Unknown data type: '"+token+"'."+(Main.pref.get("csv ImportString").equals("") ? " Maybe add an format string in preferences." : ""));77 throw new JDOMException("Unknown data type: '"+token+"'."+(Main.pref.get("csv.importstring").equals("") ? " Maybe add an format string in preferences." : "")); 78 78 } 79 79 data.add(new GpsPoint(new LatLon(lat, lon), time)); -
src/org/openstreetmap/josm/tools/ImageProvider.java
r91 r93 28 28 */ 29 29 public static enum OverlayPosition {NORTHWEST, NORTHEAST, SOUTHWEST, SOUTHEAST} 30 30 31 31 /** 32 32 * The icon cache 33 33 */ 34 34 private static Map<URL, Image> cache = new HashMap<URL, Image>(); 35 35 36 36 /** 37 37 * Return an image from the specified location. … … 44 44 if (subdir != "") 45 45 subdir += "/"; 46 46 String ext = name.indexOf('.') != -1 ? "" : ".png"; 47 47 URL path = Main.class.getResource("/images/"+subdir+name+ext); 48 48 if (path == null)
Note:
See TracChangeset
for help on using the changeset viewer.