Changeset 35508 in osm for applications/editors


Ignore:
Timestamp:
2020-07-11T12:54:08+02:00 (4 years ago)
Author:
raupach
Message:

refactoring, new tags, consider/display existing tags

Location:
applications/editors/josm/plugins/HouseNumberTaggingTool
Files:
1 added
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/HouseNumberTaggingTool

    • Property svn:ignore
      •  

        old new  
        66spotbugs-josm-HouseNumberTaggingTool.xml
        77javadoc
         8.idea
         9JOSM-HouseNumberTaggingTool.iml
  • applications/editors/josm/plugins/HouseNumberTaggingTool/src/org/openstreetmap/josm/plugins/housenumbertool/Dto.java

    r34070 r35508  
    99public class Dto implements Serializable {
    1010
    11     private static final long serialVersionUID = 5226513739078369787L;
     11    private static final long serialVersionUID = 7719940860196679722L;
    1212
    1313    private boolean saveBuilding = true;
     14    private boolean saveSource = true;
    1415    private boolean saveCountry = true;
    1516    private boolean saveState = true;
    1617    private boolean saveCity = true;
     18    private boolean saveSuburb = true;
    1719    private boolean savePostcode = true;
    1820    private boolean saveStreet = true;
     
    2224   
    2325    private String building = "yes";
     26    private String source;
    2427    private String country;
    2528    private String state;
    2629    private String city;
     30    private String suburb;
    2731    private String postcode;
    2832    private String street;
     
    166170        this.place = place;
    167171    }
     172
     173    public boolean isSaveSuburb() {
     174        return saveSuburb;
     175    }
     176
     177    public void setSaveSuburb(boolean saveSuburb) {
     178        this.saveSuburb = saveSuburb;
     179    }
     180
     181    public String getSuburb() {
     182        return suburb;
     183    }
     184
     185    public void setSuburb(String suburb) {
     186        this.suburb = suburb;
     187    }
     188
     189    public boolean isSaveSource() {
     190        return saveSource;
     191    }
     192
     193    public void setSaveSource(boolean saveSource) {
     194        this.saveSource = saveSource;
     195    }
     196
     197    public String getSource() {
     198        return source;
     199    }
     200
     201    public void setSource(String source) {
     202        this.source = source;
     203    }
    168204}
  • applications/editors/josm/plugins/HouseNumberTaggingTool/src/org/openstreetmap/josm/plugins/housenumbertool/TagDialog.java

    r35506 r35508  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.housenumbertool;
    3 
    4 import static org.openstreetmap.josm.tools.I18n.tr;
    5 import static org.openstreetmap.josm.tools.I18n.trn;
    6 
    7 import java.awt.Dimension;
    8 import java.awt.GridBagConstraints;
    9 import java.awt.GridBagLayout;
    10 import java.awt.event.ActionEvent;
    11 import java.awt.event.ItemEvent;
    12 import java.awt.event.ItemListener;
    13 import java.io.File;
    14 import java.io.FileInputStream;
    15 import java.io.FileOutputStream;
    16 import java.io.ObjectInputStream;
    17 import java.io.ObjectOutputStream;
    18 import java.util.ArrayList;
    19 import java.util.Arrays;
    20 import java.util.Collection;
    21 import java.util.List;
    22 import java.util.Set;
    23 import java.util.TreeSet;
    24 import java.util.logging.Level;
    25 import java.util.logging.Logger;
    26 import java.util.regex.Matcher;
    27 import java.util.regex.Pattern;
    28 
    29 import javax.swing.ButtonGroup;
    30 import javax.swing.JCheckBox;
    31 import javax.swing.JComboBox;
    32 import javax.swing.JLabel;
    33 import javax.swing.JPanel;
    34 import javax.swing.JRadioButton;
    35 import javax.swing.JSlider;
    36 import javax.swing.JTextField;
    37 import javax.swing.SwingUtilities;
    383
    394import org.openstreetmap.josm.command.ChangePropertyCommand;
     
    4813import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
    4914
     15import javax.swing.*;
     16import java.awt.*;
     17import java.awt.event.ActionEvent;
     18import java.awt.event.ItemEvent;
     19import java.awt.event.ItemListener;
     20import java.io.*;
     21import java.util.List;
     22import java.util.*;
     23import java.util.logging.Level;
     24import java.util.logging.Logger;
     25
     26import static org.openstreetmap.josm.tools.I18n.tr;
     27import static org.openstreetmap.josm.tools.I18n.trn;
     28
    5029/**
    5130 * @author Oliver Raupach 09.01.2012
     
    5736
    5837    private static final String TAG_BUILDING = "building";
     38    private static final String TAG_SOURCE = "source";
    5939    private static final String TAG_ADDR_COUNTRY = "addr:country";
    6040    private static final String TAG_ADDR_STATE = "addr:state";
     
    6444    private static final String TAG_ADDR_STREET = "addr:street";
    6545    private static final String TAG_ADDR_PLACE = "addr:place";
     46    private static final String TAG_ADDR_SUBURB = "addr:suburb";
    6647
    6748    private static final String[] BUILDING_STRINGS = {
     
    8263    private static final String TEMPLATE_DATA = "/template.data";
    8364
     65    private AutoCompletingComboBox source;
    8466    private AutoCompletingComboBox country;
    8567    private AutoCompletingComboBox state;
     68    private AutoCompletingComboBox suburb;
    8669    private AutoCompletingComboBox city;
    8770    private AutoCompletingComboBox postcode;
     
    8972    private JTextField housnumber;
    9073    private JCheckBox buildingEnabled;
     74    private JCheckBox sourceEnabled;
    9175    private JCheckBox countryEnabled;
    9276    private JCheckBox stateEnabled;
    9377    private JCheckBox cityEnabled;
     78    private JCheckBox suburbEnabled;
    9479    private JCheckBox zipEnabled;
    9580    private JCheckBox streetEnabled;
     
    9883    private JComboBox<String> building;
    9984    private JRadioButton streetRadio;
     85    private JRadioButton placeRadio;
    10086
    10187    /**
     
    11197        JPanel editPanel = createContentPane();
    11298
    113         setPreferredSize(new Dimension(700, 300));
    114         setMinimumSize(new Dimension(700, 300));
     99        setPreferredSize(new Dimension(900, 500));
     100        setMinimumSize(new Dimension(900, 500));
    115101
    116102        setContent(editPanel);
     
    137123        GridBagConstraints c = new GridBagConstraints();
    138124
     125        JLabel labelNewValues = new JLabel();
     126        Font newLabelFont = new Font(labelNewValues.getFont().getName(), Font.BOLD, labelNewValues.getFont().getSize());
     127        labelNewValues.setFont(newLabelFont);
     128        labelNewValues.setText(tr("New values:"));
     129        c.fill = GridBagConstraints.HORIZONTAL;
     130        c.gridx = 3;
     131        c.gridy = 0;
     132        c.weightx = 0;
     133        c.gridwidth = 1;
     134        c.insets = new Insets(0, 5, 10, 5);
     135        editPanel.add(labelNewValues, c);
     136
     137        JLabel labelExistingValues = new JLabel();
     138        labelExistingValues.setFont(newLabelFont);
     139        labelExistingValues.setText(tr("Existing values:"));
     140        c.fill = GridBagConstraints.HORIZONTAL;
     141        c.gridx = 5;
     142        c.gridy = 0;
     143        c.weightx = 0;
     144        c.gridwidth = 1;
     145        c.insets = new Insets(0, 5, 10, 5);
     146        editPanel.add(labelExistingValues, c);
     147
     148        JButton getAllButton = new JButton("<<");
     149        getAllButton.setPreferredSize(new Dimension(60, 24));
     150        getAllButton.setToolTipText(tr("Accept all existing values"));
     151        getAllButton.addActionListener(actionEvent -> acceptAllExistingValues());
     152        GridBagConstraints buttonContstraints = new GridBagConstraints();
     153        buttonContstraints.fill = GridBagConstraints.NONE;
     154        buttonContstraints.gridx = 6;
     155        buttonContstraints.gridy = 0;
     156        buttonContstraints.weightx = 0;
     157        buttonContstraints.gridwidth = 1;
     158        buttonContstraints.anchor = GridBagConstraints.EAST;
     159        buttonContstraints.insets = new Insets(0, 5, 10, 5);
     160        editPanel.add(getAllButton, buttonContstraints);
     161
     162        // building
    139163        buildingEnabled = new JCheckBox(TAG_BUILDING);
    140164        buildingEnabled.setFocusable(false);
     
    143167        c.fill = GridBagConstraints.HORIZONTAL;
    144168        c.gridx = 0;
    145         c.gridy = 0;
     169        c.gridy = 1;
    146170        c.weightx = 0;
    147171        c.gridwidth = 3;
     172        c.insets = new Insets(5, 5, 0, 5);
    148173        editPanel.add(buildingEnabled, c);
    149174
     
    153178        building.setMaximumRowCount(50);
    154179        c.gridx = 3;
    155         c.gridy = 0;
    156         c.weightx = 1;
    157         c.gridwidth = 1;
     180        c.gridy = 1;
     181        c.weightx = 1;
     182        c.gridwidth = 1;
     183        c.insets = new Insets(5, 5, 0, 5);
    158184        editPanel.add(building, c);
     185
     186        JButton getBuildingButton = new JButton("<");
     187        getBuildingButton.setPreferredSize(new Dimension(45, 24));
     188        getBuildingButton.setToolTipText(tr("Accept existing value"));
     189        getBuildingButton.addActionListener(actionEvent -> building.setSelectedItem(selection.get(TAG_BUILDING)));
     190        c.fill = GridBagConstraints.NONE;
     191        c.gridx = 4;
     192        c.gridy = 1;
     193        c.weightx = 0;
     194        c.gridwidth = 1;
     195        c.insets = new Insets(5, 5, 0, 5);
     196        editPanel.add(getBuildingButton, c);
     197
     198        JTextField existingBuilding = new JTextField();
     199        existingBuilding.setText(selection.get(TAG_BUILDING));
     200        existingBuilding.setPreferredSize(new Dimension(200, 24));
     201        existingBuilding.setEditable(false);
     202        c.fill = GridBagConstraints.HORIZONTAL;
     203        c.gridx = 5;
     204        c.gridy = 1;
     205        c.weightx = 1;
     206        c.gridwidth = 2;
     207        c.insets = new Insets(5, 5, 0, 5);
     208        editPanel.add(existingBuilding, c);
     209
     210        // source
     211        sourceEnabled = new JCheckBox(TAG_SOURCE);
     212        sourceEnabled.setFocusable(false);
     213        sourceEnabled.setSelected(dto.isSaveBuilding());
     214        sourceEnabled.setToolTipText(APPLY_CHANGES);
     215        c.fill = GridBagConstraints.HORIZONTAL;
     216        c.gridx = 0;
     217        c.gridy = 2;
     218        c.weightx = 0;
     219        c.gridwidth = 3;
     220        c.insets = new Insets(5, 5, 0, 5);
     221        editPanel.add(sourceEnabled, c);
     222
     223        source = new AutoCompletingComboBox();
     224        source.setPossibleAcItems(acm.getTagValues(TAG_SOURCE));
     225        source.setPreferredSize(new Dimension(200, 24));
     226        source.setEditable(true);
     227        source.setSelectedItem(dto.getSource());
     228        c.gridx = 3;
     229        c.gridy = 2;
     230        c.weightx = 1;
     231        c.gridwidth = 1;
     232        c.insets = new Insets(5, 5, 0, 5);
     233        editPanel.add(source, c);
     234
     235        JButton getSourceButton = new JButton("<");
     236        getSourceButton.setPreferredSize(new Dimension(45, 24));
     237        getSourceButton.setToolTipText(tr("Accept existing value"));
     238        getSourceButton.addActionListener(actionEvent -> source.setSelectedItem(selection.get(TAG_SOURCE)));
     239        c.fill = GridBagConstraints.NONE;
     240        c.gridx = 4;
     241        c.gridy = 2;
     242        c.weightx = 0;
     243        c.gridwidth = 1;
     244        c.insets = new Insets(5, 5, 0, 5);
     245        editPanel.add(getSourceButton, c);
     246
     247        JTextField existingSource = new JTextField();
     248        existingSource.setText(selection.get(TAG_SOURCE));
     249        existingSource.setPreferredSize(new Dimension(200, 24));
     250        existingSource.setEditable(false);
     251        c.fill = GridBagConstraints.HORIZONTAL;
     252        c.gridx = 5;
     253        c.gridy = 2;
     254        c.weightx = 1;
     255        c.gridwidth = 2;
     256        c.insets = new Insets(5, 5, 0, 5);
     257        editPanel.add(existingSource, c);
    159258
    160259        // country
     
    166265        c.fill = GridBagConstraints.HORIZONTAL;
    167266        c.gridx = 0;
    168         c.gridy = 1;
     267        c.gridy = 3;
    169268        c.weightx = 0;
    170269        c.gridwidth = 3;
     270        c.insets = new Insets(5, 5, 0, 5);
    171271        editPanel.add(countryEnabled, c);
    172272
     
    178278        c.fill = GridBagConstraints.HORIZONTAL;
    179279        c.gridx = 3;
    180         c.gridy = 1;
    181         c.weightx = 1;
    182         c.gridwidth = 1;
     280        c.gridy = 3;
     281        c.weightx = 1;
     282        c.gridwidth = 1;
     283        c.insets = new Insets(5, 5, 0, 5);
    183284        editPanel.add(country, c);
     285
     286        JButton getCountryButton = new JButton("<");
     287        getCountryButton.setPreferredSize(new Dimension(45, 24));
     288        getCountryButton.setToolTipText(tr("Accept existing value"));
     289        getCountryButton.addActionListener(actionEvent -> country.setSelectedItem(selection.get(TAG_ADDR_COUNTRY)));
     290        c.fill = GridBagConstraints.NONE;
     291        c.gridx = 4;
     292        c.gridy = 3;
     293        c.weightx = 0;
     294        c.gridwidth = 1;
     295        c.insets = new Insets(5, 5, 0, 5);
     296        editPanel.add(getCountryButton, c);
     297
     298        JTextField existingCountry = new JTextField();
     299        existingCountry.setText(selection.get(TAG_ADDR_COUNTRY));
     300        existingCountry.setPreferredSize(new Dimension(200, 24));
     301        existingCountry.setEditable(false);
     302        c.fill = GridBagConstraints.HORIZONTAL;
     303        c.gridx = 5;
     304        c.gridy = 3;
     305        c.weightx = 1;
     306        c.gridwidth = 2;
     307        c.insets = new Insets(5, 5, 0, 5);
     308        editPanel.add(existingCountry, c);
    184309
    185310        // state
     
    188313        stateEnabled.setSelected(dto.isSaveState());
    189314        stateEnabled.setToolTipText(APPLY_CHANGES);
    190         c = new GridBagConstraints();
    191315        c.fill = GridBagConstraints.HORIZONTAL;
    192316        c.gridx = 0;
    193         c.gridy = 2;
     317        c.gridy = 4;
    194318        c.weightx = 0;
    195319        c.gridwidth = 3;
     320        c.insets = new Insets(5, 5, 0, 5);
    196321        editPanel.add(stateEnabled, c);
    197322
     
    203328        c.fill = GridBagConstraints.HORIZONTAL;
    204329        c.gridx = 3;
    205         c.gridy = 2;
    206         c.weightx = 1;
    207         c.gridwidth = 1;
     330        c.gridy = 4;
     331        c.weightx = 1;
     332        c.gridwidth = 1;
     333        c.insets = new Insets(5, 5, 0, 5);
    208334        editPanel.add(state, c);
     335
     336        JButton getStateButton = new JButton("<");
     337        getStateButton.setPreferredSize(new Dimension(45, 24));
     338        getStateButton.setToolTipText(tr("Accept existing value"));
     339        getStateButton.addActionListener(actionEvent -> state.setSelectedItem(selection.get(TAG_ADDR_STATE)));
     340        c.fill = GridBagConstraints.NONE;
     341        c.gridx = 4;
     342        c.gridy = 4;
     343        c.weightx = 0;
     344        c.gridwidth = 1;
     345        c.insets = new Insets(5, 5, 0, 5);
     346        editPanel.add(getStateButton, c);
     347
     348        JTextField existingState= new JTextField();
     349        existingState.setText(selection.get(TAG_ADDR_STATE));
     350        existingState.setPreferredSize(new Dimension(200, 24));
     351        existingState.setEditable(false);
     352        c.fill = GridBagConstraints.HORIZONTAL;
     353        c.gridx = 5;
     354        c.gridy = 4;
     355        c.weightx = 1;
     356        c.gridwidth = 2;
     357        c.insets = new Insets(5, 5, 0, 5);
     358        editPanel.add(existingState, c);
     359
     360        // suburb
     361        suburbEnabled = new JCheckBox(TAG_ADDR_SUBURB);
     362        suburbEnabled.setFocusable(false);
     363        suburbEnabled.setSelected(dto.isSaveSuburb());
     364        suburbEnabled.setToolTipText(APPLY_CHANGES);
     365        c.fill = GridBagConstraints.HORIZONTAL;
     366        c.gridx = 0;
     367        c.gridy = 5;
     368        c.weightx = 0;
     369        c.gridwidth = 3;
     370        c.insets = new Insets(5, 5, 0, 5);
     371        editPanel.add(suburbEnabled, c);
     372
     373        suburb = new AutoCompletingComboBox();
     374        suburb.setPossibleAcItems(acm.getTagValues(TAG_ADDR_SUBURB));
     375        suburb.setPreferredSize(new Dimension(200, 24));
     376        suburb.setEditable(true);
     377        suburb.setSelectedItem(dto.getSuburb());
     378        c.fill = GridBagConstraints.HORIZONTAL;
     379        c.gridx = 3;
     380        c.gridy = 5;
     381        c.weightx = 1;
     382        c.gridwidth = 1;
     383        c.insets = new Insets(5, 5, 0, 5);
     384        editPanel.add(suburb, c);
     385
     386        JButton getSuburbButton = new JButton("<");
     387        getSuburbButton.setPreferredSize(new Dimension(45, 24));
     388        getSuburbButton.setToolTipText(tr("Accept existing value"));
     389        getSuburbButton.addActionListener(actionEvent -> suburb.setSelectedItem(selection.get(TAG_ADDR_SUBURB)));
     390        c.fill = GridBagConstraints.NONE;
     391        c.gridx = 4;
     392        c.gridy = 5;
     393        c.weightx = 0;
     394        c.gridwidth = 1;
     395        c.insets = new Insets(5, 5, 0, 5);
     396        editPanel.add(getSuburbButton, c);
     397
     398        JTextField existingSuburb = new JTextField();
     399        existingSuburb.setText(selection.get(TAG_ADDR_SUBURB));
     400        existingSuburb.setPreferredSize(new Dimension(200, 24));
     401        existingSuburb.setEditable(false);
     402        c.fill = GridBagConstraints.HORIZONTAL;
     403        c.gridx = 5;
     404        c.gridy = 5;
     405        c.weightx = 1;
     406        c.gridwidth = 2;
     407        c.insets = new Insets(5, 5, 0, 5);
     408        editPanel.add(existingSuburb, c);
    209409
    210410        // city
     
    215415        c.fill = GridBagConstraints.HORIZONTAL;
    216416        c.gridx = 0;
    217         c.gridy = 3;
     417        c.gridy = 6;
    218418        c.weightx = 0;
    219419        c.gridwidth = 3;
     420        c.insets = new Insets(5, 5, 0, 5);
    220421        editPanel.add(cityEnabled, c);
    221422
     
    227428        c.fill = GridBagConstraints.HORIZONTAL;
    228429        c.gridx = 3;
    229         c.gridy = 3;
    230         c.weightx = 1;
    231         c.gridwidth = 1;
     430        c.gridy = 6;
     431        c.weightx = 1;
     432        c.gridwidth = 1;
     433        c.insets = new Insets(5, 5, 0, 5);
    232434        editPanel.add(city, c);
     435
     436        JButton getCityButton = new JButton("<");
     437        getCityButton.setPreferredSize(new Dimension(45, 24));
     438        getCityButton.setToolTipText(tr("Accept existing value"));
     439        getCityButton.addActionListener(actionEvent -> city.setSelectedItem(selection.get(TAG_ADDR_CITY)));
     440        c.fill = GridBagConstraints.NONE;
     441        c.gridx = 4;
     442        c.gridy = 6;
     443        c.weightx = 0;
     444        c.gridwidth = 1;
     445        c.insets = new Insets(5, 5, 0, 5);
     446        editPanel.add(getCityButton, c);
     447
     448        JTextField existingCity = new JTextField();
     449        existingCity.setText(selection.get(TAG_ADDR_CITY));
     450        existingCity.setPreferredSize(new Dimension(200, 24));
     451        existingCity.setEditable(false);
     452        c.fill = GridBagConstraints.HORIZONTAL;
     453        c.gridx = 5;
     454        c.gridy = 6;
     455        c.weightx = 1;
     456        c.gridwidth = 2;
     457        c.insets = new Insets(5, 5, 0, 5);
     458        editPanel.add(existingCity, c);
    233459
    234460        // postcode
     
    239465        c.fill = GridBagConstraints.HORIZONTAL;
    240466        c.gridx = 0;
    241         c.gridy = 4;
     467        c.gridy = 7;
    242468        c.weightx = 0;
    243469        c.gridwidth = 3;
     470        c.insets = new Insets(5, 5, 0, 5);
    244471        editPanel.add(zipEnabled, c);
    245472
     
    251478        c.fill = GridBagConstraints.HORIZONTAL;
    252479        c.gridx = 3;
    253         c.gridy = 4;
    254         c.weightx = 1;
    255         c.gridwidth = 1;
     480        c.gridy = 7;
     481        c.weightx = 1;
     482        c.gridwidth = 1;
     483        c.insets = new Insets(5, 5, 0, 5);
    256484        editPanel.add(postcode, c);
     485
     486        JButton getPostcodeButton = new JButton("<");
     487        getPostcodeButton.setPreferredSize(new Dimension(45, 24));
     488        getPostcodeButton.setToolTipText(tr("Accept existing value"));
     489        getPostcodeButton.addActionListener(actionEvent -> postcode.setSelectedItem(selection.get(TAG_ADDR_POSTCODE)));
     490        c.fill = GridBagConstraints.NONE;
     491        c.gridx = 4;
     492        c.gridy = 7;
     493        c.weightx = 0;
     494        c.gridwidth = 1;
     495        c.insets = new Insets(5, 5, 0, 5);
     496        editPanel.add(getPostcodeButton, c);
     497
     498        JTextField existingPostcode = new JTextField();
     499        existingPostcode.setText(selection.get(TAG_ADDR_POSTCODE));
     500        existingPostcode.setPreferredSize(new Dimension(200, 24));
     501        existingPostcode.setEditable(false);
     502        c.fill = GridBagConstraints.HORIZONTAL;
     503        c.gridx = 5;
     504        c.gridy = 7;
     505        c.weightx = 1;
     506        c.gridwidth = 2;
     507        c.insets = new Insets(5, 5, 0, 5);
     508        editPanel.add(existingPostcode, c);
    257509
    258510        // street
     
    263515        c.fill = GridBagConstraints.HORIZONTAL;
    264516        c.gridx = 0;
    265         c.gridy = 5;
    266         c.weightx = 0;
    267         c.gridwidth = 1;
     517        c.gridy = 8;
     518        c.weightx = 0;
     519        c.gridwidth = 1;
     520        c.insets = new Insets(5, 5, 0, 5);
    268521        editPanel.add(streetEnabled, c);
    269522
     
    274527        c.fill = GridBagConstraints.HORIZONTAL;
    275528        c.gridx = 1;
    276         c.gridy = 5;
    277         c.weightx = 0;
    278         c.gridwidth = 1;
     529        c.gridy = 8;
     530        c.weightx = 0;
     531        c.gridwidth = 1;
     532        c.insets = new Insets(5, 5, 0, 5);
    279533        editPanel.add(streetRadio, c);
    280534
    281         JRadioButton placeRadio = new JRadioButton("addr:place");
     535        placeRadio = new JRadioButton("addr:place");
    282536        placeRadio.setToolTipText(TAG_STREET_OR_PLACE);
    283537        placeRadio.setSelected(!dto.isTagStreet());
     
    285539        c.fill = GridBagConstraints.HORIZONTAL;
    286540        c.gridx = 2;
    287         c.gridy = 5;
    288         c.weightx = 0;
    289         c.gridwidth = 1;
     541        c.gridy = 8;
     542        c.weightx = 0;
     543        c.gridwidth = 1;
     544        c.insets = new Insets(5, 5, 0, 5);
    290545        editPanel.add(placeRadio, c);
    291546
    292547        ButtonGroup g = new ButtonGroup();
    293         g.add( streetRadio );
     548        g.add(streetRadio);
    294549        g.add(placeRadio);
    295550
     
    305560        c.fill = GridBagConstraints.HORIZONTAL;
    306561        c.gridx = 3;
    307         c.gridy = 5;
    308         c.weightx = 1;
    309         c.gridwidth = 1;
     562        c.gridy = 8;
     563        c.weightx = 1;
     564        c.gridwidth = 1;
     565        c.insets = new Insets(5, 5, 0, 5);
    310566        editPanel.add(street, c);
     567
     568        JButton getStreetButton = new JButton("<");
     569        getStreetButton.setPreferredSize(new Dimension(45, 24));
     570        getStreetButton.setToolTipText(tr("Accept existing value"));
     571        getStreetButton.addActionListener(actionEvent -> updateStreetOrPlaceValues());
     572        c.fill = GridBagConstraints.NONE;
     573        c.gridx = 4;
     574        c.gridy = 8;
     575        c.weightx = 0;
     576        c.gridwidth = 1;
     577        c.insets = new Insets(5, 5, 0, 5);
     578        editPanel.add(getStreetButton, c);
     579
     580        JTextField streetOrPlace = new JTextField();
     581        streetOrPlace.setText(getStreetOrPlaceTag());
     582        streetOrPlace.setPreferredSize(new Dimension(50, 24));
     583        streetOrPlace.setEditable(false);
     584        c.fill = GridBagConstraints.HORIZONTAL;
     585        c.gridx = 5;
     586        c.gridy = 8;
     587        c.weightx = 0;
     588        c.gridwidth = 1;
     589        c.insets = new Insets(5, 5, 0, 5);
     590        editPanel.add(streetOrPlace, c);
     591
     592        JTextField existingStreet = new JTextField();
     593        existingStreet.setText(getStreetOrPlaceValue());
     594        existingStreet.setPreferredSize(new Dimension(100, 24));
     595        existingStreet.setEditable(false);
     596        c.fill = GridBagConstraints.HORIZONTAL;
     597        c.gridx = 6;
     598        c.gridy = 8;
     599        c.weightx = 1;
     600        c.gridwidth = 1;
     601        c.insets = new Insets(5, 5, 0, 5);
     602        editPanel.add(existingStreet, c);
     603
    311604
    312605        // housenumber
     
    317610        c.fill = GridBagConstraints.HORIZONTAL;
    318611        c.gridx = 0;
    319         c.gridy = 6;
     612        c.gridy = 9;
    320613        c.weightx = 0;
    321614        c.gridwidth = 3;
     615        c.insets = new Insets(5, 5, 0, 5);
    322616        editPanel.add(housenumberEnabled, c);
    323617
     
    325619        housnumber.setPreferredSize(new Dimension(200, 24));
    326620
    327         String number = incrementHouseNumber(dto.getHousenumber(), dto.getHousenumberChangeValue());
     621        String number = HouseNumberHelper.incrementHouseNumber(dto.getHousenumber(), dto.getHousenumberChangeValue());
    328622        if (number != null) {
    329623            housnumber.setText(number);
     
    332626        c.fill = GridBagConstraints.HORIZONTAL;
    333627        c.gridx = 3;
    334         c.gridy = 6;
    335         c.weightx = 1;
    336         c.gridwidth = 1;
     628        c.gridy = 9;
     629        c.weightx = 1;
     630        c.gridwidth = 1;
     631        c.insets = new Insets(5, 5, 0, 5);
    337632        editPanel.add(housnumber, c);
    338633
     634        JButton getHousenumberButton = new JButton("<");
     635        getHousenumberButton.setPreferredSize(new Dimension(45, 24));
     636        getHousenumberButton.setToolTipText(tr("Accept existing value"));
     637        getHousenumberButton.addActionListener(actionEvent -> housnumber.setText(selection.get(TAG_ADDR_HOUSENUMBER)));
     638        c.fill = GridBagConstraints.NONE;
     639        c.gridx = 4;
     640        c.gridy = 9;
     641        c.weightx = 0;
     642        c.gridwidth = 1;
     643        c.insets = new Insets(5, 5, 0, 5);
     644        editPanel.add(getHousenumberButton, c);
     645
     646        JTextField existingHousenumber = new JTextField();
     647        existingHousenumber.setText(selection.get(TAG_ADDR_HOUSENUMBER));
     648        existingHousenumber.setPreferredSize(new Dimension(200, 24));
     649        existingHousenumber.setEditable(false);
     650        c.fill = GridBagConstraints.HORIZONTAL;
     651        c.gridx = 5;
     652        c.gridy = 9;
     653        c.weightx = 1;
     654        c.gridwidth = 2;
     655        c.insets = new Insets(5, 5, 0, 5);
     656        editPanel.add(existingHousenumber, c);
     657
     658        // increment
    339659        JLabel seqLabel = new JLabel(tr("House number increment:"));
    340660        c.fill = GridBagConstraints.HORIZONTAL;
    341661        c.gridx = 0;
    342         c.gridy = 7;
     662        c.gridy = 10;
    343663        c.weightx = 0;
    344664        c.gridwidth = 3;
     665        c.insets = new Insets(5, 5, 0, 5);
    345666        editPanel.add(seqLabel, c);
    346667
    347         housenumberChangeSequence = new JSlider(JSlider.HORIZONTAL,  FPS_MIN, FPS_MAX, dto.getHousenumberChangeValue());
     668        housenumberChangeSequence = new JSlider(JSlider.HORIZONTAL, FPS_MIN, FPS_MAX, dto.getHousenumberChangeValue());
    348669        housenumberChangeSequence.setPaintTicks(true);
    349670        housenumberChangeSequence.setMajorTickSpacing(1);
     
    352673        housenumberChangeSequence.setSnapToTicks(true);
    353674        c.gridx = 3;
    354         c.gridy = 7;
    355         c.weightx = 1;
    356         c.gridwidth = 1;
     675        c.gridy = 10;
     676        c.weightx = 1;
     677        c.gridwidth = 4;
     678        c.insets = new Insets(20, 5, 10, 5);
    357679        editPanel.add(housenumberChangeSequence, c);
    358680
     
    360682    }
    361683
    362     static String incrementHouseNumber(String number, int increment) {
    363         if (number != null) {
    364             try {
    365                 Matcher m = Pattern.compile("([^\\pN]+)?(\\pN+)([^\\pN]+)?").matcher(number);
    366                 if (m.matches()) {
    367                     String prefix = m.group(1) != null ? m.group(1) : "";
    368                     int n = Integer.parseInt(m.group(2)) + increment;
    369                     String suffix = m.group(3) != null ? m.group(3) : "";
    370                     return prefix + n + suffix;
    371                 }
    372             } catch (NumberFormatException e)  {
    373                 // Do nothing
    374             }
    375         }
    376         return null;
     684    private void acceptAllExistingValues() {
     685        updateStreetOrPlaceValues();
     686        building.setSelectedItem(selection.get(TAG_BUILDING));
     687        source.setSelectedItem(selection.get(TAG_SOURCE));
     688        country.setSelectedItem(selection.get(TAG_ADDR_COUNTRY));
     689        state.setSelectedItem(selection.get(TAG_ADDR_STATE));
     690        suburb.setSelectedItem(selection.get(TAG_ADDR_SUBURB));
     691        city.setSelectedItem(selection.get(TAG_ADDR_CITY));
     692        postcode.setSelectedItem(selection.get(TAG_ADDR_POSTCODE));
     693        housnumber.setText(selection.get(TAG_ADDR_HOUSENUMBER));
     694    }
     695
     696    private void updateStreetOrPlaceValues() {
     697        if (selection.hasTag(TAG_ADDR_PLACE)) {
     698            placeRadio.setSelected(true);
     699            street.setSelectedItem(selection.get(TAG_ADDR_PLACE));
     700        }else {
     701            streetRadio.setSelected(true);
     702            street.setSelectedItem(selection.get(TAG_ADDR_STREET));
     703        }
     704    }
     705
     706    private String getStreetOrPlaceValue() {
     707        if (selection.hasTag(TAG_ADDR_PLACE)) {
     708            return selection.get(TAG_ADDR_PLACE);
     709        } else if (selection.hasTag(TAG_ADDR_STREET)) {
     710            return selection.get(TAG_ADDR_STREET);
     711        } else {
     712            return "";
     713        }
     714    }
     715
     716    private String getStreetOrPlaceTag() {
     717        if (selection.hasTag(TAG_ADDR_PLACE)) {
     718            return TAG_ADDR_PLACE;
     719        } else if (selection.hasTag(TAG_ADDR_STREET)) {
     720            return TAG_ADDR_STREET;
     721        } else {
     722            return "";
     723        }
    377724    }
    378725
     
    382729            Dto dto = new Dto();
    383730            dto.setSaveBuilding(buildingEnabled.isSelected());
     731            dto.setSaveSource(sourceEnabled.isSelected());
    384732            dto.setSaveCity(cityEnabled.isSelected());
    385733            dto.setSaveCountry(countryEnabled.isSelected());
     
    389737            dto.setSaveStreet(streetEnabled.isSelected());
    390738            dto.setTagStreet(streetRadio.isSelected());
     739            dto.setSaveSuburb(suburbEnabled.isSelected());
    391740
    392741            dto.setBuilding((String) building.getSelectedItem());
     742            dto.setSource(getAutoCompletingComboBoxValue(source));
    393743            dto.setCity(getAutoCompletingComboBoxValue(city));
    394744            dto.setCountry(getAutoCompletingComboBoxValue(country));
     
    397747            dto.setStreet(getAutoCompletingComboBoxValue(street));
    398748            dto.setState(getAutoCompletingComboBoxValue(state));
     749            dto.setSuburb(getAutoCompletingComboBoxValue(suburb));
    399750            dto.setHousenumberChangeValue(housenumberChangeSequence.getValue());
    400751
     
    449800        }
    450801
     802        if (dto.isSaveSource()) {
     803            String value = selection.get(TagDialog.TAG_SOURCE);
     804            if (value == null || (value != null && !value.equals(dto.getSource()))) {
     805                ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_SOURCE, dto.getSource());
     806                commands.add(command);
     807            }
     808        }
     809
    451810        if (dto.isSaveCity()) {
    452811            String value = selection.get(TagDialog.TAG_ADDR_CITY);
     
    461820            if (value == null || (value != null && !value.equals(dto.getCountry()))) {
    462821                ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_COUNTRY, dto.getCountry());
     822                commands.add(command);
     823            }
     824        }
     825
     826        if (dto.isSaveSuburb())  {
     827            String value = selection.get(TagDialog.TAG_ADDR_SUBURB);
     828            if (value == null || (value != null && !value.equals(dto.getSuburb()))) {
     829                ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_SUBURB, dto.getSuburb());
    463830                commands.add(command);
    464831            }
     
    547914            if (fileName.exists()) {
    548915                try (
    549                     FileInputStream file = new FileInputStream(fileName);
    550                     ObjectInputStream o = new ObjectInputStream(file);
     916                        FileInputStream file = new FileInputStream(fileName);
     917                        ObjectInputStream o = new ObjectInputStream(file);
    551918                ) {
    552919                    dto = (Dto) o.readObject();
    553920                }
    554921            } else {
    555                 dto.setCity(selection.get(TagDialog.TAG_ADDR_CITY));
    556                 dto.setCountry(selection.get(TagDialog.TAG_ADDR_COUNTRY));
    557                 dto.setHousenumber(selection.get(TagDialog.TAG_ADDR_HOUSENUMBER));
    558                 dto.setPostcode(selection.get(TagDialog.TAG_ADDR_POSTCODE));
    559                 dto.setStreet(selection.get(TagDialog.TAG_ADDR_STREET));
    560                 dto.setState(selection.get(TagDialog.TAG_ADDR_STATE));
     922                loadExistingValuesToDto(dto);
    561923            }
    562924        } catch (Exception ex) {
    563925            LOGGER.log(Level.SEVERE, ex.getMessage());
    564926            fileName.delete();
     927            loadExistingValuesToDto(dto);
    565928        }
    566929        return dto;
     930    }
     931
     932    private void loadExistingValuesToDto(Dto dto) {
     933        dto.setCity(selection.get(TagDialog.TAG_ADDR_CITY));
     934        dto.setCountry(selection.get(TagDialog.TAG_ADDR_COUNTRY));
     935        dto.setSource(selection.get(TagDialog.TAG_SOURCE));
     936        dto.setHousenumber(selection.get(TagDialog.TAG_ADDR_HOUSENUMBER));
     937        dto.setPostcode(selection.get(TagDialog.TAG_ADDR_POSTCODE));
     938        dto.setStreet(selection.get(TagDialog.TAG_ADDR_STREET));
     939        dto.setState(selection.get(TagDialog.TAG_ADDR_STATE));
     940        dto.setSuburb(selection.get(TagDialog.TAG_ADDR_SUBURB));
    567941    }
    568942
  • applications/editors/josm/plugins/HouseNumberTaggingTool/test

    • Property svn:ignore set to
      report
      build
      jacoco.exec
  • applications/editors/josm/plugins/HouseNumberTaggingTool/test/unit/org/openstreetmap/josm/plugins/housenumbertool/HouseNumberHelperTest.java

    r35507 r35508  
    1010 * Unit tests of {@link TagDialog}.
    1111 */
    12 public class TagDialogTest {
     12public class HouseNumberHelperTest {
    1313
    1414    /**
    15      * Unit test of {@link TagDialog#incrementHouseNumber}
     15     * Unit test of {@link HouseNumberHelper#incrementHouseNumber}
    1616     */
    1717    @Test
    1818    public void testIncrementHouseNumber() {
    19         assertEquals("2", TagDialog.incrementHouseNumber("1", 1));
    20         assertEquals("12", TagDialog.incrementHouseNumber("10", 2));
    21         assertEquals("2A", TagDialog.incrementHouseNumber("1A", 1));
    22         assertEquals("E2", TagDialog.incrementHouseNumber("E1", 1));
    23         //assertEquals("۲", TagDialog.incrementHouseNumber("۱", 1)); // FIXME: how to increment persian numbers ?
    24         assertEquals("2", TagDialog.incrementHouseNumber("۱", 1));
    25         assertNull(TagDialog.incrementHouseNumber(null, 1));
     19        assertEquals("2", HouseNumberHelper.incrementHouseNumber("1", 1));
     20        assertEquals("12", HouseNumberHelper.incrementHouseNumber("10", 2));
     21        assertEquals("2A", HouseNumberHelper.incrementHouseNumber("1A", 1));
     22        assertEquals("E2", HouseNumberHelper.incrementHouseNumber("E1", 1));
     23        //assertEquals("۲", HouseNumberHelper.incrementHouseNumber("۱", 1)); // FIXME: how to increment persian numbers ?
     24        assertEquals("2", HouseNumberHelper.incrementHouseNumber("۱", 1));
     25        assertNull(HouseNumberHelper.incrementHouseNumber(null, 1));
    2626    }
    2727}
Note: See TracChangeset for help on using the changeset viewer.