Changeset 23970 in osm for applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap
- Timestamp:
- 2010-10-31T19:36:05+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/AddressNode.java
r23967 r23970 171 171 } 172 172 return TagUtils.getAddrCountryValue(osmObject); 173 } 174 175 /** 176 * Removes all addresss related tags from the node or way. 177 */ 178 public void removeAllAddressTags() { 179 removeOSMTag(TagUtils.ADDR_CITY_TAG); 180 removeOSMTag(TagUtils.ADDR_COUNTRY_TAG); 181 removeOSMTag(TagUtils.ADDR_POSTCODE_TAG); 182 removeOSMTag(TagUtils.ADDR_HOUSENUMBER_TAG); 183 removeOSMTag(TagUtils.ADDR_STATE_TAG); 184 removeOSMTag(TagUtils.ADDR_STREET_TAG); 173 185 } 174 186 -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/INodeEntity.java
r23961 r23970 58 58 */ 59 59 public LatLon getCoor(); 60 61 /** 62 * Adds a command listener. 63 * @param listener 64 */ 65 public void addCommandListener(ICommandListener listener); 66 67 /** 68 * Removes a command listener. 69 * @param listener 70 */ 71 public void removeCommandListener(ICommandListener listener); 60 72 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/NodeEntityBase.java
r23967 r23970 19 19 import java.util.List; 20 20 21 import org.openstreetmap.josm. Main;22 import org.openstreetmap.josm.command.C hangeCommand;21 import org.openstreetmap.josm.command.ChangePropertyCommand; 22 import org.openstreetmap.josm.command.Command; 23 23 import org.openstreetmap.josm.data.coor.LatLon; 24 24 import org.openstreetmap.josm.data.osm.BBox; … … 29 29 public class NodeEntityBase implements INodeEntity, Comparable<INodeEntity> { 30 30 public static final String ANONYMOUS = tr("No name"); 31 private static List<IAddressEditContainerListener> listeners = new ArrayList<IAddressEditContainerListener>(); 31 private static List<IAddressEditContainerListener> containerListeners = new ArrayList<IAddressEditContainerListener>(); 32 private List<ICommandListener> cmdListeners = new ArrayList<ICommandListener>(); 32 33 33 34 protected OsmPrimitive osmObject; … … 53 54 */ 54 55 public static void addChangedListener(IAddressEditContainerListener listener) { 55 listeners.add(listener);56 containerListeners.add(listener); 56 57 } 57 58 … … 61 62 */ 62 63 public static void removeChangedListener(IAddressEditContainerListener listener) { 63 listeners.remove(listener);64 containerListeners.remove(listener); 64 65 } 65 66 … … 68 69 */ 69 70 protected static void fireEntityChanged(INodeEntity entity) { 70 for (IAddressEditContainerListener listener : listeners) {71 for (IAddressEditContainerListener listener : containerListeners) { 71 72 listener.entityChanged(entity); 72 73 } 73 74 } 75 76 /** 77 * Adds a command listener. 78 * @param listener 79 */ 80 public void addCommandListener(ICommandListener listener) { 81 cmdListeners.add(listener); 82 } 83 84 /** 85 * Removes a command listener. 86 * @param listener 87 */ 88 public void removeCommandListener(ICommandListener listener) { 89 cmdListeners.remove(listener); 90 } 91 92 /** 93 * Notifies clients that an entity has issued a command. 94 * 95 * @param source the entity that issued the command. 96 * @param cmd the command to execute. 97 */ 98 protected void fireCommandIssued(Command cmd) { 99 if (cmdListeners.size() == 0) { 100 throw new RuntimeException("Object has no TX context: " + this); 101 } 102 103 for (ICommandListener l : cmdListeners) { 104 l.commandIssued(this, cmd); 105 } 106 } 74 107 75 108 public OsmPrimitive getOsmObject() { … … 79 112 @Override 80 113 public List<INodeEntity> getChildren() { 81 // TODO Auto-generated method stub82 114 return null; 83 115 } … … 109 141 * @param tag The tag to change. 110 142 * @param newValue The new value for the tag. 143 * @param cmd The surrounding command sequence 111 144 */ 112 145 protected void setOSMTag(String tag, String newValue) { 113 OsmPrimitive oldObject = osmObject; 114 OsmPrimitive newObject = null; 115 116 // I would appreciate a clone method... 117 if (oldObject instanceof Node) { 118 newObject = new Node(); 119 } else if (oldObject instanceof Way) { 120 newObject = new Way(); 121 } 146 if (StringUtils.isNullOrEmpty(tag)) return; 122 147 123 if (newObject != null) { 124 newObject.cloneFrom(oldObject); 125 newObject.put(tag, newValue); 126 Main.main.undoRedo.add( new ChangeCommand(oldObject, newObject)); 148 if (osmObject != null && osmObject.hasKey(tag)) { 149 fireCommandIssued(new ChangePropertyCommand(osmObject, tag, newValue)); 127 150 fireEntityChanged(this); 128 } else { 129 throw new RuntimeException("Cannot modify tag for " + osmObject); 130 } 151 } 152 } 153 154 /** 155 * Removes the given tag from the OSM object. 156 * 157 * @param tag the tag 158 */ 159 protected void removeOSMTag(String tag) { 160 setOSMTag(tag, null); // a value of null removes the tag 131 161 } 132 162 -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/AbstractAddressEditAction.java
r23943 r23970 15 15 16 16 import java.awt.event.ActionEvent; 17 17 import java.util.ArrayList; 18 import java.util.List; 19 20 import org.openstreetmap.josm.Main; 18 21 import org.openstreetmap.josm.actions.JosmAction; 22 import org.openstreetmap.josm.command.Command; 23 import org.openstreetmap.josm.command.SequenceCommand; 19 24 import org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer; 20 25 import org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener; 26 import org.openstreetmap.josm.plugins.fixAddresses.ICommandListener; 21 27 import org.openstreetmap.josm.plugins.fixAddresses.INodeEntity; 28 import org.openstreetmap.josm.plugins.fixAddresses.StringUtils; 22 29 23 30 /** … … 34 41 35 42 @SuppressWarnings("serial") 36 public abstract class AbstractAddressEditAction extends JosmAction implements IAddressEditContainerListener {43 public abstract class AbstractAddressEditAction extends JosmAction implements IAddressEditContainerListener, ICommandListener { 37 44 private AddressEditSelectionEvent event; 38 45 protected AddressEditContainer container; 46 private List<Command> commands; 47 private String txName; 39 48 40 49 /** … … 167 176 updateEnabledState(); 168 177 } 178 179 /** 180 * Begins the transaction (command sequence). Must be called by every subclass before 181 * any modification on OSM objects starts. 182 * 183 * @param txName the name of the transaction (e. g. "change address tags"). 184 */ 185 public void beginTransaction(String txName) { 186 if (commands != null && commands.size() > 0) { 187 throw new RuntimeException("TX has not been closed (missing finishTransaction?)"); 188 } 189 190 commands = new ArrayList<Command>(); 191 if (StringUtils.isNullOrEmpty(txName)) { 192 throw new RuntimeException("Transaction must have a name"); 193 } 194 this.txName = txName; 195 } 196 197 /** 198 * Finishes the transaction and passes the command sequence to the framework. 199 */ 200 public void finishTransaction() { 201 if (commands == null) { 202 throw new RuntimeException("No command list available. Did you forget to call beginTransaction?"); 203 } 204 // execute the command 205 Main.main.undoRedo.add(new SequenceCommand(txName, commands)); 206 commands.clear(); 207 container.invalidate(); 208 } 209 210 /** 211 * Begins the transaction for a single object. 212 * 213 * @param entity the entity 214 */ 215 public void beginObjectTransaction(INodeEntity entity) { 216 if (entity != null) { 217 entity.addCommandListener(this); 218 } else { 219 throw new RuntimeException("Entity must not be null"); 220 } 221 } 222 223 /** 224 * Finishes the transaction for a single object. 225 * 226 * @param entity the entity 227 */ 228 public void finishObjectTransaction(INodeEntity entity) { 229 if (entity != null) { 230 entity.removeCommandListener(this); 231 } else { 232 throw new RuntimeException("Entity must not be null"); 233 } 234 } 235 236 /* (non-Javadoc) 237 * @see org.openstreetmap.josm.plugins.fixAddresses.ICommandListener#commandIssued(org.openstreetmap.josm.plugins.fixAddresses.INodeEntity, org.openstreetmap.josm.command.Command) 238 */ 239 @Override 240 public void commandIssued(INodeEntity entity, Command command) { 241 if (commands == null) { 242 throw new RuntimeException("No command list available. Did you forget to call beginTransaction?"); 243 } 244 commands.add(command); 245 } 169 246 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/AddressEditDialog.java
r23969 r23970 75 75 private GuessAddressDataAction guessAddressAction = new GuessAddressDataAction(); 76 76 private SelectAddressesInMapAction selectAddressesInMapAction = new SelectAddressesInMapAction(); 77 private RemoveAddressTagsAction removeAddressTagsAction = new RemoveAddressTagsAction(); 77 78 78 79 private AbstractAddressEditAction[] actions = new AbstractAddressEditAction[] { … … 80 81 guessAddressAction, 81 82 applyAllGuessesAction, 82 selectAddressesInMapAction 83 selectAddressesInMapAction, 84 removeAddressTagsAction 83 85 }; 84 86 private JLabel streetLabel; … … 145 147 146 148 unresolvedButtons.add(new JSeparator()); 149 150 SideButton removeAddressTags = new SideButton(removeAddressTagsAction); 151 unresolvedButtons.add(removeAddressTags); 152 153 unresolvedButtons.add(new JSeparator()); 154 147 155 SideButton selectInMap = new SideButton(selectAddressesInMapAction); 148 156 unresolvedButtons.add(selectInMap); -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/ApplyAllGuessesAction.java
r23944 r23970 50 50 51 51 private void applyGuesses(List<AddressNode> addrToFix) { 52 beginTransaction(tr("Applied guessed values")); 52 53 List<AddressNode> addrToFixShadow = new ArrayList<AddressNode>(addrToFix); 53 54 for (AddressNode aNode : addrToFixShadow) { 55 beginObjectTransaction(aNode); 54 56 aNode.applyAllGuesses(); 57 finishObjectTransaction(aNode); 55 58 } 59 finishTransaction(); 56 60 } 57 61 -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/AssignAddressToStreetAction.java
r23944 r23970 26 26 * 27 27 */ 28 public class AssignAddressToStreetAction extends AbstractAddressEditAction {28 public class AssignAddressToStreetAction extends AbstractAddressEditAction { 29 29 30 30 public AssignAddressToStreetAction() { … … 43 43 public void addressEditActionPerformed(AddressEditSelectionEvent ev) { 44 44 StreetNode streetNode = ev.getSelectedStreet(); 45 45 46 46 if (streetNode != null && ev.getSelectedUnresolvedAddresses() != null) { 47 beginTransaction(tr("Set street name") + " '" + streetNode.getName() + "'"); 47 48 for (AddressNode addrNode : ev.getSelectedUnresolvedAddresses()) { 48 addrNode.assignStreet(streetNode); 49 beginObjectTransaction(addrNode); 50 addrNode.assignStreet(streetNode); 51 finishObjectTransaction(addrNode); 49 52 } 53 finishTransaction(); 50 54 } 55 51 56 } 52 57
Note:
See TracChangeset
for help on using the changeset viewer.