Ticket #8180: 8180v1.patch

File 8180v1.patch, 4.0 KB (added by Don-vip, 11 years ago)
  • core/data/defaultpresets.xml

     
    3535  default: default string to display (defaults to "")
    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
    4041  key: key to set
  • core/data/tagging-preset.xsd

     
    117117                <attribute name="default" type="string" />
    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" />
    122123                <attribute name="name" use="prohibited" />
  • core/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

     
    377377        public String default_;
    378378        public String originalValue;
    379379        public String use_last_as_default = "false";
     380        public String length;
    380381
    381382        private JComponent value;
    382383
     
    386387            Usage usage = determineTextUsage(sel, key);
    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)) {
    391395                    // selected osm primitives are untagged or filling default values feature is enabled
  • core/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingTextField.java

     
    3232 *
    3333 */
    3434public class AutoCompletingTextField extends JTextField implements ComboBoxEditor, TableCellEditor {
     35
     36    private Integer maxChars;
     37   
    3538    /**
    3639     * The document model for the editor
    3740     */
     
    4346         */
    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);
    4862                return;
     
    194208        }
    195209    }
    196210
     211    /**
     212     * Sets the maximum number of characters allowed.
     213     * @param max maximum number of characters allowed
     214     * @since 5577
     215     */
     216    public void setMaxChars(Integer max) {
     217        maxChars = max;
     218    }
     219
    197220    /* ------------------------------------------------------------------------------------ */
    198221    /* TableCellEditor interface                                                            */
    199222    /* ------------------------------------------------------------------------------------ */