Changeset 5982 in josm


Ignore:
Timestamp:
2013-06-01T22:35:06+02:00 (7 years ago)
Author:
Don-vip
Message:

ParallelWayAction: handle nautical mile SoM + listen to preferences changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java

    r5960 r5982  
    2424import org.openstreetmap.josm.Main;
    2525import org.openstreetmap.josm.data.Bounds;
     26import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
     27import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
    2628import org.openstreetmap.josm.data.coor.EastNorth;
    2729import org.openstreetmap.josm.data.osm.Node;
     
    7981 * @author Ole Jørgen Brønner (olejorgenb)
    8082 */
    81 public class ParallelWayAction extends MapMode implements AWTEventListener, MapViewPaintable {
    82 
    83     private static final long serialVersionUID = 1L;
     83public class ParallelWayAction extends MapMode implements AWTEventListener, MapViewPaintable, PreferenceChangedListener {
    8484
    8585    private enum Mode {
     
    100100    private double snapDistanceImperial;
    101101    private double snapDistanceChinese;
     102    private double snapDistanceNautical;
    102103
    103104    private ModifiersSpec snapModifierCombo;
     
    119120    private WaySegment referenceSegment;
    120121    private ParallelWays pWays;
    121     LinkedHashSet<Way> sourceWays;
     122    private LinkedHashSet<Way> sourceWays;
    122123    private EastNorth helperLineStart;
    123124    private EastNorth helperLineEnd;
     
    131132        mv = mapFrame.mapView;
    132133        updateModeLocalPreferences();
     134        Main.pref.addPreferenceChangeListener(this);
    133135    }
    134136
     
    199201    private void updateModeLocalPreferences() {
    200202        // @formatter:off
    201         //snapThreshold        = Main.pref.getDouble (prefKey("snap-threshold"), 0.35); // Old preference was stored in meters, hence the new name (percent)
    202203        snapThreshold        = Main.pref.getDouble (prefKey("snap-threshold-percent"), 0.70);
    203204        snapDefault          = Main.pref.getBoolean(prefKey("snap-default"),      true);
     
    207208        snapDistanceImperial = Main.pref.getDouble(prefKey("snap-distance-imperial"), 1);
    208209        snapDistanceChinese  = Main.pref.getDouble(prefKey("snap-distance-chinese"), 1);
     210        snapDistanceNautical = Main.pref.getDouble(prefKey("snap-distance-nautical"), 0.1);
    209211
    210212        snapModifierCombo           = new ModifiersSpec(getStringPref("snap-modifier-combo",             "?sC"));
     
    400402        }
    401403
    402         //// Calculate distance to the reference line
     404        // Calculate distance to the reference line
    403405        EastNorth enp = mv.getEastNorth((int) p.getX(), (int) p.getY());
    404406        EastNorth nearestPointOnRefLine = Geometry.closestPointToLine(referenceSegment.getFirstNode().getEastNorth(),
     
    423425            } else if (som.equals(NavigatableComponent.IMPERIAL_SOM)) {
    424426                snapDistance = snapDistanceImperial * NavigatableComponent.IMPERIAL_SOM.aValue;
     427            } else if (som.equals(NavigatableComponent.NAUTICAL_MILE_SOM)) {
     428                snapDistance = snapDistanceNautical * NavigatableComponent.NAUTICAL_MILE_SOM.aValue;
    425429            } else {
    426430                snapDistance = snapDistanceMetric; // Metric system by default
     
    577581        return getStringPref(subKey, null);
    578582    }
     583
     584    @Override
     585    public void preferenceChanged(PreferenceChangeEvent e) {
     586        if (e.getKey().startsWith(prefKey(""))) {
     587            updateAllPreferences();
     588        }
     589    }
    579590}
Note: See TracChangeset for help on using the changeset viewer.