Ignore:
Timestamp:
2015-06-20T14:36:00+02:00 (9 years ago)
Author:
Don-vip
Message:

fix many checkstyle violations

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
20 edited

Legend:

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

    r8475 r8509  
    2929    }
    3030
    31     public AbstractInfoAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean register, String toolbarId, boolean installAdapters) {
     31    public AbstractInfoAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean register,
     32            String toolbarId, boolean installAdapters) {
    3233        super(name, iconName, tooltip, shortcut, register, toolbarId, installAdapters);
    3334    }
     
    4647                        tr("Continue"),
    4748                        ImageProvider.get("ok"),
    48                         trn("Click to continue and to open {0} browser", "Click to continue and to open {0} browsers", numBrowsers, numBrowsers),
     49                        trn("Click to continue and to open {0} browser", "Click to continue and to open {0} browsers",
     50                                numBrowsers, numBrowsers),
    4951                        null // no specific help topic
    5052                ),
  • trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java

    r8469 r8509  
    146146    @Override
    147147    protected void updateEnabledState() {
     148        ImageryType type = info.getImageryType();
    148149        // never enable blacklisted entries. Do not add same imagery layer twice (fix #2519)
    149         if (info.isBlacklisted() /*|| isLayerAlreadyPresent()*/) { // FIXME check disabled to allow several instances with different settings (see #7981)
     150        if (info.isBlacklisted() /*|| isLayerAlreadyPresent()*/) {
     151            // FIXME check disabled to allow several instances with different settings (see #7981)
    150152            setEnabled(false);
    151         } else if (info.getImageryType() == ImageryType.TMS || info.getImageryType() == ImageryType.BING || info.getImageryType() == ImageryType.SCANEX) {
     153        } else if (type == ImageryType.TMS || type == ImageryType.BING || type == ImageryType.SCANEX) {
    152154            setEnabled(true);
    153155        } else if (Main.isDisplayingMapView() && !Main.map.mapView.getAllLayers().isEmpty()) {
  • trunk/src/org/openstreetmap/josm/actions/DiskAccessAction.java

    r7578 r8509  
    4242     * @since 5438
    4343     */
    44     public DiskAccessAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean register, String toolbarId, boolean installAdapters) {
     44    public DiskAccessAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean register,
     45            String toolbarId, boolean installAdapters) {
    4546        super(name, iconName, tooltip, shortcut, register, toolbarId, installAdapters);
    4647    }
     
    8485     *                 If false, only the file filters that include {@code extension} will be proposed
    8586     * @param lastDirProperty The name of the property used to setup the AbstractFileChooser initial directory.
    86      *        This property will then be updated to the new "last directory" chosen by the user. If null, the default property "lastDirectory" will be used.
     87     *        This property will then be updated to the new "last directory" chosen by the user.
     88     *        If null, the default property "lastDirectory" will be used.
    8789     * @return The {@code AbstractFileChooser}.
    8890     * @since 5438
    8991     */
    90     public static AbstractFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, String extension, int selectionMode, boolean allTypes, String lastDirProperty) {
    91         return new FileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, extension, allTypes, selectionMode).openFileChooser();
     92    public static AbstractFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, String extension,
     93            int selectionMode, boolean allTypes, String lastDirProperty) {
     94        return new FileChooserManager(open, lastDirProperty)
     95            .createFileChooser(multiple, title, extension, allTypes, selectionMode).openFileChooser();
    9296    }
    9397
     
    102106     *                      <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
    103107     *                      <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li></ul>
    104      * @param lastDirProperty The name of the property used to setup the AbstractFileChooser initial directory. This property will then be updated to the new "last directory" chosen by the user
     108     * @param lastDirProperty The name of the property used to setup the AbstractFileChooser initial directory.
     109     * This property will then be updated to the new "last directory" chosen by the user
    105110     * @return The {@code AbstractFileChooser}.
    106111     * @since 5438
    107112     */
    108     public static AbstractFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, FileFilter filter, int selectionMode, String lastDirProperty) {
     113    public static AbstractFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, FileFilter filter,
     114            int selectionMode, String lastDirProperty) {
    109115        return new FileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, filter, selectionMode).openFileChooser();
    110116    }
     
    121127     *                      <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
    122128     *                      <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li></ul>
    123      * @param lastDirProperty The name of the property used to setup the JFileChooser initial directory. This property will then be updated to the new "last directory" chosen by the user
     129     * @param lastDirProperty The name of the property used to setup the JFileChooser initial directory.
     130     * This property will then be updated to the new "last directory" chosen by the user
    124131     * @return The {@code AbstractFileChooser}.
    125132     * @since 5438
     
    127134    public static AbstractFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title,
    128135            Collection<? extends FileFilter> filters, FileFilter defaultFilter, int selectionMode, String lastDirProperty) {
    129         return new FileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, filters, defaultFilter, selectionMode).openFileChooser();
     136        return new FileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, filters, defaultFilter, selectionMode)
     137                .openFileChooser();
    130138    }
    131139}
  • trunk/src/org/openstreetmap/josm/actions/DownloadAlongAction.java

    r7937 r8509  
    4444        super(name, iconName, tooltip, shortcut, registerInToolbar);
    4545    }
    46    
     46
    4747    protected static void addToDownload(Area a, Rectangle2D r, Collection<Rectangle2D> results, double maxArea) {
    4848        Area tmp = new Area(r);
     
    7474        }
    7575    }
    76    
     76
    7777    /**
    7878     * Area "a" contains the hull that we would like to download data for. however we
     
    9292     * the areas if applicable.
    9393     */
    94     protected static void confirmAndDownloadAreas(Area a, double maxArea, boolean osmDownload, boolean gpxDownload, String title, ProgressMonitor progressMonitor) {
     94    protected static void confirmAndDownloadAreas(Area a, double maxArea, boolean osmDownload, boolean gpxDownload, String title,
     95            ProgressMonitor progressMonitor) {
    9596        List<Rectangle2D> toDownload = new ArrayList<>();
    9697        addToDownload(a, a.getBounds(), toDownload, maxArea);
     
    99100        }
    100101        JPanel msg = new JPanel(new GridBagLayout());
    101         msg.add(new JLabel(tr("<html>This action will require {0} individual<br>" + "download requests. Do you wish<br>to continue?</html>", toDownload.size())), GBC.eol());
    102         if (JOptionPane.OK_OPTION != JOptionPane.showConfirmDialog(Main.parent, msg, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE)) {
     102        msg.add(new JLabel(
     103                tr("<html>This action will require {0} individual<br>" + "download requests. Do you wish<br>to continue?</html>",
     104                        toDownload.size())), GBC.eol());
     105        if (JOptionPane.OK_OPTION != JOptionPane.showConfirmDialog(Main.parent, msg, title,
     106                JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE)) {
    103107            return;
    104108        }
  • trunk/src/org/openstreetmap/josm/actions/DownloadPrimitiveAction.java

    r8378 r8509  
    2828    public DownloadPrimitiveAction() {
    2929        super(tr("Download object..."), "downloadprimitive", tr("Download OSM object by ID."),
    30                 Shortcut.registerShortcut("system:download_primitive", tr("File: {0}", tr("Download object...")), KeyEvent.VK_O, Shortcut.CTRL_SHIFT), true);
     30                Shortcut.registerShortcut("system:download_primitive", tr("File: {0}", tr("Download object...")),
     31                        KeyEvent.VK_O, Shortcut.CTRL_SHIFT), true);
    3132        putValue("help", ht("/Action/DownloadObject"));
    3233    }
     
    4445     * @param newLayer if the data should be downloaded into a new layer
    4546     * @param ids List of primitive id to download
    46      * @param downloadReferrers if the referrers of the object should be downloaded as well, i.e., parent relations, and for nodes, additionally, parent ways
     47     * @param downloadReferrers if the referrers of the object should be downloaded as well, i.e., parent relations, and for nodes,
     48     * additionally, parent ways
    4749     * @param full if the members of a relation should be downloaded as well
    4850     */
  • trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java

    r8443 r8509  
    8080        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
    8181        if (!(layer instanceof OsmDataLayer) && !(layer instanceof GpxLayer))
    82             throw new IllegalArgumentException(MessageFormat.format("Expected instance of OsmDataLayer or GpxLayer. Got ''{0}''.", layer.getClass().getName()));
     82            throw new IllegalArgumentException(MessageFormat.format("Expected instance of OsmDataLayer or GpxLayer. Got ''{0}''.",
     83                    layer.getClass().getName()));
    8384
    8485        File file = createAndOpenSaveFileChooser(tr("Export GPX file"), GpxImporter.FILE_FILTER);
  • trunk/src/org/openstreetmap/josm/actions/JosmAction.java

    r8324 r8509  
    7373     * TODO: do not pass Icon, pass ImageProvider instead
    7474     */
    75     public JosmAction(String name, ImageProvider icon, String tooltip, Shortcut shortcut, boolean registerInToolbar, String toolbarId, boolean installAdapters) {
     75    public JosmAction(String name, ImageProvider icon, String tooltip, Shortcut shortcut, boolean registerInToolbar,
     76            String toolbarId, boolean installAdapters) {
    7677        super(name);
    7778        if(icon != null)
     
    111112     * @param installAdapters false, if you don't want to install layer changed and selection changed adapters
    112113     */
    113     public JosmAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean registerInToolbar, String toolbarId, boolean installAdapters) {
     114    public JosmAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean registerInToolbar,
     115            String toolbarId, boolean installAdapters) {
    114116        this(name, iconName == null ? null : new ImageProvider(iconName), tooltip, shortcut, registerInToolbar,
    115117                toolbarId == null ? iconName : toolbarId, installAdapters);
  • trunk/src/org/openstreetmap/josm/actions/JumpToAction.java

    r8443 r8509  
    128128                ll = new LatLon(Double.parseDouble(lat.getText()), Double.parseDouble(lon.getText()));
    129129            } catch (NumberFormatException ex) {
    130                 JOptionPane.showMessageDialog(Main.parent, tr("Could not parse Latitude, Longitude or Zoom. Please check."), tr("Unable to parse Lon/Lat"), JOptionPane.ERROR_MESSAGE);
     130                JOptionPane.showMessageDialog(Main.parent,
     131                        tr("Could not parse Latitude, Longitude or Zoom. Please check."),
     132                        tr("Unable to parse Lon/Lat"), JOptionPane.ERROR_MESSAGE);
    131133            }
    132134        }
  • trunk/src/org/openstreetmap/josm/actions/SessionSaveAsAction.java

    r8426 r8509  
    8989            fc = createAndOpenFileChooser(false, false, tr("Save session"), joz, JFileChooser.FILES_ONLY, "lastDirectory");
    9090        } else {
    91             fc = createAndOpenFileChooser(false, false, tr("Save session"), Arrays.asList(new FileFilter[]{jos, joz}), jos, JFileChooser.FILES_ONLY, "lastDirectory");
     91            fc = createAndOpenFileChooser(false, false, tr("Save session"), Arrays.asList(new FileFilter[]{jos, joz}), jos,
     92                    JFileChooser.FILES_ONLY, "lastDirectory");
    9293        }
    9394
  • trunk/src/org/openstreetmap/josm/actions/SimplifyWayAction.java

    r8459 r8509  
    4444     */
    4545    public SimplifyWayAction() {
    46         super(tr("Simplify Way"), "simplify", tr("Delete unnecessary nodes from a way."), Shortcut.registerShortcut("tools:simplify", tr("Tool: {0}", tr("Simplify Way")),
    47                 KeyEvent.VK_Y, Shortcut.SHIFT), true);
     46        super(tr("Simplify Way"), "simplify", tr("Delete unnecessary nodes from a way."),
     47                Shortcut.registerShortcut("tools:simplify", tr("Tool: {0}", tr("Simplify Way")), KeyEvent.VK_Y, Shortcut.SHIFT), true);
    4848        putValue("help", ht("/Action/SimplifyWay"));
    4949    }
  • trunk/src/org/openstreetmap/josm/actions/ToggleAction.java

    r8390 r8509  
    4040     * @param installAdapters false, if you don't want to install layer changed and selection changed adapters
    4141     */
    42     public ToggleAction(String name, ImageProvider icon, String tooltip, Shortcut shortcut, boolean registerInToolbar, String toolbarId, boolean installAdapters) {
     42    public ToggleAction(String name, ImageProvider icon, String tooltip, Shortcut shortcut, boolean registerInToolbar,
     43            String toolbarId, boolean installAdapters) {
    4344        super(name, icon, tooltip, shortcut, registerInToolbar, toolbarId, installAdapters);
    4445        // It is required to set the SELECTED_KEY to a non-null value in order to let Swing components update it
     
    115116    /**
    116117     * Toggles the selcted action state, if needed according to the ActionEvent that trigerred the action.
    117      * This method will do nothing if the action event comes from a Swing component supporting the SELECTED_KEY property because the component already set the selected state.
     118     * This method will do nothing if the action event comes from a Swing component supporting the SELECTED_KEY property because
     119     * the component already set the selected state.
    118120     * This method needs to be called especially if the action is associated with a keyboard shortcut to ensure correct selected state.
    119121     * @see <a href="https://weblogs.java.net/blog/zixle/archive/2005/11/changes_to_acti.html">Changes to Actions in 1.6</a>
  • trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java

    r8338 r8509  
    464464
    465465        Main.main.undoRedo.add(new SequenceCommand(
    466                 trn("Dupe {0} node into {1} nodes", "Dupe {0} nodes into {1} nodes", selectedNodes.size(), selectedNodes.size(), selectedNodes.size()+allNewNodes.size()), cmds));
     466                trn("Dupe {0} node into {1} nodes", "Dupe {0} nodes into {1} nodes",
     467                        selectedNodes.size(), selectedNodes.size(), selectedNodes.size()+allNewNodes.size()), cmds));
    467468        getCurrentDataSet().setSelected(allNewNodes);
    468469    }
  • trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java

    r8443 r8509  
    3535     *
    3636     * @param id the primitive id
    37      * @param type The primitive type. Must be one of {@link OsmPrimitiveType#NODE NODE}, {@link OsmPrimitiveType#WAY WAY}, {@link OsmPrimitiveType#RELATION RELATION}
     37     * @param type The primitive type. Must be one of {@link OsmPrimitiveType#NODE NODE},
     38     * {@link OsmPrimitiveType#WAY WAY}, {@link OsmPrimitiveType#RELATION RELATION}
    3839     */
    3940    public static void handlePrimitiveGoneException(long id, OsmPrimitiveType type) {
  • trunk/src/org/openstreetmap/josm/actions/ValidateAction.java

    r8378 r8509  
    124124         * @param formerValidatedPrimitives the last collection of primitives being validates. May be null.
    125125         */
    126         public ValidationTask(Collection<Test> tests, Collection<OsmPrimitive> validatedPrimitives, Collection<OsmPrimitive> formerValidatedPrimitives) {
     126        public ValidationTask(Collection<Test> tests, Collection<OsmPrimitive> validatedPrimitives,
     127                Collection<OsmPrimitive> formerValidatedPrimitives) {
    127128            super(tr("Validating"), false /*don't ignore exceptions */);
    128129            this.validatedPrimitives  = validatedPrimitives;
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r8465 r8509  
    626626    }
    627627
    628     private void insertNodeIntoAllNearbySegments(List<WaySegment> wss, Node n, Collection<OsmPrimitive> newSelection, Collection<Command> cmds, List<Way> replacedWays, List<Way> reuseWays) {
     628    private void insertNodeIntoAllNearbySegments(List<WaySegment> wss, Node n, Collection<OsmPrimitive> newSelection,
     629            Collection<Command> cmds, List<Way> replacedWays, List<Way> reuseWays) {
    629630        Map<Way, List<Integer>> insertPoints = new HashMap<>();
    630631        for (WaySegment ws : wss) {
     
    12931294
    12941295    private class SnapHelper {
    1295         private boolean snapOn; // snapping is turned on
    1296 
    1297         private boolean active; // snapping is active for current mouse position
    1298         private boolean fixed; // snap angle is fixed
    1299         private boolean absoluteFix; // snap angle is absolute
    1300 
    1301         private boolean drawConstructionGeometry;
    1302         private boolean showProjectedPoint;
    1303         private boolean showAngle;
    1304 
    1305         private boolean snapToProjections;
    1306 
    1307         private EastNorth dir2;
    1308         private EastNorth projected;
    1309         private String labelText;
    1310         private double lastAngle;
    1311 
    1312         private double customBaseHeading=-1; // angle of base line, if not last segment)
    1313         private EastNorth segmentPoint1; // remembered first point of base segment
    1314         private EastNorth segmentPoint2; // remembered second point of base segment
    1315         private EastNorth projectionSource; // point that we are projecting to the line
    1316 
    1317         private double[] snapAngles;
    1318         private double snapAngleTolerance;
    1319 
    1320         private double pe,pn; // (pe,pn) - direction of snapping line
    1321         private double e0,n0; // (e0,n0) - origin of snapping line
    1322 
    1323         private final String fixFmt="%d "+tr("FIX");
    1324         private Color snapHelperColor;
    1325         private Color highlightColor;
    1326 
    1327         private Stroke normalStroke;
    1328         private Stroke helperStroke;
    1329         private Stroke highlightStroke;
    1330 
    1331         private JCheckBoxMenuItem checkBox;
    1332 
    1333         public void init() {
    1334             snapOn=false;
    1335             checkBox.setState(snapOn);
    1336             fixed=false; absoluteFix=false;
    1337 
    1338             Collection<String> angles = Main.pref.getCollection("draw.anglesnap.angles",
    1339                     Arrays.asList("0","30","45","60","90","120","135","150","180"));
    1340 
    1341             snapAngles = new double[2*angles.size()];
    1342             int i=0;
    1343             for (String s: angles) {
    1344                 try {
    1345                     snapAngles[i] = Double.parseDouble(s); i++;
    1346                     snapAngles[i] = 360-Double.parseDouble(s); i++;
    1347                 } catch (NumberFormatException e) {
    1348                     Main.warn("Incorrect number in draw.anglesnap.angles preferences: "+s);
    1349                     snapAngles[i]=0;i++;
    1350                     snapAngles[i]=0;i++;
    1351                 }
    1352             }
    1353             snapAngleTolerance = Main.pref.getDouble("draw.anglesnap.tolerance", 5.0);
    1354             drawConstructionGeometry = Main.pref.getBoolean("draw.anglesnap.drawConstructionGeometry", true);
    1355             showProjectedPoint = Main.pref.getBoolean("draw.anglesnap.drawProjectedPoint", true);
    1356             snapToProjections = Main.pref.getBoolean("draw.anglesnap.projectionsnap", true);
    1357 
    1358             showAngle = Main.pref.getBoolean("draw.anglesnap.showAngle", true);
    1359             useRepeatedShortcut = Main.pref.getBoolean("draw.anglesnap.toggleOnRepeatedA", true);
    1360 
    1361             normalStroke = rubberLineStroke;
    1362             snapHelperColor = Main.pref.getColor(marktr("draw angle snap"), Color.ORANGE);
    1363 
    1364             highlightColor = Main.pref.getColor(marktr("draw angle snap highlight"), ORANGE_TRANSPARENT);
    1365             highlightStroke = GuiHelper.getCustomizedStroke(Main.pref.get("draw.anglesnap.stroke.highlight","10"));
    1366             helperStroke = GuiHelper.getCustomizedStroke(Main.pref.get("draw.anglesnap.stroke.helper","1 4"));
    1367         }
    1368 
    1369         public void saveAngles(String ... angles) {
    1370             Main.pref.putCollection("draw.anglesnap.angles", Arrays.asList(angles));
    1371         }
    1372 
    1373         public  void setMenuCheckBox(JCheckBoxMenuItem checkBox) {
    1374             this.checkBox = checkBox;
    1375         }
    1376 
    1377         public  void drawIfNeeded(Graphics2D g2, MapView mv) {
    1378             if (!snapOn || !active)
    1379                 return;
    1380             Point p1=mv.getPoint(getCurrentBaseNode());
    1381             Point p2=mv.getPoint(dir2);
    1382             Point p3=mv.getPoint(projected);
    1383             GeneralPath b;
    1384             if (drawConstructionGeometry) {
    1385                 g2.setColor(snapHelperColor);
    1386                 g2.setStroke(helperStroke);
    1387 
    1388                 b = new GeneralPath();
    1389                 if (absoluteFix) {
    1390                     b.moveTo(p2.x,p2.y);
    1391                     b.lineTo(2*p1.x-p2.x,2*p1.y-p2.y); // bi-directional line
    1392                 } else {
    1393                     b.moveTo(p2.x,p2.y);
    1394                     b.lineTo(p3.x,p3.y);
    1395                 }
    1396                 g2.draw(b);
    1397             }
    1398             if (projectionSource != null) {
    1399                 g2.setColor(snapHelperColor);
    1400                 g2.setStroke(helperStroke);
    1401                 b = new GeneralPath();
    1402                 b.moveTo(p3.x,p3.y);
    1403                 Point pp=mv.getPoint(projectionSource);
    1404                 b.lineTo(pp.x,pp.y);
    1405                 g2.draw(b);
    1406             }
    1407 
    1408             if (customBaseHeading >= 0) {
    1409                 g2.setColor(highlightColor);
    1410                 g2.setStroke(highlightStroke);
    1411                 b = new GeneralPath();
    1412                 Point pp1=mv.getPoint(segmentPoint1);
    1413                 Point pp2=mv.getPoint(segmentPoint2);
    1414                 b.moveTo(pp1.x,pp1.y);
    1415                 b.lineTo(pp2.x,pp2.y);
    1416                 g2.draw(b);
    1417             }
    1418 
    1419             g2.setColor(rubberLineColor);
    1420             g2.setStroke(normalStroke);
    1421             b = new GeneralPath();
    1422             b.moveTo(p1.x,p1.y);
    1423             b.lineTo(p3.x,p3.y);
    1424             g2.draw(b);
    1425 
    1426             g2.drawString(labelText, p3.x-5, p3.y+20);
    1427             if (showProjectedPoint) {
    1428                 g2.setStroke(normalStroke);
    1429                 g2.drawOval(p3.x-5, p3.y-5, 10, 10); // projected point
    1430             }
    1431 
    1432             g2.setColor(snapHelperColor);
    1433             g2.setStroke(helperStroke);
    1434         }
    1435 
    1436         /* If mouse position is close to line at 15-30-45-... angle, remembers this direction
    1437          */
    1438         public void checkAngleSnapping(EastNorth currentEN, double baseHeading, double curHeading) {
    1439             EastNorth p0 = getCurrentBaseNode().getEastNorth();
    1440             EastNorth snapPoint = currentEN;
    1441             double angle = -1;
    1442 
    1443             double activeBaseHeading = (customBaseHeading>=0)? customBaseHeading : baseHeading;
    1444 
    1445             if (snapOn && (activeBaseHeading>=0)) {
    1446                 angle = curHeading - activeBaseHeading;
    1447                 if (angle < 0) {
    1448                     angle+=360;
    1449                 }
    1450                 if (angle > 360) {
    1451                     angle=0;
    1452                 }
    1453 
    1454                 double nearestAngle;
    1455                 if (fixed) {
    1456                     nearestAngle = lastAngle; // if direction is fixed use previous angle
    1457                     active = true;
    1458                 } else {
    1459                     nearestAngle = getNearestAngle(angle);
    1460                     if (getAngleDelta(nearestAngle, angle) < snapAngleTolerance) {
    1461                         active = (customBaseHeading>=0)? true : Math.abs(nearestAngle - 180) > 1e-3;
    1462                         // if angle is to previous segment, exclude 180 degrees
    1463                         lastAngle = nearestAngle;
    1464                     } else {
    1465                         active=false;
    1466                     }
    1467                 }
    1468 
    1469                 if (active) {
    1470                     double phi;
    1471                     e0 = p0.east();
    1472                     n0 = p0.north();
    1473                     buildLabelText((nearestAngle<=180) ? nearestAngle : nearestAngle-360);
    1474 
    1475                     phi = (nearestAngle + activeBaseHeading) * Math.PI / 180;
    1476                     // (pe,pn) - direction of snapping line
    1477                     pe = Math.sin(phi);
    1478                     pn = Math.cos(phi);
    1479                     double scale = 20 * Main.map.mapView.getDist100Pixel();
    1480                     dir2 = new EastNorth(e0 + scale * pe, n0 + scale * pn);
    1481                     snapPoint = getSnapPoint(currentEN);
    1482                 } else {
    1483                     noSnapNow();
    1484                 }
    1485             }
    1486 
    1487             // find out the distance, in metres, between the base point and projected point
    1488             LatLon mouseLatLon = Main.map.mapView.getProjection().eastNorth2latlon(snapPoint);
    1489             double distance = getCurrentBaseNode().getCoor().greatCircleDistance(mouseLatLon);
    1490             double hdg = Math.toDegrees(p0.heading(snapPoint));
    1491             // heading of segment from current to calculated point, not to mouse position
    1492 
    1493             if (baseHeading >= 0) { // there is previous line segment with some heading
    1494                 angle = hdg - baseHeading;
    1495                 if (angle < 0) {
    1496                     angle+=360;
    1497                 }
    1498                 if (angle > 360) {
    1499                     angle=0;
    1500                 }
    1501             }
    1502             showStatusInfo(angle, hdg, distance, isSnapOn());
    1503         }
    1504 
    1505         private void buildLabelText(double nearestAngle) {
    1506             if (showAngle) {
    1507                 if (fixed) {
    1508                     if (absoluteFix) {
    1509                         labelText = "=";
    1510                     } else {
    1511                         labelText = String.format(fixFmt, (int) nearestAngle);
    1512                     }
    1513                 } else {
    1514                     labelText = String.format("%d", (int) nearestAngle);
    1515                 }
    1516             } else {
    1517                 if (fixed) {
    1518                     if (absoluteFix) {
    1519                         labelText = "=";
    1520                     } else {
    1521                         labelText = String.format(tr("FIX"), 0);
    1522                     }
    1523                 } else {
    1524                     labelText = "";
    1525                 }
    1526             }
    1527         }
    1528 
    1529         public  EastNorth getSnapPoint(EastNorth p) {
    1530             if (!active)
    1531                 return p;
    1532             double de=p.east()-e0;
    1533             double dn=p.north()-n0;
    1534             double l = de*pe+dn*pn;
    1535             double delta = Main.map.mapView.getDist100Pixel()/20;
    1536             if (!absoluteFix && l<delta) {
    1537                 active=false;
    1538                 return p;
    1539             } //  do not go backward!
    1540 
    1541             projectionSource=null;
    1542             if (snapToProjections) {
    1543                 DataSet ds = getCurrentDataSet();
    1544                 Collection<Way> selectedWays = ds.getSelectedWays();
    1545                 if (selectedWays.size()==1) {
    1546                     Way w = selectedWays.iterator().next();
    1547                     Collection<EastNorth> pointsToProject = new ArrayList<>();
    1548                     if (w.getNodesCount()<1000) {
    1549                         for (Node n: w.getNodes()) {
    1550                             pointsToProject.add(n.getEastNorth());
    1551                         }
    1552                     }
    1553                     if (customBaseHeading >= 0) {
    1554                         pointsToProject.add(segmentPoint1);
    1555                         pointsToProject.add(segmentPoint2);
    1556                     }
    1557                     EastNorth enOpt=null;
    1558                     double dOpt=1e5;
    1559                     for (EastNorth en: pointsToProject) { // searching for besht projection
    1560                         double l1 = (en.east()-e0)*pe+(en.north()-n0)*pn;
    1561                         double d1 = Math.abs(l1-l);
    1562                         if (d1 < delta && d1 < dOpt) {
    1563                             l=l1;
    1564                             enOpt = en;
    1565                             dOpt = d1;
    1566                         }
    1567                     }
    1568                     if (enOpt!=null) {
    1569                         projectionSource =  enOpt;
    1570                     }
    1571                 }
    1572             }
    1573             return projected = new EastNorth(e0+l*pe, n0+l*pn);
    1574         }
    1575 
    1576 
    1577         public void noSnapNow() {
    1578             active=false;
    1579             dir2=null; projected=null;
    1580             labelText=null;
    1581         }
    1582 
    1583         public void setBaseSegment(WaySegment seg) {
    1584             if (seg==null) return;
    1585             segmentPoint1=seg.getFirstNode().getEastNorth();
    1586             segmentPoint2=seg.getSecondNode().getEastNorth();
    1587 
    1588             double hdg = segmentPoint1.heading(segmentPoint2);
    1589             hdg=Math.toDegrees(hdg);
    1590             if (hdg<0) {
    1591                 hdg+=360;
    1592             }
    1593             if (hdg>360) {
    1594                 hdg-=360;
    1595             }
    1596             customBaseHeading=hdg;
    1597         }
    1598 
    1599         private void nextSnapMode() {
    1600             if (snapOn) {
    1601                 // turn off snapping if we are in fixed mode or no actile snapping line exist
    1602                 if (fixed || !active) {
    1603                     snapOn = false;
    1604                     unsetFixedMode();
    1605                 } else {
    1606                     setFixedMode();
    1607                 }
    1608             } else {
    1609                 snapOn=true;
    1610                 unsetFixedMode();
    1611             }
    1612             checkBox.setState(snapOn);
    1613             customBaseHeading=-1;
    1614         }
    1615 
    1616         private void enableSnapping() {
    1617             snapOn = true;
    1618             checkBox.setState(snapOn);
    1619             customBaseHeading=-1;
    1620             unsetFixedMode();
    1621         }
    1622 
    1623         private void toggleSnapping() {
    1624             snapOn = !snapOn;
    1625             checkBox.setState(snapOn);
    1626             customBaseHeading=-1;
    1627             unsetFixedMode();
    1628         }
    1629 
    1630         public void setFixedMode() {
    1631             if (active) {
    1632                 fixed=true;
    1633             }
    1634         }
    1635 
    1636 
    1637         public  void unsetFixedMode() {
    1638             fixed=false;
    1639             absoluteFix=false;
    1640             lastAngle=0;
    1641             active=false;
    1642         }
    1643 
    1644         public  boolean isActive() {
    1645             return active;
    1646         }
    1647 
    1648         public  boolean isSnapOn() {
    1649             return snapOn;
    1650         }
    1651 
    1652         private double getNearestAngle(double angle) {
    1653             double delta,minDelta=1e5, bestAngle=0.0;
    1654             for (double snapAngle : snapAngles) {
    1655                 delta = getAngleDelta(angle, snapAngle);
    1656                 if (delta < minDelta) {
    1657                     minDelta = delta;
    1658                     bestAngle = snapAngle;
    1659                 }
    1660             }
    1661             if (Math.abs(bestAngle-360) < 1e-3) {
    1662                 bestAngle=0;
    1663             }
    1664             return bestAngle;
    1665         }
    1666 
    1667         private double getAngleDelta(double a, double b) {
    1668             double delta = Math.abs(a-b);
    1669             if (delta>180)
    1670                 return 360-delta;
    1671             else
    1672                 return delta;
    1673         }
    1674 
    1675         private void unFixOrTurnOff() {
    1676             if (absoluteFix) {
    1677                 unsetFixedMode();
    1678             } else {
    1679                 toggleSnapping();
    1680             }
    1681         }
    1682 
    1683         private MouseListener anglePopupListener = new PopupMenuLauncher(new JPopupMenu() {
    1684             private JCheckBoxMenuItem repeatedCb = new JCheckBoxMenuItem(
     1296        private final class AnglePopupMenu extends JPopupMenu {
     1297
     1298            private final JCheckBoxMenuItem repeatedCb = new JCheckBoxMenuItem(
    16851299                    new AbstractAction(tr("Toggle snapping by {0}", getShortcut().getKeyText())) {
    1686                 @Override public void actionPerformed(ActionEvent e) {
     1300                @Override
     1301                public void actionPerformed(ActionEvent e) {
    16871302                    boolean sel=((JCheckBoxMenuItem) e.getSource()).getState();
    16881303                    Main.pref.put("draw.anglesnap.toggleOnRepeatedA", sel);
     
    16901305                }
    16911306            });
    1692             private JCheckBoxMenuItem helperCb = new JCheckBoxMenuItem(
     1307
     1308            private final JCheckBoxMenuItem helperCb = new JCheckBoxMenuItem(
    16931309                    new AbstractAction(tr("Show helper geometry")) {
    1694                 @Override public void actionPerformed(ActionEvent e) {
     1310                @Override
     1311                public void actionPerformed(ActionEvent e) {
    16951312                    boolean sel=((JCheckBoxMenuItem) e.getSource()).getState();
    16961313                    Main.pref.put("draw.anglesnap.drawConstructionGeometry", sel);
     
    17011318                }
    17021319            });
    1703             private JCheckBoxMenuItem projectionCb = new JCheckBoxMenuItem(
     1320
     1321            private final JCheckBoxMenuItem projectionCb = new JCheckBoxMenuItem(
    17041322                    new AbstractAction(tr("Snap to node projections")) {
    1705                 @Override public void actionPerformed(ActionEvent e) {
     1323                @Override
     1324                public void actionPerformed(ActionEvent e) {
    17061325                    boolean sel=((JCheckBoxMenuItem) e.getSource()).getState();
    17071326                    Main.pref.put("draw.anglesnap.projectionsnap", sel);
     
    17101329                }
    17111330            });
    1712             {
     1331
     1332            private AnglePopupMenu() {
    17131333                helperCb.setState(Main.pref.getBoolean("draw.anglesnap.drawConstructionGeometry",true));
    17141334                projectionCb.setState(Main.pref.getBoolean("draw.anglesnap.projectionsnapgvff",true));
     
    17461366                });
    17471367            }
    1748         }) {
     1368        }
     1369
     1370        private boolean snapOn; // snapping is turned on
     1371
     1372        private boolean active; // snapping is active for current mouse position
     1373        private boolean fixed; // snap angle is fixed
     1374        private boolean absoluteFix; // snap angle is absolute
     1375
     1376        private boolean drawConstructionGeometry;
     1377        private boolean showProjectedPoint;
     1378        private boolean showAngle;
     1379
     1380        private boolean snapToProjections;
     1381
     1382        private EastNorth dir2;
     1383        private EastNorth projected;
     1384        private String labelText;
     1385        private double lastAngle;
     1386
     1387        private double customBaseHeading=-1; // angle of base line, if not last segment)
     1388        private EastNorth segmentPoint1; // remembered first point of base segment
     1389        private EastNorth segmentPoint2; // remembered second point of base segment
     1390        private EastNorth projectionSource; // point that we are projecting to the line
     1391
     1392        private double[] snapAngles;
     1393        private double snapAngleTolerance;
     1394
     1395        private double pe,pn; // (pe,pn) - direction of snapping line
     1396        private double e0,n0; // (e0,n0) - origin of snapping line
     1397
     1398        private final String fixFmt="%d "+tr("FIX");
     1399        private Color snapHelperColor;
     1400        private Color highlightColor;
     1401
     1402        private Stroke normalStroke;
     1403        private Stroke helperStroke;
     1404        private Stroke highlightStroke;
     1405
     1406        private JCheckBoxMenuItem checkBox;
     1407
     1408        private MouseListener anglePopupListener = new PopupMenuLauncher(new AnglePopupMenu()) {
    17491409            @Override
    17501410            public void mouseClicked(MouseEvent e) {
     
    17561416            }
    17571417        };
     1418
     1419        public void init() {
     1420            snapOn=false;
     1421            checkBox.setState(snapOn);
     1422            fixed=false; absoluteFix=false;
     1423
     1424            Collection<String> angles = Main.pref.getCollection("draw.anglesnap.angles",
     1425                    Arrays.asList("0","30","45","60","90","120","135","150","180"));
     1426
     1427            snapAngles = new double[2*angles.size()];
     1428            int i=0;
     1429            for (String s: angles) {
     1430                try {
     1431                    snapAngles[i] = Double.parseDouble(s); i++;
     1432                    snapAngles[i] = 360-Double.parseDouble(s); i++;
     1433                } catch (NumberFormatException e) {
     1434                    Main.warn("Incorrect number in draw.anglesnap.angles preferences: "+s);
     1435                    snapAngles[i]=0;i++;
     1436                    snapAngles[i]=0;i++;
     1437                }
     1438            }
     1439            snapAngleTolerance = Main.pref.getDouble("draw.anglesnap.tolerance", 5.0);
     1440            drawConstructionGeometry = Main.pref.getBoolean("draw.anglesnap.drawConstructionGeometry", true);
     1441            showProjectedPoint = Main.pref.getBoolean("draw.anglesnap.drawProjectedPoint", true);
     1442            snapToProjections = Main.pref.getBoolean("draw.anglesnap.projectionsnap", true);
     1443
     1444            showAngle = Main.pref.getBoolean("draw.anglesnap.showAngle", true);
     1445            useRepeatedShortcut = Main.pref.getBoolean("draw.anglesnap.toggleOnRepeatedA", true);
     1446
     1447            normalStroke = rubberLineStroke;
     1448            snapHelperColor = Main.pref.getColor(marktr("draw angle snap"), Color.ORANGE);
     1449
     1450            highlightColor = Main.pref.getColor(marktr("draw angle snap highlight"), ORANGE_TRANSPARENT);
     1451            highlightStroke = GuiHelper.getCustomizedStroke(Main.pref.get("draw.anglesnap.stroke.highlight","10"));
     1452            helperStroke = GuiHelper.getCustomizedStroke(Main.pref.get("draw.anglesnap.stroke.helper","1 4"));
     1453        }
     1454
     1455        public void saveAngles(String ... angles) {
     1456            Main.pref.putCollection("draw.anglesnap.angles", Arrays.asList(angles));
     1457        }
     1458
     1459        public void setMenuCheckBox(JCheckBoxMenuItem checkBox) {
     1460            this.checkBox = checkBox;
     1461        }
     1462
     1463        public void drawIfNeeded(Graphics2D g2, MapView mv) {
     1464            if (!snapOn || !active)
     1465                return;
     1466            Point p1=mv.getPoint(getCurrentBaseNode());
     1467            Point p2=mv.getPoint(dir2);
     1468            Point p3=mv.getPoint(projected);
     1469            GeneralPath b;
     1470            if (drawConstructionGeometry) {
     1471                g2.setColor(snapHelperColor);
     1472                g2.setStroke(helperStroke);
     1473
     1474                b = new GeneralPath();
     1475                if (absoluteFix) {
     1476                    b.moveTo(p2.x,p2.y);
     1477                    b.lineTo(2*p1.x-p2.x,2*p1.y-p2.y); // bi-directional line
     1478                } else {
     1479                    b.moveTo(p2.x,p2.y);
     1480                    b.lineTo(p3.x,p3.y);
     1481                }
     1482                g2.draw(b);
     1483            }
     1484            if (projectionSource != null) {
     1485                g2.setColor(snapHelperColor);
     1486                g2.setStroke(helperStroke);
     1487                b = new GeneralPath();
     1488                b.moveTo(p3.x,p3.y);
     1489                Point pp=mv.getPoint(projectionSource);
     1490                b.lineTo(pp.x,pp.y);
     1491                g2.draw(b);
     1492            }
     1493
     1494            if (customBaseHeading >= 0) {
     1495                g2.setColor(highlightColor);
     1496                g2.setStroke(highlightStroke);
     1497                b = new GeneralPath();
     1498                Point pp1=mv.getPoint(segmentPoint1);
     1499                Point pp2=mv.getPoint(segmentPoint2);
     1500                b.moveTo(pp1.x,pp1.y);
     1501                b.lineTo(pp2.x,pp2.y);
     1502                g2.draw(b);
     1503            }
     1504
     1505            g2.setColor(rubberLineColor);
     1506            g2.setStroke(normalStroke);
     1507            b = new GeneralPath();
     1508            b.moveTo(p1.x,p1.y);
     1509            b.lineTo(p3.x,p3.y);
     1510            g2.draw(b);
     1511
     1512            g2.drawString(labelText, p3.x-5, p3.y+20);
     1513            if (showProjectedPoint) {
     1514                g2.setStroke(normalStroke);
     1515                g2.drawOval(p3.x-5, p3.y-5, 10, 10); // projected point
     1516            }
     1517
     1518            g2.setColor(snapHelperColor);
     1519            g2.setStroke(helperStroke);
     1520        }
     1521
     1522        /* If mouse position is close to line at 15-30-45-... angle, remembers this direction
     1523         */
     1524        public void checkAngleSnapping(EastNorth currentEN, double baseHeading, double curHeading) {
     1525            EastNorth p0 = getCurrentBaseNode().getEastNorth();
     1526            EastNorth snapPoint = currentEN;
     1527            double angle = -1;
     1528
     1529            double activeBaseHeading = (customBaseHeading>=0)? customBaseHeading : baseHeading;
     1530
     1531            if (snapOn && (activeBaseHeading>=0)) {
     1532                angle = curHeading - activeBaseHeading;
     1533                if (angle < 0) {
     1534                    angle+=360;
     1535                }
     1536                if (angle > 360) {
     1537                    angle=0;
     1538                }
     1539
     1540                double nearestAngle;
     1541                if (fixed) {
     1542                    nearestAngle = lastAngle; // if direction is fixed use previous angle
     1543                    active = true;
     1544                } else {
     1545                    nearestAngle = getNearestAngle(angle);
     1546                    if (getAngleDelta(nearestAngle, angle) < snapAngleTolerance) {
     1547                        active = (customBaseHeading>=0)? true : Math.abs(nearestAngle - 180) > 1e-3;
     1548                        // if angle is to previous segment, exclude 180 degrees
     1549                        lastAngle = nearestAngle;
     1550                    } else {
     1551                        active=false;
     1552                    }
     1553                }
     1554
     1555                if (active) {
     1556                    double phi;
     1557                    e0 = p0.east();
     1558                    n0 = p0.north();
     1559                    buildLabelText((nearestAngle<=180) ? nearestAngle : nearestAngle-360);
     1560
     1561                    phi = (nearestAngle + activeBaseHeading) * Math.PI / 180;
     1562                    // (pe,pn) - direction of snapping line
     1563                    pe = Math.sin(phi);
     1564                    pn = Math.cos(phi);
     1565                    double scale = 20 * Main.map.mapView.getDist100Pixel();
     1566                    dir2 = new EastNorth(e0 + scale * pe, n0 + scale * pn);
     1567                    snapPoint = getSnapPoint(currentEN);
     1568                } else {
     1569                    noSnapNow();
     1570                }
     1571            }
     1572
     1573            // find out the distance, in metres, between the base point and projected point
     1574            LatLon mouseLatLon = Main.map.mapView.getProjection().eastNorth2latlon(snapPoint);
     1575            double distance = getCurrentBaseNode().getCoor().greatCircleDistance(mouseLatLon);
     1576            double hdg = Math.toDegrees(p0.heading(snapPoint));
     1577            // heading of segment from current to calculated point, not to mouse position
     1578
     1579            if (baseHeading >= 0) { // there is previous line segment with some heading
     1580                angle = hdg - baseHeading;
     1581                if (angle < 0) {
     1582                    angle+=360;
     1583                }
     1584                if (angle > 360) {
     1585                    angle=0;
     1586                }
     1587            }
     1588            showStatusInfo(angle, hdg, distance, isSnapOn());
     1589        }
     1590
     1591        private void buildLabelText(double nearestAngle) {
     1592            if (showAngle) {
     1593                if (fixed) {
     1594                    if (absoluteFix) {
     1595                        labelText = "=";
     1596                    } else {
     1597                        labelText = String.format(fixFmt, (int) nearestAngle);
     1598                    }
     1599                } else {
     1600                    labelText = String.format("%d", (int) nearestAngle);
     1601                }
     1602            } else {
     1603                if (fixed) {
     1604                    if (absoluteFix) {
     1605                        labelText = "=";
     1606                    } else {
     1607                        labelText = String.format(tr("FIX"), 0);
     1608                    }
     1609                } else {
     1610                    labelText = "";
     1611                }
     1612            }
     1613        }
     1614
     1615        public EastNorth getSnapPoint(EastNorth p) {
     1616            if (!active)
     1617                return p;
     1618            double de=p.east()-e0;
     1619            double dn=p.north()-n0;
     1620            double l = de*pe+dn*pn;
     1621            double delta = Main.map.mapView.getDist100Pixel()/20;
     1622            if (!absoluteFix && l<delta) {
     1623                active=false;
     1624                return p;
     1625            } //  do not go backward!
     1626
     1627            projectionSource=null;
     1628            if (snapToProjections) {
     1629                DataSet ds = getCurrentDataSet();
     1630                Collection<Way> selectedWays = ds.getSelectedWays();
     1631                if (selectedWays.size()==1) {
     1632                    Way w = selectedWays.iterator().next();
     1633                    Collection<EastNorth> pointsToProject = new ArrayList<>();
     1634                    if (w.getNodesCount()<1000) {
     1635                        for (Node n: w.getNodes()) {
     1636                            pointsToProject.add(n.getEastNorth());
     1637                        }
     1638                    }
     1639                    if (customBaseHeading >= 0) {
     1640                        pointsToProject.add(segmentPoint1);
     1641                        pointsToProject.add(segmentPoint2);
     1642                    }
     1643                    EastNorth enOpt=null;
     1644                    double dOpt=1e5;
     1645                    for (EastNorth en: pointsToProject) { // searching for besht projection
     1646                        double l1 = (en.east()-e0)*pe+(en.north()-n0)*pn;
     1647                        double d1 = Math.abs(l1-l);
     1648                        if (d1 < delta && d1 < dOpt) {
     1649                            l=l1;
     1650                            enOpt = en;
     1651                            dOpt = d1;
     1652                        }
     1653                    }
     1654                    if (enOpt!=null) {
     1655                        projectionSource =  enOpt;
     1656                    }
     1657                }
     1658            }
     1659            return projected = new EastNorth(e0+l*pe, n0+l*pn);
     1660        }
     1661
     1662        public void noSnapNow() {
     1663            active=false;
     1664            dir2=null; projected=null;
     1665            labelText=null;
     1666        }
     1667
     1668        public void setBaseSegment(WaySegment seg) {
     1669            if (seg==null) return;
     1670            segmentPoint1=seg.getFirstNode().getEastNorth();
     1671            segmentPoint2=seg.getSecondNode().getEastNorth();
     1672
     1673            double hdg = segmentPoint1.heading(segmentPoint2);
     1674            hdg=Math.toDegrees(hdg);
     1675            if (hdg<0) {
     1676                hdg+=360;
     1677            }
     1678            if (hdg>360) {
     1679                hdg-=360;
     1680            }
     1681            customBaseHeading=hdg;
     1682        }
     1683
     1684        private void nextSnapMode() {
     1685            if (snapOn) {
     1686                // turn off snapping if we are in fixed mode or no actile snapping line exist
     1687                if (fixed || !active) {
     1688                    snapOn = false;
     1689                    unsetFixedMode();
     1690                } else {
     1691                    setFixedMode();
     1692                }
     1693            } else {
     1694                snapOn=true;
     1695                unsetFixedMode();
     1696            }
     1697            checkBox.setState(snapOn);
     1698            customBaseHeading=-1;
     1699        }
     1700
     1701        private void enableSnapping() {
     1702            snapOn = true;
     1703            checkBox.setState(snapOn);
     1704            customBaseHeading=-1;
     1705            unsetFixedMode();
     1706        }
     1707
     1708        private void toggleSnapping() {
     1709            snapOn = !snapOn;
     1710            checkBox.setState(snapOn);
     1711            customBaseHeading=-1;
     1712            unsetFixedMode();
     1713        }
     1714
     1715        public void setFixedMode() {
     1716            if (active) {
     1717                fixed=true;
     1718            }
     1719        }
     1720
     1721        public  void unsetFixedMode() {
     1722            fixed=false;
     1723            absoluteFix=false;
     1724            lastAngle=0;
     1725            active=false;
     1726        }
     1727
     1728        public  boolean isActive() {
     1729            return active;
     1730        }
     1731
     1732        public  boolean isSnapOn() {
     1733            return snapOn;
     1734        }
     1735
     1736        private double getNearestAngle(double angle) {
     1737            double delta,minDelta=1e5, bestAngle=0.0;
     1738            for (double snapAngle : snapAngles) {
     1739                delta = getAngleDelta(angle, snapAngle);
     1740                if (delta < minDelta) {
     1741                    minDelta = delta;
     1742                    bestAngle = snapAngle;
     1743                }
     1744            }
     1745            if (Math.abs(bestAngle-360) < 1e-3) {
     1746                bestAngle=0;
     1747            }
     1748            return bestAngle;
     1749        }
     1750
     1751        private double getAngleDelta(double a, double b) {
     1752            double delta = Math.abs(a-b);
     1753            if (delta>180)
     1754                return 360-delta;
     1755            else
     1756                return delta;
     1757        }
     1758
     1759        private void unFixOrTurnOff() {
     1760            if (absoluteFix) {
     1761                unsetFixedMode();
     1762            } else {
     1763                toggleSnapping();
     1764            }
     1765        }
    17581766    }
    17591767
    17601768    private class SnapChangeAction extends JosmAction {
     1769        /**
     1770         * Constructs a new {@code SnapChangeAction}.
     1771         */
    17611772        public SnapChangeAction() {
    17621773            super(tr("Angle snapping"), /* ICON() */ "anglesnap",
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java

    r8470 r8509  
    174174    /** {@code true}, if dual alignment mode is enabled. User wants following extrude to be dual aligned. */
    175175    private boolean dualAlignEnabled;
    176     /** {@code true}, if dual alignment is active. User is dragging the mouse, required conditions are met. Treat {@link #mode} (extrude/translate/create_new) as dual aligned. */
     176    /** {@code true}, if dual alignment is active. User is dragging the mouse, required conditions are met.
     177     * Treat {@link #mode} (extrude/translate/create_new) as dual aligned. */
    177178    private boolean dualAlignActive;
    178179    /** Dual alignment reference segments */
     
    622623        Node prevNode = getPreviousNode(selectedSegment.lowerIndex);
    623624        boolean nodeOverlapsSegment = prevNode != null && Geometry.segmentsParallel(initialN1en, prevNode.getEastNorth(), initialN1en, newN1en);
    624         // segmentAngleZero marks subset of nodeOverlapsSegment. nodeOverlapsSegment is true if angle between segments is 0 or PI, segmentAngleZero only if angle is 0
     625        // segmentAngleZero marks subset of nodeOverlapsSegment.
     626        // nodeOverlapsSegment is true if angle between segments is 0 or PI, segmentAngleZero only if angle is 0
    625627        boolean segmentAngleZero = prevNode != null && Math.abs(Geometry.getCornerAngle(prevNode.getEastNorth(), initialN1en, newN1en)) < 1e-5;
    626628        boolean hasOtherWays = hasNodeOtherWays(selectedSegment.getFirstNode(), selectedSegment.way);
     
    927929            if (newN1en == null || newN2en == null) return bestMovement;
    928930            if (keepSegmentDirection && isOppositeDirection(newN1en, newN2en, initialN1en, initialN2en)) {
    929                 EastNorth collapsedSegmentPosition = Geometry.getLineLineIntersection(dualAlignSegment1.p1, dualAlignSegment1.p2, dualAlignSegment2.p1, dualAlignSegment2.p2);
     931                EastNorth collapsedSegmentPosition = Geometry.getLineLineIntersection(dualAlignSegment1.p1, dualAlignSegment1.p2,
     932                        dualAlignSegment2.p1, dualAlignSegment2.p2);
    930933                newN1en = collapsedSegmentPosition;
    931934                newN2en = collapsedSegmentPosition;
     
    11721175            // Graphics2D calls 'user space'. Essentially a manhattan distance of manhattan distances.
    11731176            // This can be used as a safe length of line to generate which will always go off-viewport.
    1174             double linelength = Math.abs(widthpoint.getX()) + Math.abs(widthpoint.getY()) + Math.abs(heightpoint.getX()) + Math.abs(heightpoint.getY());
    1175 
    1176             return new Line2D.Double(start, new Point2D.Double(start.getX() + (unitvector.getX() * linelength) , start.getY() + (unitvector.getY() * linelength)));
     1177            double linelength = Math.abs(widthpoint.getX()) + Math.abs(widthpoint.getY())
     1178                    + Math.abs(heightpoint.getX()) + Math.abs(heightpoint.getY());
     1179
     1180            return new Line2D.Double(start, new Point2D.Double(start.getX() + (unitvector.getX() * linelength) , start.getY()
     1181                    + (unitvector.getY() * linelength)));
    11771182        } catch (NoninvertibleTransformException e) {
    1178             return new Line2D.Double(start, new Point2D.Double(start.getX() + (unitvector.getX() * 10) , start.getY() + (unitvector.getY() * 10)));
     1183            return new Line2D.Double(start, new Point2D.Double(start.getX() + (unitvector.getX() * 10) , start.getY()
     1184                    + (unitvector.getY() * 10)));
    11791185        }
    11801186    }
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWays.java

    r8459 r8509  
    8989        }
    9090
    91         // Ugly method of ensuring that the offset isn't inverted. I'm sure there is a better and more elegant way, but I'm starting to get sleepy, so I do this for now.
     91        // Ugly method of ensuring that the offset isn't inverted. I'm sure there is a better and more elegant way
    9292        Way refWay = ways.get(refWayIndex);
    9393        boolean refWayReversed = true;
  • trunk/src/org/openstreetmap/josm/actions/relation/SelectMembersAction.java

    r8338 r8509  
    2323    /**
    2424     * Constructs a new <code>SelectMembersAction</code>.
    25      * @param add if <code>true</code>, the members will be added to current selection. If <code>false</code>, the members will replace the current selection.
     25     * @param add if <code>true</code>, the members will be added to current selection.
     26     * If <code>false</code>, the members will replace the current selection.
    2627     */
    2728    public SelectMembersAction(boolean add) {
  • trunk/src/org/openstreetmap/josm/actions/relation/SelectRelationAction.java

    r7937 r8509  
    2020    /**
    2121     * Constructs a new <code>SelectRelationAction</code>.
    22      * @param add if <code>true</code>, the relation will be added to current selection. If <code>false</code>, the relation will replace the current selection.
     22     * @param add if <code>true</code>, the relation will be added to current selection.
     23     * If <code>false</code>, the relation will replace the current selection.
    2324     */
    2425    public SelectRelationAction(boolean add) {
    25         putValue(SHORT_DESCRIPTION, add ? tr("Add the selected relations to the current selection") : tr("Set the current selection to the list of selected relations"));
     26        putValue(SHORT_DESCRIPTION, add ? tr("Add the selected relations to the current selection") :
     27            tr("Set the current selection to the list of selected relations"));
    2628        putValue(SMALL_ICON, ImageProvider.get("dialogs", "select"));
    2729        putValue(NAME, add ? tr("Select relation (add)") : tr("Select relation"));
  • trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java

    r8470 r8509  
    322322                    new ToolbarPreferences.ActionDefinition(Main.main.menu.search);
    323323            aDef.getParameters().put(SEARCH_EXPRESSION, initialValues);
    324             aDef.setName(Utils.shortenString(initialValues.text, MAX_LENGTH_SEARCH_EXPRESSION_DISPLAY)); // Display search expression as tooltip instead of generic one
     324            // Display search expression as tooltip instead of generic one
     325            aDef.setName(Utils.shortenString(initialValues.text, MAX_LENGTH_SEARCH_EXPRESSION_DISPLAY));
    325326            // parametrized action definition is now composed
    326327            ActionParser actionParser = new ToolbarPreferences.ActionParser(null);
     
    348349                .addKeyword("<i>key</i>=", null, tr("matches if ''key'' exists"))
    349350                .addKeyword("<i>key</i>><i>value</i>", null, tr("matches if ''key'' is greater than ''value'' (analogously, less than)"))
    350                 .addKeyword("\"key\"=\"value\"", "\"\"=\"\"", tr("to quote operators.<br>Within quoted strings the <b>\"</b> and <b>\\</b> characters need to be escaped by a preceding <b>\\</b> (e.g. <b>\\\"</b> and <b>\\\\</b>)."), "\"addr:street\"")
     351                .addKeyword("\"key\"=\"value\"", "\"\"=\"\"",
     352                        tr("to quote operators.<br>Within quoted strings the <b>\"</b> and <b>\\</b> characters need to be escaped by a preceding <b>\\</b> (e.g. <b>\\\"</b> and <b>\\\\</b>)."),
     353                        "\"addr:street\"")
    351354                , GBC.eol());
    352355        right.add(new SearchKeywordRow(hcbSearchString)
     
    373376                .addKeyword("id:", "id:", tr("objects with given ID"), "id:0 (new objects)")
    374377                .addKeyword("version:", "version:", tr("objects with given version"), "version:0 (objects without an assigned version)")
    375                 .addKeyword("changeset:", "changeset:", tr("objects with given changeset ID"), "changeset:0 (objects without an assigned changeset)")
    376                 .addKeyword("timestamp:", "timestamp:", tr("objects with last modification timestamp within range"), "timestamp:2012/", "timestamp:2008/2011-02-04T12")
     378                .addKeyword("changeset:", "changeset:", tr("objects with given changeset ID"),
     379                        "changeset:0 (objects without an assigned changeset)")
     380                .addKeyword("timestamp:", "timestamp:", tr("objects with last modification timestamp within range"), "timestamp:2012/",
     381                        "timestamp:2008/2011-02-04T12")
    377382                , GBC.eol());
    378383            right.add(new SearchKeywordRow(hcbSearchString)
     
    404409                .addKeyword("allinview", "allinview ", tr("objects (and all its way nodes / relation members) in current view"))
    405410                .addKeyword("indownloadedarea", "indownloadedarea ", tr("objects in downloaded area"))
    406                 .addKeyword("allindownloadedarea", "allindownloadedarea ", tr("objects (and all its way nodes / relation members) in downloaded area"))
     411                .addKeyword("allindownloadedarea", "allindownloadedarea ",
     412                        tr("objects (and all its way nodes / relation members) in downloaded area"))
    407413                , GBC.eol());
    408414        }
Note: See TracChangeset for help on using the changeset viewer.