Changeset 608 in josm


Ignore:
Timestamp:
2008-04-17T03:03:28+02:00 (16 years ago)
Author:
framm
Message:
  • new extrude mode allows creation of rectangular shapes
  • new AlignInRectangle function
  • additional information in status bar about length, heading, and angle of segment being drawn
  • helper line from last node to mouse cursor (disable with edit.helper-line=false)
Location:
trunk
Files:
14 added
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/.settings/org.eclipse.jdt.ui.prefs

    r444 r608  
    1 #Thu Nov 01 00:40:04 CET 2007
     1#Wed Apr 16 17:01:39 CEST 2008
    22eclipse.preferences.version=1
    33formatter_profile=_josm
    44formatter_settings_version=10
    5 org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">// License\: GPL. \n</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="false" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">// License\: GPL. Copyright 2007 by Immanuel Scholz and others\n${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
     5org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">// License\: GPL. \n</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="false" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">// License\: GPL. For details, see LICENSE file.\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r484 r608  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. See LICENSE file for details.
    22package org.openstreetmap.josm.actions.mapmode;
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.AWTEvent;
     7import java.awt.BasicStroke;
     8import java.awt.Color;
    69import java.awt.Cursor;
     10import java.awt.Graphics;
     11import java.awt.Graphics2D;
     12import java.awt.Point;
     13import java.awt.Toolkit;
     14import java.awt.event.AWTEventListener;
    715import java.awt.event.ActionEvent;
     16import java.awt.event.InputEvent;
    817import java.awt.event.KeyEvent;
    918import java.awt.event.MouseEvent;
    10 import javax.swing.KeyStroke;
    11 import javax.swing.JComponent;
     19import java.awt.geom.GeneralPath;
    1220import java.util.ArrayList;
    1321import java.util.Collection;
     
    1624import java.util.HashSet;
    1725import java.util.Iterator;
     26import java.util.LinkedList;
     27import java.util.List;
    1828import java.util.Map;
    1929import java.util.Set;
    20 import java.util.LinkedList;
    21 import java.util.List;
    22 
     30
     31import javax.swing.JComponent;
    2332import javax.swing.JOptionPane;
     33import javax.swing.KeyStroke;
    2434
    2535import org.openstreetmap.josm.Main;
     
    2838import org.openstreetmap.josm.command.Command;
    2939import org.openstreetmap.josm.command.SequenceCommand;
     40import org.openstreetmap.josm.data.Preferences;
     41import org.openstreetmap.josm.data.SelectionChangedListener;
    3042import org.openstreetmap.josm.data.coor.EastNorth;
     43import org.openstreetmap.josm.data.coor.LatLon;
     44import org.openstreetmap.josm.data.osm.DataSet;
    3145import org.openstreetmap.josm.data.osm.Node;
    32 import org.openstreetmap.josm.tools.Pair;
    3346import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3447import org.openstreetmap.josm.data.osm.Way;
    3548import org.openstreetmap.josm.data.osm.WaySegment;
    3649import org.openstreetmap.josm.gui.MapFrame;
     50import org.openstreetmap.josm.gui.MapView;
     51import org.openstreetmap.josm.gui.layer.MapViewPaintable;
    3752import org.openstreetmap.josm.tools.ImageProvider;
     53import org.openstreetmap.josm.tools.Pair;
    3854
    3955/**
    4056 *
    41  */
    42 public class DrawAction extends MapMode {
    43        
     57 */ 
     58public class DrawAction extends MapMode implements MapViewPaintable, SelectionChangedListener, AWTEventListener {
     59               
    4460        private static Node lastUsedNode = null;
    45 
     61        private double PHI=Math.toRadians(90);
     62
     63        private boolean ctrl;
     64        private boolean alt;
     65        private boolean shift;
     66        private boolean mouseOnExistingNode;
     67        private boolean drawHelperLine;
     68        private Point mousePos;
     69        private Color selectedColor;
     70       
     71        private Node currentBaseNode;
     72        private EastNorth currentMouseEastNorth;
     73       
    4674        public DrawAction(MapFrame mapFrame) {
    4775                super(tr("Draw"), "node/autonode", tr("Draw nodes"),
     
    5381               
    5482                //putValue("help", "Action/AddNode/Autnode");
     83                selectedColor = Preferences.getPreferencesColor("selected", Color.YELLOW);
     84               
     85                drawHelperLine = Main.pref.getBoolean("draw.helper-line", true);
    5586        }
    5687
     
    6697                super.enterMode();
    6798                Main.map.mapView.addMouseListener(this);
    68         }
    69 
     99                Main.map.mapView.addMouseMotionListener(this);
     100                Main.map.mapView.addTemporaryLayer(this);
     101                DataSet.selListeners.add(this);
     102                try {
     103                        Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
     104                } catch (SecurityException ex) {
     105                }
     106                // would like to but haven't got mouse position yet:
     107                // computeHelperLine(false, false, false);
     108        }
    70109        @Override public void exitMode() {
    71110                super.exitMode();
    72111                Main.map.mapView.removeMouseListener(this);
     112                Main.map.mapView.removeMouseMotionListener(this);
     113                Main.map.mapView.removeTemporaryLayer(this);
     114                DataSet.selListeners.remove(this);
     115                try {
     116                        Toolkit.getDefaultToolkit().removeAWTEventListener(this);
     117                } catch (SecurityException ex) {
     118                }
     119        }
     120       
     121        /**
     122         * redraw to (possibly) get rid of helper line if selection changes.
     123         */
     124        public void eventDispatched(AWTEvent event) {
     125                InputEvent e = (InputEvent) event;
     126                ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
     127                alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0;
     128                shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
     129                computeHelperLine();
     130        }
     131        /**
     132         * redraw to (possibly) get rid of helper line if selection changes.
     133         */
     134        public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
     135                computeHelperLine();
    73136        }
    74137
     
    80143         */
    81144        @Override public void mouseClicked(MouseEvent e) {
     145
    82146                if (e.getButton() != MouseEvent.BUTTON1)
    83147                        return;
    84148
    85                 boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
    86                 boolean alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0;
    87                 boolean shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
     149                // we copy ctrl/alt/shift from the event just in case our global
     150                // AWTEvent didn't make it through the security manager. Unclear
     151                // if that can ever happen but better be safe.
     152                ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
     153                alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0;
     154                shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
     155                mousePos = e.getPoint();
    88156               
    89157                Collection<OsmPrimitive> selection = Main.ds.getSelected();
     
    94162                boolean newNode = false;
    95163                Node n = null;
     164               
    96165                if (!ctrl) {
    97                         n = Main.map.mapView.getNearestNode(e.getPoint());
     166                        n = Main.map.mapView.getNearestNode(mousePos);
    98167                }
    99168               
     
    256325                Main.main.undoRedo.add(c);
    257326                lastUsedNode = n;
     327                computeHelperLine();
     328                Main.map.mapView.repaint();
     329        }
     330       
     331        @Override public void mouseMoved(MouseEvent e) {
     332
     333                // we copy ctrl/alt/shift from the event just in case our global
     334                // AWTEvent didn't make it through the security manager. Unclear
     335                // if that can ever happen but better be safe.
     336               
     337                ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
     338                alt = (e.getModifiers() & ActionEvent.ALT_MASK) != 0;
     339                shift = (e.getModifiers() & ActionEvent.SHIFT_MASK) != 0;
     340                mousePos = e.getPoint();
     341               
     342                computeHelperLine();
     343        }
     344       
     345        /**
     346         * This method prepares data required for painting the "helper line" from
     347         * the last used position to the mouse cursor. It duplicates some code from
     348         * mouseClicked() (FIXME).
     349         */
     350        private void computeHelperLine() {
     351               
     352                double distance = -1;
     353                double angle = -1;
     354
     355                Collection<OsmPrimitive> selection = Main.ds.getSelected();
     356
     357                Node selectedNode = null;
     358                Way selectedWay = null;
     359                Node currentMouseNode = null;
     360                mouseOnExistingNode = false;
     361
     362                Main.map.statusLine.setAngle(-1);
     363                Main.map.statusLine.setHeading(-1);
     364                Main.map.statusLine.setDist(-1);
     365
     366                if (!ctrl && mousePos != null) {
     367                        currentMouseNode = Main.map.mapView.getNearestNode(mousePos);
     368                }
     369               
     370                if (currentMouseNode != null) {
     371                        // user clicked on node
     372                        if (selection.isEmpty()) return;
     373                        currentMouseEastNorth = currentMouseNode.eastNorth;
     374                        mouseOnExistingNode = true;
     375                } else {
     376                        // no node found in clicked area
     377                        currentMouseEastNorth = Main.map.mapView.getEastNorth(mousePos.x, mousePos.y);
     378                }
     379               
     380                for (OsmPrimitive p : selection) {
     381                        if (p instanceof Node) {
     382                                if (selectedNode != null) return;
     383                                selectedNode = (Node) p;
     384                        } else if (p instanceof Way) {
     385                                if (selectedWay != null) return;
     386                                selectedWay = (Way) p;
     387                        }
     388                }
     389               
     390                // the node from which we make a connection
     391                currentBaseNode = null;
     392                Node previousNode = null;
     393               
     394                if (selectedNode == null) {
     395                        if (selectedWay == null) return;
     396                        if (lastUsedNode == selectedWay.nodes.get(0) || lastUsedNode == selectedWay.nodes.get(selectedWay.nodes.size()-1)) {
     397                                currentBaseNode = lastUsedNode;
     398                                if (lastUsedNode == selectedWay.nodes.get(selectedWay.nodes.size()-1) && selectedWay.nodes.size() > 1) {
     399                                        previousNode = selectedWay.nodes.get(selectedWay.nodes.size()-2);
     400                                }
     401                        }
     402                } else if (selectedWay == null) {
     403                        currentBaseNode = selectedNode;
     404                } else {
     405                        if (selectedNode == selectedWay.nodes.get(0) || selectedNode == selectedWay.nodes.get(selectedWay.nodes.size()-1)) {
     406                                currentBaseNode = selectedNode;
     407                        }                       
     408                }
     409               
     410                if (currentBaseNode == null || currentBaseNode == currentMouseNode) {
     411                        return; // Don't create zero length way segments.
     412                }
     413               
     414                Main.map.mapView.repaint();
     415               
     416                // find out the distance, in metres, between the base point and the mouse cursor
     417                LatLon mouseLatLon = Main.proj.eastNorth2latlon(currentMouseEastNorth);
     418                distance = currentBaseNode.coor.greatCircleDistance(mouseLatLon);
     419                double hdg = Math.toDegrees(currentBaseNode.coor.heading(mouseLatLon));
     420                if (previousNode != null) {
     421                        angle = hdg - Math.toDegrees(previousNode.coor.heading(currentBaseNode.coor));
     422                        if (angle < 0) angle += 360;
     423                }
     424                Main.map.statusLine.setAngle(angle);
     425                Main.map.statusLine.setHeading(hdg);
     426                Main.map.statusLine.setDist(distance);
     427                updateStatusLine();
     428        }
     429       
     430        /**
     431         * Repaint on mouse exit so that the helper line goes away.
     432         */
     433        @Override public void mouseExited(MouseEvent e) {
     434                mousePos = e.getPoint();
    258435                Main.map.mapView.repaint();
    259436        }
     
    347524                        A = seg.a.eastNorth;
    348525                        B = seg.b.eastNorth;
    349                         double a = P.distance(B);
    350                         double b = P.distance(A);
    351                         double c = A.distance(B);
     526                        double a = P.distanceSq(B);
     527                        double b = P.distanceSq(A);
     528                        double c = A.distanceSq(B);
    352529                        double q = (a - b + c) / (2*c);
    353530                        n.eastNorth = new EastNorth(
     
    362539                return a * d - b * c;
    363540        }
    364 
     541       
     542        public void paint(Graphics g, MapView mv) {
     543
     544                // don't draw line if disabled in prefs
     545                if (!drawHelperLine) return;
     546               
     547                // sanity checks
     548                if (Main.map.mapView == null) return;
     549                if (mousePos == null) return;
     550               
     551                // if shift key is held ("no auto-connect"), don't draw a line
     552                if (shift) return;
     553               
     554                // don't draw line if we don't know where from or where to
     555                if (currentBaseNode == null) return;
     556                if (currentMouseEastNorth == null) return;
     557               
     558                // don't draw line if mouse is outside window
     559                if (!Main.map.mapView.getBounds().contains(mousePos)) return;
     560               
     561                Graphics2D g2 = (Graphics2D) g;
     562                g2.setColor(selectedColor);
     563                g2.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
     564                GeneralPath b = new GeneralPath();
     565                Point p1=mv.getPoint(currentBaseNode.eastNorth);
     566                Point p2=mv.getPoint(currentMouseEastNorth);
     567
     568                double t = Math.atan2(p2.y-p1.y, p2.x-p1.x) + Math.PI;
     569               
     570                b.moveTo(p1.x,p1.y); b.lineTo(p2.x, p2.y);
     571               
     572                // if alt key is held ("start new way"), draw a little perpendicular line
     573                if (alt) {
     574                        b.moveTo((int)(p1.x + 8*Math.cos(t+PHI)), (int)(p1.y + 8*Math.sin(t+PHI)));
     575                        b.lineTo((int)(p1.x + 8*Math.cos(t-PHI)), (int)(p1.y + 8*Math.sin(t-PHI)));
     576                }
     577               
     578                g2.draw(b);
     579                g2.setStroke(new BasicStroke(1));       
     580
     581        }
    365582       
    366583        @Override public String getModeHelpText() {
    367                 return tr("Click to add a new node. Ctrl: no node re-use/auto-insert. Shift: no auto-connect. Alt: new way");
     584                String rv;
     585               
     586                if (currentBaseNode != null && !shift) {
     587                        if (mouseOnExistingNode) {
     588                                if (alt && /* FIXME: way exists */true)
     589                                    rv = tr("Click to create a new way to the existing node.");
     590                                else   
     591                                        rv =tr("Click to make a connection to the existing node.");
     592                        } else {
     593                                if (alt && /* FIXME: way exists */true)
     594                                    rv = tr("Click to insert a nose and create a new way.");
     595                                else   
     596                                        rv = tr("Click to insert a new node and make a connection.");
     597                        }
     598                }
     599                else {
     600                        rv = tr("Click to insert a new node.");
     601                }
     602
     603                //rv.append(tr("Click to add a new node. Ctrl: no node re-use/auto-insert. Shift: no auto-connect. Alt: new way"));
     604                //rv.append(tr("Click to add a new node. Ctrl: no node re-use/auto-insert. Shift: no auto-connect. Alt: new way"));
     605                return rv.toString();
    368606        }
    369607}
  • trunk/src/org/openstreetmap/josm/actions/mapmode/MapMode.java

    r373 r608  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. See LICENSE file for details.
    22package org.openstreetmap.josm.actions.mapmode;
    33
     
    1818 * is another.
    1919 *
    20  * MapModes should register/deregister all necessary listener on the map's view
     20 * MapModes should register/deregister all necessary listeners on the map's view
    2121 * control.
    2222 */
     
    5757        protected void updateStatusLine() {
    5858                Main.map.statusLine.setHelpText(getModeHelpText());
     59                Main.map.statusLine.repaint();
    5960        }
    6061       
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r486 r608  
    22package org.openstreetmap.josm.data;
    33
     4import java.awt.Color;
    45import java.io.BufferedReader;
    56import java.io.File;
     
    1819
    1920import org.openstreetmap.josm.Main;
     21import org.openstreetmap.josm.tools.ColorHelper;
    2022
    2123
     
    259261                out.close();
    260262        }
     263       
     264        /**
     265         * Convenience method for accessing colour preferences.
     266         *
     267         * @param colName name of the colour
     268         * @param def default value
     269         * @return a Color object for the configured colour, or the default value if none configured.
     270         */
     271        public static Color getPreferencesColor(String colName, Color def) {
     272                String colStr = Main.pref.get("color."+colName);
     273                if (colStr.equals("")) {
     274                        Main.pref.put("color."+colName, ColorHelper.color2html(def));
     275                        return def;
     276                }
     277                return ColorHelper.html2color(colStr);
     278        }
    261279}
  • trunk/src/org/openstreetmap/josm/data/coor/Coordinate.java

    r486 r608  
    4141         * Return the squared distance of the northing/easting values between
    4242         * this and the argument.
     43         *
     44         * This method does NOT compute a great circle distance between two
     45         * locations!
    4346         *
    4447         * @param other The other point to calculate the distance to.
     
    4649         *              regarding to the x/y values.
    4750         */
     51        public double distanceSq(Coordinate other) {
     52                return (x-other.x)*(x-other.x)+(y-other.y)*(y-other.y);
     53        }
     54       
     55        /**
     56         * Return the distance of the northing/easting values between this and
     57         * the argument.
     58         *
     59         * This method does NOT compute a great circle distance between two
     60         * locations!
     61         *
     62         * @param other The other point to calculate the distance to.
     63         * @return The square of the distance between this and the other point,
     64         *              regarding to the x/y values.
     65         */
    4866        public double distance(Coordinate other) {
    49                 return (x-other.x)*(x-other.x)+(y-other.y)*(y-other.y);
     67                return Math.sqrt(distanceSq(other));
    5068        }
    5169
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r589 r608  
    5858         * @return distance in metres.
    5959         */
    60         public int distance(LatLon other) {
    61                 return (int) (Math.acos(
     60        public double greatCircleDistance(LatLon other) {
     61                return (Math.acos(
    6262                        Math.sin(Math.toRadians(lat())) * Math.sin(Math.toRadians(other.lat())) +
    6363                    Math.cos(Math.toRadians(lat()))*Math.cos(Math.toRadians(other.lat())) *
    6464                                  Math.cos(Math.toRadians(other.lon()-lon()))) * 6378135);
     65        }
     66       
     67        /**
     68         * Returns the heading, in radians, that you have to use to get from
     69         * this lat/lon to another.
     70         *
     71         * @param other the "destination" position
     72         * @return heading
     73         */
     74        public double heading(LatLon other) {
     75                double rv;
     76                if (other.lat() == lat()) {
     77                        rv = (other.lon()>lon() ? Math.PI / 2 : Math.PI * 3 / 2);
     78                } else {
     79                        rv = Math.atan((other.lon()-lon())/(other.lat()-lat()));
     80                        if (rv < 0) rv += Math.PI;
     81                        if (other.lon() < lon()) rv += Math.PI;
     82                }
     83                return rv;
    6584        }
    6685
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java

    r599 r608  
    1818
    1919import org.openstreetmap.josm.Main;
     20import org.openstreetmap.josm.data.Preferences;
    2021import org.openstreetmap.josm.data.osm.DataSet;
    2122import org.openstreetmap.josm.data.osm.Node;
     
    335336                }
    336337        }
    337        
    338         public static Color getPreferencesColor(String colName, Color def) {
    339                 String colStr = Main.pref.get("color."+colName);
    340                 if (colStr.equals("")) {
    341                         Main.pref.put("color."+colName, ColorHelper.color2html(def));
    342                         return def;
    343                 }
    344                 return ColorHelper.html2color(colStr);
    345         }
    346338
    347339        // NW 111106 Overridden from SimplePaintVisitor in josm-1.4-nw1
    348340        // Shows areas before non-areas
    349341        public void visitAll(DataSet data) {
    350                 inactiveColor = getPreferencesColor("inactive", Color.DARK_GRAY);
    351                 selectedColor = getPreferencesColor("selected", Color.YELLOW);
    352                 nodeColor = getPreferencesColor("node", Color.RED);
    353                 dfltWayColor = getPreferencesColor("way", darkblue);
    354                 incompleteColor = getPreferencesColor("incomplete way", darkerblue);
    355                 backgroundColor = getPreferencesColor("background", Color.BLACK);
    356                 untaggedColor = getPreferencesColor("untagged",Color.GRAY);
    357                 textColor = getPreferencesColor ("text", Color.WHITE);
     342                inactiveColor = Preferences.getPreferencesColor("inactive", Color.DARK_GRAY);
     343                selectedColor = Preferences.getPreferencesColor("selected", Color.YELLOW);
     344                nodeColor = Preferences.getPreferencesColor("node", Color.RED);
     345                dfltWayColor = Preferences.getPreferencesColor("way", darkblue);
     346                incompleteColor = Preferences.getPreferencesColor("incomplete way", darkerblue);
     347                backgroundColor = Preferences.getPreferencesColor("background", Color.BLACK);
     348                untaggedColor = Preferences.getPreferencesColor("untagged",Color.GRAY);
     349                textColor = Preferences.getPreferencesColor ("text", Color.WHITE);
    358350                showDirectionArrow = Main.pref.getBoolean("draw.segment.direction");
    359351                showRelevantDirectionsOnly = Main.pref.getBoolean("draw.segment.relevant_directions_only");
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r597 r608  
    1111import java.util.Iterator;
    1212import org.openstreetmap.josm.Main;
     13import org.openstreetmap.josm.data.Preferences;
    1314import org.openstreetmap.josm.data.osm.DataSet;
    1415import org.openstreetmap.josm.data.osm.Relation;
     
    6869
    6970        public void visitAll(DataSet data) {
    70                 inactiveColor = getPreferencesColor("inactive", Color.DARK_GRAY);
    71                 selectedColor = getPreferencesColor("selected", Color.WHITE);
    72                 nodeColor = getPreferencesColor("node", Color.RED);
    73                 dfltWayColor = getPreferencesColor("way", darkblue);
    74                 untaggedWayColor = getPreferencesColor("untagged way", darkgreen);
    75                 incompleteColor = getPreferencesColor("incomplete way", darkerblue);
    76                 backgroundColor = getPreferencesColor("background", Color.BLACK);
     71                inactiveColor = Preferences.getPreferencesColor("inactive", Color.DARK_GRAY);
     72                selectedColor = Preferences.getPreferencesColor("selected", Color.WHITE);
     73                nodeColor = Preferences.getPreferencesColor("node", Color.RED);
     74                dfltWayColor = Preferences.getPreferencesColor("way", darkblue);
     75                untaggedWayColor = Preferences.getPreferencesColor("untagged way", darkgreen);
     76                incompleteColor = Preferences.getPreferencesColor("incomplete way", darkerblue);
     77                backgroundColor = Preferences.getPreferencesColor("background", Color.BLACK);
    7778                showDirectionArrow = Main.pref.getBoolean("draw.segment.direction");
    7879                showRelevantDirectionsOnly = Main.pref.getBoolean("draw.segment.relevant_directions_only");
     
    226227                return screen.intersects(bbox);
    227228        }
    228 
    229         public static Color getPreferencesColor(String colName, Color def) {
    230                 String colStr = Main.pref.get("color."+colName);
    231                 if (colStr.equals("")) {
    232                         Main.pref.put("color."+colName, ColorHelper.color2html(def));
    233                         return def;
    234                 }
    235                 return ColorHelper.html2color(colStr);
    236         }
    237229       
    238230        public void setGraphics(Graphics g) {
  • trunk/src/org/openstreetmap/josm/gui/GettingStarted.java

    r582 r608  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. See LICENSE file for details.
     2
    23package org.openstreetmap.josm.gui;
    34
     
    4849                panel = new JPanel(new GridBagLayout());
    4950               
    50                 panel.add(new JLabel(tr("<html><h2>You are running the latest JOSM version with built-in mappaint support.</h2>" +
    51                 "<h3>The mappaint plugin is no longer necessary and has been removed from your configuration<br>" +
    52                 "file (if it was present). You can now switch between the \"classic\" display and the mappaint<br>" +
    53                 "style by toggling the \"Wireframe\" option in the \"View\" menu.</h3>" +
    54                 "<h3>If you have not used new JOSM versions for a while, you will also discover that this JOSM<br>" +
    55                 "is \"modeless\". It (almost) does away with the old edit modes, like \"add node and connect\" etc.;<br>"+
    56                 "instead, there are only four modes: zoom, select, edit, and delete. The edit mode will do what<br>"+
    57                 "you want in most cases (also see the mini help about modifier keys at the bottom of the screen)." +
     51                panel.add(new JLabel(tr("<html><h2>You are running the latest JOSM version with some geometry extensions.</h2>" +
     52                "<h3>New elements in the status bar will inform you about the orientation and size<br>" +
     53                "of the object being drawn. There is a new \"extrude\" mode that you can use to create<br>" +
     54                "rectangular shapes (see below for a short video on this).</h3>" +
     55                "<h3>There is also a new option in the tools menu that will make existing shapes into proper<br>" +
     56                "rectangles. Note that all this is dependend on the projection you're using; you must use<br>"+
     57                "a projection in which rectangles look rectangular and not skewed. Try it out.</h3>"+
     58                "<h3>If you dislike the helper line dangling from the mouse cursor, set the \"draw.helper-line\"<br>"+
     59                "preference to \"false\"."+
    5860                "</h3>")), GBC.eol());
    5961
    60                 // remove these two keys from preferences if present
     62        /*
    6163                boolean changePrefs = ! (
    6264                        "0.5".equals(Main.pref.get("osm-server.version", "0.5")) &&
     
    6971                        panel.add(new JLabel(tr("<html><h3>Your preferences have been changed by removing <b>osm-server.version</b> and/or <b>osm-server.additional-versions</b> which were still referring to 0.4.</h3></html>")), GBC.eol());
    7072                }
     73        */
    7174               
    7275                addLine("wiki", tr("Read the [Wiki page on API 0.5]"));
     76                addLine("extrudevideo", tr("Short (sound-less) [video] demonstrating the new \"extrude\" feature"));
    7377
    7478                addLine("audio", tr("This version also has built-in support for [Audio Mapping] with continuously recorded sound tracks."));
     
    120124                else if (e.getActionCommand().equals("mailinglist"))
    121125                        OpenBrowser.displayUrl("mailto:newbies-subscribe@openstreetmap.org?subject=subscribe");
     126                else if (e.getActionCommand().equals("extrudevideo"))
     127                        OpenBrowser.displayUrl("http://josm.openstreetmap.de/download/tutorials/josm-extrude-feature.mpeg");
    122128    }
    123129}
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r563 r608  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. See LICENSE file for details.
     2
    23package org.openstreetmap.josm.gui;
    34
     
    1415
    1516import org.openstreetmap.josm.Main;
     17import org.openstreetmap.josm.actions.AlignInRectangleAction;
    1618import org.openstreetmap.josm.actions.JosmAction;
    1719import org.openstreetmap.josm.actions.AboutAction;
     
    9395        public final JosmAction alignInCircle = new AlignInCircleAction();
    9496        public final JosmAction alignInLine = new AlignInLineAction();
     97        public final JosmAction alignInRect = new AlignInRectangleAction();
    9598        public final JosmAction mergeNodes = new MergeNodesAction();
    9699        public final JosmAction joinNodeWay = new JoinNodeWayAction();
     
    207210                current = toolsMenu.add(alignInLine);
    208211                current.setAccelerator(alignInLine.shortCut);
     212                current = toolsMenu.add(alignInRect);
     213                current.setAccelerator(alignInRect.shortCut);
    209214                toolsMenu.addSeparator();
    210215                current = toolsMenu.add(mergeNodes);
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r582 r608  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. See LICENSE file for details.
     2
    23package org.openstreetmap.josm.gui;
    34
     
    1617import org.openstreetmap.josm.actions.mapmode.DeleteAction;
    1718import org.openstreetmap.josm.actions.mapmode.DrawAction;
     19import org.openstreetmap.josm.actions.mapmode.ExtrudeAction;
    1820import org.openstreetmap.josm.actions.mapmode.MapMode;
    1921import org.openstreetmap.josm.actions.mapmode.SelectAction;
     
    8183                toolBarActions.add(new IconToggleButton(new DrawAction(this)));
    8284                toolBarActions.add(new IconToggleButton(new DeleteAction(this)));
    83 
     85                toolBarActions.add(new IconToggleButton(new ExtrudeAction(this)));
     86               
    8487                for (Component c : toolBarActions.getComponents())
    8588                        toolGroup.add((AbstractButton)c);
  • trunk/src/org/openstreetmap/josm/gui/MapScaler.java

    r588 r608  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. See LICENSE file for details.
     2
    23package org.openstreetmap.josm.gui;
    34
     
    2829                LatLon ll1 = mv.getLatLon(0,0);
    2930                LatLon ll2 = mv.getLatLon(100,0);
    30                 int dist = ll1.distance(ll2);
    31                 String text = dist > 1000 ? (Math.round(dist/100)/10.0)+"km" : dist+"m";
     31                double dist = ll1.greatCircleDistance(ll2);
     32                String text = dist > 1000 ? (Math.round(dist/100)/10.0)+"km" : Math.round(dist*10)/10+"m";
    3233                Rectangle2D bound = g.getFontMetrics().getStringBounds(text, g);
    3334                g.setColor(ColorHelper.html2color(Main.pref.get("color.scale", "#ffffff")));
  • trunk/src/org/openstreetmap/josm/gui/MapStatus.java

    r582 r608  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. See LICENSE file for details.
     2
    23package org.openstreetmap.josm.gui;
    34
     
    56
    67import java.awt.AWTEvent;
     8import java.awt.Color;
    79import java.awt.Cursor;
    810import java.awt.Dimension;
     
    3840import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
    3941import org.openstreetmap.josm.tools.GBC;
     42import org.openstreetmap.josm.tools.ImageProvider;
    4043
    4144/**
     
    4750 *
    4851 * The background thread does not alter any data of the map (read only thread).
    49  * Also it is rather fail safe. In case of some error in the data, it just do
     52 * Also it is rather fail safe. In case of some error in the data, it just does
    5053 * nothing instead of whining and complaining.
    5154 *
     
    5558
    5659        /**
    57          * The MapView this status belongs.
     60         * The MapView this status belongs to.
    5861         */
    5962        final MapView mv;
    60         /**
    61          * The position of the mouse cursor.
    62          */
    63         DecimalFormat latlon = new DecimalFormat("###0.0000000");
    64         JTextField positionText = new JTextField(25);
    6563       
    66         /**
    67          * The field holding the name of the object under the mouse.
    68          */
    69         JTextField nameText = new JTextField(30);
    70 
    71         /**
    72          * The field holding information about what the user can do.
    73          */
    74         JTextField helpText = new JTextField();
    75        
     64        /**
     65         * A small user interface component that consists of an image label and
     66         * a fixed text content to the right of the image.
     67         */
     68        class ImageLabel extends JPanel {
     69                private JLabel tf;
     70                private JLabel lbl;
     71                private int chars;
     72                public ImageLabel(String img, String tooltip, int chars) {
     73                        super();
     74                        setLayout(new GridBagLayout());
     75                        setBackground(Color.decode("#b8cfe5"));
     76                        add(lbl = new JLabel(ImageProvider.get("statusline/"+img+".png")), GBC.std().anchor(GBC.WEST).insets(0,1,1,0));
     77                        add(tf = new JLabel(), GBC.std().fill(GBC.BOTH).anchor(GBC.WEST).insets(2,1,1,0));
     78                        setToolTipText(tooltip);
     79                        this.chars = chars;
     80                }
     81                public void setText(String t) {
     82                        tf.setText(t);
     83                }
     84                @Override public Dimension getPreferredSize() {
     85                        return new Dimension(25 + chars*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getPreferredSize().height);
     86                }
     87                @Override public Dimension getMinimumSize() {
     88                        return new Dimension(25 + chars*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getMinimumSize().height);
     89                }
     90        }
     91
     92    DecimalFormat latlon = new DecimalFormat("###0.0000");
     93    ImageLabel lonText = new ImageLabel("lon", tr("The geographic longitude at the mouse pointer."), 8);
     94    ImageLabel nameText = new ImageLabel("name", tr("The name of the object at the mouse pointer."), 20);
     95    JTextField helpText = new JTextField();
     96    ImageLabel latText = new ImageLabel("lat", tr("The geograpgic latitude at the mouse pointer."), 7);
     97    ImageLabel angleText = new ImageLabel("angle", tr("The angle between the previous and the current way segment."), 6);
     98    ImageLabel headingText = new ImageLabel("heading", tr("The (compass) heading of the line segment being drawn."), 6);
     99    ImageLabel distText = new ImageLabel("dist", tr("The length of the new way segment being drawn."), 8);
     100
    76101        /**
    77102         * The collector class that waits for notification and then update
     
    119144                                        continue;
    120145
     146                                OsmPrimitive osmNearest = null;
     147                                // Set the text label in the bottom status bar
     148                                osmNearest = mv.getNearest(ms.mousePos);
     149                                if (osmNearest != null) {
     150                                        NameVisitor visitor = new NameVisitor();
     151                                        osmNearest.visit(visitor);
     152                                        nameText.setText(visitor.name);
     153                                } else
     154                                        nameText.setText("(no object)");                               
     155
    121156                                // This try/catch is a hack to stop the flooding bug reports about this.
    122157                                // The exception needed to handle with in the first place, means that this
     
    132167                                                if (osms != null && osms.equals(osmStatus) && ms.modifiers == oldModifiers)
    133168                                                        continue;
    134                                         /*
    135                                         osmStatus = osms;
    136                                         oldModifiers = ms.modifiers;
    137 
    138                                         OsmPrimitive osmNearest = null;
    139                                         // Set the text label in the bottom status bar
    140                                         osmNearest = mv.getNearest(ms.mousePos);
    141                                         if (osmNearest != null) {
    142                                                 NameVisitor visitor = new NameVisitor();
    143                                                 osmNearest.visit(visitor);
    144                                                 nameText.setText(visitor.name);
    145                                         } else
    146                                                 nameText.setText("");
    147                                         */
    148                                        
    149169
    150170                                                if (popup != null) {
     
    247267                                if ((e.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) == 0) {
    248268                                        LatLon p = mv.getLatLon(e.getX(),e.getY());
    249                                         positionText.setText(latlon.format(p.lat())+" "+latlon.format(p.lon()));
     269                                        latText.setText(latlon.format(p.lat()));
     270                                        lonText.setText(latlon.format(p.lon()));
    250271                                }
    251272                        }
    252273                });
    253274
    254                 positionText.setEditable(false);
    255                 nameText.setEditable(false);
    256                 helpText.setEditable(false);
    257275                setLayout(new GridBagLayout());
    258276                setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    259                 add(new JLabel(tr("Lat/Lon")+" "), GBC.std());
    260                 add(positionText, GBC.std());
    261                 //add(new JLabel(" "+tr("Object")+" "));
    262                 //add(nameText);
    263                 add(helpText, GBC.eol().fill(GBC.HORIZONTAL));
    264                 positionText.setMinimumSize(new Dimension(positionText.getMinimumSize().height, 200));
     277
     278        add(latText, GBC.std());
     279        add(lonText, GBC.std().insets(3,0,0,0));
     280        add(headingText, GBC.std().insets(3,0,0,0));
     281        add(angleText, GBC.std().insets(3,0,0,0));
     282        add(distText, GBC.std().insets(3,0,0,0));
     283
     284                helpText.setEditable(false);
     285                add(nameText, GBC.std().insets(3,0,0,0));
     286                add(helpText, GBC.eol().insets(3,0,0,0).fill(GBC.HORIZONTAL));
    265287               
    266288                // The background thread
     
    317339        public void setHelpText(String t) {
    318340                helpText.setText(t);
    319         }
     341                helpText.setToolTipText(t);
     342        }
     343        public void setAngle(double a) {
     344                angleText.setText(a < 0 ? "--" : Math.round(a*10)/10.0 + "°");
     345        }
     346        public void setHeading(double h) {
     347                headingText.setText(h < 0 ? "--" : Math.round(h*10)/10.0 + "°");
     348        }
     349        public void setDist(double dist) {
     350                String text = dist > 1000 ? (Math.round(dist/100)/10.0)+"km" : Math.round(dist*10)/10 +"m";
     351                distText.setText(dist < 0 ? "--" : text);
     352        }
     353       
    320354}
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r582 r608  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. See LICENSE file for details.
     2
    23package org.openstreetmap.josm.gui;
    34
     
    2324import org.openstreetmap.josm.actions.MoveAction;
    2425import org.openstreetmap.josm.data.Bounds;
     26import org.openstreetmap.josm.data.Preferences;
    2527import org.openstreetmap.josm.data.SelectionChangedListener;
    2628import org.openstreetmap.josm.data.coor.EastNorth;
     
    2931import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3032import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    31 import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor;
    3233import org.openstreetmap.josm.data.projection.Projection;
    3334import org.openstreetmap.josm.gui.layer.Layer;
     35import org.openstreetmap.josm.gui.layer.MapViewPaintable;
    3436import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    3537import org.openstreetmap.josm.gui.layer.OsmDataLayer.ModifiedChangedListener;
     
    7981        private Layer activeLayer;
    8082       
     83        private LinkedList<MapViewPaintable> temporaryLayers = new LinkedList<MapViewPaintable>();
     84       
    8185        /**
    8286         * The listener of the active layer changes.
     
    195199                if (center == null)
    196200                        return; // no data loaded yet.
    197                 g.setColor(SimplePaintVisitor.getPreferencesColor("background", Color.BLACK));
     201                g.setColor(Preferences.getPreferencesColor("background", Color.BLACK));
    198202                g.fillRect(0, 0, getWidth(), getHeight());
    199203
     
    203207                                l.paint(g, this);
    204208                }
     209               
    205210                if (getActiveLayer() != null && getActiveLayer().visible)
    206211                        getActiveLayer().paint(g, this);
    207212
     213                for (MapViewPaintable mvp : temporaryLayers) {
     214                        mvp.paint(g, this);
     215                }
     216               
    208217                // draw world borders
    209218                g.setColor(Color.WHITE);
     
    330339                        firePropertyChange("scale", oldScale, scale);
    331340        }
     341       
     342        public boolean addTemporaryLayer(MapViewPaintable mvp) {
     343                if (temporaryLayers.contains(mvp)) return false;
     344                return temporaryLayers.add(mvp);
     345        }
     346       
     347        public boolean removeTemporaryLayer(MapViewPaintable mvp) {
     348                return temporaryLayers.remove(mvp);
     349        }
    332350}
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r582 r608  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. See LICENSE file for details.
     2
    23package org.openstreetmap.josm.gui;
    34
     
    9899         */
    99100        public LatLon getLatLon(int x, int y) {
    100                 EastNorth eastNorth = new EastNorth(
    101                                 center.east() + (x - getWidth()/2.0)*scale,
    102                                 center.north() - (y - getHeight()/2.0)*scale);
    103                 return getProjection().eastNorth2latlon(eastNorth);
     101
     102                return getProjection().eastNorth2latlon(getEastNorth(x, y));
    104103        }
    105104
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r343 r608  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. See LICENSE file for details.
    22package org.openstreetmap.josm.gui.dialogs;
    33
     
    3131import org.openstreetmap.josm.Main;
    3232import org.openstreetmap.josm.command.ConflictResolveCommand;
     33import org.openstreetmap.josm.data.Preferences;
    3334import org.openstreetmap.josm.data.SelectionChangedListener;
    3435import org.openstreetmap.josm.data.osm.DataSet;
     
    3839import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3940import org.openstreetmap.josm.data.osm.Way;
    40 import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor;
    4141import org.openstreetmap.josm.data.osm.visitor.Visitor;
    4242import org.openstreetmap.josm.gui.ConflictResolver;
     
    144144         */
    145145        public void paintConflicts(final Graphics g, final NavigatableComponent nc) {
    146                 Color preferencesColor = SimplePaintVisitor.getPreferencesColor("conflict", Color.gray);
     146                Color preferencesColor = Preferences.getPreferencesColor("conflict", Color.gray);
    147147                if (preferencesColor.equals(Color.BLACK))
    148148                        return;
  • trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java

    r602 r608  
    1 //License: GPL. Copyright 2007 by Immanuel Scholz, Raphael Mack and others
     1// License: GPL. See LICENSE file for details.
    22
    33package org.openstreetmap.josm.gui.layer;
     
    321321                                               
    322322                                            // draw line, if no maxLineLength is set or the line is shorter.
    323                                             if (maxLineLength == -1 || trkPnt.latlon.distance(oldWp.latlon) <= maxLineLength){
     323                                            if (maxLineLength == -1 || trkPnt.latlon.greatCircleDistance(oldWp.latlon) <= maxLineLength){
    324324                                                g.drawLine(old.x, old.y, screen.x, screen.y);
    325325
  • trunk/src/org/openstreetmap/josm/gui/layer/Layer.java

    r304 r608  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. See LICENSE file for details.
     2
    23package org.openstreetmap.josm.gui.layer;
    34
     
    2930 * @author imi
    3031 */
    31 abstract public class Layer implements Destroyable {
     32abstract public class Layer implements Destroyable, MapViewPaintable {
    3233
    3334        /**
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r508 r608  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. See LICENSE file for details.
     2
    23package org.openstreetmap.josm.gui.layer;
    34
     
    3334import org.openstreetmap.josm.actions.SaveAsAction;
    3435import org.openstreetmap.josm.command.Command;
     36import org.openstreetmap.josm.data.Preferences;
    3537import org.openstreetmap.josm.data.coor.EastNorth;
    3638import org.openstreetmap.josm.data.osm.DataSet;
     
    153155                                        Point p1 = mv.getPoint(en1);
    154156                                        Point p2 = mv.getPoint(en2);
    155                                         Color color = inactive ? SimplePaintVisitor.getPreferencesColor("inactive", Color.DARK_GRAY) :
    156                                                         SimplePaintVisitor.getPreferencesColor("downloaded Area", Color.YELLOW);
     157                                        Color color = inactive ? Preferences.getPreferencesColor("inactive", Color.DARK_GRAY) :
     158                                                        Preferences.getPreferencesColor("downloaded Area", Color.YELLOW);
    157159                                        g.setColor(color);
    158160                                        g.drawRect(Math.min(p1.x,p2.x), Math.min(p1.y, p2.y), Math.abs(p2.x-p1.x), Math.abs(p2.y-p1.y));
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/PlayHeadMarker.java

    r582 r608  
     1// License: GPL. See LICENSE file for details.
     2
    13package org.openstreetmap.josm.gui.layer.markerlayer;
    24
     
    226228                        for (Marker m : AudioMarker.recentlyPlayedMarker().parentLayer.data) {
    227229                                if (m instanceof AudioMarker) {
    228                                         double distanceSquared = m.eastNorth.distance(en);
     230                                        double distanceSquared = m.eastNorth.distanceSq(en);
    229231                                        if (distanceSquared < closestAudioMarkerDistanceSquared) {
    230232                                                ca = (AudioMarker) m;
Note: See TracChangeset for help on using the changeset viewer.