Ignore:
Timestamp:
04.09.2009 10:49:53 (3 years ago)
Author:
Gubaer
Message:

Improved auto completion
fixed #2729: Auto completion with numbers sometimes annoying (only fixed in presets, relation editor, not in property dialog)
fixed #2320: Preset dialog for house numbers should have autocompletion (auto completion now supported in all preset dialogs)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/AutoCompletingTextField.java

    r2040 r2048  
    22package org.openstreetmap.josm.gui.tagging; 
    33 
     4import java.awt.Component; 
    45import java.awt.event.FocusAdapter; 
    56import java.awt.event.FocusEvent; 
     
    89import java.util.logging.Logger; 
    910 
     11import javax.swing.ComboBoxEditor; 
    1012import javax.swing.JTextField; 
    1113import javax.swing.text.AttributeSet; 
     
    1416import javax.swing.text.PlainDocument; 
    1517 
    16 import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionList; 
     18import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 
    1719 
    1820/** 
     
    2527 * 
    2628 */ 
    27 public class AutoCompletingTextField extends JTextField { 
     29public class AutoCompletingTextField extends JTextField implements ComboBoxEditor { 
    2830 
    2931    static private Logger logger = Logger.getLogger(AutoCompletingTextField.class.getName()); 
     
    5456                return; 
    5557            } 
     58 
    5659            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            } 
    5776            String prefix = currentText.substring(0, offs); 
    5877            autoCompletionList.applyFilter(prefix+str); 
     
    150169        this.autoCompletionList = autoCompletionList; 
    151170    } 
     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 
    152190} 
Note: See TracChangeset for help on using the changeset viewer.