@Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
// find out if our key is already used in the selection.
Usage usage = determineTextUsage(sel, key);
AutoCompletingTextField textField = new AutoCompletingTextField();
if (alternative_autocomplete_keys != null) {
initAutoCompletionField(textField, (key + "," + alternative_autocomplete_keys).split(","));
} else {
initAutoCompletionField(textField, key);
}
if (length != null && !length.isEmpty()) {
textField.setMaxChars(Integer.valueOf(length));
}
if (usage.unused()){
if (auto_increment_selected != 0 && auto_increment != null) {
try {
textField.setText(Integer.toString(Integer.parseInt(LAST_VALUES.get(key)) + auto_increment_selected));
} catch (NumberFormatException ex) {
// Ignore - cannot auto-increment if last was non-numeric
}
}
else if (!usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) {
// selected osm primitives are untagged or filling default values feature is enabled
if (!"false".equals(use_last_as_default) && LAST_VALUES.containsKey(key) && !presetInitiallyMatches) {
textField.setText(LAST_VALUES.get(key));
} else {
textField.setText(default_);
}
} else {
// selected osm primitives are tagged and filling default values feature is disabled
textField.setText("");
}
value = textField;
originalValue = null;
} else if (usage.hasUniqueValue()) {
// all objects use the same value
textField.setText(usage.getFirst());
value = textField;
originalValue = usage.getFirst();
} else {
// the objects have different values
JosmComboBox<String> comboBox = new JosmComboBox<>(usage.values.toArray(new String[0]));