Skip to content

Commit

Permalink
see #21408 - fixups (patch by marcello)
Browse files Browse the repository at this point in the history
git-svn-id: https://josm.openstreetmap.de/svn/trunk@18258 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
don-vip committed Oct 8, 2021
1 parent fa61fe2 commit 0a7154e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
26 changes: 12 additions & 14 deletions src/org/openstreetmap/josm/gui/tagging/ac/AutoCompTextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class AutoCompTextField<E> extends JosmTextField implements TableCellEdit
/** true if the combobox should autocomplete */
private boolean autocompleteEnabled = true;
/** a filter to enforce max. text length */
private MaxLengthDocumentFilter docFilter;
private transient MaxLengthDocumentFilter docFilter;
/** the model */
protected AutoCompComboBoxModel<E> model;
/** Whether to autocomplete numbers */
Expand Down Expand Up @@ -202,12 +202,8 @@ public synchronized void addAutoCompListener(AutoCompListener l) {
*
* @param l the autoComp listener to be removed
*/
public synchronized void removeActionListener(AutoCompListener l) {
if ((l != null) && (getAction() == l)) {
setAction(null);
} else {
listenerList.remove(AutoCompListener.class, l);
}
public synchronized void removeAutoCompListener(AutoCompListener l) {
listenerList.remove(AutoCompListener.class, l);
}

/**
Expand Down Expand Up @@ -244,6 +240,8 @@ protected void fireAutoCompEvent(int id, Object item) {
case AutoCompEvent.AUTOCOMP_BEFORE:
((AutoCompListener) listeners[i + 1]).autoCompBefore(e);
break;
default:
break;
}
}
}
Expand All @@ -260,22 +258,22 @@ protected void fireAutoCompEvent(int id, Object item) {
*/
@Override
public void keyTyped(KeyEvent e) {
if (autocompleteEnabled) {
// if selection is at the end
if (getSelectionEnd() == getText().length()) {
final String oldText = getText().substring(0, getSelectionStart());
// We got the event before the editor component could see it. Let the editor do its job first.
SwingUtilities.invokeLater(() -> autocomplete(oldText));
}
// if selection is at the end
if (autocompleteEnabled && getSelectionEnd() == getText().length()) {
final String oldText = getText().substring(0, getSelectionStart());
// We got the event before the editor component could see it. Let the editor do its job first.
SwingUtilities.invokeLater(() -> autocomplete(oldText));
}
}

@Override
public void keyPressed(KeyEvent e) {
// not interested
}

@Override
public void keyReleased(KeyEvent e) {
// not interested
}

/* ------------------------------------------------------------------------------------ */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract class TaggingPresetItem {
/**
* Display OSM keys as {@linkplain org.openstreetmap.josm.gui.widgets.OsmIdTextField#setHint hint}
*/
protected static BooleanProperty DISPLAY_KEYS_AS_HINT = new BooleanProperty("taggingpreset.display-keys-as-hint", true);
protected static final BooleanProperty DISPLAY_KEYS_AS_HINT = new BooleanProperty("taggingpreset.display-keys-as-hint", true);

protected void initAutoCompletionField(AutoCompletingTextField field, String... key) {
initAutoCompletionField(field, Arrays.asList(key));
Expand Down Expand Up @@ -96,7 +96,7 @@ protected List<AutoCompletionItem> getAllForKeys(List<String> keys) {
* @return {@code true} if matches (positive), {@code null} if neutral, {@code false} if mismatches (negative).
*/
public Boolean matches(Map<String, String> tags) {
return null;
return null; // NOSONAR
}

protected static Set<TaggingPresetType> getType(String types) throws SAXException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public final class TaggingPresets {
/**
* Sort presets menu alphabetically
*/
public static BooleanProperty SORT_MENU = new BooleanProperty("taggingpreset.sortvalues", true);
public static final BooleanProperty SORT_MENU = new BooleanProperty("taggingpreset.sortvalues", true);
/**
* Custom icon sources
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private List<String> getValuesFromCode(String valuesFrom) {
*/
private List<String> checkListsSameLength(List<String> a, List<String> b, String name) {
if (a != null && a.size() != b.size()) {
Logging.error(tr("Broken tagging preset \"{0}-{1}\" - number of items in ''{2}List'' must be the same as in ''values''",
Logging.error(tr("Broken tagging preset \"{0}-{1}\" - number of items in ''{2}'' must be the same as in ''values''",
key, text, name));
Logging.error(tr("Detailed information: {0} <> {1}", a, b));
return null; // NOSONAR
Expand Down Expand Up @@ -291,10 +291,10 @@ protected void initListEntriesFromAttributes() {
List<String> localeShortDescriptionsList = splitEscaped(delimiter, locale_short_descriptions);
List<String> shortDescriptionsList = splitEscaped(delimiter, short_descriptions);

displayList = checkListsSameLength(displayList, valueList, "display");
localeDisplayList = checkListsSameLength(localeDisplayList, valueList, "localeDisplay");
shortDescriptionsList = checkListsSameLength(shortDescriptionsList, valueList, "shortDescriptions");
localeShortDescriptionsList = checkListsSameLength(localeShortDescriptionsList, valueList, "localeShortDescriptions");
displayList = checkListsSameLength(displayList, valueList, "display_values");
localeDisplayList = checkListsSameLength(localeDisplayList, valueList, "locale_display_values");
shortDescriptionsList = checkListsSameLength(shortDescriptionsList, valueList, "short_descriptions");
localeShortDescriptionsList = checkListsSameLength(localeShortDescriptionsList, valueList, "locale_short_descriptions");

for (int i = 0; i < valueList.size(); i++) {
final PresetListEntry e = new PresetListEntry(valueList.get(i), this);
Expand Down
17 changes: 9 additions & 8 deletions src/org/openstreetmap/josm/gui/widgets/OrientationAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
*/
public class OrientationAction extends AbstractAction implements PropertyChangeListener {
/** Default for {@link #RTL_LANGUAGES} */
public static final List<String> DEFAULT_RTL_LANGUAGES = Arrays.asList("ar", "he", "fa", "iw", "ur", "lld");
private static final List<String> DEFAULT_RTL_LANGUAGES = Arrays.asList("ar", "he", "fa", "iw", "ur");

/** Default for {@link #LOCALIZED_KEYS} */
public static final List<String> DEFAULT_LOCALIZED_KEYS = Arrays.asList(
private static final List<String> DEFAULT_LOCALIZED_KEYS = Arrays.asList(
"(\\p{Alnum}+_)?name", "addr", "description", "fixme", "note", "source", "strapline", "operator");

/**
Expand All @@ -56,12 +56,13 @@ public class OrientationAction extends AbstractAction implements PropertyChangeL
public static final ListProperty LOCALIZED_KEYS = new ListProperty("properties.localized-keys", DEFAULT_LOCALIZED_KEYS);

private static final Pattern LANG_PATTERN = Pattern.compile(":([a-z]{2,3})$");
private static final String NEW_STATE = "newState";

private Component component;
private ImageIcon iconRTL;
private ImageIcon iconLTR;
protected static Set<String> RTLLanguages = new HashSet<>(RTL_LANGUAGES.get());
protected static Pattern localizedKeys = compile_localized_keys();
protected static final Set<String> RTLLanguages = new HashSet<>(RTL_LANGUAGES.get());
protected static final Pattern localizedKeys = compileLocalizedKeys();

/**
* Constructs a new {@code OrientationAction}.
Expand All @@ -83,7 +84,7 @@ public OrientationAction(Component component) {

@Override
public void actionPerformed(ActionEvent e) {
firePropertyChange("orientationAction", null, getValue("newState"));
firePropertyChange("orientationAction", null, getValue(NEW_STATE));
}

/**
Expand All @@ -94,12 +95,12 @@ public void updateState() {
putValue(Action.NAME, tr("Right to Left"));
putValue(Action.SMALL_ICON, iconRTL);
putValue(Action.SHORT_DESCRIPTION, tr("Switch the text orientation to Right-to-Left."));
putValue("newState", ComponentOrientation.RIGHT_TO_LEFT);
putValue(NEW_STATE, ComponentOrientation.RIGHT_TO_LEFT);
} else {
putValue(Action.NAME, tr("Left to Right"));
putValue(Action.SMALL_ICON, iconLTR);
putValue(Action.SHORT_DESCRIPTION, tr("Switch the text orientation to Left-to-Right."));
putValue("newState", ComponentOrientation.LEFT_TO_RIGHT);
putValue(NEW_STATE, ComponentOrientation.LEFT_TO_RIGHT);
}
}

Expand Down Expand Up @@ -205,7 +206,7 @@ public static ComponentOrientation getNamelikeOrientation(String key) {
return ComponentOrientation.LEFT_TO_RIGHT;
}

private static Pattern compile_localized_keys() {
private static Pattern compileLocalizedKeys() {
return Pattern.compile("^(" + String.join("|", LOCALIZED_KEYS.get()) + ")$");
}
}

0 comments on commit 0a7154e

Please sign in to comment.