Changeset 23915 in osm for applications/editors
- Timestamp:
- 2010-10-30T16:05:06+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/AddressEditContainer.java
r23894 r23915 63 63 private List<AddressNode> unresolvedAddresses = new ArrayList<AddressNode>(100); 64 64 private List<AddressNode> incompleteAddresses = new ArrayList<AddressNode>(100); 65 65 private HashMap<String, AddressNode> addressCache = new HashMap<String, AddressNode>(); 66 66 private HashSet<Node> visitedNodes = new HashSet<Node>(); 67 67 private HashSet<Way> visitedWays = new HashSet<Way>(); … … 126 126 return; 127 127 } 128 129 AddressNode aNode = NodeFactory.createNode(n); 128 129 String aid = "" + n.getId(); 130 AddressNode aNode = null; 131 if (!addressCache.containsKey(aid)) { 132 aNode = NodeFactory.createNode(n); 133 if (aNode != null) { 134 addressCache.put(aid, aNode); 135 } 136 } else { 137 aNode = addressCache.get(aid); 138 aNode.setOsmObject(n); 139 } 130 140 131 141 if (aNode != null) { … … 404 414 405 415 @Override 406 public void entityChanged( ) {416 public void entityChanged(INodeEntity entity) { 407 417 invalidate(); 408 418 } -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/AddressNode.java
r23894 r23915 15 15 16 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 import org.openstreetmap.josm.plugins.addressEdit.gui.GuessAddressDataAction; 17 18 18 19 public class AddressNode extends NodeEntityBase { 19 20 private static final String MISSING_TAG = "?"; 20 public static final String MISSING_TAG = "?"; 21 22 private String guessedStreetName; 21 23 22 24 public AddressNode(OsmPrimitive osmObject) { 23 25 super(osmObject); 24 26 } 25 27 28 /* (non-Javadoc) 29 * @see org.openstreetmap.josm.plugins.addressEdit.NodeEntityBase#setOsmObject(org.openstreetmap.josm.data.osm.OsmPrimitive) 30 */ 31 @Override 32 public void setOsmObject(OsmPrimitive osmObject) { 33 super.setOsmObject(osmObject); 34 } 35 26 36 /** 27 37 * Checks if the underlying address node has all tags usually needed to describe an address. … … 45 55 } 46 56 57 /** 58 * Returns <tt>true</tt>, if this address node has a street name. 59 * @return 60 */ 47 61 public boolean hasStreetName() { 48 62 return TagUtils.hasAddrStreetTag(osmObject); 49 63 } 50 64 65 /** 66 * Returns the street name guessed by the nearest-neighbour search. 67 * @return the guessedStreetName 68 */ 69 public String getGuessedStreetName() { 70 return guessedStreetName; 71 } 72 73 /** 74 * @param guessedStreetName the guessedStreetName to set 75 */ 76 public void setGuessedStreetName(String guessedStreetName) { 77 this.guessedStreetName = guessedStreetName; 78 fireEntityChanged(this); 79 } 80 51 81 /** 52 82 * Gets the name of the post code associated with this address. … … 142 172 setStreetName(node.getName()); 143 173 node.addAddress(this); 144 fireEntityChanged(); 174 fireEntityChanged(this); 175 } 176 } 177 178 public void applyGuessedStreet() { 179 if (!StringUtils.isNullOrEmpty(getGuessedStreetName())) { 180 setOSMTag(TagUtils.ADDR_STREET_TAG, guessedStreetName); 145 181 } 146 182 } … … 195 231 // TODO: Add further countries here 196 232 // DE 197 return String.format("%s %s, %s-%s %s (%s)", 198 node.getStreet(), 233 String guessed = node.getGuessedStreetName(); 234 String sName = node.getStreet(); 235 if (!StringUtils.isNullOrEmpty(guessed) && MISSING_TAG.equals(sName)) { 236 sName = String.format("(%s)", guessed); 237 } 238 239 return String.format("%s %s, %s-%s %s (%s) ", 240 sName, 199 241 node.getHouseNumber(), 200 242 node.getCountry(), -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/IAddressEditContainerListener.java
r23834 r23915 14 14 package org.openstreetmap.josm.plugins.addressEdit; 15 15 16 16 17 public interface IAddressEditContainerListener { 17 18 /** … … 24 25 * Notifies clients that an entity has been changed. 25 26 */ 26 public void entityChanged( );27 public void entityChanged(INodeEntity node); 27 28 } -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/NodeEntityBase.java
r23894 r23915 39 39 40 40 /** 41 * @param osmObject the osmObject to set 42 */ 43 protected void setOsmObject(OsmPrimitive osmObject) { 44 this.osmObject = osmObject; 45 } 46 47 /** 41 48 * Adds a change listener. 42 49 * @param listener … … 57 64 * Notifies clients that the address container changed. 58 65 */ 59 protected static void fireEntityChanged( ) {66 protected static void fireEntityChanged(INodeEntity entity) { 60 67 for (IAddressEditContainerListener listener : listeners) { 61 listener.entityChanged( );68 listener.entityChanged(entity); 62 69 } 63 70 } -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/AbstractAddressEditAction.java
r23834 r23915 16 16 import java.awt.event.ActionEvent; 17 17 18 import javax.swing.AbstractAction;19 import javax.swing.Icon;18 import org.openstreetmap.josm.actions.JosmAction; 19 import org.openstreetmap.josm.plugins.addressEdit.AddressEditContainer; 20 20 21 public abstract class AbstractAddressEditAction extends AbstractAction {21 public abstract class AbstractAddressEditAction extends JosmAction { 22 22 23 23 /** … … 27 27 28 28 private AddressEditSelectionEvent event; 29 protected AddressEditContainer container; 29 30 30 31 /** … … 32 33 * @param icon 33 34 */ 34 public AbstractAddressEditAction(String name, Icon icon) { 35 super(name, icon); 35 public AbstractAddressEditAction(String name, String iconName, String tooltip) { 36 super(name, iconName, tooltip, null, true); 37 36 38 setEnabled(false); 37 39 } … … 41 43 */ 42 44 public AbstractAddressEditAction(String name) { 43 this(name, null); 45 this(name, null, ""); 46 } 47 48 /** 49 * @return the container 50 */ 51 public AddressEditContainer getContainer() { 52 return container; 44 53 } 45 54 46 55 /** 47 * Updates 'enabled' state. 56 * @param container the container to set 57 */ 58 public void setContainer(AddressEditContainer container) { 59 this.container = container; 60 updateEnabledState(container); 61 } 62 63 /** 64 * Updates 'enabled' state depending on the given selection event. 48 65 * @param ev 49 66 * @return … … 51 68 public void updateEnabledState(AddressEditSelectionEvent ev) { 52 69 // If the tree selection changes, we will get a new event. So this is safe. 53 this.event = ev; // save for later use. 70 super.updateEnabledState(); 71 this.event = ev; // save for later use. 72 if (ev != null) { 73 updateEnabledState(ev); 74 } 54 75 } 76 77 /** 78 * Updates 'enabled' state depending on the given address container object. 79 * @param container The address container (maybe null). 80 * @return 81 */ 82 protected abstract void updateEnabledState(AddressEditContainer container); 55 83 56 84 /* (non-Javadoc) … … 60 88 public void actionPerformed(ActionEvent arg0) { 61 89 if (event != null) { // use the event acquired previously. 62 addressEditActionPerformed(event); 90 addressEditActionPerformed(event); 91 event = null; // consume event 92 } else { 93 actionPerformed(arg0); 63 94 } 64 95 } -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/AddressEditDialog.java
r23880 r23915 69 69 private JTable streetTable; 70 70 71 /* Actions */ 71 72 private AssignAddressToStreetAction resolveAction = new AssignAddressToStreetAction(); 73 private GuessAddressDataAction guessAddressAction = new GuessAddressDataAction(); 72 74 73 75 private AbstractAddressEditAction[] actions = new AbstractAddressEditAction[] { 74 resolveAction 76 resolveAction, 77 guessAddressAction 75 78 }; 76 79 private JLabel streetLabel; … … 123 126 SideButton assign = new SideButton(resolveAction, "assignstreet_24"); 124 127 unresolvedButtons.add(assign); 128 SideButton guess = new SideButton(guessAddressAction); 129 unresolvedButtons.add(guess); 125 130 unresolvedPanel.add(unresolvedButtons, BorderLayout.SOUTH); 126 131 … … 140 145 } else { 141 146 this.getContentPane().add(new JLabel(tr("(No data)")), BorderLayout.CENTER); 147 } 148 149 for (int i = 0; i < actions.length; i++) { 150 actions[i].setContainer(addressEditContainer); 142 151 } 143 152 … … 226 235 public void containerChanged(AddressEditContainer container) { 227 236 updateHeaders(); 237 238 for (int i = 0; i < actions.length; i++) { 239 actions[i].setContainer(container); 240 } 228 241 } 229 242 230 243 @Override 231 public void entityChanged( ) {244 public void entityChanged(INodeEntity entity) { 232 245 updateHeaders(); 233 246 } -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/AddressEditTableModel.java
r23835 r23915 18 18 import org.openstreetmap.josm.plugins.addressEdit.AddressEditContainer; 19 19 import org.openstreetmap.josm.plugins.addressEdit.IAddressEditContainerListener; 20 import org.openstreetmap.josm.plugins.addressEdit.INodeEntity; 20 21 21 22 public class AddressEditTableModel extends DefaultTableModel implements IAddressEditContainerListener{ … … 39 40 40 41 @Override 41 public void entityChanged( ) {42 public void entityChanged(INodeEntity entity) { 42 43 fireTableDataChanged(); 43 44 } -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/AssignAddressToStreetAction.java
r23876 r23915 16 16 import static org.openstreetmap.josm.tools.I18n.tr; 17 17 18 import org.openstreetmap.josm.plugins.addressEdit.AddressEditContainer; 18 19 import org.openstreetmap.josm.plugins.addressEdit.AddressNode; 19 20 import org.openstreetmap.josm.plugins.addressEdit.StreetNode; … … 51 52 @Override 52 53 public void updateEnabledState(AddressEditSelectionEvent ev) { 53 super.updateEnabledState(ev);54 54 setEnabled(ev.getSelectedStreet() != null && ev.getSelectedUnresolvedAddresses() != null); 55 } 56 57 @Override 58 public void updateEnabledState(AddressEditContainer container) { 59 // we only accept a selection here 60 setEnabled(false); 55 61 } 56 62 -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/IncompleteAddressesTableModel.java
r23884 r23915 18 18 import org.openstreetmap.josm.plugins.addressEdit.AddressEditContainer; 19 19 import org.openstreetmap.josm.plugins.addressEdit.AddressNode; 20 import org.openstreetmap.josm.plugins.addressEdit.StringUtils; 20 21 21 22 public class IncompleteAddressesTableModel extends AddressEditTableModel { … … 76 77 return aNode.getPostCode(); 77 78 case 4: 78 return aNode.getStreet(); 79 if (!StringUtils.isNullOrEmpty(aNode.getGuessedStreetName()) && 80 AddressNode.MISSING_TAG.equals(aNode.getStreet())) { 81 82 return "(" + aNode.getGuessedStreetName() + ")"; 83 } else { 84 return aNode.getStreet(); 85 } 79 86 default: 80 87 throw new RuntimeException("Invalid column index: " + column); -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/UnresolvedAddressesTableModel.java
r23894 r23915 33 33 import org.openstreetmap.josm.plugins.addressEdit.AddressEditContainer; 34 34 import org.openstreetmap.josm.plugins.addressEdit.AddressNode; 35 import org.openstreetmap.josm.plugins.addressEdit.StringUtils; 35 36 36 37 /** … … 92 93 switch (column) { 93 94 case 0: 94 return aNode.getStreet(); 95 String guessed = aNode.getGuessedStreetName(); 96 String cur = aNode.getStreet(); 97 if (!StringUtils.isNullOrEmpty(guessed) && 98 AddressNode.MISSING_TAG.equals(cur)) { 99 100 return "*" + guessed; 101 } else { 102 return aNode.getStreet(); 103 } 95 104 case 1: 96 105 return aNode.getHouseNumber(); … … 100 109 return aNode.getPostCode(); 101 110 case 4: 102 return aNode.getName(); 111 return aNode.getName(); 103 112 default: 104 113 throw new RuntimeException("Invalid column index: " + column);
Note:
See TracChangeset
for help on using the changeset viewer.