Changeset 5579 in josm


Ignore:
Timestamp:
2012-11-13T21:18:57+01:00 (11 years ago)
Author:
Don-vip
Message:

see #8180 - Presets: Allow length of input box for text

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/defaultpresets.xml

    r5559 r5579  
    3636  use_last_as_default: true/false/force (default is "false")
    3737  match: none/key/key!/keyvalue (default is "none", see below for more information)
     38  length: length of input box (number of characters allowed)
    3839
    3940combo: combo box, with multiple choices and possible to enter free form text
  • trunk/data/tagging-preset.xsd

    r5180 r5579  
    118118                <attribute name="use_last_as_default" type="tns:last_default" />
    119119                <attribute name="match" type="tns:match" />
     120        <attribute name="length" type="positiveInteger" />
    120121
    121122                <attribute name="type" use="prohibited" />
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r5563 r5579  
    378378        public String originalValue;
    379379        public String use_last_as_default = "false";
     380        public String length;
    380381
    381382        private JComponent value;
     
    387388            AutoCompletingTextField textField = new AutoCompletingTextField();
    388389            initAutoCompletionField(textField, key);
     390            if (length != null && !length.isEmpty()) {
     391                textField.setMaxChars(new Integer(length));
     392            }
    389393            if (usage.unused()){
    390394                if (!usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) {
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingTextField.java

    r5266 r5579  
    3333 */
    3434public class AutoCompletingTextField extends JTextField implements ComboBoxEditor, TableCellEditor {
     35
     36    private Integer maxChars;
     37   
    3538    /**
    3639     * The document model for the editor
     
    4447        @Override
    4548        public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
     49           
     50            // If a maximum number of characters is specified, avoid to exceed it
     51            if (maxChars != null && str != null && getLength() + str.length() > maxChars) {
     52                int allowedLength = maxChars-getLength();
     53                if (allowedLength > 0) {
     54                    str = str.substring(0, allowedLength);
     55                } else {
     56                    return;
     57                }
     58            }
     59           
    4660            if (autoCompletionList == null) {
    4761                super.insertString(offs, str, a);
     
    195209    }
    196210
     211    /**
     212     * Sets the maximum number of characters allowed.
     213     * @param max maximum number of characters allowed
     214     * @since 5579
     215     */
     216    public void setMaxChars(Integer max) {
     217        maxChars = max;
     218    }
     219
    197220    /* ------------------------------------------------------------------------------------ */
    198221    /* TableCellEditor interface                                                            */
Note: See TracChangeset for help on using the changeset viewer.