Skip to content

Commit

Permalink
AddressDialog: Update combobox usage for JOSM r18173+
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <tsmock@fb.com>
  • Loading branch information
tsmock committed Dec 16, 2021
1 parent 9e1addb commit 28efff2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Expand Up @@ -6,9 +6,9 @@ plugin.link=https://github.com/JOSM/areaselector
plugin.requires=log4j;austriaaddresshelper;ejml
# Minimum required JOSM version to run this plugin, choose the lowest version possible that is compatible.
# You can check if the plugin compiles against this version by executing `./gradlew minJosmVersionClasses`.
plugin.main.version=15017
plugin.main.version=18173
# Version of JOSM against which the plugin is compiled
# Please check, if the specified version is available for download from https://josm.openstreetmap.de/download/ .
# If not, choose the next higher number that is available, or the gradle build will break.
plugin.compile.version=18303
plugin.compile.version=18173
plugin.canloadatruntime=true
48 changes: 24 additions & 24 deletions src/org/openstreetmap/josm/plugins/areaselector/AddressDialog.java
Expand Up @@ -42,7 +42,7 @@
import org.openstreetmap.josm.gui.ExtendedDialog;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.layer.Layer;
import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox;
import org.openstreetmap.josm.gui.tagging.ac.AutoCompComboBox;
import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
import org.openstreetmap.josm.spi.preferences.Config;
import org.openstreetmap.josm.tools.GBC;
Expand Down Expand Up @@ -82,7 +82,7 @@ public class AddressDialog extends ExtendedDialog implements ChangeListener {
protected JTextField houseNumField;
protected ButtonGroup houseNumChange;

protected AutoCompletingComboBox streetNameField, cityField, postCodeField, countryField, houseNameField, buildingField, tagsField, sourceField;
protected AutoCompComboBox<AutoCompletionItem> streetNameField, cityField, postCodeField, countryField, houseNameField, buildingField, tagsField, sourceField;

protected static final String[] BUTTON_TEXTS = new String[] {tr("OK"), tr("Cancel")};
protected static final String[] BUTTON_ICONS = new String[] {"ok", "cancel"};
Expand Down Expand Up @@ -125,8 +125,8 @@ public AddressDialog(OsmPrimitive selectedOsmObject, OsmPrimitive originalOsmObj

AutoCompletionManager acm = AutoCompletionManager.of(OsmDataManager.getInstance().getEditDataSet());

houseNameField = new AutoCompletingComboBox();
houseNameField.setPossibleAcItems(acm.getTagValues(TAG_HOUSENAME));
houseNameField = new AutoCompComboBox<>();
houseNameField.getModel().addAllElements(acm.getTagValues(TAG_HOUSENAME));
houseNameField.setEditable(true);

houseNumField = new JTextField();
Expand Down Expand Up @@ -177,29 +177,29 @@ public void actionPerformed(ActionEvent e) {
});
houseNumPanel.add(skip);

streetNameField = new AutoCompletingComboBox();
streetNameField.setPossibleAcItems(acm.getTagValues(TAG_STREETNAME));
streetNameField = new AutoCompComboBox<>();
streetNameField.getModel().addAllElements(acm.getTagValues(TAG_STREETNAME));
streetNameField.setEditable(true);
streetNameField.setSelectedItem(Config.getPref().get(PREF_STREETNAME));

cityField = new AutoCompletingComboBox();
cityField.setPossibleAcItems(acm.getTagValues(TAG_CITY));
cityField = new AutoCompComboBox<>();
cityField.getModel().addAllElements(acm.getTagValues(TAG_CITY));
cityField.setEditable(true);
cityField.setSelectedItem(Config.getPref().get(PREF_CITY));

postCodeField = new AutoCompletingComboBox();
postCodeField.setPossibleAcItems(acm.getTagValues(TAG_POSTCODE));
postCodeField = new AutoCompComboBox<>();
postCodeField.getModel().addAllElements(acm.getTagValues(TAG_POSTCODE));
postCodeField.setEditable(true);
postCodeField.setSelectedItem(Config.getPref().get(PREF_POSTCODE));

countryField = new AutoCompletingComboBox();
countryField.setPossibleAcItems(acm.getTagValues(TAG_COUNTRY));
countryField = new AutoCompComboBox<>();
countryField.getModel().addAllElements(acm.getTagValues(TAG_COUNTRY));
countryField.setEditable(true);
countryField.setSelectedItem(Config.getPref().get(PREF_COUNTRY));


buildingField = new AutoCompletingComboBox();
buildingField.setPossibleAcItems(acm.getTagValues(TAG_BUILDING));
buildingField = new AutoCompComboBox<>();
buildingField.getModel().addAllElements(acm.getTagValues(TAG_BUILDING));
buildingField.setEditable(true);
buildingField.setSelectedItem(Config.getPref().get(PREF_BUILDING));

Expand All @@ -226,12 +226,12 @@ public void actionPerformed(ActionEvent e) {
}


tagsField = new AutoCompletingComboBox();
tagsField.setPossibleAcItems(aciTags);
tagsField = new AutoCompComboBox<>();
tagsField.getModel().addAllElements(aciTags);
tagsField.setEditable(true);
tagsField.setSelectedItem(otherTags.length() > 0 ? otherTags : Config.getPref().get(PREF_TAGS));

sourceField = new AutoCompletingComboBox();
sourceField = new AutoCompComboBox<>();
AutoCompletionSet sourceValues = acm.getTagValues(TAG_SOURCE);

ArrayList<String> sources = new ArrayList<>();
Expand All @@ -241,12 +241,12 @@ public void actionPerformed(ActionEvent e) {
}
}
Collections.reverse(sources);
String source = sources.stream().map(Object::toString).collect(Collectors.joining("; ")).toString();
String source = sources.stream().map(Object::toString).collect(Collectors.joining("; "));
if (!source.isEmpty()) {
sourceValues.add(new AutoCompletionItem(source));
}

