Ignore:
Timestamp:
2009-12-13T11:48:12+01:00 (14 years ago)
Author:
jttt
Message:

Fixed some of the warnings found by FindBugs

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

Legend:

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

    r2548 r2626  
    1919import java.text.ParsePosition;
    2020import java.util.Locale;
    21 import java.util.logging.Logger;
    2221
    2322import javax.swing.AbstractAction;
     
    5251 */
    5352public final class AddNodeAction extends JosmAction {
    54     static private final Logger logger = Logger.getLogger(AddNodeAction.class.getName());
     53    //static private final Logger logger = Logger.getLogger(AddNodeAction.class.getName());
    5554
    5655    public AddNodeAction() {
     
    311310        }
    312311
    313         class TextFieldFocusHandler implements FocusListener {
     312        static class TextFieldFocusHandler implements FocusListener {
    314313            public void focusGained(FocusEvent e) {
    315314                Component c = e.getComponent();
  • trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java

    r2610 r2626  
    5656    // HelperClass
    5757    // Saves a node and two positions where to insert the node into the ways
    58     private class NodeToSegs implements Comparable<NodeToSegs> {
     58    private static class NodeToSegs implements Comparable<NodeToSegs> {
    5959        public int pos;
    6060        public Node n;
     
    7171                return this.pos - o.pos;
    7272        }
     73
     74        @Override
     75        public int hashCode() {
     76            return pos;
     77        }
     78
     79        @Override
     80        public boolean equals(Object o) {
     81            if (o instanceof NodeToSegs)
     82                return compareTo((NodeToSegs) o) == 0;
     83            else
     84                return false;
     85        }
    7386    }
    7487
    7588    // HelperClass
    7689    // Saves a relation and a role an OsmPrimitve was part of until it was stripped from all relations
    77     private class RelationRole {
     90    private static class RelationRole {
    7891        public final Relation rel;
    7992        public final String role;
  • trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java

    r2596 r2626  
    3737public final class OrthogonalizeAction extends JosmAction {
    3838    String USAGE = "<h3>"+
    39             "When one or more ways are selected, the shape is adjusted, such that all angles are 90 or 180 degrees.<h3>"+
    40             "You can add two nodes to the selection. Then the direction is fixed by these two reference nodes.<h3>"+
    41             "(Afterwards, you can undo the movement for certain nodes:<br>"+
    42             "Select them and press the shortcut for Orthogonalize / Undo. The default is Shift-Q.)";
     39    "When one or more ways are selected, the shape is adjusted, such that all angles are 90 or 180 degrees.<h3>"+
     40    "You can add two nodes to the selection. Then the direction is fixed by these two reference nodes.<h3>"+
     41    "(Afterwards, you can undo the movement for certain nodes:<br>"+
     42    "Select them and press the shortcut for Orthogonalize / Undo. The default is Shift-Q.)";
    4343
    4444    public OrthogonalizeAction() {
     
    7272     * This action can be triggered by shortcut only.
    7373     */
    74     public class Undo extends JosmAction {
     74    public static class Undo extends JosmAction {
    7575        public Undo() {
    7676            super(tr("Orthogonalize Shape / Undo"),
    77                 "ortho",
    78                 tr("Undo orthogonalization for certain nodes"),
    79                 Shortcut.registerShortcut("tools:orthogonalizeUndo", tr("Tool: {0}", tr("Orthogonalize Shape / Undo")),
    80                         KeyEvent.VK_Q,
    81                         Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true);
     77                    "ortho",
     78                    tr("Undo orthogonalization for certain nodes"),
     79                    Shortcut.registerShortcut("tools:orthogonalizeUndo", tr("Tool: {0}", tr("Orthogonalize Shape / Undo")),
     80                            KeyEvent.VK_Q,
     81                            Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), true);
    8282        }
    8383        public void actionPerformed(ActionEvent e) {
     
    103103            catch (InvalidUserInputException ex) {
    104104                JOptionPane.showMessageDialog(
    105                     Main.parent,
    106                     tr("Orthogonalize Shape / Undo\n"+
     105                        Main.parent,
     106                        tr("Orthogonalize Shape / Undo\n"+
    107107                        "Please select nodes that were moved by the previous Orthogonalize Shape action!"),
    108                     tr("Undo Orthogonalize Shape"),
    109                     JOptionPane.INFORMATION_MESSAGE);
     108                        tr("Undo Orthogonalize Shape"),
     109                        JOptionPane.INFORMATION_MESSAGE);
    110110            }
    111111        }
     
    143143                else if (p instanceof Way) {
    144144                    wayDataList.add(new WayData((Way) p));
    145                 }
    146                 else {      // maybe a relation got selected...
     145                } else
    147146                    throw new InvalidUserInputException("Selection must consist only of ways and nodes.");
    148                 }
    149             }
    150             if (wayDataList.isEmpty()) {
     147            }
     148            if (wayDataList.isEmpty())
    151149                throw new InvalidUserInputException("usage");
    152             }
    153150            else  {
    154151                if (nodeList.size() == 2 || nodeList.isEmpty()) {
     
    186183                    } else
    187184                        throw new IllegalStateException();
    188                    
     185
    189186                    Main.main.undoRedo.add(new SequenceCommand(tr("Orthogonalize"), commands));
    190187                    Main.map.repaint();
    191                    
     188
    192189                } else
    193190                    throw new InvalidUserInputException("usage");
     
    196193            if (ex.getMessage().equals("usage")) {
    197194                JOptionPane.showMessageDialog(
    198                     Main.parent,
    199                     "<html><h2>"+tr("Usage")+tr(USAGE),
    200                     tr("Orthogonalize Shape"),
    201                     JOptionPane.INFORMATION_MESSAGE);
     195                        Main.parent,
     196                        "<html><h2>"+tr("Usage")+tr(USAGE),
     197                        tr("Orthogonalize Shape"),
     198                        JOptionPane.INFORMATION_MESSAGE);
    202199            }
    203200            else {
    204201                JOptionPane.showMessageDialog(
    205                     Main.parent,
    206                     "<html><h3>"+tr(ex.getMessage())+"<br><hr><h3>"+tr("Usage")+tr(USAGE),
    207                     tr("Selected Elements cannot be orthogonalized"),
    208                     JOptionPane.INFORMATION_MESSAGE);
     202                        Main.parent,
     203                        "<html><h3>"+tr(ex.getMessage())+"<br><hr><h3>"+tr("Usage")+tr(USAGE),
     204                        tr("Selected Elements cannot be orthogonalized"),
     205                        JOptionPane.INFORMATION_MESSAGE);
    209206            }
    210207        }
     
    232229     **/
    233230    private static Collection<Command> orthogonalize(ArrayList<WayData> wayDataList, ArrayList<Node> headingNodes)
    234         throws InvalidUserInputException
     231    throws InvalidUserInputException
    235232    {
    236233        // find average heading
     
    263260        } catch (RejectedAngleException ex) {
    264261            throw new InvalidUserInputException(
    265                 "<html>Please make sure all selected ways head in a similar direction<br>"+
    266                 "or orthogonalize them one by one.");
     262                    "<html>Please make sure all selected ways head in a similar direction<br>"+
     263            "or orthogonalize them one by one.");
    267264        }
    268265
     
    302299            int s_size = s.size();
    303300            for (int dummy = 0; dummy < s_size; ++ dummy) {
    304                 if (s.isEmpty()) break;
     301                if (s.isEmpty()) {
     302                    break;
     303                }
    305304                final Node dummy_n = s.iterator().next();     // pick arbitrary element of s
    306305
     
    357356        // rotate back and log the change
    358357        final Collection<Command> commands = new LinkedList<Command>();
    359 //        OrthogonalizeAction.rememberMovements.clear();
     358        //        OrthogonalizeAction.rememberMovements.clear();
    360359        for (Node n: allNodes) {
    361360            EastNorth tmp = new EastNorth(nX.get(n), nY.get(n));
     
    366365                final double EPSILON = 1E-6;
    367366                if (Math.abs(dx) > Math.abs(EPSILON * tmp.east()) ||
    368                     Math.abs(dy) > Math.abs(EPSILON * tmp.east())) {
     367                        Math.abs(dy) > Math.abs(EPSILON * tmp.east()))
    369368                    throw new AssertionError();
    370                 }
    371369            }
    372370            else {
     
    386384        final public int nNode;           // Number of Nodes of the Way
    387385        public Direction[] segDirections; // Direction of the segments
    388                                           // segment i goes from node i to node (i+1)
     386        // segment i goes from node i to node (i+1)
    389387        public EastNorth segSum;          // (Vector-)sum of all horizontal segments plus the sum of all vertical
    390                                           //     segments turned by 90 degrees
     388        //     segments turned by 90 degrees
    391389        public double heading;            // heading of segSum == approximate heading of the way
    392390        public WayData(Way pWay) {
     
    422420            // sum up segments
    423421            EastNorth h = new EastNorth(0.,0.);
    424             double lh = EN.abs(h);
     422            //double lh = EN.abs(h);
    425423            EastNorth v = new EastNorth(0.,0.);
    426             double lv = EN.abs(v);
     424            //double lv = EN.abs(v);
    427425            for (int i = 0; i < nSeg; ++i) {
    428426                EastNorth segment = EN.diff(en[i+1], en[i]);
    429                 if      (segDirections[i] == Direction.RIGHT) h = EN.sum(h,segment);
    430                 else if (segDirections[i] == Direction.UP)    v = EN.sum(v,segment);
    431                 else if (segDirections[i] == Direction.LEFT)  h = EN.diff(h,segment);
    432                 else if (segDirections[i] == Direction.DOWN)  v = EN.diff(v,segment);
    433                 else throw new IllegalStateException();
     427                if      (segDirections[i] == Direction.RIGHT) {
     428                    h = EN.sum(h,segment);
     429                } else if (segDirections[i] == Direction.UP) {
     430                    v = EN.sum(v,segment);
     431                } else if (segDirections[i] == Direction.LEFT) {
     432                    h = EN.diff(h,segment);
     433                } else if (segDirections[i] == Direction.DOWN) {
     434                    v = EN.diff(v,segment);
     435                } else throw new IllegalStateException();
    434436                /**
    435437                 * When summing up the length of the sum vector should increase.
     
    437439                 * So only uncomment this for testing
    438440                 **/
    439 //                if (segDirections[i].ordinal() % 2 == 0) {
    440 //                    if (EN.abs(h) < lh) throw new AssertionError();
    441 //                    lh = EN.abs(h);
    442 //                } else {
    443 //                    if (EN.abs(v) < lv) throw new AssertionError();
    444 //                    lv = EN.abs(v);
    445 //                }
     441                //                if (segDirections[i].ordinal() % 2 == 0) {
     442                //                    if (EN.abs(h) < lh) throw new AssertionError();
     443                //                    lh = EN.abs(h);
     444                //                } else {
     445                //                    if (EN.abs(v) < lv) throw new AssertionError();
     446                //                    lv = EN.abs(v);
     447                //                }
    446448            }
    447449            // rotate the vertical vector by 90 degrees (clockwise) and add it to the horizontal vector
    448450            segSum = EN.sum(h, new EastNorth(v.north(), - v.east()));
    449 //            if (EN.abs(segSum) < lh) throw new AssertionError();
     451            //            if (EN.abs(segSum) < lh) throw new AssertionError();
    450452            this.heading = EN.polar(new EastNorth(0.,0.), segSum);
    451453        }
     
    456458        public Direction changeBy(int directionChange) {
    457459            int tmp = (this.ordinal() + directionChange) % 4;
    458             if (tmp < 0) tmp += 4;          // the % operator can return negative value
     460            if (tmp < 0) {
     461                tmp += 4;          // the % operator can return negative value
     462            }
    459463            return Direction.values()[tmp];
    460464        }
     
    465469     */
    466470    private static double standard_angle_0_to_2PI(double a) {
    467         while (a >= 2 * Math.PI) a -= 2 * Math.PI;
    468         while (a < 0)            a += 2 * Math.PI;
     471        while (a >= 2 * Math.PI) {
     472            a -= 2 * Math.PI;
     473        }
     474        while (a < 0) {
     475            a += 2 * Math.PI;
     476        }
    469477        return a;
    470478    }
     
    474482     */
    475483    private static double standard_angle_mPI_to_PI(double a) {
    476         while (a > Math.PI)    a -= 2 * Math.PI;
    477         while (a <= - Math.PI) a += 2 * Math.PI;
     484        while (a > Math.PI) {
     485            a -= 2 * Math.PI;
     486        }
     487        while (a <= - Math.PI) {
     488            a += 2 * Math.PI;
     489        }
    478490        return a;
    479491    }
     
    499511            return new EastNorth(en1.east() - en2.east(), en1.north() - en2.north());
    500512        }
    501         public static double abs(EastNorth en) {
    502             return Math.sqrt(en.east() * en.east() + en.north() * en.north());
    503         }
    504         public static String toString(EastNorth en) {
    505             return "["+u(en.east())+","+u(en.north())+"]";
    506         }
    507         public static long u(double d) {
    508             return Math.round(d * 1000000.);
    509         }
    510513        public static double polar(EastNorth en1, EastNorth en2) {
    511514            return Math.atan2(en2.north() - en1.north(), en2.east() -  en1.east());
     
    523526        double d_m90 = Math.abs(a + Math.PI / 2);
    524527        int dirChange;
    525         if (d0 < deltaMax)         dirChange =  0;
    526         else if (d90 < deltaMax)   dirChange =  1;
    527         else if (d_m90 < deltaMax) dirChange = -1;
    528         else {
     528        if (d0 < deltaMax) {
     529            dirChange =  0;
     530        } else if (d90 < deltaMax) {
     531            dirChange =  1;
     532        } else if (d_m90 < deltaMax) {
     533            dirChange = -1;
     534        } else {
    529535            a = standard_angle_0_to_2PI(a);
    530536            double d180 = Math.abs(a - Math.PI);
    531             if (d180 < deltaMax)   dirChange = 2;
    532             else {
     537            if (d180 < deltaMax) {
     538                dirChange = 2;
     539            } else
    533540                throw new RejectedAngleException();
    534             }
    535541        }
    536542        return dirChange;
  • trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java

    r2598 r2626  
    3838        MultiFetchServerObjectReader reader = new MultiFetchServerObjectReader();
    3939        reader.append(getCurrentDataSet(),id, type);
    40         DataSet ds = null;
    4140        try {
    42             ds = reader.parseOsm(NullProgressMonitor.INSTANCE);
     41            DataSet ds = reader.parseOsm(NullProgressMonitor.INSTANCE);
     42            Main.map.mapView.getEditLayer().mergeFrom(ds);
    4343        } catch(Exception e) {
    4444            ExceptionDialogUtil.explainException(e);
    4545        }
    46         Main.map.mapView.getEditLayer().mergeFrom(ds);
    4746    }
    4847
Note: See TracChangeset for help on using the changeset viewer.