Skip to content

Commit

Permalink
Dynamic matching of AddressLines to tags
Browse files Browse the repository at this point in the history
References #7
  • Loading branch information
kmpoppe committed Apr 16, 2021
1 parent 2e19775 commit 5e9ed34
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
2 changes: 1 addition & 1 deletion fhrsPlugin/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project name="fhrsPlugin" default="dist" basedir=".">
<property name="commit.message" value="FHRS"/>
<property name="plugin.main.version" value="16538"/>
<property name="version.entry.commit.revision" value="0.2"/>
<property name="version.entry.commit.revision" value="0.2.1"/>
<property name="plugin.author" value="Kai Michael Poppe"/>
<property name="plugin.class" value="org.openstreetmap.josm.plugins.fhrs.FHRSPlugin"/>
<property name="plugin.description" value="Search establishments in FHRS API and merge data into OSM"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.openstreetmap.josm.gui.*;

import org.openstreetmap.josm.plugins.*;
import org.openstreetmap.josm.tools.I18n;

import java.awt.event.*;
import java.io.BufferedReader;
Expand Down Expand Up @@ -100,10 +101,10 @@ private void createMenu() {
final MainMenu menu = MainApplication.getMenu();
if (FHRSMenu == null) {
FHRSMenu = menu.addMenu("FHRS", "FHRS", 0, menu.getDefaultMenuPos(), "help");
FHRSGet = new JMenuItem("Get information");
FHRSGet = new JMenuItem(I18n.tr("Get information"));
FHRSGet.setEnabled(true);
FHRSGet.addActionListener(getFHRSAction);
FHRSSearch = new JMenuItem("Search entry");
FHRSSearch = new JMenuItem(I18n.tr("Search entry"));
FHRSSearch.setEnabled(true);
FHRSSearch.addActionListener(searchFHRSAction);
FHRSMenu.add(FHRSGet);
Expand Down Expand Up @@ -320,7 +321,7 @@ public void updateObjectData(String fhrsId) {
}
}
if (osmTags.size() > 0) {
Map<String, String> osmTagsToSet = mergeTagsDialog.showTagsDialog(osmTags, warnCapitalization);
Map<String, String> osmTagsToSet = mergeTagsDialog.showTagsDialog(osmTags, warnCapitalization, JsonToOSM);
if (osmTagsToSet != null && osmTagsToSet.size() > 0) {
ChangePropertyCommand changePropertyCommand =
new ChangePropertyCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,29 @@
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableRowSorter;

import org.openstreetmap.josm.plugins.fhrs.FHRSPlugin.fhrsAuthority;

public class mergeTagsDialog {

public static Map<String, String> showTagsDialog (final Map<String, FHRSPlugin.oldAndNewValues> osmTags, boolean warnCapitalization) {
public static Map<String, String> showTagsDialog (final Map<String, FHRSPlugin.oldAndNewValues> osmTags, boolean warnCapitalization, final Map<String, String> JsonToOSM) {
final JPanel panel = new JPanel();
Object[][] columnValues = {};
final List<Object[]> columnValuesList = new ArrayList<Object[]>();
final List<String> tagList = new ArrayList<>(osmTags.keySet());
final Map<String, String> returnValues = new HashMap<String, String>();
Collections.sort(tagList);
String jsonDisplay = "";
for(final String osmTag : tagList) {
final FHRSPlugin.oldAndNewValues oanv = osmTags.get(osmTag);
for(Map.Entry<String, String> entry : JsonToOSM.entrySet()) {
if (entry.getValue() == osmTag) jsonDisplay = entry.getKey();
}
if (oanv.newValue != "") {
columnValuesList.add(new Object[] {
false,
jsonDisplay,
osmTag,
oanv.newValue,
oanv.oldValue
Expand All @@ -41,9 +47,18 @@ public static Map<String, String> showTagsDialog (final Map<String, FHRSPlugin.o
osmTagsTable.setRowHeight(20);
osmTagsTable.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(new JCheckBox()));
osmTagsTable.getColumnModel().getColumn(2).setCellEditor(new CustomTableCellEditor());
osmTagsTable.getColumnModel().getColumn(3).setCellEditor(new CustomTableCellEditor());
osmTagsTable.getColumnModel().getColumn(1).setPreferredWidth(200);
osmTagsTable.getColumnModel().getColumn(2).setPreferredWidth(200);
osmTagsTable.getColumnModel().getColumn(3).setPreferredWidth(200);
osmTagsTable.getColumnModel().getColumn(4).setPreferredWidth(200);

TableRowSorter<osmTagsTableModel> sorter = new TableRowSorter<osmTagsTableModel>(thisTableModel);
osmTagsTable.setRowSorter(sorter);
List<RowSorter.SortKey> sortKeys = new ArrayList<>(25);
sortKeys.add(new RowSorter.SortKey(1, SortOrder.ASCENDING));
sorter.setSortKeys(sortKeys);

panel.setLayout(new BorderLayout());
panel.add(osmTagsTable.getTableHeader(), BorderLayout.PAGE_START);
panel.add(osmTagsTable, BorderLayout.CENTER);
Expand All @@ -58,7 +73,7 @@ public static Map<String, String> showTagsDialog (final Map<String, FHRSPlugin.o
null, null, null);
for(int row = 0; row < osmTagsTable.getRowCount(); row++) {
if ((Boolean)osmTagsTable.getValueAt(row, 0)) {
returnValues.put(osmTagsTable.getValueAt(row, 1).toString(), osmTagsTable.getValueAt(row, 2).toString());
returnValues.put(osmTagsTable.getValueAt(row, 2).toString(), osmTagsTable.getValueAt(row, 3).toString());
}
}
if (result == JOptionPane.OK_OPTION){
Expand All @@ -82,17 +97,30 @@ public Object getCellEditorValue() {

@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
if (value instanceof String && table.getValueAt(row, 1) == "fhrs:authority") {
editor = new DefaultCellEditor(new JTextField());
if (column == 2) {
JComboBox<String> oComboBox = new JComboBox<String>();
oComboBox.addItem("addr:city");
oComboBox.addItem("addr:housename");
oComboBox.addItem("addr:housenumber");
oComboBox.addItem("addr:street");
oComboBox.addItem("addr:unit");
oComboBox.setSelectedItem(value.toString());
if (table.getValueAt(row, 1).toString().substring(0, 5).equals("Addre")) {
editor = new DefaultCellEditor(oComboBox);
} else {
JTextField roTextField = new JTextField();
roTextField.setEditable(false);
editor = new DefaultCellEditor(roTextField);
}
}
if (table.getValueAt(row, 1) == "LocalAuthorityName" && column == 3) {
JComboBox<String> oComboBox = new JComboBox<String>();
for (fhrsAuthority auth: FHRSPlugin.fhrsAuthorities) {
oComboBox.addItem(auth.name);
}
oComboBox.setSelectedItem(value.toString());
editor = new DefaultCellEditor(oComboBox);
} else if (value instanceof String && table.getValueAt(row, 1) != "fhrs:authority") {
editor = new DefaultCellEditor(new JTextField());
//} else if (value instanceof Boolean) {
// editor = new DefaultCellEditor(new JCheckBox());
}

return editor.getTableCellEditorComponent(table, value, isSelected, row, column);
Expand All @@ -101,7 +129,7 @@ public Component getTableCellEditorComponent(JTable table, Object value, boolean

static class osmTagsTableModel extends AbstractTableModel {
private static final long serialVersionUID = 1L;
String[] columnNames = { "Merge", "Tag", "New value", "Old Value" };
String[] columnNames = { "Merge", "FHRS Data", "Tag", "New value", "Old Value" };
public Object[][] data;

@Override
Expand Down Expand Up @@ -135,7 +163,7 @@ public Class getColumnClass(final int c) {
*/
@Override
public boolean isCellEditable(final int row, final int col) {
return (col == 0 || col == 2);
return (col == 0 || col == 2 || col == 3);
}

/*
Expand Down

0 comments on commit 5e9ed34

Please sign in to comment.