Changeset 93 in josm for src


Ignore:
Timestamp:
2006-04-23T00:41:38+02:00 (18 years ago)
Author:
imi
Message:
  • added "insert node into line segment" mapmode
  • added direction hint to line segments
Location:
src/org/openstreetmap/josm
Files:
1 added
20 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/Main.java

    r92 r93  
    322322                        } else if (s.startsWith("--selection=")) {
    323323                                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:")) {
    325325                                Bounds b = DownloadAction.osmurl2bounds(s);
    326326                                if (b == null)
    327                                         System.out.println("Ignoring malformed url: "+s);
     327                                        JOptionPane.showMessageDialog(main, "Ignoring malformed url: "+s);
    328328                                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());
    330330                        } else {
    331331                                main.openAction.openFile(new File(s));
     
    344344        private static void downloadFromParamString(boolean rawGps, String s) {
    345345                s = s.replaceAll("^(osm:/?/?)|(--download(gps)?=)", "");
    346                 System.out.println(s);
    347                 System.exit(1);
    348346                StringTokenizer st = new StringTokenizer(s, ",");
    349347                if (st.countTokens() != 4) {
     
    355353                        main.downloadAction.download(rawGps, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
    356354                } catch (NumberFormatException e) {
    357                         JOptionPane.showMessageDialog(main, "Could not parse the Coordinates.");
     355                        JOptionPane.showMessageDialog(main, "Could not parse the Coordinates: "+s);
    358356                }
    359357        }
  • src/org/openstreetmap/josm/actions/AutoScaleAction.java

    r91 r93  
    55import java.util.Collection;
    66
    7 import javax.swing.KeyStroke;
    8 import javax.swing.MenuElement;
     7import javax.swing.AbstractAction;
    98
    109import org.openstreetmap.josm.Main;
     
    1615import org.openstreetmap.josm.gui.MapFrame;
    1716import org.openstreetmap.josm.gui.layer.Layer;
     17import org.openstreetmap.josm.tools.ImageProvider;
    1818
    1919/**
     
    2727        private final MapFrame mapFrame;
    2828
    29         private class Action extends JosmAction {
     29        private class Action extends AbstractAction {
    3030                private final AutoScaleMode mode;
    3131                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.");
    3334                        this.mode = mode;
    34         }
     35                }
    3536                public void actionPerformed(ActionEvent e) {
    3637                        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                }
    4244        }
    43        
     45
    4446        public AutoScaleAction(final MapFrame mapFrame) {
     47                super(KeyEvent.VK_A, 0);
    4548                for (AutoScaleMode mode : AutoScaleMode.values())
    4649                        actions.add(new Action(mode));
     
    5154                                if (mode == AutoScaleMode.selection)
    5255                                        mapFrame.mapView.recalculateCenterScale();
    53             }
     56                        }
    5457                });
    5558        }
     
    7982                }
    8083                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        }
    8985}
  • src/org/openstreetmap/josm/actions/GroupAction.java

    r91 r93  
    33import java.awt.event.ActionEvent;
    44import java.awt.event.ActionListener;
     5import java.awt.event.KeyEvent;
     6import java.beans.PropertyChangeEvent;
     7import java.beans.PropertyChangeListener;
    58import java.util.ArrayList;
    69import java.util.List;
    710
    8 import javax.swing.AbstractAction;
    911import javax.swing.Action;
    1012import javax.swing.Icon;
    1113import javax.swing.JMenuItem;
    1214import javax.swing.JPopupMenu;
     15import javax.swing.KeyStroke;
    1316
    1417import org.openstreetmap.josm.gui.IconToggleButton;
     
    1720
    1821
    19 public class GroupAction extends AbstractAction {
     22public class GroupAction extends JosmAction {
    2023
    2124        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;
    2338
    2439        protected void setCurrent(int current) {
     40                if (this.current != -1)
     41                        actions.get(this.current).removePropertyChangeListener(forwardActiveListener);
     42                actions.get(current).addPropertyChangeListener(forwardActiveListener);
     43
    2544                this.current = current;
    2645                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>&nbsp;</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        }
    2968
    3069        public void actionPerformed(ActionEvent e) {
     
    3372                        b.setSelected(!b.isSelected());
    3473                        openPopup(b);
    35                 } else
     74                } else {
     75                        if (cycle)
     76                                setCurrent((current+1)%actions.size());
     77                        else
     78                                cycle = true;
    3679                        actions.get(current).actionPerformed(e);
    37     }
     80                }
     81        }
    3882
    3983        private void openPopup(IconToggleButton b) {
     
    4589                                public void actionPerformed(ActionEvent e) {
    4690                                        setCurrent(j);
    47                 }
     91                                }
    4892                        });
    4993                        popup.add(item);
    5094                }
    5195                popup.show(b, b.getWidth(), 0);
    52     }
     96        }
    5397}
  • src/org/openstreetmap/josm/actions/JosmAction.java

    r92 r93  
    3333                super(name, ImageProvider.get(iconName));
    3434                putValue(SHORT_DESCRIPTION, "<html>"+tooltip+" <font size='-2'>"+shortCutName+"</font>&nbsp;</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);
    3744        }
    3845}
  • src/org/openstreetmap/josm/actions/WmsServerAction.java

    r86 r93  
    3939            }
    4040        } else {
    41             WmsServerLayer layer = new WmsServerLayer(Main.pref.get("wmsServerBaseUrl", "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&"));
    4242            if (mapFrame == null)
    4343                Main.main.setMapFrame(new MapFrame(layer));
  • src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java

    r86 r93  
    33import java.awt.event.KeyEvent;
    44import java.awt.event.MouseEvent;
     5import java.util.ArrayList;
     6import java.util.Collection;
     7import java.util.LinkedList;
    58
    69import javax.swing.JOptionPane;
    710
    811import org.openstreetmap.josm.Main;
     12import org.openstreetmap.josm.actions.GroupAction;
    913import org.openstreetmap.josm.command.AddCommand;
     14import org.openstreetmap.josm.command.ChangeCommand;
     15import org.openstreetmap.josm.command.Command;
     16import org.openstreetmap.josm.command.SequenceCommand;
    1017import org.openstreetmap.josm.data.osm.Node;
     18import org.openstreetmap.josm.data.osm.Segment;
     19import org.openstreetmap.josm.data.osm.Way;
    1120import org.openstreetmap.josm.gui.MapFrame;
    1221
     
    2332public class AddNodeAction extends MapMode {
    2433
    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;
    2749        }
    2850
     
    4062         * If user clicked with the left button, add a node at the current mouse
    4163         * 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.
    4268         */
    4369        @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)
    4883                                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                                }
    49108                        }
    50                         mv.editLayer().add(new AddCommand(Main.ds, node));
    51                         mv.repaint();
     109
     110                        c = new SequenceCommand(cmds);
    52111                }
     112                mv.editLayer().add(c);
     113                mv.repaint();
    53114        }
    54115}
  • src/org/openstreetmap/josm/actions/mapmode/AddSegmentAction.java

    r87 r93  
    136136
    137137                        Segment ls = new Segment(start, end);
    138                         mv.editLayer().add(new AddCommand(Main.ds, ls));
     138                        mv.editLayer().add(new AddCommand(ls));
    139139                }
    140140
  • src/org/openstreetmap/josm/actions/mapmode/AddWayAction.java

    r90 r93  
    118118                }
    119119               
    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));
    123123                Main.ds.clearSelection();
    124124                mv.repaint();
  • src/org/openstreetmap/josm/actions/mapmode/MapMode.java

    r91 r93  
    1111import org.openstreetmap.josm.gui.MapFrame;
    1212import org.openstreetmap.josm.gui.MapView;
     13import org.openstreetmap.josm.tools.ImageProvider;
    1314
    1415/**
     
    3233
    3334        /**
    34          * Construct a mapMode with the given icon and the given MapFrame
     35         * Constructor for mapmodes without an menu
    3536         */
    3637        public MapMode(String name, String iconName, String tooltip, String keyname, int keystroke, MapFrame mapFrame) {
    3738                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);
    3850                this.mapFrame = mapFrame;
    3951                mv = mapFrame.mapView;
     
    4557         */
    4658        public void registerListener() {
    47                 firePropertyChange("active", false, true);
     59                putValue("active", true);
    4860        }
    49        
     61
    5062        /**
    5163         * Unregister all listener previously registered.
     
    5365         */
    5466        public void unregisterListener() {
    55                 firePropertyChange("active", true, false);
     67                putValue("active", false);
    5668        }
    5769
  • src/org/openstreetmap/josm/command/AddCommand.java

    r86 r93  
    33import java.util.Collection;
    44
    5 import org.openstreetmap.josm.data.osm.DataSet;
     5import org.openstreetmap.josm.Main;
    66import org.openstreetmap.josm.data.osm.OsmPrimitive;
    77import org.openstreetmap.josm.data.osm.visitor.AddVisitor;
     
    1717
    1818        /**
    19          * The dataset this command operates on.
    20          */
    21         private DataSet ds;
    22 
    23         /**
    2419         * The primitive to add to the dataset.
    2520         */
     
    2924         * Create the command and specify the element to add.
    3025         */
    31         public AddCommand(DataSet ds, OsmPrimitive osm) {
    32                 this.ds = ds;
     26        public AddCommand(OsmPrimitive osm) {
    3327                this.osm = osm;
    3428        }
    3529
    3630        @Override public void executeCommand() {
    37                 osm.visit(new AddVisitor(ds));
     31                osm.visit(new AddVisitor(Main.ds));
    3832        }
    3933
    4034        @Override public void undoCommand() {
    41                 osm.visit(new DeleteVisitor(ds));
     35                osm.visit(new DeleteVisitor(Main.ds));
    4236        }
    4337
  • src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r86 r93  
    66
    77import org.openstreetmap.josm.Main;
     8import org.openstreetmap.josm.data.osm.Node;
    89import org.openstreetmap.josm.data.osm.Segment;
    9 import org.openstreetmap.josm.data.osm.Node;
    1010import org.openstreetmap.josm.data.osm.Way;
    1111import org.openstreetmap.josm.gui.NavigatableComponent;
     
    3232         */
    3333        private final NavigatableComponent nc;
     34        private static final double PHI = Math.toRadians(20);
    3435
    3536        /**
     
    7576                        }
    7677                }
     78
    7779                for (Segment ls : w.segments)
    7880                        if (!ls.selected) // selected already in good color
     
    104106                Point p2 = nc.getPoint(ls.to.eastNorth);
    105107                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                }
    106114        }
    107115
  • src/org/openstreetmap/josm/gui/IconToggleButton.java

    r91 r93  
    3434                addMouseListener(new MouseAdapter(){
    3535                        @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;
    3737            }
    3838                });
  • src/org/openstreetmap/josm/gui/MapFrame.java

    r91 r93  
    55import java.awt.Container;
    66import java.awt.event.ActionEvent;
     7import java.awt.event.ActionListener;
    78import java.beans.PropertyChangeEvent;
    89import java.beans.PropertyChangeListener;
     
    1617import org.openstreetmap.josm.Main;
    1718import org.openstreetmap.josm.actions.AutoScaleAction;
    18 import org.openstreetmap.josm.actions.mapmode.AddNodeAction;
    1919import org.openstreetmap.josm.actions.mapmode.AddSegmentAction;
    2020import org.openstreetmap.josm.actions.mapmode.AddWayAction;
     
    2424import org.openstreetmap.josm.actions.mapmode.SelectionAction;
    2525import org.openstreetmap.josm.actions.mapmode.ZoomAction;
     26import org.openstreetmap.josm.actions.mapmode.AddNodeAction.AddNodeGroup;
    2627import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
    2728import org.openstreetmap.josm.gui.dialogs.LayerList;
     
    6970                setLayout(new BorderLayout());
    7071
    71                 AutoScaleAction autoScaleAction = new AutoScaleAction(this);
     72                final AutoScaleAction autoScaleAction = new AutoScaleAction(this);
    7273                add(mapView = new MapView(autoScaleAction), BorderLayout.CENTER);
    7374                mapView.addLayer(layer);
     
    7980                toolBarActions.add(new IconToggleButton(selectionAction));
    8081                toolBarActions.add(new IconToggleButton(new MoveAction(this)));
    81                 toolBarActions.add(new IconToggleButton(new AddNodeAction(this)));
     82                toolBarActions.add(new IconToggleButton(new AddNodeGroup(this)));
    8283                toolBarActions.add(new IconToggleButton(new AddSegmentAction(this)));
    8384                toolBarActions.add(new IconToggleButton(new AddWayAction(this, selectionAction)));
     
    9798                autoScaleButton.setText(null);
    9899                autoScaleButton.setSelected(mapView.isAutoScale());
     100                autoScaleAction.putValue("active", true);
    99101                mapView.addPropertyChangeListener(new PropertyChangeListener(){
    100102                        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                                }
    103107                        }
     108                });
     109                autoScaleButton.addActionListener(new ActionListener(){
     110                        public void actionPerformed(ActionEvent e) {
     111                                if (!autoScaleButton.groupbutton)
     112                                        autoScaleButton.setSelected(true);
     113            }
    104114                });
    105115
     
    146156         */
    147157        public void selectMapMode(MapMode mapMode) {
     158                if (mapMode == this.mapMode)
     159                        return;
    148160                if (this.mapMode != null)
    149161                        this.mapMode.unregisterListener();
  • src/org/openstreetmap/josm/gui/MapView.java

    r91 r93  
    5353         * Whether to adjust the scale property on every resize.
    5454         */
    55         boolean autoScale = true;
     55        private boolean autoScale = true;
    5656
    5757        /**
  • src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r86 r93  
    104104
    105105        /**
    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) {
    129110                double minDistanceSq = Double.MAX_VALUE;
    130                 OsmPrimitive minPrimitive = null;
    131        
    132                 // nodes
     111                Node minPrimitive = null;
    133112                for (Node n : Main.ds.nodes) {
    134113                        if (n.deleted)
     
    141120                        }
    142121                }
    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)
    151136                                        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;
    172158                // segments
    173159                for (Segment ls : Main.ds.segments) {
     
    185171                        }
    186172                }
    187        
    188173                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;
    189206        }
    190207
     
    243260                return c;
    244261        }
    245        
     262
    246263        /**
    247264         * @return The projection to be used in calculating stuff.
  • src/org/openstreetmap/josm/gui/PreferenceDialog.java

    r86 r93  
    7272                                pwd = null;
    7373                        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());
    7879
    7980                        for (int i = 0; i < colors.getRowCount(); ++i) {
     
    154155         */
    155156        private JCheckBox forceRawGpsLines = new JCheckBox("Force lines if no segments imported.");
    156 
     157        private JCheckBox directionHint = new JCheckBox("Draw Direction Arrows");
    157158        private JTable colors;
    158159
     
    200201                });
    201202
    202                 // drawRawGpsLines
    203203                drawRawGpsLines.addActionListener(new ActionListener(){
    204204                        public void actionPerformed(ActionEvent e) {
     
    212212                osmDataUsername.setText(Main.pref.get("osm-server.username"));
    213213                osmDataPassword.setText(Main.pref.get("osm-server.password"));
    214                 wmsServerBaseUrl.setText(Main.pref.get("wmsServerBaseUrl", "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("csvImportString"));
    216                 drawRawGpsLines.setSelected(Main.pref.getBoolean("drawRawGpsLines"));
     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"));
    217217                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"));
    219219                forceRawGpsLines.setEnabled(drawRawGpsLines.isSelected());
     220                directionHint.setToolTipText("Draw direction hints for all segments.");
     221                directionHint.setSelected(Main.pref.getBoolean("draw.segment.direction"));
    220222
    221223
     
    292294                display.add(drawRawGpsLines, GBC.eol().insets(20,0,0,0));
    293295                display.add(forceRawGpsLines, GBC.eop().insets(40,0,0,0));
     296                display.add(directionHint, GBC.eop().insets(20,0,0,0));
    294297                display.add(new JLabel("Colors"), GBC.eol());
    295298                colors.setPreferredScrollableViewportSize(new Dimension(100,112));
  • src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r92 r93  
    1212import java.io.IOException;
    1313import java.io.Reader;
    14 import java.net.HttpURLConnection;
    1514import java.net.MalformedURLException;
    1615import java.net.URL;
     16import java.net.URLConnection;
    1717import java.util.Collection;
    1818import java.util.LinkedList;
     
    7272                        sel = mode != SearchMode.remove ? new LinkedList<OsmPrimitive>() : Main.ds.allNonDeletedPrimitives();
    7373                        try {
    74                         HttpURLConnection con = (HttpURLConnection)url.openConnection();
     74                        URLConnection con = url.openConnection();
    7575                        Reader in = new ProgressReader(con, progress);
    7676                                currentAction.setText("Downloading...");
     
    227227
    228228        public static void search(String search, SearchMode mode) {
    229             if (search.startsWith("http://")) {
    230                 SelectionWebsiteLoader loader = new SelectionWebsiteLoader(search, mode);
     229                if (search.startsWith("http://") || search.startsWith("ftp://") || search.startsWith("https://") || search.startsWith("file:/")) {
     230                        SelectionWebsiteLoader loader = new SelectionWebsiteLoader(search, mode);
    231231                if (loader.url != null) {
    232232                        Main.worker.execute(loader);
  • src/org/openstreetmap/josm/io/ProgressReader.java

    r92 r93  
    44import java.io.InputStreamReader;
    55import java.io.Reader;
    6 import java.net.HttpURLConnection;
     6import java.net.URLConnection;
    77
    88import javax.swing.BoundedRangeModel;
     
    1717        private final BoundedRangeModel progress;
    1818
    19         public ProgressReader(HttpURLConnection con, BoundedRangeModel progress) throws IOException {
     19        public ProgressReader(URLConnection con, BoundedRangeModel progress) throws IOException {
    2020                this.in = new InputStreamReader(con.getInputStream());
    2121                this.progress = progress;
  • src/org/openstreetmap/josm/io/RawCsvReader.java

    r78 r93  
    3131        public Collection<GpsPoint> parse() throws JDOMException, IOException {
    3232                Collection<GpsPoint> data = new LinkedList<GpsPoint>();
    33                 String formatStr = Main.pref.get("csvImportString");
     33                String formatStr = Main.pref.get("csv.importstring");
    3434                if (formatStr == null)
    3535                        formatStr = in.readLine();
     
    5353                // test for completness
    5454                if (!format.contains("lat") || !format.contains("lon")) {
    55                         if (Main.pref.get("csvImportString").equals(""))
     55                        if (Main.pref.get("csv.importstring").equals(""))
    5656                                throw new JDOMException("Format string in data is incomplete or not found. Try setting an manual format string in Preferences.");
    5757                        throw new JDOMException("Format string is incomplete. Need at least 'lat' and 'lon' specification");
     
    7575                                                st.nextToken();
    7676                                        else
    77                                                 throw new JDOMException("Unknown data type: '"+token+"'."+(Main.pref.get("csvImportString").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." : ""));
    7878                                }
    7979                                data.add(new GpsPoint(new LatLon(lat, lon), time));
  • src/org/openstreetmap/josm/tools/ImageProvider.java

    r91 r93  
    2828         */
    2929        public static enum OverlayPosition {NORTHWEST, NORTHEAST, SOUTHWEST, SOUTHEAST}
    30        
     30
    3131        /**
    3232         * The icon cache
    3333         */
    3434        private static Map<URL, Image> cache = new HashMap<URL, Image>();
    35        
     35
    3636        /**
    3737         * Return an image from the specified location.
     
    4444                if (subdir != "")
    4545                        subdir += "/";
    46         String ext = name.indexOf('.') != -1 ? "" : ".png";
     46                String ext = name.indexOf('.') != -1 ? "" : ".png";
    4747                URL path = Main.class.getResource("/images/"+subdir+name+ext);
    4848                if (path == null)
Note: See TracChangeset for help on using the changeset viewer.