Changeset 29475 in osm


Ignore:
Timestamp:
2013-04-04T19:10:01+02:00 (12 years ago)
Author:
raupach
Message:

add slider and dropbox

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

Legend:

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

    r27510 r29475  
    22=================================
    33
    4 Simple tool to tag house numbers. Select house and press 'Y'. Select your addr-tags and press OK.
     4Simple tool to tag house numbers. Select house and press 'k'. Select your addr-tags and press OK.
    55
    66author: Oliver Raupach, oliver@raupach.cc
  • applications/editors/josm/plugins/HouseNumberTaggingTool/src/org/openstreetmap/josm/plugins/housenumbertool/Dto.java

    r27510 r29475  
    88public class Dto implements Serializable
    99{
    10 
    11    /**
    12     *
    13     */
    14    private static final long serialVersionUID = -4025800761473341695L;
     10   private static final long serialVersionUID = -4035800761473241695L;
    1511
    1612   private boolean saveBuilding = true;
     
    2218   private boolean saveHousenumber = true;
    2319
     20   private String building = "yes";
    2421   private String country;
    2522   private String state;
     
    2825   private String street;
    2926   private String housenumber;
     27   private int housenumberChangeValue = 0;
    3028
    3129   public boolean isSaveBuilding()
     
    158156      this.saveState = saveState;
    159157   }
     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   }
    160178}
  • applications/editors/josm/plugins/HouseNumberTaggingTool/src/org/openstreetmap/josm/plugins/housenumbertool/LaunchAction.java

    r28039 r29475  
    1414{
    1515
    16    /**
    17     *
    18     */
    1916   private static final long serialVersionUID = -3508864293222033185L;
    2017   private OsmPrimitive selection = null;
  • applications/editors/josm/plugins/HouseNumberTaggingTool/src/org/openstreetmap/josm/plugins/housenumbertool/TagDialog.java

    r28039 r29475  
    44import static org.openstreetmap.josm.tools.I18n.trn;
    55
    6 import java.awt.*;
     6import java.awt.Dimension;
     7import java.awt.GridBagConstraints;
     8import java.awt.GridBagLayout;
    79import java.awt.event.ActionEvent;
    810import java.io.File;
     
    1214import java.io.ObjectOutputStream;
    1315import java.util.ArrayList;
     16import java.util.Arrays;
    1417import java.util.Collection;
    1518import java.util.TreeSet;
     
    1821
    1922import javax.swing.JCheckBox;
     23import javax.swing.JComboBox;
     24import javax.swing.JLabel;
    2025import javax.swing.JPanel;
     26import javax.swing.JSlider;
    2127import javax.swing.JTextField;
    2228import javax.swing.SwingUtilities;
     
    4551   public static final String TAG_ADDR_HOUSENUMBER = "addr:housenumber";
    4652   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   
    5059   private static final long serialVersionUID = 6414385452106276923L;
     60
    5161   static private final Logger logger = Logger.getLogger(TagDialog.class.getName());
     62
    5263   private String pluginDir;
    5364   private AutoCompletionManager acm;
     
    5566
    5667   public static final String TEMPLATE_DATA = "/template.data";
    57  
     68
    5869   private AutoCompletingComboBox country;
    59     private AutoCompletingComboBox state;
     70   private AutoCompletingComboBox state;
    6071   private AutoCompletingComboBox city;
    6172   private AutoCompletingComboBox postcode;
     
    6475   private JCheckBox buildingEnabled;
    6576   private JCheckBox countryEnabled;
    66     private JCheckBox stateEnabled;
     77   private JCheckBox stateEnabled;
    6778   private JCheckBox cityEnabled;
    6879   private JCheckBox zipEnabled;
    6980   private JCheckBox streetEnabled;
    7081   private JCheckBox housenumberEnabled;
     82   private JSlider housenumberChangeSequence;
     83   private JComboBox building;
    7184
    7285   public TagDialog(String pluginDir, OsmPrimitive p_selection)
    7386   {
    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);
    7988      this.pluginDir = pluginDir;
    8089      this.selection = p_selection;
    8190
    82        JPanel editPanel = createContentPane();
    83 
     91      JPanel editPanel = createContentPane();
    8492
    8593      setContent(editPanel);
    86        setButtonIcons(new String[] {"ok.png", "cancel.png" });
    87        setDefaultButton(1);
    88        setupDialog();
    89        getRootPane().setDefaultButton(defaultButton);
     94      setButtonIcons(new String[] { "ok.png", "cancel.png" });
     95      setDefaultButton(1);
     96      setupDialog();
     97      getRootPane().setDefaultButton(defaultButton);
    9098
    9199      // middle of the screen
     
    102110   }
    103111
    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());
    316322         
    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   }
    434473
    435474   private Dto loadDto()
     
    437476      Dto dto = new Dto();
    438477      File fileName = new File(pluginDir + TagDialog.TEMPLATE_DATA);
    439      
     478
    440479      try
    441480      {
    442        
     481
    443482         if (fileName.exists())
    444483         {
     
    451490         else
    452491         {
    453                 dto.setCity(selection.get(TagDialog.TAG_ADDR_CITY));
    454                 dto.setCountry(selection.get(TagDialog.TAG_ADDR_COUNTRY)); 
    455                 dto.setHousenumber(selection.get(TagDialog.TAG_ADDR_HOUSENUMBER));
    456                 dto.setPostcode(selection.get(TagDialog.TAG_ADDR_POSTCODE));
    457                 dto.setStreet(selection.get(TagDialog.TAG_ADDR_STREET));
    458                 dto.setState(selection.get(TagDialog.TAG_ADDR_STATE));
     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));
    459498         }
    460499
     
    464503         logger.log(Level.SEVERE, ex.getMessage());
    465504         if (fileName != null)
    466          { 
    467                 fileName.delete();
     505         {
     506            fileName.delete();
    468507         }
    469508      }
Note: See TracChangeset for help on using the changeset viewer.