Changeset 2048 in josm for trunk/src/org/openstreetmap/josm/gui/tagging/AutoCompletingTextField.java
- Timestamp:
- 04.09.2009 10:49:53 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/AutoCompletingTextField.java
r2040 r2048 2 2 package org.openstreetmap.josm.gui.tagging; 3 3 4 import java.awt.Component; 4 5 import java.awt.event.FocusAdapter; 5 6 import java.awt.event.FocusEvent; … … 8 9 import java.util.logging.Logger; 9 10 11 import javax.swing.ComboBoxEditor; 10 12 import javax.swing.JTextField; 11 13 import javax.swing.text.AttributeSet; … … 14 16 import javax.swing.text.PlainDocument; 15 17 16 import org.openstreetmap.josm.gui. dialogs.relation.ac.AutoCompletionList;18 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 17 19 18 20 /** … … 25 27 * 26 28 */ 27 public class AutoCompletingTextField extends JTextField {29 public class AutoCompletingTextField extends JTextField implements ComboBoxEditor { 28 30 29 31 static private Logger logger = Logger.getLogger(AutoCompletingTextField.class.getName()); … … 54 56 return; 55 57 } 58 56 59 String currentText = getText(0, getLength()); 60 // if the text starts with a number we don't autocomplete 61 // 62 try { 63 Long.parseLong(str); 64 if (currentText.length() == 0) { 65 // we don't autocomplete on numbers 66 super.insertString(offs, str, a); 67 return; 68 } 69 Long.parseLong(currentText); 70 super.insertString(offs, str, a); 71 return; 72 } catch(NumberFormatException e) { 73 // either the new text or the current text isn't a number. We continue with 74 // autocompletion 75 } 57 76 String prefix = currentText.substring(0, offs); 58 77 autoCompletionList.applyFilter(prefix+str); … … 150 169 this.autoCompletionList = autoCompletionList; 151 170 } 171 172 public Component getEditorComponent() { 173 return this; 174 } 175 176 public Object getItem() { 177 return getText(); 178 } 179 180 public void setItem(Object anObject) { 181 if (anObject == null) { 182 setText(""); 183 } else { 184 setText(anObject.toString()); 185 } 186 187 } 188 189 152 190 }
Note: See TracChangeset
for help on using the changeset viewer.
