Changeset 29475 in osm
- Timestamp:
- 2013-04-04T19:10:01+02:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/HouseNumberTaggingTool
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/HouseNumberTaggingTool/README
r27510 r29475 2 2 ================================= 3 3 4 Simple tool to tag house numbers. Select house and press ' Y'. Select your addr-tags and press OK.4 Simple tool to tag house numbers. Select house and press 'k'. Select your addr-tags and press OK. 5 5 6 6 author: Oliver Raupach, oliver@raupach.cc -
applications/editors/josm/plugins/HouseNumberTaggingTool/src/org/openstreetmap/josm/plugins/housenumbertool/Dto.java
r27510 r29475 8 8 public class Dto implements Serializable 9 9 { 10 11 /** 12 * 13 */ 14 private static final long serialVersionUID = -4025800761473341695L; 10 private static final long serialVersionUID = -4035800761473241695L; 15 11 16 12 private boolean saveBuilding = true; … … 22 18 private boolean saveHousenumber = true; 23 19 20 private String building = "yes"; 24 21 private String country; 25 22 private String state; … … 28 25 private String street; 29 26 private String housenumber; 27 private int housenumberChangeValue = 0; 30 28 31 29 public boolean isSaveBuilding() … … 158 156 this.saveState = saveState; 159 157 } 158 159 public int getHousenumberChangeValue() 160 { 161 return housenumberChangeValue; 162 } 163 164 public void setHousenumberChangeValue(int housenumberChangeValue) 165 { 166 this.housenumberChangeValue = housenumberChangeValue; 167 } 168 169 public String getBuilding() 170 { 171 return building; 172 } 173 174 public void setBuilding(String building) 175 { 176 this.building = building; 177 } 160 178 } -
applications/editors/josm/plugins/HouseNumberTaggingTool/src/org/openstreetmap/josm/plugins/housenumbertool/LaunchAction.java
r28039 r29475 14 14 { 15 15 16 /**17 *18 */19 16 private static final long serialVersionUID = -3508864293222033185L; 20 17 private OsmPrimitive selection = null; -
applications/editors/josm/plugins/HouseNumberTaggingTool/src/org/openstreetmap/josm/plugins/housenumbertool/TagDialog.java
r28039 r29475 4 4 import static org.openstreetmap.josm.tools.I18n.trn; 5 5 6 import java.awt.*; 6 import java.awt.Dimension; 7 import java.awt.GridBagConstraints; 8 import java.awt.GridBagLayout; 7 9 import java.awt.event.ActionEvent; 8 10 import java.io.File; … … 12 14 import java.io.ObjectOutputStream; 13 15 import java.util.ArrayList; 16 import java.util.Arrays; 14 17 import java.util.Collection; 15 18 import java.util.TreeSet; … … 18 21 19 22 import javax.swing.JCheckBox; 23 import javax.swing.JComboBox; 24 import javax.swing.JLabel; 20 25 import javax.swing.JPanel; 26 import javax.swing.JSlider; 21 27 import javax.swing.JTextField; 22 28 import javax.swing.SwingUtilities; … … 45 51 public static final String TAG_ADDR_HOUSENUMBER = "addr:housenumber"; 46 52 public static final String TAG_ADDR_STREET = "addr:street"; 47 /** 48 * 49 */ 53 54 public static final String[] buildingStrings = {"yes", "apartments", "chapel", "church", "commercial", "dormitory", "hotel", "house", "residential", "terrace", "industrial", "retail", "warehouse", "cathedral", "civic", "hospital", "school", "train_station", "transportation", "university", "public", "bridge", "bunker", "cabin", "construction", "farm_auxiliary", "garage", "garages" , "greenhouse", "hangar", "hut", "roof", "shed", "stable" }; 55 56 private static final int FPS_MIN = -2; 57 private static final int FPS_MAX = 2; 58 50 59 private static final long serialVersionUID = 6414385452106276923L; 60 51 61 static private final Logger logger = Logger.getLogger(TagDialog.class.getName()); 62 52 63 private String pluginDir; 53 64 private AutoCompletionManager acm; … … 55 66 56 67 public static final String TEMPLATE_DATA = "/template.data"; 57 68 58 69 private AutoCompletingComboBox country; 59 70 private AutoCompletingComboBox state; 60 71 private AutoCompletingComboBox city; 61 72 private AutoCompletingComboBox postcode; … … 64 75 private JCheckBox buildingEnabled; 65 76 private JCheckBox countryEnabled; 66 77 private JCheckBox stateEnabled; 67 78 private JCheckBox cityEnabled; 68 79 private JCheckBox zipEnabled; 69 80 private JCheckBox streetEnabled; 70 81 private JCheckBox housenumberEnabled; 82 private JSlider housenumberChangeSequence; 83 private JComboBox building; 71 84 72 85 public TagDialog(String pluginDir, OsmPrimitive p_selection) 73 86 { 74 super(Main.parent, 75 tr("House Number Editor"), 76 new String[] { tr("OK"), tr("Cancel")}, 77 true 78 ); 87 super(Main.parent, tr("House Number Editor"), new String[] { tr("OK"), tr("Cancel") }, true); 79 88 this.pluginDir = pluginDir; 80 89 this.selection = p_selection; 81 90 82 JPanel editPanel = createContentPane(); 83 91 JPanel editPanel = createContentPane(); 84 92 85 93 setContent(editPanel); 86 87 88 89 94 setButtonIcons(new String[] { "ok.png", "cancel.png" }); 95 setDefaultButton(1); 96 setupDialog(); 97 getRootPane().setDefaultButton(defaultButton); 90 98 91 99 // middle of the screen … … 102 110 } 103 111 104 private JPanel createContentPane() { 105 acm = selection.getDataSet().getAutoCompletionManager(); 106 107 Dto dto = loadDto(); 108 109 JPanel editPanel = new JPanel(new GridBagLayout()); 110 GridBagConstraints c = new GridBagConstraints(); 111 112 buildingEnabled = new JCheckBox(TAG_BUILDING); 113 buildingEnabled.setFocusable(false); 114 buildingEnabled.setSelected(dto.isSaveBuilding()); 115 c.fill = GridBagConstraints.HORIZONTAL; 116 c.gridx = 0; 117 c.gridy = 0; 118 c.weightx = 0; 119 editPanel.add(buildingEnabled, c); 120 121 JTextField building = new JTextField(); 122 building.setPreferredSize(new Dimension(200, 24)); 123 building.setText("yes"); 124 building.setEditable(false); 125 c.gridx = 1; 126 c.gridy = 0; 127 c.weightx = 1; 128 editPanel.add(building, c); 129 130 // country 131 countryEnabled = new JCheckBox(TAG_ADDR_COUNTRY); 132 countryEnabled.setFocusable(false); 133 countryEnabled.setSelected(dto.isSaveCountry()); 134 c = new GridBagConstraints(); 135 c.fill = GridBagConstraints.HORIZONTAL; 136 c.gridx = 0; 137 c.gridy = 1; 138 c.weightx = 0; 139 editPanel.add(countryEnabled, c); 140 141 country = new AutoCompletingComboBox(); 142 country.setPossibleACItems(acm.getValues(TAG_ADDR_COUNTRY)); 143 country.setPreferredSize(new Dimension(200, 24)); 144 country.setEditable(true); 145 country.setSelectedItem(dto.getCountry()); 146 c.fill = GridBagConstraints.HORIZONTAL; 147 c.gridx = 1; 148 c.gridy = 1; 149 c.weightx = 1; 150 editPanel.add(country, c); 151 152 // state 153 stateEnabled = new JCheckBox(TAG_ADDR_STATE); 154 stateEnabled.setFocusable(false); 155 stateEnabled.setSelected(dto.isSaveState()); 156 c = new GridBagConstraints(); 157 c.fill = GridBagConstraints.HORIZONTAL; 158 c.gridx = 0; 159 c.gridy = 2; 160 c.weightx = 0; 161 editPanel.add(stateEnabled, c); 162 163 state = new AutoCompletingComboBox(); 164 state.setPossibleACItems(acm.getValues(TAG_ADDR_STATE)); 165 state.setPreferredSize(new Dimension(200, 24)); 166 state.setEditable(true); 167 state.setSelectedItem(dto.getState()); 168 c.fill = GridBagConstraints.HORIZONTAL; 169 c.gridx = 1; 170 c.gridy = 2; 171 c.weightx = 1; 172 editPanel.add(state, c); 173 174 // city 175 cityEnabled = new JCheckBox(TAG_ADDR_CITY); 176 cityEnabled.setFocusable(false); 177 cityEnabled.setSelected(dto.isSaveCity()); 178 c.fill = GridBagConstraints.HORIZONTAL; 179 c.gridx = 0; 180 c.gridy = 3; 181 c.weightx = 0; 182 editPanel.add(cityEnabled, c); 183 184 city = new AutoCompletingComboBox(); 185 city.setPossibleACItems(acm.getValues(TAG_ADDR_CITY)); 186 city.setPreferredSize(new Dimension(200, 24)); 187 city.setEditable(true); 188 city.setSelectedItem(dto.getCity()); 189 c.fill = GridBagConstraints.HORIZONTAL; 190 c.gridx = 1; 191 c.gridy = 3; 192 c.weightx = 1; 193 editPanel.add(city, c); 194 195 // postcode 196 zipEnabled = new JCheckBox(TAG_ADDR_POSTCODE); 197 zipEnabled.setFocusable(false); 198 zipEnabled.setSelected(dto.isSavePostcode()); 199 c.fill = GridBagConstraints.HORIZONTAL; 200 c.gridx = 0; 201 c.gridy = 4; 202 c.weightx = 0; 203 editPanel.add(zipEnabled, c); 204 205 postcode = new AutoCompletingComboBox(); 206 postcode.setPossibleACItems(acm.getValues(TAG_ADDR_POSTCODE)); 207 postcode.setPreferredSize(new Dimension(200, 24)); 208 postcode.setEditable(true); 209 postcode.setSelectedItem(dto.getPostcode()); 210 c.fill = GridBagConstraints.HORIZONTAL; 211 c.gridx = 1; 212 c.gridy = 4; 213 c.weightx = 1; 214 editPanel.add(postcode, c); 215 216 // street 217 streetEnabled = new JCheckBox(TAG_ADDR_STREET); 218 streetEnabled.setFocusable(false); 219 streetEnabled.setSelected(dto.isSaveStreet()); 220 c.fill = GridBagConstraints.HORIZONTAL; 221 c.gridx = 0; 222 c.gridy = 5; 223 c.weightx = 0; 224 editPanel.add(streetEnabled, c); 225 226 street = new AutoCompletingComboBox(); 227 street.setPossibleItems(getPossibleStreets()); 228 street.setPreferredSize(new Dimension(200, 24)); 229 street.setEditable(true); 230 street.setSelectedItem(dto.getStreet()); 231 c.fill = GridBagConstraints.HORIZONTAL; 232 c.gridx = 1; 233 c.gridy = 5; 234 c.weightx = 1; 235 editPanel.add(street, c); 236 237 // housenumber 238 housenumberEnabled = new JCheckBox(TAG_ADDR_HOUSENUMBER); 239 housenumberEnabled.setFocusable(false); 240 housenumberEnabled.setSelected(dto.isSaveHousenumber()); 241 c.fill = GridBagConstraints.HORIZONTAL; 242 c.gridx = 0; 243 c.gridy = 6; 244 c.weightx = 0; 245 editPanel.add(housenumberEnabled, c); 246 247 housnumber = new JTextField(); 248 housnumber.setPreferredSize(new Dimension(200, 24)); 249 int number = 0; 250 try { 251 number = Integer.valueOf(dto.getHousenumber()) + 2; 252 } catch (NumberFormatException e) { 253 } 254 if (number > 0) 255 housnumber.setText(String.valueOf(number)); 256 c.fill = GridBagConstraints.HORIZONTAL; 257 c.gridx = 1; 258 c.gridy = 6; 259 c.weightx = 1; 260 editPanel.add(housnumber, c); 261 return editPanel; 262 } 263 264 @Override 265 protected void buttonAction(int buttonIndex, ActionEvent evt) { 266 if (buttonIndex == 0) { 267 Dto dto = new Dto(); 268 dto.setSaveBuilding(buildingEnabled.isSelected()); 269 dto.setSaveCity(cityEnabled.isSelected()); 270 dto.setSaveCountry(countryEnabled.isSelected()); 271 dto.setSaveState(stateEnabled.isSelected()); 272 dto.setSaveHousenumber(housenumberEnabled.isSelected()); 273 dto.setSavePostcode(zipEnabled.isSelected()); 274 dto.setSaveStreet(streetEnabled.isSelected()); 275 276 dto.setCity(getAutoCompletingComboBoxValue(city)); 277 dto.setCountry(getAutoCompletingComboBoxValue(country)); 278 dto.setHousenumber(housnumber.getText()); 279 dto.setPostcode(getAutoCompletingComboBoxValue(postcode)); 280 dto.setStreet(getAutoCompletingComboBoxValue(street)); 281 dto.setState(getAutoCompletingComboBoxValue(state)); 282 283 updateJOSMSelection(selection, dto); 284 saveDto(dto); 285 } 286 setVisible(false); 287 } 288 289 private String getAutoCompletingComboBoxValue(AutoCompletingComboBox box) { 290 Object item = box.getSelectedItem(); 291 if ( item != null) 292 { 293 if (item instanceof String) 294 { 295 return (String) item; 296 } 297 if (item instanceof AutoCompletionListItem) 298 { 299 return ((AutoCompletionListItem) item).getValue(); 300 } 301 return item.toString(); 302 } 303 else 304 { 305 return ""; 306 } 307 } 308 309 protected void saveDto(Dto dto) 310 { 311 File path = new File(pluginDir); 312 File fileName = new File(pluginDir + TagDialog.TEMPLATE_DATA); 313 314 try 315 { 112 private JPanel createContentPane() 113 { 114 acm = selection.getDataSet().getAutoCompletionManager(); 115 116 Dto dto = loadDto(); 117 118 JPanel editPanel = new JPanel(new GridBagLayout()); 119 GridBagConstraints c = new GridBagConstraints(); 120 121 buildingEnabled = new JCheckBox(TAG_BUILDING); 122 buildingEnabled.setFocusable(false); 123 buildingEnabled.setSelected(dto.isSaveBuilding()); 124 c.fill = GridBagConstraints.HORIZONTAL; 125 c.gridx = 0; 126 c.gridy = 0; 127 c.weightx = 0; 128 editPanel.add(buildingEnabled, c); 129 130 Arrays.sort(buildingStrings); 131 building = new JComboBox(buildingStrings); 132 building.setSelectedItem(dto.getBuilding()); 133 building.setMaximumRowCount(50); 134 c.gridx = 1; 135 c.gridy = 0; 136 c.weightx = 1; 137 editPanel.add(building, c); 138 139 // country 140 countryEnabled = new JCheckBox(TAG_ADDR_COUNTRY); 141 countryEnabled.setFocusable(false); 142 countryEnabled.setSelected(dto.isSaveCountry()); 143 c = new GridBagConstraints(); 144 c.fill = GridBagConstraints.HORIZONTAL; 145 c.gridx = 0; 146 c.gridy = 1; 147 c.weightx = 0; 148 editPanel.add(countryEnabled, c); 149 150 country = new AutoCompletingComboBox(); 151 country.setPossibleACItems(acm.getValues(TAG_ADDR_COUNTRY)); 152 country.setPreferredSize(new Dimension(200, 24)); 153 country.setEditable(true); 154 country.setSelectedItem(dto.getCountry()); 155 c.fill = GridBagConstraints.HORIZONTAL; 156 c.gridx = 1; 157 c.gridy = 1; 158 c.weightx = 1; 159 editPanel.add(country, c); 160 161 // state 162 stateEnabled = new JCheckBox(TAG_ADDR_STATE); 163 stateEnabled.setFocusable(false); 164 stateEnabled.setSelected(dto.isSaveState()); 165 c = new GridBagConstraints(); 166 c.fill = GridBagConstraints.HORIZONTAL; 167 c.gridx = 0; 168 c.gridy = 2; 169 c.weightx = 0; 170 editPanel.add(stateEnabled, c); 171 172 state = new AutoCompletingComboBox(); 173 state.setPossibleACItems(acm.getValues(TAG_ADDR_STATE)); 174 state.setPreferredSize(new Dimension(200, 24)); 175 state.setEditable(true); 176 state.setSelectedItem(dto.getState()); 177 c.fill = GridBagConstraints.HORIZONTAL; 178 c.gridx = 1; 179 c.gridy = 2; 180 c.weightx = 1; 181 editPanel.add(state, c); 182 183 // city 184 cityEnabled = new JCheckBox(TAG_ADDR_CITY); 185 cityEnabled.setFocusable(false); 186 cityEnabled.setSelected(dto.isSaveCity()); 187 c.fill = GridBagConstraints.HORIZONTAL; 188 c.gridx = 0; 189 c.gridy = 3; 190 c.weightx = 0; 191 editPanel.add(cityEnabled, c); 192 193 city = new AutoCompletingComboBox(); 194 city.setPossibleACItems(acm.getValues(TAG_ADDR_CITY)); 195 city.setPreferredSize(new Dimension(200, 24)); 196 city.setEditable(true); 197 city.setSelectedItem(dto.getCity()); 198 c.fill = GridBagConstraints.HORIZONTAL; 199 c.gridx = 1; 200 c.gridy = 3; 201 c.weightx = 1; 202 editPanel.add(city, c); 203 204 // postcode 205 zipEnabled = new JCheckBox(TAG_ADDR_POSTCODE); 206 zipEnabled.setFocusable(false); 207 zipEnabled.setSelected(dto.isSavePostcode()); 208 c.fill = GridBagConstraints.HORIZONTAL; 209 c.gridx = 0; 210 c.gridy = 4; 211 c.weightx = 0; 212 editPanel.add(zipEnabled, c); 213 214 postcode = new AutoCompletingComboBox(); 215 postcode.setPossibleACItems(acm.getValues(TAG_ADDR_POSTCODE)); 216 postcode.setPreferredSize(new Dimension(200, 24)); 217 postcode.setEditable(true); 218 postcode.setSelectedItem(dto.getPostcode()); 219 c.fill = GridBagConstraints.HORIZONTAL; 220 c.gridx = 1; 221 c.gridy = 4; 222 c.weightx = 1; 223 editPanel.add(postcode, c); 224 225 // street 226 streetEnabled = new JCheckBox(TAG_ADDR_STREET); 227 streetEnabled.setFocusable(false); 228 streetEnabled.setSelected(dto.isSaveStreet()); 229 c.fill = GridBagConstraints.HORIZONTAL; 230 c.gridx = 0; 231 c.gridy = 5; 232 c.weightx = 0; 233 editPanel.add(streetEnabled, c); 234 235 street = new AutoCompletingComboBox(); 236 street.setPossibleItems(getPossibleStreets()); 237 street.setPreferredSize(new Dimension(200, 24)); 238 street.setEditable(true); 239 street.setSelectedItem(dto.getStreet()); 240 c.fill = GridBagConstraints.HORIZONTAL; 241 c.gridx = 1; 242 c.gridy = 5; 243 c.weightx = 1; 244 editPanel.add(street, c); 245 246 // housenumber 247 housenumberEnabled = new JCheckBox(TAG_ADDR_HOUSENUMBER); 248 housenumberEnabled.setFocusable(false); 249 housenumberEnabled.setSelected(dto.isSaveHousenumber()); 250 c.fill = GridBagConstraints.HORIZONTAL; 251 c.gridx = 0; 252 c.gridy = 6; 253 c.weightx = 0; 254 editPanel.add(housenumberEnabled, c); 255 256 housnumber = new JTextField(); 257 housnumber.setPreferredSize(new Dimension(200, 24)); 258 259 int number = 0; 260 try 261 { 262 number = Integer.valueOf(dto.getHousenumber()) + dto.getHousenumberChangeValue(); 263 } 264 catch (NumberFormatException e) 265 { 266 } 267 if (number > 0) 268 { 269 housnumber.setText(String.valueOf(number)); 270 } 271 272 273 c.fill = GridBagConstraints.HORIZONTAL; 274 c.gridx = 1; 275 c.gridy = 6; 276 c.weightx = 1; 277 editPanel.add(housnumber, c); 278 279 JLabel seqLabel = new JLabel(tr("Housenumber increment:")); 280 c.fill = GridBagConstraints.HORIZONTAL; 281 c.gridx = 0; 282 c.gridy = 7; 283 c.weightx = 0; 284 editPanel.add(seqLabel, c); 285 286 housenumberChangeSequence = new JSlider(JSlider.HORIZONTAL, FPS_MIN, FPS_MAX, dto.getHousenumberChangeValue()); 287 housenumberChangeSequence.setPaintTicks(true); 288 housenumberChangeSequence.setMajorTickSpacing(1); 289 housenumberChangeSequence.setMinorTickSpacing(1); 290 housenumberChangeSequence.setPaintLabels(true); 291 housenumberChangeSequence.setSnapToTicks(true); 292 c.gridx = 1; 293 c.gridy = 7; 294 c.weightx = 1; 295 editPanel.add(housenumberChangeSequence, c); 296 297 return editPanel; 298 } 299 300 @Override 301 protected void buttonAction(int buttonIndex, ActionEvent evt) 302 { 303 if (buttonIndex == 0) 304 { 305 Dto dto = new Dto(); 306 dto.setSaveBuilding(buildingEnabled.isSelected()); 307 dto.setSaveCity(cityEnabled.isSelected()); 308 dto.setSaveCountry(countryEnabled.isSelected()); 309 dto.setSaveState(stateEnabled.isSelected()); 310 dto.setSaveHousenumber(housenumberEnabled.isSelected()); 311 dto.setSavePostcode(zipEnabled.isSelected()); 312 dto.setSaveStreet(streetEnabled.isSelected()); 313 314 dto.setBuilding((String) building.getSelectedItem()); 315 dto.setCity(getAutoCompletingComboBoxValue(city)); 316 dto.setCountry(getAutoCompletingComboBoxValue(country)); 317 dto.setHousenumber(housnumber.getText()); 318 dto.setPostcode(getAutoCompletingComboBoxValue(postcode)); 319 dto.setStreet(getAutoCompletingComboBoxValue(street)); 320 dto.setState(getAutoCompletingComboBoxValue(state)); 321 dto.setHousenumberChangeValue(housenumberChangeSequence.getValue()); 316 322 317 path.mkdirs(); 318 319 320 FileOutputStream file = new FileOutputStream(fileName); 321 ObjectOutputStream o = new ObjectOutputStream(file); 322 o.writeObject(dto); 323 o.close(); 324 } 325 catch (Exception ex) 326 { 327 logger.log(Level.SEVERE, ex.getMessage()); 328 329 if (fileName != null) 330 { 331 fileName.delete(); 332 } 333 } 334 } 335 336 protected void updateJOSMSelection(OsmPrimitive selection, Dto dto) 337 { 338 ArrayList<Command> commands = new ArrayList<Command>(); 339 340 if (dto.isSaveBuilding()) 341 { 342 String value = selection.get(TagDialog.TAG_BUILDING); 343 if (value == null || (value != null && !value.equals("yes"))) 344 { 345 ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_BUILDING, "yes"); 346 commands.add(command); 347 } 348 } 349 350 if (dto.isSaveCity()) 351 { 352 String value = selection.get(TagDialog.TAG_ADDR_CITY); 353 if (value == null || (value != null && !value.equals(dto.getCity()))) 354 { 355 ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_CITY, dto.getCity()); 356 commands.add(command); 357 } 358 } 359 360 if (dto.isSaveCountry()) 361 { 362 String value = selection.get(TagDialog.TAG_ADDR_COUNTRY); 363 if (value == null || (value != null && !value.equals(dto.getCountry()))) 364 { 365 ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_COUNTRY, dto.getCountry()); 366 commands.add(command); 367 } 368 } 369 370 if (dto.isSaveHousenumber()) 371 { 372 String value = selection.get(TagDialog.TAG_ADDR_HOUSENUMBER); 373 if (value == null || (value != null && !value.equals(dto.getHousenumber()))) 374 { 375 ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_HOUSENUMBER, dto.getHousenumber()); 376 commands.add(command); 377 } 378 } 379 380 if (dto.isSavePostcode()) 381 { 382 String value = selection.get(TagDialog.TAG_ADDR_POSTCODE); 383 if (value == null || (value != null && !value.equals(dto.getPostcode()))) 384 { 385 ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_POSTCODE, dto.getPostcode()); 386 commands.add(command); 387 } 388 } 389 390 if (dto.isSaveStreet()) 391 { 392 String value = selection.get(TagDialog.TAG_ADDR_STREET); 393 if (value == null || (value != null && !value.equals(dto.getStreet()))) 394 { 395 ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_STREET, dto.getStreet()); 396 commands.add(command); 397 } 398 } 399 400 if (dto.isSaveState()) 401 { 402 String value = selection.get(TagDialog.TAG_ADDR_STATE); 403 if (value == null || (value != null && !value.equals(dto.getState()))) 404 { 405 ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_STATE, dto.getState()); 406 commands.add(command); 407 } 408 } 409 410 if (commands.size() > 0) 411 { 412 SequenceCommand sequenceCommand = new SequenceCommand(trn("Updating properties of up to {0} object", "Updating properties of up to {0} objects", commands.size(), commands.size()), commands); 413 414 // executes the commands and adds them to the undo/redo chains 415 Main.main.undoRedo.add(sequenceCommand); 416 } 417 } 418 419 private Collection<String> getPossibleStreets() { 420 /** 421 * Generates a list of all visible names of highways in order to do 422 * autocompletion on the road name. 423 */ 424 final TreeSet<String> names = new TreeSet<String>(); 425 for (OsmPrimitive osm : Main.main.getCurrentDataSet() 426 .allNonDeletedPrimitives()) { 427 if (osm.getKeys() != null && osm.keySet().contains("highway") 428 && osm.keySet().contains("name")) { 429 names.add(osm.get("name")); 430 } 431 } 432 return names; 433 } 323 updateJOSMSelection(selection, dto); 324 saveDto(dto); 325 } 326 setVisible(false); 327 } 328 329 private String getAutoCompletingComboBoxValue(AutoCompletingComboBox box) 330 { 331 Object item = box.getSelectedItem(); 332 if (item != null) 333 { 334 if (item instanceof String) 335 { 336 return (String) item; 337 } 338 if (item instanceof AutoCompletionListItem) 339 { 340 return ((AutoCompletionListItem) item).getValue(); 341 } 342 return item.toString(); 343 } 344 else 345 { 346 return ""; 347 } 348 } 349 350 protected void saveDto(Dto dto) 351 { 352 File path = new File(pluginDir); 353 File fileName = new File(pluginDir + TagDialog.TEMPLATE_DATA); 354 355 try 356 { 357 path.mkdirs(); 358 359 FileOutputStream file = new FileOutputStream(fileName); 360 ObjectOutputStream o = new ObjectOutputStream(file); 361 o.writeObject(dto); 362 o.close(); 363 } 364 catch (Exception ex) 365 { 366 logger.log(Level.SEVERE, ex.getMessage()); 367 368 if (fileName != null) 369 { 370 fileName.delete(); 371 } 372 } 373 } 374 375 protected void updateJOSMSelection(OsmPrimitive selection, Dto dto) 376 { 377 ArrayList<Command> commands = new ArrayList<Command>(); 378 379 if (dto.isSaveBuilding()) 380 { 381 String value = selection.get(TagDialog.TAG_BUILDING); 382 if (value == null || (value != null && !value.equals(dto.getBuilding()))) 383 { 384 ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_BUILDING, dto.getBuilding()); 385 commands.add(command); 386 } 387 } 388 389 if (dto.isSaveCity()) 390 { 391 String value = selection.get(TagDialog.TAG_ADDR_CITY); 392 if (value == null || (value != null && !value.equals(dto.getCity()))) 393 { 394 ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_CITY, dto.getCity()); 395 commands.add(command); 396 } 397 } 398 399 if (dto.isSaveCountry()) 400 { 401 String value = selection.get(TagDialog.TAG_ADDR_COUNTRY); 402 if (value == null || (value != null && !value.equals(dto.getCountry()))) 403 { 404 ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_COUNTRY, dto.getCountry()); 405 commands.add(command); 406 } 407 } 408 409 if (dto.isSaveHousenumber()) 410 { 411 String value = selection.get(TagDialog.TAG_ADDR_HOUSENUMBER); 412 if (value == null || (value != null && !value.equals(dto.getHousenumber()))) 413 { 414 ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_HOUSENUMBER, dto.getHousenumber()); 415 commands.add(command); 416 } 417 } 418 419 if (dto.isSavePostcode()) 420 { 421 String value = selection.get(TagDialog.TAG_ADDR_POSTCODE); 422 if (value == null || (value != null && !value.equals(dto.getPostcode()))) 423 { 424 ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_POSTCODE, dto.getPostcode()); 425 commands.add(command); 426 } 427 } 428 429 if (dto.isSaveStreet()) 430 { 431 String value = selection.get(TagDialog.TAG_ADDR_STREET); 432 if (value == null || (value != null && !value.equals(dto.getStreet()))) 433 { 434 ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_STREET, dto.getStreet()); 435 commands.add(command); 436 } 437 } 438 439 if (dto.isSaveState()) 440 { 441 String value = selection.get(TagDialog.TAG_ADDR_STATE); 442 if (value == null || (value != null && !value.equals(dto.getState()))) 443 { 444 ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_STATE, dto.getState()); 445 commands.add(command); 446 } 447 } 448 449 if (commands.size() > 0) 450 { 451 SequenceCommand sequenceCommand = new SequenceCommand(trn("Updating properties of up to {0} object", "Updating properties of up to {0} objects", commands.size(), commands.size()), commands); 452 453 // executes the commands and adds them to the undo/redo chains 454 Main.main.undoRedo.add(sequenceCommand); 455 } 456 } 457 458 private Collection<String> getPossibleStreets() 459 { 460 /** 461 * Generates a list of all visible names of highways in order to do autocompletion on the road name. 462 */ 463 TreeSet<String> names = new TreeSet<String>(); 464 for (OsmPrimitive osm : Main.main.getCurrentDataSet().allNonDeletedPrimitives()) 465 { 466 if (osm.getKeys() != null && osm.keySet().contains("highway") && osm.keySet().contains("name")) 467 { 468 names.add(osm.get("name")); 469 } 470 } 471 return names; 472 } 434 473 435 474 private Dto loadDto() … … 437 476 Dto dto = new Dto(); 438 477 File fileName = new File(pluginDir + TagDialog.TEMPLATE_DATA); 439 478 440 479 try 441 480 { 442 481 443 482 if (fileName.exists()) 444 483 { … … 451 490 else 452 491 { 453 454 455 456 457 458 492 dto.setCity(selection.get(TagDialog.TAG_ADDR_CITY)); 493 dto.setCountry(selection.get(TagDialog.TAG_ADDR_COUNTRY)); 494 dto.setHousenumber(selection.get(TagDialog.TAG_ADDR_HOUSENUMBER)); 495 dto.setPostcode(selection.get(TagDialog.TAG_ADDR_POSTCODE)); 496 dto.setStreet(selection.get(TagDialog.TAG_ADDR_STREET)); 497 dto.setState(selection.get(TagDialog.TAG_ADDR_STATE)); 459 498 } 460 499 … … 464 503 logger.log(Level.SEVERE, ex.getMessage()); 465 504 if (fileName != null) 466 { 467 505 { 506 fileName.delete(); 468 507 } 469 508 }
Note:
See TracChangeset
for help on using the changeset viewer.