Changeset 22153 in osm for applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
- Timestamp:
- 2010-07-02T00:51:25+02:00 (15 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
r22101 r22153 6 6 import java.awt.GridBagLayout; 7 7 import java.awt.Point; 8 import java.awt.Rectangle; 8 9 import java.awt.Toolkit; 9 10 import java.awt.event.ActionEvent; 10 11 import java.awt.event.ActionListener; 12 import java.awt.event.ComponentAdapter; 13 import java.awt.event.ComponentEvent; 11 14 import java.awt.event.KeyEvent; 12 15 import java.awt.event.MouseEvent; … … 25 28 26 29 import javax.swing.ButtonGroup; 30 import javax.swing.ImageIcon; 27 31 import javax.swing.JButton; 28 32 import javax.swing.JDialog; … … 36 40 import org.openstreetmap.josm.command.AddCommand; 37 41 import org.openstreetmap.josm.command.ChangeCommand; 42 import org.openstreetmap.josm.command.ChangePropertyCommand; 38 43 import org.openstreetmap.josm.command.Command; 39 44 import org.openstreetmap.josm.command.SequenceCommand; … … 73 78 final JTextField inputNumber = new JTextField(); 74 79 final JTextField inputStreet = new JTextField(); 80 JLabel link = new JLabel(); 81 private Way selectedWay; 75 82 76 83 MapFrame mapFrame; … … 87 94 super.enterMode(); 88 95 if (dialog == null) { 89 JPanel p = new JPanel(new GridBagLayout()); 90 JLabel number = new JLabel(tr("Number")); 91 JLabel street = new JLabel(tr("Street")); 92 p.add(number, GBC.std().insets(0, 0, 5, 0)); 93 p.add(inputNumber, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 5, 0, 5)); 94 p.add(street, GBC.std().insets(0, 0, 5, 0)); 95 inputStreet.setEditable(false); 96 p.add(inputStreet, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 5, 0, 5)); 97 clearButton = new JButton("Clear"); 98 clearButton.addActionListener(new ActionListener() { 99 public void actionPerformed(ActionEvent e) { 100 inputNumber.setText(""); 101 inputStreet.setText(""); 102 } 103 }); 104 ButtonGroup bgIncremental = new ButtonGroup(); 105 bgIncremental.add(plus_one); 106 bgIncremental.add(plus_two); 107 bgIncremental.add(minus_one); 108 bgIncremental.add(minus_two); 109 p.add(minus_one, GBC.std().insets(10, 0, 10, 0)); 110 p.add(plus_one, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0)); 111 p.add(minus_two, GBC.std().insets(10, 0, 10, 0)); 112 p.add(plus_two, GBC.std().insets(10, 0, 10, 0)); 113 p.add(clearButton, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0)); 114 115 final Object[] options = {}; 116 final JOptionPane pane = new JOptionPane(p, 117 JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, 118 null, options, null); 119 dialog = pane.createDialog(Main.parent, tr("Enter addresses")); 120 dialog.setModal(false); 121 dialog.setAlwaysOnTop(true); 96 createDialog(); 122 97 } 123 98 dialog.setVisible(true); … … 135 110 if (e.getButton() != MouseEvent.BUTTON1) 136 111 return; 112 137 113 MapView mv = Main.map.mapView; 138 114 Point mousePos = e.getPoint(); … … 140 116 mouseOnExistingWays = new ArrayList<Way>(); 141 117 Node currentMouseNode = mv.getNearestNode(mousePos, OsmPrimitive.isSelectablePredicate); 142 if(currentMouseNode != null) { 118 if (currentMouseNode != null) { 143 119 String num = currentMouseNode.get(tagHouseNumber); 144 120 if (num != null) { … … 146 122 Integer.parseInt(num); 147 123 inputNumber.setText(num); 124 applyInputNumberChange(); 148 125 } catch (NumberFormatException en) { 149 126 System.out.println("Unable to parse house number \"" + num + "\""); 150 127 } 151 128 } 152 if (currentMouseNode.get(tagHouseStreet) != null) 129 if (currentMouseNode.get(tagHouseStreet) != null) { 153 130 inputStreet.setText(currentMouseNode.get(tagHouseNumber)); 154 else { 131 setSelectedWay(null); 132 } else { 155 133 // check if the node belongs to an associatedStreet relation 156 134 List<OsmPrimitive> l = currentMouseNode.getReferrers(); … … 159 137 if (osm.hasKey(relationStreetNameAttr)) { 160 138 inputStreet.setText(osm.get(relationStreetNameAttr)); 139 setSelectedWay(null); 161 140 break; 162 141 } else { … … 164 143 if (rm.getRole().equals(relationAddrStreetRole)) { 165 144 OsmPrimitive osp = rm.getMember(); 166 if (osp.hasKey(tagHighwayName)) { 145 if (osp instanceof Way && osp.hasKey(tagHighwayName)) { 167 146 inputStreet.setText(osp.get(tagHighwayName)); 147 setSelectedWay((Way)osp); 168 148 break; 169 149 } … … 182 162 // clicked on existing highway => set new street name 183 163 inputStreet.setText(mouseOnExistingWays.get(0).get(tagHighwayName)); 164 setSelectedWay(mouseOnExistingWays.get(0)); 184 165 } else if (mouseOnExistingWays.size() == 0) { 185 166 // clicked a non highway and not a node => add the new address … … 188 169 } else { 189 170 Node n = Main.map.mapView.getNearestNode(mousePos, OsmPrimitive.isSelectablePredicate); 171 Collection<Command> cmds = new LinkedList<Command>(); 190 172 if (n == null) 191 n = createNewNode(e); 192 addAddrToNode(n); 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); 178 } 193 179 } 194 180 } … … 197 183 } 198 184 199 private void addAddrToNode(Node n) { 200 // add the tag addr:housenumber in node and member in relation 201 } 202 203 private Node createNewNode(MouseEvent e) { 185 private void addAddrToNode(Node n, Collection<Command> cmds) { 186 try { 187 // add the tag addr:housenumber in node and member in relation 188 cmds.add(new ChangePropertyCommand(n, tagHouseNumber, inputNumber.getText())); 189 cmds.add(new ChangePropertyCommand(n, tagHouseStreet, inputStreet.getText())); 190 applyInputNumberChange(); 191 } catch (NumberFormatException en) { 192 System.out.println("Unable to parse house number \"" + inputNumber.getText() + "\""); 193 } 194 } 195 196 private Node createNewNode(MouseEvent e, Collection<Command> cmds) { 204 197 // DrawAction.mouseReleased() but without key modifiers 205 198 Node n = new Node(Main.map.mapView.getLatLon(e.getX(), e.getY())); 206 Collection<Command> cmds = new LinkedList<Command>();207 199 cmds.add(new AddCommand(n)); 208 200 List<WaySegment> wss = Main.map.mapView.getNearestWaySegments(e.getPoint(), OsmPrimitive.isSelectablePredicate); … … 239 231 adjustNode(segSet, n); 240 232 241 Command c = new SequenceCommand("Add node address", cmds);242 Main.main.undoRedo.add(c);243 233 return n; 244 234 } … … 326 316 return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); 327 317 } 318 319 private void applyInputNumberChange() { 320 Integer num = Integer.parseInt(inputNumber.getText()); 321 if (plus_one.isSelected()) 322 num = num + 1; 323 if (plus_two.isSelected()) 324 num = num + 2; 325 if (minus_one.isSelected() && num > 1) 326 num = num - 1; 327 if (minus_two.isSelected() && num > 2) 328 num = num - 2; 329 inputNumber.setText(num.toString()); 330 } 331 332 private void createDialog() { 333 ImageIcon iconLink = ImageProvider.get(null, "Mf_relation.png"); 334 link.setIcon(iconLink); 335 link.setEnabled(false); 336 JPanel p = new JPanel(new GridBagLayout()); 337 JLabel number = new JLabel(tr("Number")); 338 JLabel street = new JLabel(tr("Street")); 339 p.add(number, GBC.std().insets(0, 0, 0, 0)); 340 p.add(inputNumber, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 0, 5)); 341 p.add(street, GBC.std().insets(0, 0, 0, 0)); 342 JPanel p2 = new JPanel(new GridBagLayout()); 343 inputStreet.setEditable(false); 344 p2.add(inputStreet, GBC.std().fill(GBC.HORIZONTAL).insets(5, 0, 0, 0)); 345 p2.add(link, GBC.eol().insets(10, 0, 0, 0)); 346 p.add(p2, GBC.eol().fill(GBC.HORIZONTAL)); 347 clearButton = new JButton("Clear"); 348 clearButton.addActionListener(new ActionListener() { 349 public void actionPerformed(ActionEvent e) { 350 inputNumber.setText(""); 351 inputStreet.setText(""); 352 setSelectedWay(null); 353 } 354 }); 355 ButtonGroup bgIncremental = new ButtonGroup(); 356 bgIncremental.add(plus_one); 357 bgIncremental.add(plus_two); 358 bgIncremental.add(minus_one); 359 bgIncremental.add(minus_two); 360 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)); 362 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)); 365 366 final Object[] options = {}; 367 final JOptionPane pane = new JOptionPane(p, 368 JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, 369 null, options, null); 370 dialog = pane.createDialog(Main.parent, tr("Enter addresses")); 371 dialog.setModal(false); 372 dialog.setAlwaysOnTop(true); 373 dialog.addComponentListener(new ComponentAdapter() { 374 protected void rememberGeometry() { 375 Main.pref.put("cadastrewms.addr_bounds", dialog.getX()+","+dialog.getY()+","+dialog.getWidth()+","+dialog.getHeight()); 376 } 377 @Override public void componentMoved(ComponentEvent e) { 378 rememberGeometry(); 379 } 380 @Override public void componentResized(ComponentEvent e) { 381 rememberGeometry(); 382 } 383 }); 384 String bounds = Main.pref.get("cadastrewms.addr_bounds",null); 385 if (bounds != null) { 386 String[] b = bounds.split(","); 387 dialog.setBounds(new Rectangle( 388 Integer.parseInt(b[0]),Integer.parseInt(b[1]),Integer.parseInt(b[2]),Integer.parseInt(b[3]))); 389 } 390 391 392 393 394 // exitMode(); 395 // Main.map.selectMapMode((MapMode)Main.map.getDefaultButtonAction()); 328 396 } 397 398 private void setSelectedWay(Way w) { 399 this.selectedWay = w; 400 if (w == null) 401 link.setEnabled(false); 402 else 403 link.setEnabled(true); 404 } 405 406 } -
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/WMSLayer.java
r21191 r22153 274 274 else 275 275 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); 276 for (GeorefImage img : images) 277 img.paint(g, mv, CadastrePlugin.backgroundTransparent, 278 CadastrePlugin.transparency, CadastrePlugin.drawBoundaries); 276 synchronized(this){ 277 for (GeorefImage img : images) 278 img.paint(g, mv, CadastrePlugin.backgroundTransparent, 279 CadastrePlugin.transparency, CadastrePlugin.drawBoundaries); 280 } 279 281 g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, savedInterpolation); 280 282 }
Note:
See TracChangeset
for help on using the changeset viewer.