diff --git a/src/org/openstreetmap/josm/plugins/shapetools/DrawableSegment.java b/src/org/openstreetmap/josm/plugins/shapetools/DrawableSegment.java index 80f60a6..c7a4775 100644 --- a/src/org/openstreetmap/josm/plugins/shapetools/DrawableSegment.java +++ b/src/org/openstreetmap/josm/plugins/shapetools/DrawableSegment.java @@ -16,7 +16,6 @@ /** * Base class used for adding colored segments on map as temporary MapViewPaintables * @author Adrian_antochi - * */ public class DrawableSegment implements MapViewPaintable { @@ -24,6 +23,10 @@ public class DrawableSegment implements MapViewPaintable { protected Color color; protected Stroke stroke; + /** + * Constructs a new {@code DrawableSegment}. + * @param segment way segment + */ public DrawableSegment(WaySegment segment) { int strokeThickness = 3; this.segment = segment; @@ -31,6 +34,11 @@ public DrawableSegment(WaySegment segment) { this.stroke = new BasicStroke(strokeThickness); } + /** + * Constructs a new {@code DrawableSegment}. + * @param segment way segment + * @param color color + */ public DrawableSegment(WaySegment segment, Color color) { int strokeThickness = 3; this.segment = segment; @@ -41,8 +49,8 @@ public DrawableSegment(WaySegment segment, Color color) { @Override public void paint(Graphics2D g, MapView mv, Bounds bbox) { if (segment != null) { - g.setColor(this.color); - g.setStroke(this.stroke); + g.setColor(color); + g.setStroke(stroke); Node firstNode = segment.getFirstNode(); Node secondNode = segment.getSecondNode(); @@ -67,7 +75,6 @@ public void setSegment(WaySegment segment) { } public WaySegment getSegment() { - return this.segment; + return segment; } - } diff --git a/src/org/openstreetmap/josm/plugins/shapetools/DrawableSegmentBuilding.java b/src/org/openstreetmap/josm/plugins/shapetools/DrawableSegmentBuilding.java index 5c67f20..bb0c55f 100644 --- a/src/org/openstreetmap/josm/plugins/shapetools/DrawableSegmentBuilding.java +++ b/src/org/openstreetmap/josm/plugins/shapetools/DrawableSegmentBuilding.java @@ -4,13 +4,17 @@ import java.awt.Color; import org.openstreetmap.josm.data.osm.WaySegment; + /** * Adding this as a temporary layer on mapview will color the selected segment green * @author Adrian_antochi - * */ public class DrawableSegmentBuilding extends DrawableSegment { + /** + * Constructs a new {@code DrawableSegmentBuilding}. + * @param segment way segment + */ public DrawableSegmentBuilding(WaySegment segment) { super(segment); this.color = Color.GREEN; diff --git a/src/org/openstreetmap/josm/plugins/shapetools/DrawableSegmentRoad.java b/src/org/openstreetmap/josm/plugins/shapetools/DrawableSegmentRoad.java index ad757f0..96dc03a 100644 --- a/src/org/openstreetmap/josm/plugins/shapetools/DrawableSegmentRoad.java +++ b/src/org/openstreetmap/josm/plugins/shapetools/DrawableSegmentRoad.java @@ -4,6 +4,7 @@ import java.awt.Color; import org.openstreetmap.josm.data.osm.WaySegment; + /** * Adding this as a temporary layer on mapview will color the selected segment yellow * @author Adrian_antochi @@ -11,9 +12,12 @@ */ public class DrawableSegmentRoad extends DrawableSegment { + /** + * Constructs a new {@code DrawableSegmentRoad}. + * @param segment way segment + */ public DrawableSegmentRoad(WaySegment segment) { super(segment); this.color = Color.YELLOW; } - } diff --git a/src/org/openstreetmap/josm/plugins/shapetools/DrawableWay.java b/src/org/openstreetmap/josm/plugins/shapetools/DrawableWay.java deleted file mode 100644 index e75a6b2..0000000 --- a/src/org/openstreetmap/josm/plugins/shapetools/DrawableWay.java +++ /dev/null @@ -1,84 +0,0 @@ -// License: GPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.shapetools; - -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Graphics2D; -import java.awt.Stroke; -import java.awt.geom.Line2D; -import java.util.List; - -import org.openstreetmap.josm.data.Bounds; -import org.openstreetmap.josm.data.osm.Node; -import org.openstreetmap.josm.data.osm.Way; -import org.openstreetmap.josm.gui.MapView; -import org.openstreetmap.josm.gui.layer.MapViewPaintable; - -/** - * Adding this as a temporary layer on mapview will color the selected way white - * - * @author Adrian_antochi - * - */ -public class DrawableWay implements MapViewPaintable { - - private Color color; - private Stroke stroke; - private Way way; - - public DrawableWay() { - int strokeThicknes = 5; - this.color = Color.WHITE; - this.stroke = new BasicStroke(strokeThicknes); - } - - public DrawableWay(Way way) { - this(); - this.way = way; - } - - public DrawableWay(Way way, Color color) { - this(); - this.color = color; - this.way = way; - } - - @Override - public void paint(Graphics2D g, MapView mv, Bounds bbox) { - - if (way != null) { - g.setStroke(stroke); - g.setColor(color); - List wayNodes = way.getNodes(); - for (int i = 0; i < wayNodes.size() - 1; i++) { - Line2D overlappingLine = new Line2D.Double(mv.getPoint(wayNodes.get(i)).getX(), mv.getPoint(wayNodes.get(i)).getY(), mv.getPoint( - wayNodes.get(i + 1)).getX(), mv.getPoint(wayNodes.get(i + 1)).getY()); - g.draw(overlappingLine); - } - } - } - - public Color getWayColor() { - return color; - } - - public void setWayColor(Color wayColor) { - this.color = wayColor; - } - - public Stroke getStroke() { - return stroke; - } - - public void setStroke(Stroke stroke) { - this.stroke = stroke; - } - - public Way getWay() { - return way; - } - - public void setWay(Way way) { - this.way = way; - } -} diff --git a/src/org/openstreetmap/josm/plugins/shapetools/Point.java b/src/org/openstreetmap/josm/plugins/shapetools/Point.java index 572fd0a..5877f9a 100644 --- a/src/org/openstreetmap/josm/plugins/shapetools/Point.java +++ b/src/org/openstreetmap/josm/plugins/shapetools/Point.java @@ -20,10 +20,6 @@ public Point(double x, double y) { this.y = y; } - public static double distance(Point x1, Point x2) { - return Math.sqrt(Math.pow(x2.x - x1.x, 2) + Math.pow(x2.y - x1.y, 2)); // always positive - } - public static double distance(Point lineX1, Point lineX2, Point p) { double A = p.x - lineX1.x; double B = p.y - lineX1.y; diff --git a/src/org/openstreetmap/josm/plugins/shapetools/ShapeMath.java b/src/org/openstreetmap/josm/plugins/shapetools/ShapeMath.java index ec23983..2a613e7 100644 --- a/src/org/openstreetmap/josm/plugins/shapetools/ShapeMath.java +++ b/src/org/openstreetmap/josm/plugins/shapetools/ShapeMath.java @@ -169,21 +169,6 @@ public static EastNorth getCentroid(WaySegment segment) { return new EastNorth(x, y); } - /** - * @return center-point of a list of ways - */ - public static EastNorth getCentroid(List wayList) { - double x = 0, y = 0; - for (int i = 0; i < wayList.size(); i++) { - EastNorth currentCenter = getCentroid(wayList.get(i)); - x += currentCenter.getX(); - y += currentCenter.getY(); - } - x = x / wayList.size(); - y = y / wayList.size(); - return new EastNorth(x, y); - } - /** * @return center-point of a set of nodes */ @@ -275,30 +260,6 @@ public static void align(WaySegment roadSegment, WaySegment toRotateSegment) { Main.map.repaint(); } - /** - * Aligns a way to a segment, mostly used to align a building to a road segment - */ - public static void align(WaySegment roadSegment, Way building) { - WaySegment closestSegment = ShapeMath.getClosestSegment(building, roadSegment); - double x1 = roadSegment.getFirstNode().getEastNorth().getX(); - double x2 = roadSegment.getSecondNode().getEastNorth().getX(); - double x3 = closestSegment.getFirstNode().getEastNorth().getX(); - double x4 = closestSegment.getSecondNode().getEastNorth().getX(); - double y1 = roadSegment.getFirstNode().getEastNorth().getY(); - double y2 = roadSegment.getSecondNode().getEastNorth().getY(); - double y3 = closestSegment.getFirstNode().getEastNorth().getY(); - double y4 = closestSegment.getSecondNode().getEastNorth().getY(); - - double requiredAngle = Math.atan2(y2 - y1, x2 - x1) - Math.atan2(y4 - y3, x4 - x3); - System.out.println("Angle calculated from align() " + requiredAngle); - - requiredAngle = normalise(requiredAngle); - - SequenceCommand commands = new SequenceCommand("aligningBuilding", rotate(building, requiredAngle, getCentroid(building))); - Main.main.undoRedo.add(commands); - Main.map.repaint(); - } - /** * Aligns the building only if the distance between the closest wall of the building and it's closest road-segment is smaller than epsilon */ diff --git a/src/org/openstreetmap/josm/plugins/shapetools/ShapeMode.java b/src/org/openstreetmap/josm/plugins/shapetools/ShapeMode.java index ec626de..00262a7 100644 --- a/src/org/openstreetmap/josm/plugins/shapetools/ShapeMode.java +++ b/src/org/openstreetmap/josm/plugins/shapetools/ShapeMode.java @@ -15,16 +15,16 @@ import org.openstreetmap.josm.gui.MapFrame; public class ShapeMode extends MapMode { - MapFrame thisMapFrame; - WaySegment firstSegment; - WaySegment secondSegment; static ButtonGroup group; static DrawableSegmentBuilding buildingSegm; static DrawableSegmentRoad roadSegm; + /** + * Constructs a new {@code ShapeMode}. + * @param mapFrame map frame + */ public ShapeMode(MapFrame mapFrame) { super("ShapeMode", "mode.png", "shapeModeTooltip", mapFrame, Cursor.getDefaultCursor()); - thisMapFrame = mapFrame; } @Override diff --git a/src/org/openstreetmap/josm/plugins/shapetools/ShapePanelDialog.java b/src/org/openstreetmap/josm/plugins/shapetools/ShapePanelDialog.java index 171d487..2b19f56 100644 --- a/src/org/openstreetmap/josm/plugins/shapetools/ShapePanelDialog.java +++ b/src/org/openstreetmap/josm/plugins/shapetools/ShapePanelDialog.java @@ -23,8 +23,10 @@ * */ public class ShapePanelDialog extends ToggleDialog { - JPanel dialogPane; + /** + * Constructs a new {@code ShapePanelDialog}. + */ public ShapePanelDialog() { super(tr("Shape actions panel"), "shapePanelButton.png", tr("Shape mode control panel"), null, 70); diff --git a/src/org/openstreetmap/josm/plugins/shapetools/ShapeToolsAction.java b/src/org/openstreetmap/josm/plugins/shapetools/ShapeToolsAction.java deleted file mode 100644 index 372f324..0000000 --- a/src/org/openstreetmap/josm/plugins/shapetools/ShapeToolsAction.java +++ /dev/null @@ -1,40 +0,0 @@ -// License: GPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.shapetools; - -import static org.openstreetmap.josm.tools.I18n.tr; - -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; - -import javax.swing.JDialog; -import javax.swing.JOptionPane; - -import org.openstreetmap.josm.Main; -import org.openstreetmap.josm.actions.JosmAction; -import org.openstreetmap.josm.tools.Shortcut; - -/** - * @author ignacio_palermo - * - */ -public class ShapeToolsAction extends JosmAction { - - public ShapeToolsAction() { - super(tr("GetNodes"), null, - tr("Displays a dialog containing loaded nodes"), Shortcut - .registerShortcut("menu:shapeTool", - tr("Menu: {0}", tr("ShapeTool one")), - KeyEvent.VK_NUMPAD3, Shortcut.CTRL), false); - } - - @Override - public void actionPerformed(ActionEvent arg0) { - ShapeToolsDialog dialog = new ShapeToolsDialog(); - JOptionPane pane = new JOptionPane(dialog, JOptionPane.PLAIN_MESSAGE, - JOptionPane.OK_CANCEL_OPTION); - JDialog dlg = pane.createDialog(Main.parent, tr("LoadNodes")); - dlg.setVisible(true); - dialog.setVisible(true); - } - -} diff --git a/src/org/openstreetmap/josm/plugins/shapetools/ShapeToolsDialog.java b/src/org/openstreetmap/josm/plugins/shapetools/ShapeToolsDialog.java deleted file mode 100644 index 169ff48..0000000 --- a/src/org/openstreetmap/josm/plugins/shapetools/ShapeToolsDialog.java +++ /dev/null @@ -1,55 +0,0 @@ -// License: GPL. For details, see LICENSE file. -package org.openstreetmap.josm.plugins.shapetools; - -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JTextField; - -import org.openstreetmap.josm.data.osm.Node; - -public class ShapeToolsDialog extends JPanel { // Temporarily not used - - static JList currentNodeList; - static JTextField angleInput; - static JComboBox directionComboBox; - static JButton rotButton; - static JButton centrButton; - static JButton alignButton; - static JButton alignBuildingButton; - static JButton getNearestSegment; - static JButton alignAllBuildings; - static JTextField epsilonInput; - - public ShapeToolsDialog() { - currentNodeList = null; - angleInput = new JTextField(); - directionComboBox = new JComboBox<>(new String[] {"Clockwise", "AntiClockwise"}); - setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - rotButton = new JButton("Rotate"); - centrButton = new JButton("DrawCenter"); - alignButton = new JButton("Align"); - alignBuildingButton = new JButton("AlignBuilding"); - getNearestSegment = new JButton("NearestSegment"); - alignAllBuildings = new JButton("AlignBuildings"); - epsilonInput = new JTextField(); - - rotButton.addMouseListener(ShapeEvents.getInstance().getRotateEvent(directionComboBox, angleInput)); - alignButton.addMouseListener(ShapeEvents.getInstance().getAlign()); - alignBuildingButton.addMouseListener(ShapeEvents.getInstance().getAlignBuildingEvent()); - getNearestSegment.addMouseListener(ShapeEvents.getInstance().getAlignBuildingEvent()); - alignAllBuildings.addMouseListener(ShapeEvents.getInstance().getAlignAllBuildings(epsilonInput)); - - add(rotButton); - add(centrButton); - add(alignButton); - add(alignBuildingButton); - add(getNearestSegment); - add(angleInput); - add(directionComboBox); - add(epsilonInput); - add(alignAllBuildings); - } -} diff --git a/src/org/openstreetmap/josm/plugins/shapetools/ShapeToolsPlugin.java b/src/org/openstreetmap/josm/plugins/shapetools/ShapeToolsPlugin.java index ca9d657..96f54fd 100644 --- a/src/org/openstreetmap/josm/plugins/shapetools/ShapeToolsPlugin.java +++ b/src/org/openstreetmap/josm/plugins/shapetools/ShapeToolsPlugin.java @@ -20,7 +20,11 @@ public class ShapeToolsPlugin extends Plugin { @SuppressWarnings("unused") private static IconToggleButton optButton; - public ShapeToolsPlugin(PluginInformation info) { + /** + * Constructs a new {@code ShapeToolsPlugin}. + * @param info plugin information + */ + public ShapeToolsPlugin(PluginInformation info) { // NO_UCD (unused code) super(info); sDialog = new ShapePanelDialog(); }