Changeset 23814 in osm for applications/editors/josm/plugins/AddressEdit/src
- Timestamp:
- 2010-10-24T18:03:48+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/AddressEditAction.java
r23808 r23814 1 1 package org.openstreetmap.josm.plugins.addressEdit; 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 2 4 3 5 import java.awt.event.ActionEvent; … … 6 8 import java.util.Collection; 7 9 10 import org.openstreetmap.josm.Main; 8 11 import org.openstreetmap.josm.actions.JosmAction; 9 12 import org.openstreetmap.josm.data.SelectionChangedListener; 10 13 import org.openstreetmap.josm.data.osm.DataSet; 11 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 16 import org.openstreetmap.josm.gui.progress.ProgressMonitor.CancelListener; 17 import org.openstreetmap.josm.plugins.addressEdit.gui.AddressEditDialog; 18 import org.openstreetmap.josm.plugins.addressEdit.gui.AddressEditModel; 12 19 import org.openstreetmap.josm.tools.Shortcut; 13 import static org.openstreetmap.josm.tools.I18n.tr;14 20 15 21 public class AddressEditAction extends JosmAction implements 16 SelectionChangedListener {22 SelectionChangedListener, CancelListener { 17 23 18 24 /** … … 20 26 */ 21 27 private static final long serialVersionUID = 1L; 28 private AddressEditModel addressModel; 29 private boolean isCanceled = false; 22 30 23 31 public AddressEditAction() { 24 super(tr("Address Editor"), "addressedit_24", tr("Handy Address Editing Functions"), 25 Shortcut.registerShortcut("tools:AddressEdit", tr("Tool: {0}", tr("Address Edit")), 26 KeyEvent.VK_A, Shortcut.GROUP_MENU, 27 InputEvent.ALT_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK), false); 28 setEnabled(false); 29 DataSet.addSelectionListener(this); 32 super(tr("Address Editor"), "addressedit_24", 33 tr("Handy Address Editing Functions"), Shortcut 34 .registerShortcut("tools:AddressEdit", tr("Tool: {0}", 35 tr("Address Edit")), KeyEvent.VK_A, 36 Shortcut.GROUP_MENU, InputEvent.ALT_DOWN_MASK 37 | InputEvent.SHIFT_DOWN_MASK), false); 38 setEnabled(false); 39 DataSet.addSelectionListener(this); 30 40 } 31 41 … … 33 43 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 34 44 synchronized (this) { 35 AddressVisitor addrVisitor = new AddressVisitor(); 36 37 for (OsmPrimitive osm : newSelection) { 38 osm.visit(addrVisitor); 39 } 40 //generateTagCode(addrVisitor); 41 42 addrVisitor.resolveAddresses(); 45 collectAddressesAndStreets(newSelection); 43 46 } 44 47 } 48 49 @Override 50 public void actionPerformed(ActionEvent arg0) { 51 collectAddressesAndStreets(Main.main.getCurrentDataSet() 52 .allPrimitives()); 53 54 if (addressModel != null) { 55 AddressEditDialog dlg = new AddressEditDialog(addressModel); 56 dlg.setVisible(true); 57 } 58 } 59 60 private void collectAddressesAndStreets( 61 final Collection<? extends OsmPrimitive> osmData) { 62 if (osmData == null || osmData.isEmpty()) 63 return; 64 65 final AddressVisitor addrVisitor = new AddressVisitor(); 66 67 //final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Prepare OSM data...")); 68 // int ticks = osmData.size(); 69 70 71 72 try { 73 for (OsmPrimitive osm : osmData) { 74 osm.visit(addrVisitor); 75 76 if (isCanceled) { 77 addrVisitor.clearData(); // free visitor data 78 return; 79 } 80 } 81 //monitor.worked(1); 82 83 // generateTagCode(addrVisitor); 84 //monitor.setCustomText(tr("Resolving addresses...")); 85 addrVisitor.resolveAddresses(); 86 //monitor.worked(1); 87 88 89 } finally { 90 //monitor.close(); 91 } 92 93 addressModel = new AddressEditModel( 94 addrVisitor.getStreetList(), 95 addrVisitor.getUnresolvedItems()); 96 } 97 98 @Override 99 protected void updateEnabledState() { 100 setEnabled(getCurrentDataSet() != null); 101 } 102 103 @Override 104 protected void updateEnabledState( 105 Collection<? extends OsmPrimitive> selection) { 106 setEnabled(selection != null && !selection.isEmpty()); 107 } 108 109 /* ----------------------------------------- */ 45 110 46 111 private void generateTagCode(AddressVisitor addrVisitor) { 47 112 /* This code is abused to generate tag utility code */ 48 113 for (String tag : addrVisitor.getTags()) { 49 String methodName = createMethodName(tag); 50 System.out.println(String.format("/** Check if OSM primitive has a tag '%s'.\n * @param osmPrimitive The OSM entity to check.*/\npublic static boolean has%sTag(OsmPrimitive osmPrimitive) {\n return osmPrimitive != null ? osmPrimitive.hasKey(%s_TAG) : false;\n}\n", 51 tag, 52 methodName, 53 tag.toUpperCase().replaceAll(":", "_"))); 54 System.out.println(String.format("/** Gets the value of tag '%s'.\n * @param osmPrimitive The OSM entity to check.*/\npublic static String get%sValue(OsmPrimitive osmPrimitive) {\n return osmPrimitive != null ? osmPrimitive.get(%s_TAG) : null;\n}\n", 55 tag, 56 methodName, 57 tag.toUpperCase().replaceAll(":", "_"))); 114 String methodName = createMethodName(tag); 115 System.out 116 .println(String 117 .format( 118 "/** Check if OSM primitive has a tag '%s'.\n * @param osmPrimitive The OSM entity to check.*/\npublic static boolean has%sTag(OsmPrimitive osmPrimitive) {\n return osmPrimitive != null ? osmPrimitive.hasKey(%s_TAG) : false;\n}\n", 119 tag, methodName, tag.toUpperCase() 120 .replaceAll(":", "_"))); 121 System.out 122 .println(String 123 .format( 124 "/** Gets the value of tag '%s'.\n * @param osmPrimitive The OSM entity to check.*/\npublic static String get%sValue(OsmPrimitive osmPrimitive) {\n return osmPrimitive != null ? osmPrimitive.get(%s_TAG) : null;\n}\n", 125 tag, methodName, tag.toUpperCase() 126 .replaceAll(":", "_"))); 58 127 } 59 128 60 129 for (String tag : addrVisitor.getTags()) { 61 System.out.println(String.format("public static final String %s_TAG = \"%s\";", tag.toUpperCase().replaceAll(":", "_"), tag)); 130 System.out.println(String.format( 131 "public static final String %s_TAG = \"%s\";", tag 132 .toUpperCase().replaceAll(":", "_"), tag)); 62 133 } 63 134 } 64 135 65 136 private String createMethodName(String osmName) { 66 137 StringBuffer result = new StringBuffer(osmName.length()); … … 79 150 nextUp = false; 80 151 } else { 81 result.append(c); 152 result.append(c); 82 153 } 83 154 } 84 155 } 85 156 86 157 return result.toString(); 87 158 } 88 159 89 160 @Override 90 public void actionPerformed(ActionEvent arg0) {91 161 public void operationCanceled() { 162 isCanceled = true; 92 163 } 93 94 164 } -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/AddressVisitor.java
r23808 r23814 129 129 return streetDict; 130 130 } 131 132 public List<StreetNode> getStreetList() { 133 return new ArrayList<StreetNode>(streetDict.values()); 134 } 131 135 132 136 public List<AddressNode> getUnresolvedItems() { … … 174 178 System.out.println("Still unresolved: " + unresolvedAddresses.size() + " addresses"); 175 179 } 180 181 public void clearData() { 182 streetDict.clear(); 183 unresolvedAddresses.clear(); 184 } 176 185 } -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/StreetNode.java
r23808 r23814 67 67 } 68 68 69 public boolean hasAddresses() { 70 return addresses != null && addresses.size() > 0; 71 } 72 69 73 public List<AddressNode> getAddresses() { 70 74 return addresses;
Note:
See TracChangeset
for help on using the changeset viewer.