Changeset 28039 in osm


Ignore:
Timestamp:
2012-03-11T14:39:53+01:00 (13 years ago)
Author:
raupach
Message:

add AutoCompleteComboBox.

Location:
applications/editors/josm/plugins/HouseNumberTaggingTool
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/HouseNumberTaggingTool/build.xml

    r27852 r28039  
    9696                <attribute name="Author" value="Oliver Raupach"/>
    9797                <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.housenumbertool.HouseNumberTaggingToolPlugin"/>
    98                 <attribute name="Plugin-Description" value="Simple tool to tag house numbers. Select house and press «Y»."/>
     98                <attribute name="Plugin-Description" value="Simple tool to tag house numbers."/>
    9999                <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/>
    100100                <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
  • applications/editors/josm/plugins/HouseNumberTaggingTool/src/org/openstreetmap/josm/plugins/housenumbertool/LaunchAction.java

    r27852 r28039  
    4747     
    4848      TagDialog dialog = new TagDialog(pluginDir, selection);
    49       dialog.setVisible(true);
    50      
     49      dialog.showDialog();
     50
    5151   }
    5252
  • applications/editors/josm/plugins/HouseNumberTaggingTool/src/org/openstreetmap/josm/plugins/housenumbertool/TagDialog.java

    r27510 r28039  
    11package org.openstreetmap.josm.plugins.housenumbertool;
    22
     3import static org.openstreetmap.josm.tools.I18n.tr;
    34import static org.openstreetmap.josm.tools.I18n.trn;
    45
    5 import java.awt.BorderLayout;
    6 import java.awt.Dimension;
    7 import java.awt.GridBagConstraints;
    8 import java.awt.GridBagLayout;
    9 import java.awt.GridLayout;
     6import java.awt.*;
    107import java.awt.event.ActionEvent;
    11 import java.awt.event.ActionListener;
    12 import java.awt.event.FocusEvent;
    13 import java.awt.event.FocusListener;
    14 import java.awt.event.KeyEvent;
    15 import java.awt.event.MouseEvent;
    16 import java.awt.event.MouseListener;
    178import java.io.File;
    189import java.io.FileInputStream;
     
    2112import java.io.ObjectOutputStream;
    2213import java.util.ArrayList;
    23 import java.util.List;
     14import java.util.Collection;
     15import java.util.TreeSet;
    2416import java.util.logging.Level;
    2517import java.util.logging.Logger;
    2618
    27 import javax.swing.JButton;
    2819import javax.swing.JCheckBox;
    29 import javax.swing.JComponent;
    30 import javax.swing.JDialog;
    3120import javax.swing.JPanel;
    32 import javax.swing.JScrollPane;
    33 import javax.swing.JTable;
    3421import javax.swing.JTextField;
    35 import javax.swing.KeyStroke;
    3622import javax.swing.SwingUtilities;
    3723
     
    4127import org.openstreetmap.josm.command.SequenceCommand;
    4228import org.openstreetmap.josm.data.osm.OsmPrimitive;
     29import org.openstreetmap.josm.gui.ExtendedDialog;
     30import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox;
    4331import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
    4432import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
     
    4634/**
    4735 * @author Oliver Raupach 09.01.2012 <http://www.oliver-raupach.de>
     36 * @author Victor Kropp 10.03.2012 <http://victor.kropp.name>
    4837 */
    49 public class TagDialog extends JDialog
     38public class TagDialog extends ExtendedDialog
    5039{
    5140   public static final String TAG_BUILDING = "building";
     
    6150   private static final long serialVersionUID = 6414385452106276923L;
    6251   static private final Logger logger = Logger.getLogger(TagDialog.class.getName());
    63    private SimpleTagTableModel model;
    6452   private String pluginDir;
    6553   private AutoCompletionManager acm;
     
    6856   public static final String TEMPLATE_DATA = "/template.data";
    6957 
    70    private JTextField country;
    71    private JTextField city;
    72    private JTextField postcode;
    73    private JTextField street;
     58   private AutoCompletingComboBox country;
     59    private AutoCompletingComboBox state;
     60   private AutoCompletingComboBox city;
     61   private AutoCompletingComboBox postcode;
     62   private AutoCompletingComboBox street;
    7463   private JTextField housnumber;
    7564   private JCheckBox buildingEnabled;
    7665   private JCheckBox countryEnabled;
     66    private JCheckBox stateEnabled;
    7767   private JCheckBox cityEnabled;
    7868   private JCheckBox zipEnabled;
    7969   private JCheckBox streetEnabled;
    8070   private JCheckBox housenumberEnabled;
    81    private JTextField state;
    82    private JCheckBox stateEnabled;
    8371
    8472   public TagDialog(String pluginDir, OsmPrimitive p_selection)
    8573   {
    86       super();
     74       super(Main.parent,
     75               tr("House Number Editor"),
     76               new String[] { tr("OK"), tr("Cancel")},
     77               true
     78       );
    8779      this.pluginDir = pluginDir;
    8880      this.selection = p_selection;
    8981
    90       model = new SimpleTagTableModel();
    91       acm = selection.getDataSet().getAutoCompletionManager();
    92 
    93       Dto dto = loadDto();
    94 
    95       setModalityType(ModalityType.APPLICATION_MODAL);
    96       setLayout(new BorderLayout(5, 5));
    97 
    98       JPanel centerPanel = new JPanel();
    99       JPanel editPanel = new JPanel(new GridBagLayout());
    100       GridBagConstraints c = new GridBagConstraints();
    101 
    102       buildingEnabled = new JCheckBox(TAG_BUILDING);
    103       buildingEnabled.setSelected(dto.isSaveBuilding());
    104       c.fill = GridBagConstraints.HORIZONTAL;
    105       c.gridx = 0;
    106       c.gridy = 0;
    107       c.weightx = 0;
    108       editPanel.add(buildingEnabled, c);
    109 
    110       JTextField building = new JTextField();
    111       building.setPreferredSize(new Dimension(200, 20));
    112       building.setText("yes");
    113       building.setEditable(false);
    114       c.gridx = 1;
    115       c.gridy = 0;
    116       c.weightx = 1;
    117       editPanel.add(building, c);
    118 
    119       // country
    120       countryEnabled = new JCheckBox(TAG_ADDR_COUNTRY);
    121       countryEnabled.setSelected(dto.isSaveCountry());
    122       c = new GridBagConstraints();
    123       c.fill = GridBagConstraints.HORIZONTAL;
    124       c.gridx = 0;
    125       c.gridy = 1;
    126       c.weightx = 0;
    127       editPanel.add(countryEnabled, c);
    128 
    129       country = new JTextField();
    130       country.addFocusListener(new MyFocusListener(acm, model, TAG_ADDR_COUNTRY));
    131       country.setPreferredSize(new Dimension(200, 20));
    132       country.setText(dto.getCountry());
    133       c.fill = GridBagConstraints.HORIZONTAL;
    134       c.gridx = 1;
    135       c.gridy = 1;
    136       c.weightx = 1;
    137       editPanel.add(country, c);
    138      
    139       // state
    140       stateEnabled = new JCheckBox(TAG_ADDR_STATE);
    141       stateEnabled.setSelected(dto.isSaveState());
    142       c = new GridBagConstraints();
    143       c.fill = GridBagConstraints.HORIZONTAL;
    144       c.gridx = 0;
    145       c.gridy = 2;
    146       c.weightx = 0;
    147       editPanel.add(stateEnabled, c);
    148 
    149       state = new JTextField();
    150       state.addFocusListener(new MyFocusListener(acm, model, TAG_ADDR_STATE));
    151       state.setPreferredSize(new Dimension(200, 20));
    152       state.setText(dto.getState());
    153       c.fill = GridBagConstraints.HORIZONTAL;
    154       c.gridx = 1;
    155       c.gridy = 2;
    156       c.weightx = 1;
    157       editPanel.add(state, c);
    158 
    159       // city
    160       cityEnabled = new JCheckBox(TAG_ADDR_CITY);
    161       cityEnabled.setSelected(dto.isSaveCity());
    162       c.fill = GridBagConstraints.HORIZONTAL;
    163       c.gridx = 0;
    164       c.gridy = 3;
    165       c.weightx = 0;
    166       editPanel.add(cityEnabled, c);
    167 
    168       city = new JTextField();
    169       city.addFocusListener(new MyFocusListener(acm, model, TAG_ADDR_CITY));
    170       city.setPreferredSize(new Dimension(200, 20));
    171       city.setText(dto.getCity());
    172       c.fill = GridBagConstraints.HORIZONTAL;
    173       c.gridx = 1;
    174       c.gridy = 3;
    175       c.weightx = 1;
    176       editPanel.add(city, c);
    177 
    178       // postcode
    179       zipEnabled = new JCheckBox(TAG_ADDR_POSTCODE);
    180       zipEnabled.setSelected(dto.isSavePostcode());
    181       c.fill = GridBagConstraints.HORIZONTAL;
    182       c.gridx = 0;
    183       c.gridy = 4;
    184       c.weightx = 0;
    185       editPanel.add(zipEnabled, c);
    186 
    187       postcode = new JTextField();
    188       postcode.addFocusListener(new MyFocusListener(acm, model, TAG_ADDR_POSTCODE));
    189       postcode.setPreferredSize(new Dimension(200, 20));
    190       postcode.setText(dto.getPostcode());
    191       c.fill = GridBagConstraints.HORIZONTAL;
    192       c.gridx = 1;
    193       c.gridy = 4;
    194       c.weightx = 1;
    195       editPanel.add(postcode, c);
    196 
    197       // street
    198       streetEnabled = new JCheckBox(TAG_ADDR_STREET);
    199       streetEnabled.setSelected(dto.isSaveStreet());
    200       c.fill = GridBagConstraints.HORIZONTAL;
    201       c.gridx = 0;
    202       c.gridy = 5;
    203       c.weightx = 0;
    204       editPanel.add(streetEnabled, c);
    205 
    206       street = new JTextField();
    207       street.setPreferredSize(new Dimension(200, 20));
    208       street.addFocusListener(new MyFocusListener(acm, model, TAG_ADDR_STREET));
    209       street.setText(dto.getStreet());
    210       c.fill = GridBagConstraints.HORIZONTAL;
    211       c.gridx = 1;
    212       c.gridy = 5;
    213       c.weightx = 1;
    214       editPanel.add(street, c);
    215 
    216       // housenumber
    217       housenumberEnabled = new JCheckBox(TAG_ADDR_HOUSENUMBER);
    218       housenumberEnabled.setSelected(dto.isSaveHousenumber());
    219       c.fill = GridBagConstraints.HORIZONTAL;
    220       c.gridx = 0;
    221       c.gridy = 6;
    222       c.weightx = 0;
    223       editPanel.add(housenumberEnabled, c);
    224 
    225       housnumber = new JTextField();
    226       housnumber.addFocusListener(new MyFocusListener(acm, model, TAG_ADDR_HOUSENUMBER));
    227       housnumber.setPreferredSize(new Dimension(200, 20));
    228       housnumber.setText(dto.getHousenumber());
    229       c.fill = GridBagConstraints.HORIZONTAL;
    230       c.gridx = 1;
    231       c.gridy = 6;
    232       c.weightx = 1;
    233       editPanel.add(housnumber, c);
    234 
    235       JPanel panelEast = new JPanel(new GridLayout(0, 1));
    236       JTable table = new JTable(model);
    237       table.setPreferredScrollableViewportSize(new Dimension(300, 200));
    238       table.addMouseListener(new MouseListener()
    239       {
    240 
    241          @Override
    242          public void mouseReleased(MouseEvent e)
    243          {
    244              JTable target = (JTable) e.getSource();
    245              int row = target.getSelectedRow();
    246              String selectedValue = (String) model.getValueAt(row, 0);
    247              String tag = model.getDisplayTag();
    248 
    249              if (tag.equals(TAG_ADDR_COUNTRY))
    250              {
    251                 country.setText(selectedValue);
    252              }
    253              if (tag.equals(TAG_ADDR_STATE))
    254              {
    255                 state.setText(selectedValue);
    256              }
    257              else if (tag.equals(TAG_ADDR_CITY))
    258              {
    259                 city.setText(selectedValue);
    260              }
    261              else if (tag.equals(TAG_ADDR_POSTCODE))
    262              {
    263                 postcode.setText(selectedValue);
    264              }
    265              else if (tag.equals(TAG_ADDR_HOUSENUMBER))
    266              {
    267                 housnumber.setText(selectedValue);
    268              }
    269              else if (tag.equals(TAG_ADDR_STREET))
    270              {
    271                 street.setText(selectedValue);
    272              }           
    273          }
    274 
    275          @Override
    276          public void mousePressed(MouseEvent e)
    277          {
    278          }
    279 
    280          @Override
    281          public void mouseExited(MouseEvent e)
    282          {
    283          }
    284 
    285          @Override
    286          public void mouseEntered(MouseEvent e)
    287          {
    288          }
    289 
    290          @Override
    291          public void mouseClicked(MouseEvent e)
    292          {
    293 
    294          }
    295       });
    296 
    297       JScrollPane scrollPane = new JScrollPane(table);
    298       table.setFillsViewportHeight(true);
    299 
    300       panelEast.add(scrollPane);
    301 
    302       JButton btnOk = new JButton("OK");
    303       btnOk.addActionListener(new OkDialogListener(this, pluginDir)
    304       {
    305 
    306          @Override
    307          public void actionPerformed(ActionEvent e)
    308          {
    309             Dto dto = new Dto();
    310             dto.setSaveBuilding(buildingEnabled.isSelected());
    311             dto.setSaveCity(cityEnabled.isSelected());
    312             dto.setSaveCountry(countryEnabled.isSelected());
    313             dto.setSaveState(stateEnabled.isSelected());
    314             dto.setSaveHousenumber(housenumberEnabled.isSelected());
    315             dto.setSavePostcode(zipEnabled.isSelected());
    316             dto.setSaveStreet(streetEnabled.isSelected());
    317 
    318             dto.setCity(city.getText());
    319             dto.setCountry(country.getText());
    320             dto.setHousenumber(housnumber.getText());
    321             dto.setPostcode(postcode.getText());
    322             dto.setStreet(street.getText());
    323             dto.setState(state.getText());
    324            
    325             updateJOSMSelection(selection, dto);
    326             saveDto(dto);
    327             tagDialog.setVisible(false);
    328          }
    329       });
    330 
    331       JButton btnCancel = new JButton("Cancel");
    332       btnCancel.addActionListener(new CancelDialogListener(this));
    333 
    334       JPanel bp = new JPanel();
    335       bp.add(btnOk);
    336       bp.add(btnCancel);
    337  
    338       centerPanel.add(editPanel);
    339       getContentPane().add(new TopPanel(), BorderLayout.NORTH);
    340       getContentPane().add(centerPanel, BorderLayout.CENTER);
    341       getContentPane().add(panelEast, BorderLayout.EAST);
    342       getContentPane().add(bp, BorderLayout.PAGE_END);
    343 
    344       ActionListener listener = new ActionListener() {
    345           public final void actionPerformed(ActionEvent e) {
    346               setVisible(false);
    347               dispose();
    348           }
    349       };
    350       KeyStroke keyStrokeESC = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true);
    351       getRootPane().registerKeyboardAction(listener, keyStrokeESC,  JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    352      
    353       pack();
     82       JPanel editPanel = createContentPane();
     83
     84
     85      setContent(editPanel);
     86       setButtonIcons(new String[] {"ok.png", "cancel.png" });
     87       setDefaultButton(1);
     88       setupDialog();
     89       getRootPane().setDefaultButton(defaultButton);
    35490
    35591      // middle of the screen
     
    366102   }
    367103
     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       {
     316         
     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        }
     434
    368435   private Dto loadDto()
    369436   {
    370437      Dto dto = new Dto();
    371 
     438      File fileName = new File(pluginDir + TagDialog.TEMPLATE_DATA);
     439     
    372440      try
    373441      {
    374          File fileName = new File(pluginDir + TagDialog.TEMPLATE_DATA);
     442       
    375443         if (fileName.exists())
    376444         {
     
    381449            o.close();
    382450         }
     451         else
     452         {
     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));
     459         }
    383460
    384461      }
     
    386463      {
    387464         logger.log(Level.SEVERE, ex.getMessage());
    388       }
    389 
    390       return dto;
    391 
    392    }
    393 
    394 }
    395 
    396 class CancelDialogListener implements ActionListener
    397 {
    398 
    399    TagDialog tagDialog;
    400 
    401    public CancelDialogListener(TagDialog tagDialog)
    402    {
    403       this.tagDialog = tagDialog;
    404    }
    405 
    406    @Override
    407    public void actionPerformed(ActionEvent e)
    408    {
    409       tagDialog.setVisible(false);
    410    }
    411 
    412 }
    413 
    414 class OkDialogListener implements ActionListener
    415 {
    416    static private final Logger logger = Logger.getLogger(OkDialogListener.class.getName());
    417 
    418    TagDialog tagDialog;
    419    String pluginDir;
    420 
    421    public OkDialogListener(TagDialog tagDialog, String pluginDir)
    422    {
    423       this.tagDialog = tagDialog;
    424       this.pluginDir = pluginDir;
    425    }
    426 
    427    @Override
    428    public void actionPerformed(ActionEvent e)
    429    {
    430    }
    431 
    432    protected void saveDto(Dto dto)
    433    {
    434 
    435       try
    436       {
    437          File path = new File(pluginDir);
    438          path.mkdirs();
    439 
    440          File fileName = new File(pluginDir + TagDialog.TEMPLATE_DATA);
    441          FileOutputStream file = new FileOutputStream(fileName);
    442          ObjectOutputStream o = new ObjectOutputStream(file);
    443          o.writeObject(dto);
    444          o.close();
    445       }
    446       catch (Exception ex)
    447       {
    448          logger.log(Level.SEVERE, ex.getMessage());
    449       }
    450    }
    451 
    452    protected void updateJOSMSelection(OsmPrimitive selection, Dto dto)
    453    {
    454       ArrayList<Command> commands = new ArrayList<Command>();
    455 
    456       if (dto.isSaveBuilding())
    457       {
    458          String value = selection.get(TagDialog.TAG_BUILDING);
    459          if (value == null || (value != null && !value.equals("yes")))
    460          {
    461             ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_BUILDING, "yes");
    462             commands.add(command);
     465         if (fileName != null)
     466         { 
     467                fileName.delete();
    463468         }
    464469      }
    465470
    466       if (dto.isSaveCity())
    467       {
    468          String value = selection.get(TagDialog.TAG_ADDR_CITY);
    469          if (value == null || (value != null && !value.equals(dto.getCity())))
    470          {
    471             ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_CITY, dto.getCity());
    472             commands.add(command);
    473          }
    474       }
    475      
    476       if (dto.isSaveCountry())
    477       {
    478          String value = selection.get(TagDialog.TAG_ADDR_COUNTRY);
    479          if (value == null || (value != null && !value.equals(dto.getCountry())))
    480          {
    481             ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_COUNTRY, dto.getCountry());
    482             commands.add(command);
    483          }
    484       }
    485      
    486       if (dto.isSaveHousenumber())
    487       {
    488          String value = selection.get(TagDialog.TAG_ADDR_HOUSENUMBER);
    489          if (value == null || (value != null && !value.equals(dto.getHousenumber())))
    490          {
    491             ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_HOUSENUMBER, dto.getHousenumber());
    492             commands.add(command);
    493          }
    494       }
    495      
    496       if (dto.isSavePostcode())
    497       {
    498          String value = selection.get(TagDialog.TAG_ADDR_POSTCODE);
    499          if (value == null || (value != null && !value.equals(dto.getPostcode())))
    500          {
    501             ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_POSTCODE, dto.getPostcode());
    502             commands.add(command);
    503          }
    504       }
    505      
    506       if (dto.isSaveStreet())
    507       {
    508          String value = selection.get(TagDialog.TAG_ADDR_STREET);
    509          if (value == null || (value != null && !value.equals(dto.getStreet())))
    510          {
    511             ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_STREET, dto.getStreet());
    512             commands.add(command);
    513          }
    514       }
    515      
    516       if (dto.isSaveState())
    517       {
    518          String value = selection.get(TagDialog.TAG_ADDR_STATE);
    519          if (value == null || (value != null && !value.equals(dto.getState())))
    520          {
    521             ChangePropertyCommand command = new ChangePropertyCommand(selection, TagDialog.TAG_ADDR_STATE, dto.getState());
    522             commands.add(command);
    523          }
    524       }     
    525      
    526       if (commands.size() > 0)
    527       {
    528          SequenceCommand sequenceCommand = new SequenceCommand(trn("Updating properties of up to {0} object", "Updating properties of up to {0} objects", commands.size(), commands.size()), commands);
    529 
    530          // executes the commands and adds them to the undo/redo chains
    531          Main.main.undoRedo.add(sequenceCommand);
    532       }
     471      return dto;
     472
    533473   }
    534 
    535474}
    536 
    537 class MyFocusListener implements FocusListener
    538 {
    539    private String tag;
    540    private SimpleTagTableModel model;
    541    private AutoCompletionManager acm;
    542 
    543    public MyFocusListener(AutoCompletionManager acm, SimpleTagTableModel model, String tag)
    544    {
    545       this.tag = tag;
    546       this.acm = acm;
    547       this.model = model;
    548    }
    549 
    550    @Override
    551    public void focusGained(FocusEvent e)
    552    {
    553       List<TagData> modelData = new ArrayList<TagData>();
    554       List<AutoCompletionListItem> values = acm.getValues(tag);
    555       for (AutoCompletionListItem value : values)
    556       {
    557          TagData tagData = new TagData(value.getValue());
    558          modelData.add(tagData);
    559          model.setDisplayTag(tag);
    560       }
    561 
    562       model.setModelData(modelData);
    563    }
    564 
    565    @Override
    566    public void focusLost(FocusEvent e)
    567    {
    568 
    569    }
    570 
    571 }
    572 
Note: See TracChangeset for help on using the changeset viewer.