Changeset 23924 in osm
- Timestamp:
- 2010-10-30T19:27:18+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/AddressEdit
- Files:
-
- 3 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/FixUnresolvedStreetsAction.java
r23920 r23924 48 48 @Override 49 49 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 50 /* this changes the dialog contents, so we do nothing here 50 51 this.newSelection = newSelection; 51 52 if (addressEditContainer != null) { 52 53 addressEditContainer.invalidate(newSelection); 53 } 54 }*/ 54 55 } 55 56 -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/AbstractAddressEditAction.java
r23923 r23924 19 19 import org.openstreetmap.josm.plugins.addressEdit.AddressEditContainer; 20 20 21 /** 22 * Base class for all address related action. An action can work as well on all addresses collected by the 23 * container or on the active selection. 24 * By default, the action is disabled and the updateEnabledState(...) have to be implemented by 25 * subclasses. There are also two separate <tt>actionPerformedXX</tt> methods to do the action on 26 * container or on selection items. 27 * Most actions will work in both cases, so it is recommended to have one single method which 28 * accepts a list of addresses or streets and executes the tasks to be done by this action. 29 * @author Oliver Wieland <oliver.wieland@online.de> 30 * 31 */ 32 33 @SuppressWarnings("serial") 21 34 public abstract class AbstractAddressEditAction extends JosmAction { 22 23 /**24 *25 */26 private static final long serialVersionUID = 3080414353417044998L;27 28 35 private AddressEditSelectionEvent event; 29 36 protected AddressEditContainer container; … … 114 121 event = null; // consume event 115 122 } else { 116 actionPerformed(arg0); 123 if (container != null) { 124 addressEditActionPerformed(container); 125 } else { // call super class hook 126 actionPerformed(arg0); 127 } 117 128 } 118 129 } … … 120 131 121 132 /** 122 * Redirected action handler 133 * Redirected action handler for doing actions on a address selection. 123 134 * @param ev 124 135 */ 125 136 public abstract void addressEditActionPerformed(AddressEditSelectionEvent ev); 126 137 138 /** 139 * Redirected action handler for doing actions on an address container. 140 * @param ev 141 */ 142 public abstract void addressEditActionPerformed(AddressEditContainer container); 143 127 144 128 145 -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/AddressEditDialog.java
r23923 r23924 56 56 import org.openstreetmap.josm.plugins.addressEdit.StreetNode; 57 57 import org.openstreetmap.josm.plugins.addressEdit.StringUtils; 58 58 import org.openstreetmap.josm.tools.ImageProvider; 59 60 @SuppressWarnings("serial") 59 61 public class AddressEditDialog extends JDialog implements ActionListener, ListSelectionListener, IAddressEditContainerListener { 60 62 private static final String UNRESOLVED_HEADER_FMT = tr("Unresolved Addresses (%d)"); 61 63 private static final String STREET_HEADER_FMT = tr("Streets (%d)"); 62 64 private static final String OK_COMMAND = tr("Close"); 63 /** 64 * 65 */ 66 private static final long serialVersionUID = 6251676464816335631L; 65 private static final String SELECT_AND_CLOSE = tr("Select and close"); 66 67 67 private AddressEditContainer editContainer; 68 68 private JTable unresolvedTable; … … 73 73 private ApplyAllGuessesAction applyAllGuessesAction = new ApplyAllGuessesAction(); 74 74 private GuessAddressDataAction guessAddressAction = new GuessAddressDataAction(); 75 private SelectAddressesInMapAction selectAddressesInMapAction = new SelectAddressesInMapAction(); 75 76 76 77 private AbstractAddressEditAction[] actions = new AbstractAddressEditAction[] { 77 78 resolveAction, 78 79 guessAddressAction, 79 applyAllGuessesAction 80 applyAllGuessesAction, 81 selectAddressesInMapAction 80 82 }; 81 83 private JLabel streetLabel; … … 89 91 */ 90 92 public AddressEditDialog(AddressEditContainer addressEditContainer) throws HeadlessException { 91 super(JOptionPane.getFrameForComponent(Main.parent), tr(" Edit Addresses"), false);93 super(JOptionPane.getFrameForComponent(Main.parent), tr("Fix unresolved addresses"), false); 92 94 93 95 this.editContainer = addressEditContainer; … … 135 137 SideButton applyAllGuesses = new SideButton(applyAllGuessesAction); 136 138 unresolvedButtons.add(applyAllGuesses); 139 140 unresolvedButtons.add(new JSeparator()); 141 SideButton selectInMap = new SideButton(selectAddressesInMapAction); 142 unresolvedButtons.add(selectInMap); 137 143 unresolvedPanel.add(unresolvedButtons, BorderLayout.SOUTH); 138 144 } catch (Exception e) { … … 163 169 164 170 JPanel buttonPanel = new JPanel(new GridLayout(1,10)); 165 JButton ok = new JButton(OK_COMMAND );171 JButton ok = new JButton(OK_COMMAND, ImageProvider.getIfAvailable(null, "ok")); 166 172 ok.addActionListener(this); 173 JButton selectAndClose = new JButton(SELECT_AND_CLOSE); 174 selectAndClose.addActionListener(this); 167 175 168 176 // Murks -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/ApplyAllGuessesAction.java
r23923 r23924 44 44 } 45 45 46 /* (non-Javadoc)47 * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#actionPerformed(java.awt.event.ActionEvent)48 */49 @Override50 public void actionPerformed(ActionEvent arg0) {51 if (container == null || container.getUnresolvedAddresses() == null) return;52 53 List<AddressNode> addrToFix = container.getUnresolvedAddresses();54 applyGuesses(addrToFix);55 }56 57 46 private void applyGuesses(List<AddressNode> addrToFix) { 58 47 List<AddressNode> addrToFixShadow = new ArrayList<AddressNode>(addrToFix); … … 66 55 // do nothing here 67 56 } 57 58 @Override 59 public void addressEditActionPerformed(AddressEditContainer container) { 60 if (container == null || container.getUnresolvedAddresses() == null) return; 61 62 List<AddressNode> addrToFix = container.getUnresolvedAddresses(); 63 applyGuesses(addrToFix); 64 } 68 65 } -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/AssignAddressToStreetAction.java
r23921 r23924 37 37 public void addressEditActionPerformed(AddressEditSelectionEvent ev) { 38 38 StreetNode streetNode = ev.getSelectedStreet(); 39 40 39 41 40 if (streetNode != null && ev.getSelectedUnresolvedAddresses() != null) { 42 41 for (AddressNode addrNode : ev.getSelectedUnresolvedAddresses()) { … … 61 60 } 62 61 62 @Override 63 public void addressEditActionPerformed(AddressEditContainer container) { 64 // we only accept a selection: nothing to do here 65 } 66 63 67 64 68 } -
applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/GuessAddressDataAction.java
r23923 r23924 24 24 import org.openstreetmap.josm.plugins.addressEdit.AddressNode; 25 25 26 /** 27 * Guesses address tags by picking the closest street node with a name. The same is done (some day) 28 * with city, post code, state,... 29 * @author Oliver Wieland <oliver.wieland@online.de> 30 * 31 */ 32 26 33 @SuppressWarnings("serial") 27 34 public class GuessAddressDataAction extends AbstractAddressEditAction { … … 33 40 } 34 41 42 /* (non-Javadoc) 43 * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.addressEdit.gui.AddressEditSelectionEvent) 44 */ 45 @Override 46 public void updateEnabledState(AddressEditSelectionEvent ev) { 47 setEnabled(ev != null && ev.getUnresolvedAddressTable() != null); 48 } 49 50 @Override 51 protected void updateEnabledState(AddressEditContainer container) { 52 setEnabled(container != null && container.getNumberOfIncompleteAddresses() > 0); 53 } 54 55 @Override 56 public void addressEditActionPerformed(AddressEditContainer container) { 57 if (container == null) return; 58 if (container.getUnresolvedAddresses() == null) return; 59 60 internalGuessAddresses(container.getIncompleteAddresses()); 61 } 62 35 63 @Override 36 64 public void addressEditActionPerformed(AddressEditSelectionEvent ev) { 65 if (ev == null || ev.getSelectedUnresolvedAddresses() == null) return; 66 67 // guess tags for selected addresses only 68 internalGuessAddresses(ev.getSelectedUnresolvedAddresses()); 37 69 } 38 70 39 /* (non-Javadoc) 40 * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#actionPerformed(java.awt.event.ActionEvent) 71 /** 72 * Internal method to start several threads guessing tag values for the given list of addresses. 73 * @param addrNodes 41 74 */ 42 @Override 43 public void actionPerformed(ActionEvent arg0) { 44 if (container == null) return; 45 if (container.getUnresolvedAddresses() == null) return; 46 75 private void internalGuessAddresses(List<AddressNode> nodes) { 76 // setup thread pool 47 77 for (int i = 0; i < threads.length; i++) { 48 78 threads[i] = new AddressFinderThread(); 49 79 } 50 51 List<AddressNode> addrNodes = new ArrayList<AddressNode>();52 addrNodes.addAll(container.getIncompleteAddresses());80 81 // work on a shadowed copy 82 List<AddressNode> addrNodes = new ArrayList<AddressNode>(nodes); 53 83 for (AddressNode aNode : addrNodes) { 54 84 if (aNode.hasStreetName()) continue; … … 76 106 } 77 107 78 /* (non-Javadoc)79 * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.addressEdit.gui.AddressEditSelectionEvent)80 */81 @Override82 public void updateEnabledState(AddressEditSelectionEvent ev) {83 // do nothing here84 }85 86 @Override87 protected void updateEnabledState(AddressEditContainer container) {88 setEnabled(container != null && container.getNumberOfIncompleteAddresses() > 0);89 }90 91 92 108 }
Note:
See TracChangeset
for help on using the changeset viewer.