Changeset 272 in josm for src/org/openstreetmap


Ignore:
Timestamp:
2007-07-04T00:44:33+02:00 (17 years ago)
Author:
imi
Message:
  • added autocomplete combobox for the property dialog again (thanks Guilhem)
Location:
src/org/openstreetmap/josm
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java

    r254 r272  
    1212import java.awt.event.ActionEvent;
    1313import java.awt.event.ActionListener;
     14import java.awt.event.FocusAdapter;
     15import java.awt.event.FocusEvent;
    1416import java.awt.event.KeyEvent;
    1517import java.awt.event.MouseAdapter;
     
    3739import javax.swing.table.DefaultTableCellRenderer;
    3840import javax.swing.table.DefaultTableModel;
     41import javax.swing.text.JTextComponent;
    3942
    4043import org.openstreetmap.josm.Main;
     
    4851import org.openstreetmap.josm.gui.annotation.ForwardActionListener;
    4952import org.openstreetmap.josm.gui.preferences.AnnotationPresetPreference;
     53import org.openstreetmap.josm.tools.AutoCompleteComboBox;
    5054import org.openstreetmap.josm.tools.GBC;
    5155import org.openstreetmap.josm.tools.ImageProvider;
     
    165169
    166170        /**
    167          * Open the add selection dialog and add a new key/value to the table (and to the
    168          * dataset, of course).
     171         * Open the add selection dialog and add a new key/value to the table (and
     172         * to the dataset, of course).
    169173         */
    170174        void add() {
     
    193197                for (int i = 0; i < data.getRowCount(); ++i)
    194198                        allData.remove(data.getValueAt(i, 0));
    195                 final JComboBox keys = new JComboBox(new Vector<String>(allData.keySet()));
     199                final AutoCompleteComboBox keys = new AutoCompleteComboBox();
     200                keys.setPossibleItems(allData.keySet());
    196201                keys.setEditable(true);
     202               
    197203                p.add(keys, BorderLayout.CENTER);
    198204
     
    200206                p.add(p2, BorderLayout.SOUTH);
    201207                p2.add(new JLabel(tr("Please select a value")), BorderLayout.NORTH);
    202                 final JComboBox values = new JComboBox();
     208                final AutoCompleteComboBox values = new AutoCompleteComboBox();
    203209                values.setEditable(true);
    204210                p2.add(values, BorderLayout.CENTER);
    205                
    206                 ActionListener link = new ActionListener() {
    207 
    208                         public void actionPerformed(ActionEvent e) {
    209                                 String key = keys.getEditor().getItem().toString();
    210                                 if (allData.containsKey(key)) {
    211                                         Vector<String> newValues = new Vector<String>(allData.get(key));
    212                                         Object oldValue = values.getSelectedItem();
    213                                         values.setModel(new DefaultComboBoxModel(newValues));
    214                                         values.setSelectedItem(oldValue);
    215                                         values.getEditor().selectAll();
     211           
     212                // get the combo box' editor component
     213                JTextComponent editor = (JTextComponent) values.getEditor().getEditorComponent();
     214                // Refresh the values model when focus is gained
     215                editor.addFocusListener(new FocusAdapter() {
     216            public void focusGained(FocusEvent e) {
     217                String key = keys.getEditor().getItem().toString();
     218                if (allData.containsKey(key)) {
     219                                        values.setPossibleItems(allData.get(key));
     220                                } else {
     221                                        values.removeAllItems();
    216222                                }
    217223            }
    218                        
    219                 };
    220                 keys.addActionListener(link);
    221                
     224        });
     225
    222226                JOptionPane pane = new JOptionPane(p, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION){
    223227                        @Override public void selectInitialValue() {
Note: See TracChangeset for help on using the changeset viewer.