Changeset 272 in josm
- Timestamp:
- 2007-07-04T00:44:33+02:00 (18 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r254 r272 12 12 import java.awt.event.ActionEvent; 13 13 import java.awt.event.ActionListener; 14 import java.awt.event.FocusAdapter; 15 import java.awt.event.FocusEvent; 14 16 import java.awt.event.KeyEvent; 15 17 import java.awt.event.MouseAdapter; … … 37 39 import javax.swing.table.DefaultTableCellRenderer; 38 40 import javax.swing.table.DefaultTableModel; 41 import javax.swing.text.JTextComponent; 39 42 40 43 import org.openstreetmap.josm.Main; … … 48 51 import org.openstreetmap.josm.gui.annotation.ForwardActionListener; 49 52 import org.openstreetmap.josm.gui.preferences.AnnotationPresetPreference; 53 import org.openstreetmap.josm.tools.AutoCompleteComboBox; 50 54 import org.openstreetmap.josm.tools.GBC; 51 55 import org.openstreetmap.josm.tools.ImageProvider; … … 165 169 166 170 /** 167 * Open the add selection dialog and add a new key/value to the table (and to the168 * 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). 169 173 */ 170 174 void add() { … … 193 197 for (int i = 0; i < data.getRowCount(); ++i) 194 198 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()); 196 201 keys.setEditable(true); 202 197 203 p.add(keys, BorderLayout.CENTER); 198 204 … … 200 206 p.add(p2, BorderLayout.SOUTH); 201 207 p2.add(new JLabel(tr("Please select a value")), BorderLayout.NORTH); 202 final JComboBox values = newJComboBox();208 final AutoCompleteComboBox values = new AutoCompleteComboBox(); 203 209 values.setEditable(true); 204 210 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.set Model(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(); 216 222 } 217 223 } 218 219 }; 220 keys.addActionListener(link); 221 224 }); 225 222 226 JOptionPane pane = new JOptionPane(p, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION){ 223 227 @Override public void selectInitialValue() {
Note:
See TracChangeset
for help on using the changeset viewer.