Changeset 22186 in osm for applications/editors/josm/plugins/cadastre-fr
- Timestamp:
- 2010-07-04T21:32:57+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/Address.java
r22153 r22186 16 16 import java.awt.event.MouseListener; 17 17 import java.awt.event.MouseMotionListener; 18 import java.awt.event.WindowEvent; 19 import java.awt.event.WindowListener; 18 20 import java.util.ArrayList; 19 21 import java.util.Collection; … … 30 32 import javax.swing.ImageIcon; 31 33 import javax.swing.JButton; 34 import javax.swing.JCheckBox; 32 35 import javax.swing.JDialog; 33 36 import javax.swing.JLabel; … … 36 39 import javax.swing.JRadioButton; 37 40 import javax.swing.JTextField; 41 import javax.swing.event.ChangeEvent; 42 import javax.swing.event.ChangeListener; 38 43 39 44 import org.openstreetmap.josm.Main; … … 61 66 private static final long serialVersionUID = 1L; 62 67 63 static final String tagHighway = "highway"; 64 static final String tagHighwayName = "name"; 65 static final String tagHouseNumber = "addr:housenumber"; 66 static final String tagHouseStreet = "addr:street"; 67 static final String relationAddrType = "associatedStreet"; 68 static final String relationStreetNameAttr = "name"; 69 static final String relationAddrStreetRole = "street"; 68 // perhaps make all these tags configurable in the future 69 private String tagHighway = "highway"; 70 private String tagHighwayName = "name"; 71 private String tagHouseNumber = "addr:housenumber"; 72 private String tagHouseStreet = "addr:street"; 73 private String tagBuilding = "building"; 74 private String relationAddrType = "associatedStreet"; 75 private String relationAddrName = "name"; 76 private String relationAddrStreetRole = "street"; 77 private String relationMemberHouse = "house"; 70 78 71 79 private JRadioButton plus_one = new JRadioButton("+1", false); 72 private JRadioButton plus_two = new JRadioButton("+2", true); 80 private JRadioButton plus_two = new JRadioButton("+2", true); // enable this by default 73 81 private JRadioButton minus_one = new JRadioButton("-1", false); 74 82 private JRadioButton minus_two = new JRadioButton("-2", false); 83 final JCheckBox tagPolygon = new JCheckBox(tr("on polygon")); 75 84 76 85 JDialog dialog = null; … … 80 89 JLabel link = new JLabel(); 81 90 private Way selectedWay; 91 private Relation selectedRelation; 82 92 83 93 MapFrame mapFrame; … … 85 95 public Address(MapFrame mapFrame) { 86 96 super(tr("Add address"), "buildings", 87 tr(" Create house number and street name relation"),97 tr("Helping tool for tag address"), 88 98 Shortcut.registerShortcut("mapmode:buildings", tr("Mode: {0}", tr("Buildings")), KeyEvent.VK_E, Shortcut.GROUP_EDIT), 89 99 mapFrame, getCursor()); … … 114 124 Point mousePos = e.getPoint(); 115 125 List<Way> mouseOnExistingWays = new ArrayList<Way>(); 126 List<Way> mouseOnExistingBuildingWays = new ArrayList<Way>(); 116 127 mouseOnExistingWays = new ArrayList<Way>(); 117 128 Node currentMouseNode = mv.getNearestNode(mousePos, OsmPrimitive.isSelectablePredicate); 118 129 if (currentMouseNode != null) { 130 // click on existing node 131 setNewSelection(currentMouseNode); 119 132 String num = currentMouseNode.get(tagHouseNumber); 120 133 if (num != null) { 121 134 try { 135 // add new address 122 136 Integer.parseInt(num); 123 137 inputNumber.setText(num); … … 129 143 if (currentMouseNode.get(tagHouseStreet) != null) { 130 144 inputStreet.setText(currentMouseNode.get(tagHouseNumber)); 131 setSelectedWay( null);145 setSelectedWay((Way)null); 132 146 } else { 133 147 // check if the node belongs to an associatedStreet relation 134 148 List<OsmPrimitive> l = currentMouseNode.getReferrers(); 149 boolean nodeBelongsToRelation = false; 135 150 for (OsmPrimitive osm : l) { 136 151 if (osm instanceof Relation && osm.hasKey("type") && osm.get("type").equals(relationAddrType)) { 137 if (osm.hasKey(relationStreetNameAttr)) { 138 inputStreet.setText(osm.get(relationStreetNameAttr)); 139 setSelectedWay(null); 140 break; 141 } else { 142 for (RelationMember rm : ((Relation)osm).getMembers()) 143 if (rm.getRole().equals(relationAddrStreetRole)) { 144 OsmPrimitive osp = rm.getMember(); 145 if (osp instanceof Way && osp.hasKey(tagHighwayName)) { 146 inputStreet.setText(osp.get(tagHighwayName)); 147 setSelectedWay((Way)osp); 148 break; 149 } 152 for (RelationMember rm : ((Relation)osm).getMembers()) { 153 if (rm.getRole().equals(relationAddrStreetRole)) { 154 OsmPrimitive osp = rm.getMember(); 155 if (osp instanceof Way && osp.hasKey(tagHighwayName)) { 156 inputStreet.setText(osp.get(tagHighwayName)); 157 setSelectedWay((Way)osp, (Relation)osm); 158 nodeBelongsToRelation = true; 159 break; 150 160 } 161 } 151 162 } 152 163 } 164 } 165 if (!nodeBelongsToRelation) { 166 // node exists but doesn't carry address information : add tags like a new node 167 Collection<Command> cmds = new LinkedList<Command>(); 168 addAddrToPrimitive(currentMouseNode, cmds); 153 169 } 154 170 } … … 158 174 if (ws.way.get(tagHighway) != null && ws.way.get(tagHighwayName) != null) 159 175 mouseOnExistingWays.add(ws.way); 176 else if (ws.way.get(tagBuilding) != null && ws.way.get(tagHouseNumber) == null) 177 mouseOnExistingBuildingWays.add(ws.way); 160 178 } 161 179 if (mouseOnExistingWays.size() == 1) { … … 163 181 inputStreet.setText(mouseOnExistingWays.get(0).get(tagHighwayName)); 164 182 setSelectedWay(mouseOnExistingWays.get(0)); 183 inputNumber.setText(""); 184 setNewSelection(mouseOnExistingWays.get(0)); 165 185 } else if (mouseOnExistingWays.size() == 0) { 166 186 // clicked a non highway and not a node => add the new address … … 168 188 Toolkit.getDefaultToolkit().beep(); 169 189 } else { 170 Node n = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isSelectablePredicate);171 190 Collection<Command> cmds = new LinkedList<Command>(); 172 if (n == null) 173 n = createNewNode(e, cmds); 174 addAddrToNode(n, cmds); 175 if (cmds.size() > 0) { 176 Command c = new SequenceCommand("Add node address", cmds); 177 Main.main.undoRedo.add(c); 191 if (tagPolygon.isSelected()) { 192 addAddrToPolygon(mouseOnExistingBuildingWays, cmds); 193 } else { 194 Node n = createNewNode(e, cmds); 195 addAddrToPrimitive(n, cmds); 178 196 } 179 197 } … … 183 201 } 184 202 185 private void addAddrToNode(Node n, Collection<Command> cmds) { 203 private void addAddrToPolygon(List<Way> mouseOnExistingBuildingWays, Collection<Command> cmds) { 204 for (Way w:mouseOnExistingBuildingWays) { 205 cmds.add(new ChangePropertyCommand(w, tagHouseNumber, inputNumber.getText())); 206 addAddrToPrimitive(w, cmds); 207 } 208 } 209 210 private void addAddrToPrimitive(OsmPrimitive osm, Collection<Command> cmds) { 211 // add the current tag addr:housenumber in node and member in relation 212 cmds.add(new ChangePropertyCommand(osm, tagHouseNumber, inputNumber.getText())); 213 if (Main.pref.getBoolean("cadastrewms.addr.dontUseRelation", false)) { 214 cmds.add(new ChangePropertyCommand(osm, tagHouseStreet, inputStreet.getText())); 215 } else if (selectedWay != null) { 216 // add the node to its relation 217 if (selectedRelation != null) { 218 RelationMember rm = new RelationMember(relationMemberHouse, osm); 219 Relation newRel = new Relation(selectedRelation); 220 newRel.addMember(rm); 221 cmds.add(new ChangeCommand(selectedRelation, newRel)); 222 } else { 223 // create new relation 224 Relation newRel = new Relation(); 225 newRel.put("type", relationAddrType); 226 newRel.put(relationAddrName, selectedWay.get(tagHighwayName)); 227 newRel.addMember(new RelationMember(relationAddrStreetRole, selectedWay)); 228 newRel.addMember(new RelationMember(relationMemberHouse, osm)); 229 cmds.add(new AddCommand(newRel)); 230 } 231 } 186 232 try { 187 // add the tag addr:housenumber in node and member in relation188 cmds.add(new ChangePropertyCommand(n, tagHouseNumber, inputNumber.getText()));189 cmds.add(new ChangePropertyCommand(n, tagHouseStreet, inputStreet.getText()));190 233 applyInputNumberChange(); 234 Command c = new SequenceCommand("Add node address", cmds); 235 Main.main.undoRedo.add(c); 236 setNewSelection(osm); 191 237 } catch (NumberFormatException en) { 192 238 System.out.println("Unable to parse house number \"" + inputNumber.getText() + "\""); … … 335 381 link.setEnabled(false); 336 382 JPanel p = new JPanel(new GridBagLayout()); 337 JLabel number = new JLabel(tr("N umber"));383 JLabel number = new JLabel(tr("Next no")); 338 384 JLabel street = new JLabel(tr("Street")); 339 385 p.add(number, GBC.std().insets(0, 0, 0, 0)); … … 350 396 inputNumber.setText(""); 351 397 inputStreet.setText(""); 352 setSelectedWay( null);398 setSelectedWay((Way)null); 353 399 } 354 400 }); … … 359 405 bgIncremental.add(minus_two); 360 406 p.add(minus_one, GBC.std().insets(10, 0, 10, 0)); 361 p.add(plus_one, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0)); 407 // p.add(plus_one, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0)); 408 p.add(plus_one, GBC.std().insets(0, 0, 10, 0)); 409 tagPolygon.setSelected(Main.pref.getBoolean("cadastrewms.addr.onBuilding", false)); 410 tagPolygon.addChangeListener(new ChangeListener() { 411 @Override 412 public void stateChanged(ChangeEvent arg0) { 413 Main.pref.put("cadastrewms.addr.onBuilding", tagPolygon.isSelected()); 414 } 415 }); 416 p.add(tagPolygon, GBC.eol().fill(GBC.HORIZONTAL).insets(0, 0, 0, 0)); 362 417 p.add(minus_two, GBC.std().insets(10, 0, 10, 0)); 363 p.add(plus_two, GBC.std().insets( 10, 0, 10, 0));364 p.add(clearButton, GBC.eol().fill(GBC.HORIZONTAL).insets( 10, 0, 0, 0));418 p.add(plus_two, GBC.std().insets(0, 0, 10, 0)); 419 p.add(clearButton, GBC.eol().fill(GBC.HORIZONTAL).insets(0, 0, 0, 0)); 365 420 366 421 final Object[] options = {}; … … 373 428 dialog.addComponentListener(new ComponentAdapter() { 374 429 protected void rememberGeometry() { 375 Main.pref.put("cadastrewms.addr _bounds", dialog.getX()+","+dialog.getY()+","+dialog.getWidth()+","+dialog.getHeight());430 Main.pref.put("cadastrewms.addr.bounds", dialog.getX()+","+dialog.getY()+","+dialog.getWidth()+","+dialog.getHeight()); 376 431 } 377 432 @Override public void componentMoved(ComponentEvent e) { … … 382 437 } 383 438 }); 384 String bounds = Main.pref.get("cadastrewms.addr_bounds",null); 439 dialog.addWindowListener(new WindowListener() { 440 @Override 441 public void windowClosing(WindowEvent arg0) { 442 exitMode(); 443 Main.map.selectMapMode((MapMode)Main.map.getDefaultButtonAction()); 444 } 445 public void windowClosed(WindowEvent e) {} 446 public void windowActivated(WindowEvent arg0) {} 447 public void windowDeactivated(WindowEvent arg0) {} 448 public void windowDeiconified(WindowEvent arg0) {} 449 public void windowIconified(WindowEvent arg0) {} 450 public void windowOpened(WindowEvent arg0) {} 451 }); 452 String bounds = Main.pref.get("cadastrewms.addr.bounds",null); 385 453 if (bounds != null) { 386 454 String[] b = bounds.split(","); … … 388 456 Integer.parseInt(b[0]),Integer.parseInt(b[1]),Integer.parseInt(b[2]),Integer.parseInt(b[3]))); 389 457 } 390 391 392 393 394 // exitMode();395 // Main.map.selectMapMode((MapMode)Main.map.getDefaultButtonAction());396 458 } 397 459 398 460 private void setSelectedWay(Way w) { 399 461 this.selectedWay = w; 400 if (w == null) 462 this.selectedRelation = null; 463 if (w == null) { 401 464 link.setEnabled(false); 402 else465 } else 403 466 link.setEnabled(true); 404 467 } 468 469 private void setSelectedWay(Way w, Relation r) { 470 setSelectedWay(w); 471 this.selectedRelation = r; 472 } 473 474 private void setNewSelection(OsmPrimitive osm) { 475 Collection<OsmPrimitive> newSelection = new LinkedList<OsmPrimitive>(Main.main.getCurrentDataSet().getSelected()); 476 newSelection.clear(); 477 newSelection.add(osm); 478 getCurrentDataSet().setSelected(osm); 479 } 405 480 406 481 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePreferenceSetting.java
r21191 r22186 41 41 private JCheckBox disableImageCropping = new JCheckBox(tr("Disable image cropping during georeferencing.")); 42 42 43 private JCheckBox autoFirstLayer = new JCheckBox(tr("Select first WMS layer in list.")); 44 45 private JCheckBox dontUseRelation = new JCheckBox(tr("Don't use relation for addresses (but \"addr:street\" on nodes).")); 46 43 47 private JRadioButton grabMultiplier1 = new JRadioButton("", true); 44 48 … … 57 61 private JRadioButton crosspiece4 = new JRadioButton("100m"); 58 62 59 private JCheckBox autoFirstLayer = new JCheckBox(tr("Select first WMS layer in list."));60 61 63 private JRadioButton grabRes1 = new JRadioButton("high"); 62 64 … … 324 326 cadastrewms.add(jLabelCacheSize, GBC.std().insets(20, 0, 0, 0)); 325 327 cadastrewms.add(cacheSize, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 200, 5)); 328 326 329 // separator 327 330 cadastrewms.add(new JSeparator(SwingConstants.HORIZONTAL), GBC.eol().fill(GBC.HORIZONTAL)); 331 332 // option to select the first WMS layer 328 333 autoFirstLayer.setSelected(Main.pref.getBoolean("cadastrewms.autoFirstLayer", false)); 329 334 autoFirstLayer.setToolTipText(tr("Automatically selects the first WMS layer if multiple layers exist when grabbing.")); 330 335 cadastrewms.add(autoFirstLayer, GBC.eop().insets(0, 0, 0, 0)); 336 337 // separator 338 cadastrewms.add(new JSeparator(SwingConstants.HORIZONTAL), GBC.eol().fill(GBC.HORIZONTAL)); 339 340 // option to use or not relations in addresses 341 dontUseRelation.setSelected(Main.pref.getBoolean("cadastrewms.addr.dontUseRelation", false)); 342 dontUseRelation.setToolTipText(tr("Enable this to use the tag \"add:street\" on nodes.")); 343 cadastrewms.add(dontUseRelation, GBC.eop().insets(0, 0, 0, 0)); 344 345 // end of dialog, scroll bar 331 346 cadastrewms.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); 332 // JTabbedPane cadastrecontent = new JTabbedPane();333 // cadastrecontent.add(cadastrewms);334 347 JScrollPane scrollpane = new JScrollPane(cadastrewms); 335 348 scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 )); 336 349 cadastrewmsMast.add(scrollpane, GBC.eol().fill(GBC.BOTH)); 337 338 350 } 339 351 … … 403 415 Main.pref.put("cadastrewms.autoFirstLayer", autoFirstLayer.isSelected()); 404 416 CacheControl.cacheEnabled = enableCache.isSelected(); 417 Main.pref.put("cadastrewms.addr.dontUseRelation", dontUseRelation.isSelected()); 405 418 CadastrePlugin.refreshConfiguration(); 406 419 CadastrePlugin.refreshMenu();
Note:
See TracChangeset
for help on using the changeset viewer.