sourceField.setPossibleAcItems(sourceValues);
sourceField.getModel().addAllElements(sourceValues);
sourceField.setEditable(true);
sourceField.setPreferredSize(new Dimension(400, 24));
sourceField.setSelectedItem(Config.getPref().get(PREF_SOURCE));
Expand Down Expand Up @@ -281,8 +281,8 @@ public void actionPerformed(ActionEvent e) {
fields.addAll(Arrays.asList(fieldArr));

for (Component field: fields){
if (field instanceof AutoCompletingComboBox){
AutoCompletingComboBox combox = (AutoCompletingComboBox) field;
if (field instanceof AutoCompComboBox){
AutoCompComboBox<?> combox = (AutoCompComboBox<?>) field;
if (selectedOsmObject.hasKey(combox.getName())){
combox.setSelectedItem(selectedOsmObject.get(combox.getName()));
}
Expand Down Expand Up @@ -328,8 +328,8 @@ public int getIndex(Component c) {

if (fields.get(i).equals(c)) {
return i;
} else if (fields.get(i) instanceof AutoCompletingComboBox) {
AutoCompletingComboBox ac = (AutoCompletingComboBox) fields.get(i);
} else if (fields.get(i) instanceof AutoCompComboBox) {
AutoCompComboBox<?> ac = (AutoCompComboBox<?>) fields.get(i);
if (Arrays.asList(ac.getComponents()).contains(c)) {
return i;
}
Expand All @@ -350,7 +350,7 @@ public int getIndex(Component c) {
}
}

protected String getAutoCompletingComboBoxValue(AutoCompletingComboBox box) {
protected String getAutoCompletingComboBoxValue(AutoCompComboBox<?> box) {
Object item = box.getSelectedItem();
if (item != null) {
if (item instanceof String) {
Expand Down

0 comments on commit 28efff2

Please sign in to comment.