Changeset 33784 in osm for applications


Ignore:
Timestamp:
2017-11-05T19:45:14+01:00 (7 years ago)
Author:
donvip
Message:

update to JOSM 12840

Location:
applications/editors/josm/plugins/alignways
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/alignways/build.xml

    r33133 r33784  
    44    <property name="commit.message" value="AlignWays: moved to Shift-Spacebar due to shortcut confilcts with core. A is too overloaded"/>
    55    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    6     <property name="plugin.main.version" value="10580"/>
     6    <property name="plugin.main.version" value="12840"/>
    77
    88    <!-- Configure these properties (replace "..." accordingly).
  • applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysAction.java

    r32466 r33784  
    11/**
    2  * 
     2 *
    33 */
    44package com.tilusnet.josm.plugins.alignways;
     
    1313import org.openstreetmap.josm.actions.JosmAction;
    1414import org.openstreetmap.josm.command.Command;
     15import org.openstreetmap.josm.data.osm.DataSet;
    1516import org.openstreetmap.josm.data.osm.Node;
     17import org.openstreetmap.josm.gui.MainApplication;
    1618import org.openstreetmap.josm.tools.Shortcut;
    1719
     
    2022/**
    2123 * @author tilusnet <tilusnet@gmail.com>
    22  * 
     24 *
    2325 */
    2426public class AlignWaysAction extends JosmAction {
     
    3133                "alignways",
    3234                tr("Makes a pair of selected way segments parallel by rotating one of them "
    33                         + "around a chosen pivot."), 
     35                        + "around a chosen pivot."),
    3436                Shortcut.registerShortcut("tools:alignways", tr("Tool: {0}", tr("Align Ways")),
    3537                                KeyEvent.VK_SPACE, Shortcut.SHIFT)
     
    4244        if (!isEnabled())
    4345            return;
    44         if (getLayerManager().getEditDataSet() == null)
     46        DataSet ds = getLayerManager().getEditDataSet();
     47        if (ds == null)
    4548            return;
    4649
    4750        Collection<Node> affectableNodes = AlignWaysSegmentMgr.getInstance(
    48                 Main.map.mapView).getSelectedNodes();
     51                MainApplication.getMap().mapView).getSelectedNodes();
    4952
    5053        // c is the last command launched, if any
     
    5962                    AlignWaysCmdKeepLength cmdAW;
    6063                    if (AlignWaysPlugin.getAwDialog().getAwOpt() == AligningModeOption.ALGN_OPT_KEEP_ANGLE) {
    61                         cmdAW = new AlignWaysCmdKeepAngles();
     64                        cmdAW = new AlignWaysCmdKeepAngles(ds);
    6265                    } else {
    63                         cmdAW = new AlignWaysCmdKeepLength();
     66                        cmdAW = new AlignWaysCmdKeepLength(ds);
    6467                    }
    6568
     
    7073                }
    7174
    72                 Main.map.mapView.repaint();
     75                MainApplication.getMap().mapView.repaint();
    7376
    7477                return;
    7578    }
    76 
    7779}
  • applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysAlgnSegment.java

    r33136 r33784  
    55import java.awt.Graphics2D;
    66import java.awt.Point;
     7import java.awt.RenderingHints;
    78import java.awt.Shape;
    8 import java.awt.RenderingHints;
    99import java.awt.geom.Ellipse2D;
    1010import java.awt.geom.Line2D;
     
    1616import java.util.Map;
    1717
    18 import org.openstreetmap.josm.Main;
    1918import org.openstreetmap.josm.data.Bounds;
    2019import org.openstreetmap.josm.data.coor.EastNorth;
     
    2221import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2322import org.openstreetmap.josm.data.osm.WaySegment;
     23import org.openstreetmap.josm.gui.MainApplication;
    2424import org.openstreetmap.josm.gui.MapView;
    2525import org.openstreetmap.josm.gui.NavigatableComponent;
     26import org.openstreetmap.josm.tools.Logging;
    2627
    2728/**
     
    132133            }
    133134        } catch (IndexOutOfBoundsException e) {
    134             Main.error(e);
     135            Logging.error(e);
    135136            return null;
    136137        }
     
    194195        final double incrementOnCircle = 2 * Math.PI / stepsOnCircle;
    195196
    196         Point p = Main.map.mapView.getPoint(node);
     197        Point p = MainApplication.getMap().mapView.getPoint(node);
    197198        for (int i = 0; i < stepsOnCircle; i++) {
    198199            double ang = i * incrementOnCircle;
     
    201202            Point pnew = new Point();
    202203            pnew.setLocation(x, y);
    203             WaySegment ws = Main.map.mapView.getNearestWaySegment(pnew, OsmPrimitive::isUsable);
     204            WaySegment ws = MainApplication.getMap().mapView.getNearestWaySegment(pnew, OsmPrimitive::isUsable);
    204205            if (ws != null &&  !ws.equals(this.segment) &&
    205206                    (ws.getFirstNode().equals(node) || ws.getSecondNode().equals(node))) {
     
    233234        // If they are, it's a bug, possibly related to tracking of DataSet deletions.
    234235        if (segment.way.getNodesCount() <= segment.lowerIndex + 1) {
    235             Main.warn("Not drawing AlignWays pivot points: underlying nodes disappeared");
     236            Logging.warn("Not drawing AlignWays pivot points: underlying nodes disappeared");
    236237            return;
    237238        }
  • applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysCmdKeepAngles.java

    r30737 r33784  
    11/**
    2  * 
     2 *
    33 */
    44package com.tilusnet.josm.plugins.alignways;
     
    1313import org.openstreetmap.josm.Main;
    1414import org.openstreetmap.josm.data.coor.EastNorth;
     15import org.openstreetmap.josm.data.osm.DataSet;
    1516import org.openstreetmap.josm.data.osm.Node;
    1617import org.openstreetmap.josm.data.osm.WaySegment;
     
    2829    private AlignableStatus alignableStatKeepAngles = AlignableStatus.ALGN_VALID;
    2930
    30     public AlignWaysCmdKeepAngles() {
     31    public AlignWaysCmdKeepAngles(DataSet ds) {
     32        super(ds);
    3133        // Now the calculatedNodes reflect the coordinates that we'd have
    3234        // without preserving the angles, i.e. preserving the length.
     
    3638        // Now we'll proceed with the hypothetical recalculation of the endpoint coordinates
    3739        // following the rule of preserving angles instead. The new nodes will be stored in nodeArr[].
    38        
     40
    3941        Node[] nodeArr = algnSeg.getSegmentEndPoints().toArray(new Node[2]);
    4042
     
    5355            return;
    5456        }
    55        
     57
    5658        ArrayList<WaySegment> alws = algnSeg.getAdjacentWaySegments(endpoint);
    5759        int alwsSize = alws.size();
     
    6062            //  - the alignee following the keep length rule
    6163            //  - the adjacent way segment
    62            
     64
    6365            Node adjOther1 = getNonEqualNode(alws.get(0), endpoint);
    6466            EastNorth enAdjOther1 = adjOther1.getEastNorth();
     
    6971                adjOther2 = getNonEqualNode(alws.get(1), endpoint);
    7072                enAdjOther2 = adjOther2.getEastNorth();
    71                
     73
    7274                // In order have a chance to align, (enAdjOther1, enAdjOther2 and endpoint) must be collinear
    7375                ArrayList<EastNorth> enAdjPts = new ArrayList<>(3);
     
    8082                    return;
    8183                }
    82                
     84
    8385            }
    8486
    8587            // Update the calculated node for angle preserving alignment
    86             AlignWaysGeomPoint isectPnt = alignedLineKeepLength.getIntersection(new AlignWaysGeomLine(enAdjOther1.getX(), enAdjOther1.getY(), 
     88            AlignWaysGeomPoint isectPnt = alignedLineKeepLength.getIntersection(new AlignWaysGeomLine(enAdjOther1.getX(), enAdjOther1.getY(),
    8789                                                                                                      endpoint.getEastNorth().getX(), endpoint.getEastNorth().getY()));
    8890            EastNorth enIsectPt = null;
     
    9698                return;
    9799            }
    98            
    99             // For the case of two adjacent segments with collinear points, the new endpoint may 
    100             // not fall between enAdjOther1 and enAdjOther2; 
    101             // this scenario is not allowed for the time being as placing the new intersection point on the line 
     100
     101            // For the case of two adjacent segments with collinear points, the new endpoint may
     102            // not fall between enAdjOther1 and enAdjOther2;
     103            // this scenario is not allowed for the time being as placing the new intersection point on the line
    102104            // triggers complications.
    103105            // TODO - find a solution
    104106            if (alwsSize == 2 && enIsectPt != null) {
    105107                int middlePtIdx = AlignWaysGeomPoint.getMiddleOf3(
    106                         new AlignWaysGeomPoint(enIsectPt), 
    107                         new AlignWaysGeomPoint(enAdjOther1), 
     108                        new AlignWaysGeomPoint(enIsectPt),
     109                        new AlignWaysGeomPoint(enAdjOther1),
    108110                        new AlignWaysGeomPoint(enAdjOther2));
    109111                if (middlePtIdx != 0) {
     
    126128                            alignableStatKeepAngles = AlignableStatus.ALGN_INV_XPOINT_FALLSOUT;
    127129                            return;
    128                            
     130
    129131                            /*
    130132                            if (middlePt.equalsEpsilon(enAdjOther1, eps)) {
     
    140142                }
    141143            }
    142            
     144
    143145            if (isectPnt != null) {
    144146                // Angle preserving alignment passed all verification tests: record it.
    145147                calculatedNodes.put(endpoint, enIsectPt);
    146148            }
    147            
    148            
     149
     150
    149151        } else {
    150152            // angle preserving alignment not possible
     
    155157    private boolean isEnSetCollinear(ArrayList<EastNorth> enAdjPts) {
    156158        ArrayList<AlignWaysGeomPoint> awAdjPts = new ArrayList<>();
    157        
     159
    158160        for (EastNorth en : enAdjPts) {
    159161            AlignWaysGeomPoint pt = new AlignWaysGeomPoint(en.getX(), en.getY());
    160162            awAdjPts.add(pt);
    161163        }
    162        
     164
    163165        return AlignWaysGeomPoint.isSetCollinear(awAdjPts);
    164166    }
     
    175177    /**
    176178     * Reports invalid alignable statuses on screen in dialog boxes.
    177      * 
     179     *
    178180     * @param stat The invalid status to report
    179181     */
  • applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysCmdKeepLength.java

    r33136 r33784  
    11/**
    2  * 
     2 *
    33 */
    44package com.tilusnet.josm.plugins.alignways;
     
    77
    88import java.util.Collection;
     9import java.util.Collections;
    910import java.util.HashMap;
    1011import java.util.HashSet;
    1112import java.util.Map;
    12 import java.util.Collections;
    1313
    1414import javax.swing.Icon;
     
    1818import org.openstreetmap.josm.command.Command;
    1919import org.openstreetmap.josm.data.coor.EastNorth;
     20import org.openstreetmap.josm.data.osm.DataSet;
    2021import org.openstreetmap.josm.data.osm.Node;
    2122import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2223import org.openstreetmap.josm.data.osm.WaySegment;
    23 import org.openstreetmap.josm.data.projection.Projections;
     24import org.openstreetmap.josm.gui.MainApplication;
     25import org.openstreetmap.josm.gui.MapView;
    2426import org.openstreetmap.josm.tools.ImageProvider;
    2527
     
    2729 * Executes one of the desired geometric actions
    2830 * needed to align the ways.
    29  * 
     31 *
    3032 * @author tilusnet <tilusnet@gmail.com>
    3133 */
    32 
    3334public class AlignWaysCmdKeepLength extends Command {
    3435
     
    5455    final Map<Node,EastNorth> calculatedNodes = new HashMap<>();
    5556
    56 
    5757    /**
    5858     * Set of nodes that were affected by the last command execution.
     
    6767    /**
    6868     * Computed rotation angle to rotate the segment
    69      * 
     69     *
    7070     */
    7171    private final double rotationAngle;
     
    8080     * TODO Limitation (for now): constructor assumes areSegsAlignable() returns true.
    8181     */
    82     public AlignWaysCmdKeepLength() {
    83 
     82    public AlignWaysCmdKeepLength(DataSet ds) {
     83        super(ds);
    8484        lastAffectedNodes = null;
    8585
    86         algnSeg = AlignWaysSegmentMgr.getInstance(Main.map.mapView)
    87                 .getAlgnSeg();
     86        MapView mapView = MainApplication.getMap().mapView;
     87        algnSeg = AlignWaysSegmentMgr.getInstance(mapView).getAlgnSeg();
    8888        WaySegment algnWS = algnSeg.getSegment();
    89         WaySegment refWS = AlignWaysSegmentMgr.getInstance(Main.map.mapView)
    90                 .getRefSeg().getSegment();
     89        WaySegment refWS = AlignWaysSegmentMgr.getInstance(mapView).getRefSeg().getSegment();
    9190
    9291        this.pivot = algnSeg.getCurrPivotCoord();
     
    123122        }
    124123
    125 
    126124        /*
    127125         * For debug only
     
    133131         * + Math.toDegrees(rotationAngle) + ")";
    134132         */
    135 
    136133    }
    137134
    138135    /**
    139136     * Helper for actually rotating the nodes.
    140      * 
     137     *
    141138     * @param setModified
    142139     *            - true if rotated nodes should be flagged "modified"
     
    236233        Collection<Node> algnNodes = displaceableNodes;
    237234        Collection<Node> refNodes = AlignWaysSegmentMgr
    238                 .getInstance(Main.map.mapView).getRefSeg()
     235                .getInstance(MainApplication.getMap().mapView).getRefSeg()
    239236                .getSegmentEndPoints();
    240237
     
    256253        // Deny action if the nodes would end up outside world
    257254        for (EastNorth en : calculatedNodes.values()) {
    258 
    259             if (Projections.inverseProject(en).isOutSideWorld())
     255            if (Main.getProjection().eastNorth2latlon(en).isOutSideWorld())
    260256                return AlignableStatus.ALGN_INV_OUTSIDE_WORLD;
    261 
    262257        }
    263258
     
    268263    /**
    269264     * Validates the circumstances of the alignment command to be executed.
    270      * 
     265     *
    271266     * @return true if the aligning action can be done, false otherwise.
    272267     */
     
    284279    /**
    285280     * Reports invalid alignable statuses on screen in dialog boxes.
    286      * 
     281     *
    287282     * @param stat The invalid status to report
    288283     */
  • applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysMode.java

    r33136 r33784  
    3131import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
    3232import org.openstreetmap.josm.gui.IconToggleButton;
    33 import org.openstreetmap.josm.gui.MapFrame;
     33import org.openstreetmap.josm.gui.MainApplication;
    3434import org.openstreetmap.josm.gui.layer.Layer;
    3535import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    5252    boolean tipShown;
    5353
    54     public AlignWaysMode(MapFrame mapFrame, String name, String desc) {
     54    public AlignWaysMode(String name, String desc) {
    5555        super(tr(name), "alignways.png", tr(desc),
    5656                Shortcut.registerShortcut("mapmode:alignways",
    5757                        tr("Mode: {0}", tr("Align Ways")),
    5858                        KeyEvent.VK_N, Shortcut.SHIFT),
    59                         mapFrame, Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
     59                        Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    6060        noneSelected = new AlignWaysSelNoneState();
    6161        referenceSelected = new AlignWaysSelRefState();
     
    6363        bothSelected = new AlignWaysSelBothState();
    6464        tipShown = false;
    65 
    6665    }
    6766
     
    8685        }
    8786
    88         awSegs = AlignWaysSegmentMgr.getInstance(Main.map.mapView);
    89         Main.map.mapView.addMouseListener(this);
    90         DataSet ds = Main.getLayerManager().getEditDataSet();
     87        awSegs = AlignWaysSegmentMgr.getInstance(MainApplication.getMap().mapView);
     88        MainApplication.getMap().mapView.addMouseListener(this);
     89        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
    9190        if (ds != null)
    9291            ds.addDataSetListener(this);
     
    107106
    108107        setCurrentState(noneSelected);
    109         Main.map.mapView.removeMouseListener(this);
    110         DataSet ds = Main.getLayerManager().getEditDataSet();
     108        MainApplication.getMap().mapView.removeMouseListener(this);
     109        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
    111110        if (ds != null)
    112111            ds.removeDataSetListener(this);
     
    144143        }
    145144
    146         Main.map.mapView.repaint();
     145        MainApplication.getMap().mapView.repaint();
    147146    }
    148147
     
    234233        tipDialog.dispose();
    235234
    236         Main.pref.put("alignways.showtips", !atp.isChkBoxSelected());
     235        Main.pref.putBoolean("alignways.showtips", !atp.isChkBoxSelected());
    237236    }
    238237
     
    273272    @Override
    274273    public void primitivesRemoved(PrimitivesRemovedEvent event) {
    275         awSegs = AlignWaysSegmentMgr.getInstance(Main.map.mapView);
     274        awSegs = AlignWaysSegmentMgr.getInstance(MainApplication.getMap().mapView);
    276275
    277276        // Check whether any of the removed primitives were part of a highlighted alignee or reference segment.
  • applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysPlugin.java

    r29771 r33784  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
    5 import org.openstreetmap.josm.Main;
    65import org.openstreetmap.josm.actions.JosmAction;
    76import org.openstreetmap.josm.gui.IconToggleButton;
     7import org.openstreetmap.josm.gui.MainApplication;
    88import org.openstreetmap.josm.gui.MainMenu;
    99import org.openstreetmap.josm.gui.MapFrame;
     
    1515 *
    1616 */
    17 
    1817public class AlignWaysPlugin extends Plugin {
    1918
     
    2928    public AlignWaysPlugin(PluginInformation info) {
    3029        super(info);
    31        
     30
    3231        // Add the action entries to the Tools Menu
    33         Main.main.menu.moreToolsMenu.addSeparator();
     32        MainApplication.getMenu().moreToolsMenu.addSeparator();
    3433        awAction = new AlignWaysAction();
    35         MainMenu.add(Main.main.menu.moreToolsMenu, awAction);
     34        MainMenu.add(MainApplication.getMenu().moreToolsMenu, awAction);
    3635    }
    3736
     
    4039        if (newFrame != null) {
    4140            // Construct the AlignWays mode toggle button
    42             awMode = new AlignWaysMode(Main.map, "alignways", tr("Align Ways mode"));
     41            awMode = new AlignWaysMode("alignways", tr("Align Ways mode"));
    4342            btn = new IconToggleButton(awMode);
    4443            btn.setVisible(true);
  • applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysSegment.java

    r33136 r33784  
    1616import java.util.Objects;
    1717
    18 import org.openstreetmap.josm.Main;
    1918import org.openstreetmap.josm.data.Bounds;
    2019import org.openstreetmap.josm.data.osm.Node;
     
    2423import org.openstreetmap.josm.gui.MapView;
    2524import org.openstreetmap.josm.gui.layer.MapViewPaintable;
     25import org.openstreetmap.josm.tools.Logging;
    2626
    2727/**
     
    6363                segmentEndPoints.add(segment.getSecondNode());
    6464            } catch (IndexOutOfBoundsException e) {
    65                 Main.error(e);
     65                Logging.error(e);
    6666            }
    6767        }
     
    9191        // If they are, it's a bug, possibly related to tracking of DataSet deletions.
    9292        if (segment.way.getNodesCount() <= segment.lowerIndex + 1) {
    93             Main.warn("Not drawing AlignWays highlighting segment: underlying nodes disappeared");
     93            Logging.warn("Not drawing AlignWays highlighting segment: underlying nodes disappeared");
    9494            return;
    9595        }
     
    112112            g.draw(new Line2D.Double(mv.getPoint(n1), mv.getPoint(n2)));
    113113        } catch (IndexOutOfBoundsException e) {
    114             Main.error(e);
     114            Logging.error(e);
    115115        }
    116116    }
  • applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysSelAlgnState.java

    r28342 r33784  
    44package com.tilusnet.josm.plugins.alignways;
    55
    6 import org.openstreetmap.josm.Main;
    76import static org.openstreetmap.josm.tools.I18n.tr;
     7
     8import org.openstreetmap.josm.gui.MainApplication;
    89
    910/**
     
    2526    @Override
    2627    public void setHelpText() {
    27         Main.map.statusLine
     28        MainApplication.getMap().statusLine
    2829                .setHelpText(tr("Ctrl-Click: select reference way segment; Alt-click: Clear selection"));
    2930    }
  • applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysSelBothState.java

    r28342 r33784  
    55
    66import static org.openstreetmap.josm.tools.I18n.tr;
    7 import org.openstreetmap.josm.Main;
     7
     8import org.openstreetmap.josm.gui.MainApplication;
    89
    910/**
     
    2526    @Override
    2627    public void setHelpText() {
    27         Main.map.statusLine
     28        MainApplication.getMap().statusLine
    2829        .setHelpText(AlignWaysPlugin.getAwAction().getShortcut().getKeyText() +
    2930                tr(": Align segments; Alt-click: Clear selection"));
  • applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysSelNoneState.java

    r28342 r33784  
    55
    66import static org.openstreetmap.josm.tools.I18n.tr;
    7 import org.openstreetmap.josm.Main;
     7
     8import org.openstreetmap.josm.gui.MainApplication;
    89
    910/**
     
    2829    @Override
    2930    public void setHelpText() {
    30         Main.map.statusLine
     31        MainApplication.getMap().statusLine
    3132        .setHelpText(tr("Ctrl-click: select reference way segment; Click: select way segment to be aligned"));
    3233    }
  • applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysSelRefState.java

    r28342 r33784  
    55
    66import static org.openstreetmap.josm.tools.I18n.tr;
    7 import org.openstreetmap.josm.Main;
     7
     8import org.openstreetmap.josm.gui.MainApplication;
    89
    910/**
     
    2526    @Override
    2627    public void setHelpText() {
    27         Main.map.statusLine
     28        MainApplication.getMap().statusLine
    2829                .setHelpText(tr("Click: select way segment to be aligned; Alt-click: Clear selection"));
    2930    }
  • applications/editors/josm/plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysState.java

    r28342 r33784  
    55
    66import static org.openstreetmap.josm.tools.I18n.tr;
    7 import org.openstreetmap.josm.Main;
     7
     8import org.openstreetmap.josm.gui.MainApplication;
    89
    910/**
     
    2122    public void altLClick(AlignWaysMode alignWaysMode) {
    2223        alignWaysMode.setCurrentState(alignWaysMode.getNoneSelected());
    23         Main.map.statusLine
     24        MainApplication.getMap().statusLine
    2425        .setHelpText(tr("Ctrl-Click: select reference way segment; Click: select way segment to be aligned"));
    2526    }
Note: See TracChangeset for help on using the changeset viewer.