Ignore:
Timestamp:
2013-11-07T13:37:16+01:00 (11 years ago)
Author:
donvip
Message:

[josm_building_tools] - see #josm7328 - bring code quality closer to JOSM core standards

Location:
applications/editors/josm/plugins/buildings_tools/src/buildings_tools
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/AddressDialog.java

    r24243 r30045  
     1// License: GPL. For details, see LICENSE file.
    12package buildings_tools;
    23
     
    4950    }
    5051
    51     public void saveValues() {
     52    public final void saveValues() {
    5253        lhousenum = housenum.getText();
    5354        lstreetname = streetname.getText();
     
    5556    }
    5657
    57     public String getHouseNum() {
     58    public final String getHouseNum() {
    5859        return housenum.getText();
    5960    }
    6061
    61     public String getStreetName() {
     62    public final String getStreetName() {
    6263        return streetname.getText();
    6364    }
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/AdvancedSettingsDialog.java

    r30010 r30045  
     1// License: GPL. For details, see LICENSE file.
    12package buildings_tools;
    23
     
    3839    }
    3940
    40     public void saveSettings() {
     41    public final void saveSettings() {
    4142        tagsModel.applyToTags(ToolSettings.getTags(), false);
    4243        ToolSettings.saveTags();
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/AngleSnap.java

    r23190 r30045  
     1// License: GPL. For details, see LICENSE file.
    12package buildings_tools;
    23
     
    1213public class AngleSnap {
    1314    private static final double PI_2 = Math.PI / 2;
    14     TreeSet<Double> snapSet = new TreeSet<Double>();
     15    final TreeSet<Double> snapSet = new TreeSet<Double>();
    1516
    16     public void clear() {
     17    public final void clear() {
    1718        snapSet.clear();
    1819    }
    1920
    20     public void addSnap(double snap) {
     21    public final void addSnap(double snap) {
    2122        snapSet.add(snap % PI_2);
    2223    }
    2324
    24     public Double addSnap(Node[] nodes) {
     25    public final Double addSnap(Node[] nodes) {
    2526        if (nodes.length == 2) {
    2627            EastNorth p1, p2;
    27             p1 = latlon2eastNorth(((Node) nodes[0]).getCoor());
    28             p2 = latlon2eastNorth(((Node) nodes[1]).getCoor());
     28            p1 = latlon2eastNorth(nodes[0].getCoor());
     29            p2 = latlon2eastNorth(nodes[1].getCoor());
    2930            double heading = p1.heading(p2);
    3031            addSnap(heading);
     
    3637    }
    3738
    38     public void addSnap(Way way) {
     39    public final void addSnap(Way way) {
    3940        for (Pair<Node, Node> pair : way.getNodePairs(false)) {
    4041            EastNorth a, b;
     
    4647    }
    4748
    48     public Double getAngle() {
     49    public final Double getAngle() {
    4950        if (snapSet.isEmpty()) {
    5051            return null;
     
    6566    }
    6667
    67     public double snapAngle(double angle) {
     68    public final double snapAngle(double angle) {
    6869        if (snapSet.isEmpty()) {
    6970            return angle;
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/Building.java

    r25905 r30045  
     1// License: GPL. For details, see LICENSE file.
    12package buildings_tools;
    2 
    3 import static org.openstreetmap.josm.tools.I18n.tr;
    43
    54import static buildings_tools.BuildingsToolsPlugin.eastNorth2latlon;
    65import static buildings_tools.BuildingsToolsPlugin.latlon2eastNorth;
     6import static org.openstreetmap.josm.tools.I18n.tr;
    77
    88import java.awt.Graphics2D;
     
    2222import org.openstreetmap.josm.command.DeleteCommand;
    2323import org.openstreetmap.josm.command.SequenceCommand;
    24 import org.openstreetmap.josm.data.coor.*;
     24import org.openstreetmap.josm.data.coor.EastNorth;
     25import org.openstreetmap.josm.data.coor.LatLon;
    2526import org.openstreetmap.josm.data.osm.BBox;
    2627import org.openstreetmap.josm.data.osm.DataSet;
     
    103104
    104105    /**
    105      * @returns Projection of the point to the heading vector in metres
     106     * @return Projection of the point to the heading vector in metres
     107     * @param p The point to project
    106108     */
    107109    private double projection1(EastNorth p) {
     
    111113
    112114    /**
    113      * @returns Projection of the point to the perpendicular of the heading
     115     * @return Projection of the point to the perpendicular of the heading
    114116     *          vector in metres
     117     * @param p The point to project
    115118     */
    116119    private double projection2(EastNorth p) {
     
    203206    }
    204207
    205     private Node findNode(EastNorth en) {
     208    private Node findNode(EastNorth pos) {
    206209        DataSet ds = Main.main.getCurrentDataSet();
    207         LatLon l = eastNorth2latlon(en);
     210        LatLon l = eastNorth2latlon(pos);
    208211        List<Node> nodes = ds.searchNodes(new BBox(l.lon() - 0.0000001, l.lat() - 0.0000001,
    209212                l.lon() + 0.0000001, l.lat() + 0.0000001));
     
    221224
    222225    /**
    223      * Returns a node with address tags under the building
     226     * Returns a node with address tags under the building.
    224227     *
    225      * @return
     228     * @return A node with address tags under the building.
    226229     */
    227230    private Node getAddressNode() {
     
    299302        w.setKeys(ToolSettings.getTags());
    300303        cmds.add(new AddCommand(w));
    301         Node addrNode;
    302         if (ToolSettings.PROP_USE_ADDR_NODE.get() && (addrNode = getAddressNode()) != null) {
    303             for (Entry<String, String> entry : addrNode.getKeys().entrySet()) {
    304                 w.put(entry.getKey(), entry.getValue());
    305             }
    306             for (OsmPrimitive p : addrNode.getReferrers()) {
    307                 Relation r = (Relation) p;
    308                 Relation rnew = new Relation(r);
    309                 for (int i = 0; i < r.getMembersCount(); i++) {
    310                     RelationMember member = r.getMember(i);
    311                     if (member.getMember() == addrNode) {
    312                         rnew.removeMember(i);
    313                         rnew.addMember(i, new RelationMember(member.getRole(), w));
     304
     305        if (ToolSettings.PROP_USE_ADDR_NODE.get()) {
     306            Node addrNode = getAddressNode();
     307            if (addrNode != null) {
     308                for (Entry<String, String> entry : addrNode.getKeys().entrySet()) {
     309                    w.put(entry.getKey(), entry.getValue());
     310                }
     311                for (OsmPrimitive p : addrNode.getReferrers()) {
     312                    Relation r = (Relation) p;
     313                    Relation rnew = new Relation(r);
     314                    for (int i = 0; i < r.getMembersCount(); i++) {
     315                        RelationMember member = r.getMember(i);
     316                        if (member.getMember() == addrNode) {
     317                            rnew.removeMember(i);
     318                            rnew.addMember(i, new RelationMember(member.getRole(), w));
     319                        }
    314320                    }
     321                    cmds.add(new ChangeCommand(r, rnew));
    315322                }
    316                 cmds.add(new ChangeCommand(r, rnew));
    317             }
    318             cmds.add(new DeleteCommand(addrNode));
     323                cmds.add(new DeleteCommand(addrNode));
     324            }
    319325        }
    320326        Command c = new SequenceCommand(tr("Create building"), cmds);
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/BuildingSizeAction.java

    r29771 r30045  
     1// License: GPL. For details, see LICENSE file.
    12package buildings_tools;
    23
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/BuildingSizeDialog.java

    r28529 r30045  
     1// License: GPL. For details, see LICENSE file.
    12package buildings_tools;
    23
     
    910
    1011import javax.swing.JButton;
     12import javax.swing.JCheckBox;
    1113import javax.swing.JFormattedTextField;
    12 import javax.swing.JCheckBox;
    1314
    1415import org.openstreetmap.josm.tools.GBC;
     
    5354    }
    5455
    55     public double width() {
     56    public final double width() {
    5657        try {
    5758            return NumberFormat.getInstance().parse(twidth.getText()).doubleValue();
     
    6970    }
    7071
    71     public boolean useAddr() {
     72    public final boolean useAddr() {
    7273        return caddr.isSelected();
    7374    }
    7475
    75     public void saveSettings() {
     76    public final void saveSettings() {
    7677        ToolSettings.setSizes(width(), lenstep());
    7778        ToolSettings.setAddrDialog(useAddr());
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/BuildingsToolsPlugin.java

    r29771 r30045  
     1// License: GPL. For details, see LICENSE file.
    12package buildings_tools;
    23
     
    1314
    1415public class BuildingsToolsPlugin extends Plugin {
    15     public static Projection proj = Projections.getProjectionByCode("EPSG:3857"); // Mercator
     16    public static final Projection MERCATOR = Projections.getProjectionByCode("EPSG:3857"); // Mercator
    1617
    1718    public static EastNorth latlon2eastNorth(LatLon p) {
    18         return proj.latlon2eastNorth(p);
     19        return MERCATOR.latlon2eastNorth(p);
    1920    }
    2021
    2122    public static LatLon eastNorth2latlon(EastNorth p) {
    22         return proj.eastNorth2latlon(p);
     23        return MERCATOR.eastNorth2latlon(p);
    2324    }
    2425
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/DrawBuildingAction.java

    r29595 r30045  
     1// License: GPL. For details, see LICENSE file.
    12package buildings_tools;
    23
     4import static buildings_tools.BuildingsToolsPlugin.latlon2eastNorth;
    35import static org.openstreetmap.josm.tools.I18n.marktr;
    46import static org.openstreetmap.josm.tools.I18n.tr;
    5 
    6 import static buildings_tools.BuildingsToolsPlugin.latlon2eastNorth;
    77
    88import java.awt.AWTEvent;
     
    2727import org.openstreetmap.josm.data.Bounds;
    2828import org.openstreetmap.josm.data.SelectionChangedListener;
    29 import org.openstreetmap.josm.data.coor.*;
     29import org.openstreetmap.josm.data.coor.EastNorth;
    3030import org.openstreetmap.josm.data.osm.DataSet;
    3131import org.openstreetmap.josm.data.osm.Node;
     
    4646    }
    4747
    48     final private Cursor cursorCrosshair;
    49     final private Cursor cursorJoinNode;
     48    private final Cursor cursorCrosshair;
     49    private final Cursor cursorJoinNode;
    5050    private Cursor currCursor;
    5151    private Cursor customCursor;
     
    6161    private boolean isAltDown;
    6262
    63     Building building = new Building();
     63    final Building building = new Building();
    6464
    6565    public DrawBuildingAction(MapFrame mapFrame) {
     
    8181            return ImageProvider.getCursor("crosshair", "building");
    8282        } catch (Exception e) {
     83            Main.error(e);
    8384        }
    8485        return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
     
    8687
    8788    /**
    88      * Displays the given cursor instead of the normal one
     89     * Displays the given cursor instead of the normal one.
    8990     *
    90      * @param Cursors
    91      *            One of the available cursors
     91     * @param c One of the available cursors
    9292     */
    9393    private void setCursor(final Cursor c) {
     
    107107            currCursor = c;
    108108        } catch (Exception e) {
     109            Main.error(e);
    109110        }
    110111    }
     
    118119        }
    119120        dlg.saveValues();
    120         String tmp;
    121         tmp = dlg.getHouseNum();
    122         if (tmp != null && tmp != "")
     121        String tmp = dlg.getHouseNum();
     122        if (tmp != null && !tmp.isEmpty())
    123123            w.put("addr:housenumber", tmp);
    124124        tmp = dlg.getStreetName();
    125         if (tmp != null && tmp != "")
     125        if (tmp != null && !tmp.isEmpty())
    126126            w.put("addr:street", tmp);
    127127    }
     
    143143            Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
    144144        } catch (SecurityException ex) {
     145            Main.error(ex);
    145146        }
    146147    }
     
    156157            Toolkit.getDefaultToolkit().removeAWTEventListener(this);
    157158        } catch (SecurityException ex) {
     159            Main.error(ex);
    158160        }
    159161        if (mode != Mode.None)
     
    162164    }
    163165
    164     public void cancelDrawing() {
     166    public final void cancelDrawing() {
    165167        mode = Mode.None;
    166168        if (Main.map == null || Main.map.mapView == null)
     
    192194
    193195        if (ev.getKeyCode() == KeyEvent.VK_ESCAPE && ev.getID() == KeyEvent.KEY_PRESSED) {
    194             if (mode != Mode.None)
     196            if (mode != Mode.None) {
    195197                ev.consume();
     198            }
    196199
    197200            cancelDrawing();
     
    225228            building.setPlace(p, ToolSettings.getWidth(), ToolSettings.getLenStep(), isShiftDown);
    226229            Main.map.statusLine.setDist(building.getLength());
    227             return this.nextMode = ToolSettings.getWidth() == 0 ? Mode.DrawingWidth : Mode.None;
     230            this.nextMode = ToolSettings.getWidth() == 0 ? Mode.DrawingWidth : Mode.None;
     231            return this.nextMode;
    228232        }
    229233    }
     
    258262        } else if (mode == Mode.DrawingAngFix) {
    259263            nextMode = modeDrawingAngFix();
    260         } else
     264        } else {
    261265            throw new AssertionError("Invalid drawing mode");
     266        }
    262267    }
    263268
    264269    @Override
    265270    public void paint(Graphics2D g, MapView mv, Bounds bbox) {
    266         if (mode == Mode.None)
    267             return;
    268         if (building.getLength() == 0)
    269             return;
     271        if (mode == Mode.None || building.getLength() == 0) {
     272            return;
     273        }
    270274
    271275        g.setColor(selectedColor);
     
    307311            if (w != null && ToolSettings.isUsingAddr())
    308312                showAddrDialog(w);
    309             if (ToolSettings.isAutoSelect() &&
    310                    (Main.main.getCurrentDataSet().getSelected().isEmpty() || isShiftDown)) {
     313            if (ToolSettings.isAutoSelect()
     314                 && (Main.main.getCurrentDataSet().getSelected().isEmpty() || isShiftDown)) {
    311315                Main.main.getCurrentDataSet().setSelected(w);
    312316            }
     
    400404    }
    401405
    402     public void updateSnap(Collection<? extends OsmPrimitive> newSelection) {
     406    public final void updateSnap(Collection<? extends OsmPrimitive> newSelection) {
    403407        building.clearAngleSnap();
    404408        // update snap only if selection isn't too big
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/MyDialog.java

    r24243 r30045  
     1// License: GPL. For details, see LICENSE file.
    12package buildings_tools;
    23
     
    1415import org.openstreetmap.josm.tools.GBC;
    1516
    16 public class MyDialog extends ExtendedDialog {
    17     private static final String[] buttonTexts = new String[] { tr("OK"), tr("Cancel") };
    18     private static final String[] buttonIcons = new String[] { "ok.png", "cancel.png" };
     17public abstract class MyDialog extends ExtendedDialog {
     18    private static final String[] BUTTON_TEXTS = new String[] {tr("OK"), tr("Cancel")};
     19    private static final String[] BUTTON_ICONS = new String[] {"ok.png", "cancel.png"};
    1920
    20     protected JPanel panel = new JPanel(new GridBagLayout());
     21    protected final JPanel panel = new JPanel(new GridBagLayout());
    2122
    22     protected void addLabelled(String str, Component c) {
     23    protected final void addLabelled(String str, Component c) {
    2324        JLabel label = new JLabel(str);
    2425        panel.add(label, GBC.std());
     
    2829
    2930    public MyDialog(String title) {
    30         super(Main.parent, title, buttonTexts, true);
     31        super(Main.parent, title, BUTTON_TEXTS, true);
    3132        contentInsets = new Insets(15, 15, 5, 15);
    32         setButtonIcons(buttonIcons);
     33        setButtonIcons(BUTTON_ICONS);
    3334
    3435        setContent(panel);
  • applications/editors/josm/plugins/buildings_tools/src/buildings_tools/ToolSettings.java

    r28529 r30045  
     1// License: GPL. For details, see LICENSE file.
    12package buildings_tools;
    23
     
    1314import org.openstreetmap.josm.data.preferences.BooleanProperty;
    1415
    15 public class ToolSettings {
    16     public static BooleanProperty PROP_USE_ADDR_NODE = new BooleanProperty("buildings_tools.addrNode", false);
     16public final class ToolSettings {
     17
     18    private ToolSettings() {
     19        // Hide default constructor for utils classes
     20    }
     21
     22    public static final BooleanProperty PROP_USE_ADDR_NODE = new BooleanProperty("buildings_tools.addrNode", false);
    1723    private static double width = 0;
    1824    private static double lenstep = 0;
    1925    private static boolean useAddr;
    20     private static final Map<String, String> tags = new HashMap<String, String>();
     26    private static final Map<String, String> TAGS = new HashMap<String, String>();
    2127    private static boolean autoSelect;
    2228
     
    4450    public static Map<String, String> getTags() {
    4551        loadTags();
    46         return tags;
     52        return TAGS;
    4753    }
    4854
    4955    public static void saveTags() {
    50         ArrayList<String> values = new ArrayList<String>(tags.size() * 2);
    51         for (Entry<String, String> entry : tags.entrySet()) {
     56        ArrayList<String> values = new ArrayList<String>(TAGS.size() * 2);
     57        for (Entry<String, String> entry : TAGS.entrySet()) {
    5258            values.add(entry.getKey());
    5359            values.add(entry.getValue());
     
    5763
    5864    private static void loadTags() {
    59         tags.clear();
     65        TAGS.clear();
    6066        Collection<String> values = Main.pref.getCollection("buildings_tools.tags",
    61                 Arrays.asList(new String[] { "building", "yes" }));
     67                Arrays.asList(new String[] {"building", "yes"}));
    6268        try {
    6369            for (Iterator<String> iterator = values.iterator(); iterator.hasNext();) {
    64                 tags.put(iterator.next(), iterator.next());
     70                TAGS.put(iterator.next(), iterator.next());
    6571            }
    6672        } catch (NoSuchElementException e) {
     73            Main.warn(e);
    6774        }
    68 
    6975    }
    7076
Note: See TracChangeset for help on using the changeset viewer.