Changeset 30045 in osm for applications/editors/josm/plugins/buildings_tools
- Timestamp:
- 2013-11-07T13:37:16+01:00 (11 years ago)
- 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. 1 2 package buildings_tools; 2 3 … … 49 50 } 50 51 51 public void saveValues() {52 public final void saveValues() { 52 53 lhousenum = housenum.getText(); 53 54 lstreetname = streetname.getText(); … … 55 56 } 56 57 57 public String getHouseNum() {58 public final String getHouseNum() { 58 59 return housenum.getText(); 59 60 } 60 61 61 public String getStreetName() {62 public final String getStreetName() { 62 63 return streetname.getText(); 63 64 } -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/AdvancedSettingsDialog.java
r30010 r30045 1 // License: GPL. For details, see LICENSE file. 1 2 package buildings_tools; 2 3 … … 38 39 } 39 40 40 public void saveSettings() {41 public final void saveSettings() { 41 42 tagsModel.applyToTags(ToolSettings.getTags(), false); 42 43 ToolSettings.saveTags(); -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/AngleSnap.java
r23190 r30045 1 // License: GPL. For details, see LICENSE file. 1 2 package buildings_tools; 2 3 … … 12 13 public class AngleSnap { 13 14 private static final double PI_2 = Math.PI / 2; 14 TreeSet<Double> snapSet = new TreeSet<Double>();15 final TreeSet<Double> snapSet = new TreeSet<Double>(); 15 16 16 public void clear() {17 public final void clear() { 17 18 snapSet.clear(); 18 19 } 19 20 20 public void addSnap(double snap) {21 public final void addSnap(double snap) { 21 22 snapSet.add(snap % PI_2); 22 23 } 23 24 24 public Double addSnap(Node[] nodes) {25 public final Double addSnap(Node[] nodes) { 25 26 if (nodes.length == 2) { 26 27 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()); 29 30 double heading = p1.heading(p2); 30 31 addSnap(heading); … … 36 37 } 37 38 38 public void addSnap(Way way) {39 public final void addSnap(Way way) { 39 40 for (Pair<Node, Node> pair : way.getNodePairs(false)) { 40 41 EastNorth a, b; … … 46 47 } 47 48 48 public Double getAngle() {49 public final Double getAngle() { 49 50 if (snapSet.isEmpty()) { 50 51 return null; … … 65 66 } 66 67 67 public double snapAngle(double angle) {68 public final double snapAngle(double angle) { 68 69 if (snapSet.isEmpty()) { 69 70 return angle; -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/Building.java
r25905 r30045 1 // License: GPL. For details, see LICENSE file. 1 2 package buildings_tools; 2 3 import static org.openstreetmap.josm.tools.I18n.tr;4 3 5 4 import static buildings_tools.BuildingsToolsPlugin.eastNorth2latlon; 6 5 import static buildings_tools.BuildingsToolsPlugin.latlon2eastNorth; 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 7 8 8 import java.awt.Graphics2D; … … 22 22 import org.openstreetmap.josm.command.DeleteCommand; 23 23 import org.openstreetmap.josm.command.SequenceCommand; 24 import org.openstreetmap.josm.data.coor.*; 24 import org.openstreetmap.josm.data.coor.EastNorth; 25 import org.openstreetmap.josm.data.coor.LatLon; 25 26 import org.openstreetmap.josm.data.osm.BBox; 26 27 import org.openstreetmap.josm.data.osm.DataSet; … … 103 104 104 105 /** 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 106 108 */ 107 109 private double projection1(EastNorth p) { … … 111 113 112 114 /** 113 * @return sProjection of the point to the perpendicular of the heading115 * @return Projection of the point to the perpendicular of the heading 114 116 * vector in metres 117 * @param p The point to project 115 118 */ 116 119 private double projection2(EastNorth p) { … … 203 206 } 204 207 205 private Node findNode(EastNorth en) {208 private Node findNode(EastNorth pos) { 206 209 DataSet ds = Main.main.getCurrentDataSet(); 207 LatLon l = eastNorth2latlon( en);210 LatLon l = eastNorth2latlon(pos); 208 211 List<Node> nodes = ds.searchNodes(new BBox(l.lon() - 0.0000001, l.lat() - 0.0000001, 209 212 l.lon() + 0.0000001, l.lat() + 0.0000001)); … … 221 224 222 225 /** 223 * Returns a node with address tags under the building 226 * Returns a node with address tags under the building. 224 227 * 225 * @return 228 * @return A node with address tags under the building. 226 229 */ 227 230 private Node getAddressNode() { … … 299 302 w.setKeys(ToolSettings.getTags()); 300 303 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 } 314 320 } 321 cmds.add(new ChangeCommand(r, rnew)); 315 322 } 316 cmds.add(new ChangeCommand(r, rnew)); 317 } 318 cmds.add(new DeleteCommand(addrNode)); 323 cmds.add(new DeleteCommand(addrNode)); 324 } 319 325 } 320 326 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. 1 2 package buildings_tools; 2 3 -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/BuildingSizeDialog.java
r28529 r30045 1 // License: GPL. For details, see LICENSE file. 1 2 package buildings_tools; 2 3 … … 9 10 10 11 import javax.swing.JButton; 12 import javax.swing.JCheckBox; 11 13 import javax.swing.JFormattedTextField; 12 import javax.swing.JCheckBox;13 14 14 15 import org.openstreetmap.josm.tools.GBC; … … 53 54 } 54 55 55 public double width() {56 public final double width() { 56 57 try { 57 58 return NumberFormat.getInstance().parse(twidth.getText()).doubleValue(); … … 69 70 } 70 71 71 public boolean useAddr() {72 public final boolean useAddr() { 72 73 return caddr.isSelected(); 73 74 } 74 75 75 public void saveSettings() {76 public final void saveSettings() { 76 77 ToolSettings.setSizes(width(), lenstep()); 77 78 ToolSettings.setAddrDialog(useAddr()); -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/BuildingsToolsPlugin.java
r29771 r30045 1 // License: GPL. For details, see LICENSE file. 1 2 package buildings_tools; 2 3 … … 13 14 14 15 public class BuildingsToolsPlugin extends Plugin { 15 public static Projection proj= Projections.getProjectionByCode("EPSG:3857"); // Mercator16 public static final Projection MERCATOR = Projections.getProjectionByCode("EPSG:3857"); // Mercator 16 17 17 18 public static EastNorth latlon2eastNorth(LatLon p) { 18 return proj.latlon2eastNorth(p);19 return MERCATOR.latlon2eastNorth(p); 19 20 } 20 21 21 22 public static LatLon eastNorth2latlon(EastNorth p) { 22 return proj.eastNorth2latlon(p);23 return MERCATOR.eastNorth2latlon(p); 23 24 } 24 25 -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/DrawBuildingAction.java
r29595 r30045 1 // License: GPL. For details, see LICENSE file. 1 2 package buildings_tools; 2 3 4 import static buildings_tools.BuildingsToolsPlugin.latlon2eastNorth; 3 5 import static org.openstreetmap.josm.tools.I18n.marktr; 4 6 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import static buildings_tools.BuildingsToolsPlugin.latlon2eastNorth;7 7 8 8 import java.awt.AWTEvent; … … 27 27 import org.openstreetmap.josm.data.Bounds; 28 28 import org.openstreetmap.josm.data.SelectionChangedListener; 29 import org.openstreetmap.josm.data.coor. *;29 import org.openstreetmap.josm.data.coor.EastNorth; 30 30 import org.openstreetmap.josm.data.osm.DataSet; 31 31 import org.openstreetmap.josm.data.osm.Node; … … 46 46 } 47 47 48 final privateCursor cursorCrosshair;49 final privateCursor cursorJoinNode;48 private final Cursor cursorCrosshair; 49 private final Cursor cursorJoinNode; 50 50 private Cursor currCursor; 51 51 private Cursor customCursor; … … 61 61 private boolean isAltDown; 62 62 63 Building building = new Building();63 final Building building = new Building(); 64 64 65 65 public DrawBuildingAction(MapFrame mapFrame) { … … 81 81 return ImageProvider.getCursor("crosshair", "building"); 82 82 } catch (Exception e) { 83 Main.error(e); 83 84 } 84 85 return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); … … 86 87 87 88 /** 88 * Displays the given cursor instead of the normal one 89 * Displays the given cursor instead of the normal one. 89 90 * 90 * @param Cursors 91 * One of the available cursors 91 * @param c One of the available cursors 92 92 */ 93 93 private void setCursor(final Cursor c) { … … 107 107 currCursor = c; 108 108 } catch (Exception e) { 109 Main.error(e); 109 110 } 110 111 } … … 118 119 } 119 120 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()) 123 123 w.put("addr:housenumber", tmp); 124 124 tmp = dlg.getStreetName(); 125 if (tmp != null && tmp != "")125 if (tmp != null && !tmp.isEmpty()) 126 126 w.put("addr:street", tmp); 127 127 } … … 143 143 Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK); 144 144 } catch (SecurityException ex) { 145 Main.error(ex); 145 146 } 146 147 } … … 156 157 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 157 158 } catch (SecurityException ex) { 159 Main.error(ex); 158 160 } 159 161 if (mode != Mode.None) … … 162 164 } 163 165 164 public void cancelDrawing() {166 public final void cancelDrawing() { 165 167 mode = Mode.None; 166 168 if (Main.map == null || Main.map.mapView == null) … … 192 194 193 195 if (ev.getKeyCode() == KeyEvent.VK_ESCAPE && ev.getID() == KeyEvent.KEY_PRESSED) { 194 if (mode != Mode.None) 196 if (mode != Mode.None) { 195 197 ev.consume(); 198 } 196 199 197 200 cancelDrawing(); … … 225 228 building.setPlace(p, ToolSettings.getWidth(), ToolSettings.getLenStep(), isShiftDown); 226 229 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; 228 232 } 229 233 } … … 258 262 } else if (mode == Mode.DrawingAngFix) { 259 263 nextMode = modeDrawingAngFix(); 260 } else 264 } else { 261 265 throw new AssertionError("Invalid drawing mode"); 266 } 262 267 } 263 268 264 269 @Override 265 270 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 } 270 274 271 275 g.setColor(selectedColor); … … 307 311 if (w != null && ToolSettings.isUsingAddr()) 308 312 showAddrDialog(w); 309 if (ToolSettings.isAutoSelect() &&310 313 if (ToolSettings.isAutoSelect() 314 && (Main.main.getCurrentDataSet().getSelected().isEmpty() || isShiftDown)) { 311 315 Main.main.getCurrentDataSet().setSelected(w); 312 316 } … … 400 404 } 401 405 402 public void updateSnap(Collection<? extends OsmPrimitive> newSelection) {406 public final void updateSnap(Collection<? extends OsmPrimitive> newSelection) { 403 407 building.clearAngleSnap(); 404 408 // 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. 1 2 package buildings_tools; 2 3 … … 14 15 import org.openstreetmap.josm.tools.GBC; 15 16 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"};17 public 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"}; 19 20 20 protected JPanel panel = new JPanel(new GridBagLayout());21 protected final JPanel panel = new JPanel(new GridBagLayout()); 21 22 22 protected void addLabelled(String str, Component c) {23 protected final void addLabelled(String str, Component c) { 23 24 JLabel label = new JLabel(str); 24 25 panel.add(label, GBC.std()); … … 28 29 29 30 public MyDialog(String title) { 30 super(Main.parent, title, buttonTexts, true);31 super(Main.parent, title, BUTTON_TEXTS, true); 31 32 contentInsets = new Insets(15, 15, 5, 15); 32 setButtonIcons( buttonIcons);33 setButtonIcons(BUTTON_ICONS); 33 34 34 35 setContent(panel); -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/ToolSettings.java
r28529 r30045 1 // License: GPL. For details, see LICENSE file. 1 2 package buildings_tools; 2 3 … … 13 14 import org.openstreetmap.josm.data.preferences.BooleanProperty; 14 15 15 public class ToolSettings { 16 public static BooleanProperty PROP_USE_ADDR_NODE = new BooleanProperty("buildings_tools.addrNode", false); 16 public 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); 17 23 private static double width = 0; 18 24 private static double lenstep = 0; 19 25 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>(); 21 27 private static boolean autoSelect; 22 28 … … 44 50 public static Map<String, String> getTags() { 45 51 loadTags(); 46 return tags;52 return TAGS; 47 53 } 48 54 49 55 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()) { 52 58 values.add(entry.getKey()); 53 59 values.add(entry.getValue()); … … 57 63 58 64 private static void loadTags() { 59 tags.clear();65 TAGS.clear(); 60 66 Collection<String> values = Main.pref.getCollection("buildings_tools.tags", 61 Arrays.asList(new String[] { "building", "yes"}));67 Arrays.asList(new String[] {"building", "yes"})); 62 68 try { 63 69 for (Iterator<String> iterator = values.iterator(); iterator.hasNext();) { 64 tags.put(iterator.next(), iterator.next());70 TAGS.put(iterator.next(), iterator.next()); 65 71 } 66 72 } catch (NoSuchElementException e) { 73 Main.warn(e); 67 74 } 68 69 75 } 70 76
Note:
See TracChangeset
for help on using the changeset viewer.