Changeset 33735 in osm for applications
- Timestamp:
- 2017-10-27T01:25:40+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins/buildings_tools
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/buildings_tools/build.xml
r32680 r33735 4 4 <property name="commit.message" value="BuildingTools: Alt key to disable tags"/> 5 5 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 6 <property name="plugin.main.version" value="1 0580"/>6 <property name="plugin.main.version" value="12987"/> 7 7 8 8 <!-- Configure these properties (replace "..." accordingly). -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/Building.java
r32728 r33735 32 32 import org.openstreetmap.josm.data.osm.RelationMember; 33 33 import org.openstreetmap.josm.data.osm.Way; 34 import org.openstreetmap.josm.gui.MainApplication; 34 35 import org.openstreetmap.josm.gui.MapView; 35 36 … … 161 162 updatePos(); 162 163 163 Main .map.statusLine.setHeading(Math.toDegrees(heading));164 MainApplication.getMap().statusLine.setHeading(Math.toDegrees(heading)); 164 165 if (this.drawingAngle != null && !ignoreConstraints) { 165 166 double ang = Math.toDegrees(heading - this.drawingAngle); … … 168 169 if (ang > 360) 169 170 ang -= 360; 170 Main .map.statusLine.setAngle(ang);171 MainApplication.getMap().statusLine.setAngle(ang); 171 172 } 172 173 } … … 179 180 heading = drawingAngle; 180 181 setLengthWidth(projection1(p2), projection2(p2)); 181 Main .map.statusLine.setHeading(Math.toDegrees(heading));182 MainApplication.getMap().statusLine.setHeading(Math.toDegrees(heading)); 182 183 } 183 184 … … 210 211 211 212 private Node findNode(EastNorth pos) { 212 DataSet ds = Main .getLayerManager().getEditDataSet();213 DataSet ds = MainApplication.getLayerManager().getEditDataSet(); 213 214 LatLon l = eastNorth2latlon(pos); 214 215 List<Node> nodes = ds.searchNodes(new BBox(l.lon() - 0.0000001, l.lat() - 0.0000001, … … 237 238 List<Node> nodes = new LinkedList<>(); 238 239 nodesloop: 239 for (Node n : Main .getLayerManager().getEditDataSet().searchNodes(bbox)) {240 for (Node n : MainApplication.getLayerManager().getEditDataSet().searchNodes(bbox)) { 240 241 if (!n.isUsable()) 241 242 continue; … … 298 299 } 299 300 w.addNode(nodes[0]); 301 DataSet ds = MainApplication.getLayerManager().getEditDataSet(); 300 302 Collection<Command> cmds = new LinkedList<>(); 301 303 for (int i = 0; i < 4; i++) { 302 304 if (created[i]) 303 cmds.add(new AddCommand( nodes[i]));304 } 305 cmds.add(new AddCommand( w));305 cmds.add(new AddCommand(ds, nodes[i])); 306 } 307 cmds.add(new AddCommand(ds, w)); 306 308 307 309 if (ToolSettings.PROP_USE_ADDR_NODE.get()) { -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/BuildingsToolsPlugin.java
r31098 r33735 2 2 package buildings_tools; 3 3 4 import org.openstreetmap.josm.Main; 4 import javax.swing.JMenu; 5 5 6 import org.openstreetmap.josm.data.coor.EastNorth; 6 7 import org.openstreetmap.josm.data.coor.LatLon; … … 8 9 import org.openstreetmap.josm.data.projection.Projections; 9 10 import org.openstreetmap.josm.gui.IconToggleButton; 11 import org.openstreetmap.josm.gui.MainApplication; 10 12 import org.openstreetmap.josm.gui.MainMenu; 11 13 import org.openstreetmap.josm.gui.MapFrame; … … 26 28 public BuildingsToolsPlugin(PluginInformation info) { 27 29 super(info); 28 MainMenu.add(Main.main.menu.dataMenu, new BuildingSizeAction()); 29 MainMenu.add(Main.main.menu.dataMenu, new MergeAddrPointsAction()); 30 JMenu dataMenu = MainApplication.getMenu().dataMenu; 31 MainMenu.add(dataMenu, new BuildingSizeAction()); 32 MainMenu.add(dataMenu, new MergeAddrPointsAction()); 30 33 } 31 34 … … 33 36 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 34 37 if (oldFrame == null && newFrame != null) { 35 Main .map.addMapMode(new IconToggleButton(new DrawBuildingAction(Main.map)));38 MainApplication.getMap().addMapMode(new IconToggleButton(new DrawBuildingAction())); 36 39 } 37 40 } -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/DrawBuildingAction.java
r32944 r33735 22 22 import java.util.Map.Entry; 23 23 24 import org.openstreetmap.josm.Main;25 24 import org.openstreetmap.josm.actions.mapmode.MapMode; 26 25 import org.openstreetmap.josm.data.Bounds; … … 31 30 import org.openstreetmap.josm.data.osm.OsmPrimitive; 32 31 import org.openstreetmap.josm.data.osm.Way; 33 import org.openstreetmap.josm.data.preferences.ColorProperty; 32 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 33 import org.openstreetmap.josm.gui.MainApplication; 34 34 import org.openstreetmap.josm.gui.MapFrame; 35 35 import org.openstreetmap.josm.gui.MapView; … … 38 38 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 39 39 import org.openstreetmap.josm.gui.util.KeyPressReleaseListener; 40 import org.openstreetmap.josm.gui.util.Modifier Listener;40 import org.openstreetmap.josm.gui.util.ModifierExListener; 41 41 import org.openstreetmap.josm.tools.ImageProvider; 42 import org.openstreetmap.josm.tools.Logging; 42 43 import org.openstreetmap.josm.tools.Shortcut; 43 44 44 45 @SuppressWarnings("serial") 45 46 public class DrawBuildingAction extends MapMode implements MapViewPaintable, SelectionChangedListener, 46 KeyPressReleaseListener, Modifier Listener {47 KeyPressReleaseListener, ModifierExListener { 47 48 private enum Mode { 48 49 None, Drawing, DrawingWidth, DrawingAngFix … … 63 64 final Building building = new Building(); 64 65 65 public DrawBuildingAction( MapFrame mapFrame) {66 public DrawBuildingAction() { 66 67 super(tr("Draw buildings"), "building", tr("Draw buildings"), 67 68 Shortcut.registerShortcut("mapmode:buildings", 68 69 tr("Mode: {0}", tr("Draw buildings")), 69 70 KeyEvent.VK_B, Shortcut.DIRECT), 70 mapFrame,getCursor());71 getCursor()); 71 72 72 73 cursorCrosshair = getCursor(); … … 79 80 return ImageProvider.getCursor("crosshair", "building"); 80 81 } catch (Exception e) { 81 Main.error(e);82 Logging.error(e); 82 83 } 83 84 return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); … … 94 95 try { 95 96 // We invoke this to prevent strange things from happening 96 EventQueue.invokeLater(new Runnable() { 97 @Override 98 public void run() { 99 // Don't change cursor when mode has changed already 100 if (!(Main.map.mapMode instanceof DrawBuildingAction)) 101 return; 102 Main.map.mapView.setCursor(c); 103 } 97 EventQueue.invokeLater(() -> { 98 MapFrame map = MainApplication.getMap(); 99 // Don't change cursor when mode has changed already 100 if (!(map.mapMode instanceof DrawBuildingAction)) 101 return; 102 map.mapView.setCursor(c); 104 103 }); 105 104 currCursor = c; 106 105 } catch (Exception e) { 107 Main.error(e);106 Logging.error(e); 108 107 } 109 108 } … … 128 127 public void enterMode() { 129 128 super.enterMode(); 129 MapFrame map = MainApplication.getMap(); 130 130 if (getLayerManager().getEditDataSet() == null) { 131 Main.map.selectSelectTool(false);132 return; 133 } 134 selectedColor = new ColorProperty(marktr("selected"), selectedColor).get();131 map.selectSelectTool(false); 132 return; 133 } 134 selectedColor = new NamedColorProperty(marktr("selected"), selectedColor).get(); 135 135 currCursor = cursorCrosshair; 136 Main.map.mapView.addMouseListener(this);137 Main.map.mapView.addMouseMotionListener(this);138 Main.map.mapView.addTemporaryLayer(this);139 Main.map.keyDetector.addKeyListener(this);140 Main.map.keyDetector.addModifierListener(this);136 map.mapView.addMouseListener(this); 137 map.mapView.addMouseMotionListener(this); 138 map.mapView.addTemporaryLayer(this); 139 map.keyDetector.addKeyListener(this); 140 map.keyDetector.addModifierExListener(this); 141 141 DataSet.addSelectionListener(this); 142 142 updateSnap(getLayerManager().getEditDataSet().getSelected()); … … 146 146 public void exitMode() { 147 147 super.exitMode(); 148 Main.map.mapView.removeMouseListener(this); 149 Main.map.mapView.removeMouseMotionListener(this); 150 Main.map.mapView.removeTemporaryLayer(this); 151 Main.map.keyDetector.removeKeyListener(this); 152 Main.map.keyDetector.removeModifierListener(this); 148 MapFrame map = MainApplication.getMap(); 149 map.mapView.removeMouseListener(this); 150 map.mapView.removeMouseMotionListener(this); 151 map.mapView.removeTemporaryLayer(this); 152 map.keyDetector.removeKeyListener(this); 153 map.keyDetector.removeModifierExListener(this); 153 154 DataSet.removeSelectionListener(this); 154 155 if (mode != Mode.None) 155 Main.map.mapView.repaint();156 map.mapView.repaint(); 156 157 mode = Mode.None; 157 158 } … … 159 160 public final void cancelDrawing() { 160 161 mode = Mode.None; 161 if (Main.map == null || Main.map.mapView == null) 162 return; 163 Main.map.statusLine.setHeading(-1); 164 Main.map.statusLine.setAngle(-1); 162 MapFrame map = MainApplication.getMap(); 163 if (map == null || map.mapView == null) 164 return; 165 map.statusLine.setHeading(-1); 166 map.statusLine.setAngle(-1); 165 167 building.reset(); 166 Main.map.mapView.repaint();168 map.mapView.repaint(); 167 169 updateStatusLine(); 168 170 } 169 171 170 172 @Override 171 public void modifiers Changed(int modifiers) {173 public void modifiersExChanged(int modifiers) { 172 174 boolean oldCtrl = ctrl; 173 175 boolean oldShift = shift; 174 updateKeyModifiers (modifiers);176 updateKeyModifiersEx(modifiers); 175 177 if (ctrl != oldCtrl || shift != oldShift) { 176 178 processMouseEvent(null); 177 179 updCursor(); 178 180 if (mode != Mode.None) 179 Main .map.mapView.repaint();181 MainApplication.getMap().mapView.repaint(); 180 182 } 181 183 } … … 200 202 n = null; 201 203 } else { 202 n = Main .map.mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);204 n = MainApplication.getMap().mapView.getNearestNode(mousePos, OsmPrimitive::isUsable); 203 205 } 204 206 if (n == null) { 205 return latlon2eastNorth(Main .map.mapView.getLatLon(mousePos.x, mousePos.y));207 return latlon2eastNorth(MainApplication.getMap().mapView.getLatLon(mousePos.x, mousePos.y)); 206 208 } else { 207 209 return latlon2eastNorth(n.getCoor()); … … 220 222 } else { 221 223 building.setPlace(p, ToolSettings.getWidth(), ToolSettings.getLenStep(), shift); 222 Main .map.statusLine.setDist(building.getLength());224 MainApplication.getMap().statusLine.setDist(building.getLength()); 223 225 this.nextMode = ToolSettings.getWidth() == 0 ? Mode.DrawingWidth : Mode.None; 224 226 return this.nextMode; … … 228 230 private Mode modeDrawingWidth() { 229 231 building.setWidth(getEastNorth()); 230 Main .map.statusLine.setDist(Math.abs(building.getWidth()));232 MainApplication.getMap().statusLine.setDist(Math.abs(building.getWidth())); 231 233 return Mode.None; 232 234 } … … 277 279 drawStartPos = mousePos; 278 280 279 Node n = Main .map.mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);281 Node n = MainApplication.getMap().mapView.getNearestNode(mousePos, OsmPrimitive::isUsable); 280 282 if (n == null) { 281 building.setBase(latlon2eastNorth(Main .map.mapView.getLatLon(mousePos.x, mousePos.y)));283 building.setBase(latlon2eastNorth(MainApplication.getMap().mapView.getLatLon(mousePos.x, mousePos.y))); 282 284 } else { 283 285 building.setBase(n); … … 320 322 if (e.getButton() != MouseEvent.BUTTON1) 321 323 return; 322 if (!Main .map.mapView.isActiveLayerDrawable())324 if (!MainApplication.getMap().mapView.isActiveLayerDrawable()) 323 325 return; 324 326 … … 334 336 updCursor(); 335 337 if (mode != Mode.None) 336 Main .map.mapView.repaint();338 MainApplication.getMap().mapView.repaint(); 337 339 } 338 340 … … 341 343 if (e.getButton() != MouseEvent.BUTTON1) 342 344 return; 343 if (!Main .map.mapView.isActiveLayerDrawable())345 if (!MainApplication.getMap().mapView.isActiveLayerDrawable()) 344 346 return; 345 347 boolean dragged = true; … … 359 361 if (mousePos == null) 360 362 return; 361 if (!Main .isDisplayingMapView())363 if (!MainApplication.isDisplayingMapView()) 362 364 return; 363 365 Node n = null; 364 366 if (!ctrl) 365 n = Main .map.mapView.getNearestNode(mousePos, OsmPrimitive::isUsable);367 n = MainApplication.getMap().mapView.getNearestNode(mousePos, OsmPrimitive::isUsable); 366 368 if (n != null) { 367 369 setCursor(cursorJoinNode); … … 377 379 @Override 378 380 public void mouseMoved(MouseEvent e) { 379 if (!Main .map.mapView.isActiveLayerDrawable())381 if (!MainApplication.getMap().mapView.isActiveLayerDrawable()) 380 382 return; 381 383 processMouseEvent(e); 382 384 updCursor(); 383 385 if (mode != Mode.None) 384 Main .map.mapView.repaint();386 MainApplication.getMap().mapView.repaint(); 385 387 } 386 388 -
applications/editors/josm/plugins/buildings_tools/src/buildings_tools/ToolSettings.java
r31361 r33735 13 13 import org.openstreetmap.josm.Main; 14 14 import org.openstreetmap.josm.data.preferences.BooleanProperty; 15 import org.openstreetmap.josm.tools.Logging; 15 16 16 17 public final class ToolSettings { … … 61 62 values.add(entry.getValue()); 62 63 } 63 Main.pref.put Collection("buildings_tools.tags", values);64 Main.pref.putList("buildings_tools.tags", values); 64 65 } 65 66 66 67 private static void loadTags() { 67 68 TAGS.clear(); 68 Collection<String> values = Main.pref.get Collection("buildings_tools.tags",69 Arrays.asList( new String[] {"building", "yes"}));69 Collection<String> values = Main.pref.getList("buildings_tools.tags", 70 Arrays.asList("building", "yes")); 70 71 try { 71 72 for (Iterator<String> iterator = values.iterator(); iterator.hasNext();) { … … 73 74 } 74 75 } catch (NoSuchElementException e) { 75 Main.warn(e);76 Logging.warn(e); 76 77 } 77 78 } 78 79 79 80 public static void setBBMode(boolean bbmode) { 80 Main.pref.put ("buildings_tools.bbmode", bbmode);81 Main.pref.putBoolean("buildings_tools.bbmode", bbmode); 81 82 } 82 83 … … 86 87 87 88 public static void setSoftCursor(boolean softCursor) { 88 Main.pref.put ("buildings_tools.softcursor", softCursor);89 Main.pref.putBoolean("buildings_tools.softcursor", softCursor); 89 90 } 90 91
Note:
See TracChangeset
for help on using the changeset viewer.