Changeset 23924 in osm


Ignore:
Timestamp:
2010-10-30T19:27:18+02:00 (14 years ago)
Author:
oliverw
Message:
  • Revised AbstractAddressEditAction
  • Added "select in map" action
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  
    4848        @Override
    4949        public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
     50                /* this changes the dialog contents, so we do nothing here
    5051                this.newSelection = newSelection;
    5152                if (addressEditContainer != null) {
    5253                        addressEditContainer.invalidate(newSelection);
    53                 }
     54                }*/
    5455        }
    5556
  • applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/AbstractAddressEditAction.java

    r23923 r23924  
    1919import org.openstreetmap.josm.plugins.addressEdit.AddressEditContainer;
    2020
     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")
    2134public abstract class AbstractAddressEditAction extends JosmAction {
    22 
    23         /**
    24          *
    25          */
    26         private static final long serialVersionUID = 3080414353417044998L;
    27 
    2835        private AddressEditSelectionEvent event;
    2936        protected AddressEditContainer container;
     
    114121                        event = null; // consume event
    115122                } else {
    116                         actionPerformed(arg0);
     123                        if (container != null) {
     124                                addressEditActionPerformed(container);
     125                        } else { // call super class hook
     126                                actionPerformed(arg0);
     127                        }
    117128                }
    118129        }
     
    120131
    121132        /**
    122          * Redirected action handler
     133         * Redirected action handler for doing actions on a address selection.
    123134         * @param ev
    124135         */
    125136        public abstract void addressEditActionPerformed(AddressEditSelectionEvent ev);
    126137       
     138        /**
     139         * Redirected action handler for doing actions on an address container.
     140         * @param ev
     141         */
     142        public abstract void addressEditActionPerformed(AddressEditContainer container);
     143       
    127144       
    128145
  • applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/AddressEditDialog.java

    r23923 r23924  
    5656import org.openstreetmap.josm.plugins.addressEdit.StreetNode;
    5757import org.openstreetmap.josm.plugins.addressEdit.StringUtils;
    58 
     58import org.openstreetmap.josm.tools.ImageProvider;
     59
     60@SuppressWarnings("serial")
    5961public class AddressEditDialog extends JDialog implements ActionListener, ListSelectionListener, IAddressEditContainerListener {
    6062        private static final String UNRESOLVED_HEADER_FMT = tr("Unresolved Addresses (%d)");
    6163        private static final String STREET_HEADER_FMT = tr("Streets (%d)");
    6264        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       
    6767        private AddressEditContainer editContainer;
    6868        private JTable unresolvedTable;
     
    7373        private ApplyAllGuessesAction applyAllGuessesAction = new ApplyAllGuessesAction();
    7474        private GuessAddressDataAction guessAddressAction = new GuessAddressDataAction();
     75        private SelectAddressesInMapAction selectAddressesInMapAction = new SelectAddressesInMapAction();
    7576       
    7677        private AbstractAddressEditAction[] actions = new AbstractAddressEditAction[] {
    7778                resolveAction,
    7879                guessAddressAction,
    79                 applyAllGuessesAction
     80                applyAllGuessesAction,
     81                selectAddressesInMapAction
    8082        };
    8183        private JLabel streetLabel;
     
    8991         */
    9092        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);
    9294       
    9395                this.editContainer = addressEditContainer;
     
    135137                                SideButton applyAllGuesses = new SideButton(applyAllGuessesAction);                                                                                                                       
    136138                                unresolvedButtons.add(applyAllGuesses);
     139                               
     140                                unresolvedButtons.add(new JSeparator());
     141                                SideButton selectInMap = new SideButton(selectAddressesInMapAction);                                                                                                                       
     142                                unresolvedButtons.add(selectInMap);
    137143                                unresolvedPanel.add(unresolvedButtons, BorderLayout.SOUTH);
    138144                        } catch (Exception e) {                         
     
    163169               
    164170                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"));
    166172                ok.addActionListener(this);
     173                JButton selectAndClose = new JButton(SELECT_AND_CLOSE);
     174                selectAndClose.addActionListener(this);
    167175               
    168176                // Murks
  • applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/ApplyAllGuessesAction.java

    r23923 r23924  
    4444        }
    4545
    46         /* (non-Javadoc)
    47          * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#actionPerformed(java.awt.event.ActionEvent)
    48          */
    49         @Override
    50         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 
    5746        private void applyGuesses(List<AddressNode> addrToFix) {
    5847                List<AddressNode> addrToFixShadow = new ArrayList<AddressNode>(addrToFix);
     
    6655                // do nothing here
    6756        }
     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        }
    6865}
  • applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/AssignAddressToStreetAction.java

    r23921 r23924  
    3737        public void addressEditActionPerformed(AddressEditSelectionEvent ev) {         
    3838                StreetNode streetNode = ev.getSelectedStreet();
    39                
    40                
     39                               
    4140                if (streetNode != null && ev.getSelectedUnresolvedAddresses() != null) {
    4241                        for (AddressNode addrNode : ev.getSelectedUnresolvedAddresses()) {
     
    6160        }
    6261
     62        @Override
     63        public void addressEditActionPerformed(AddressEditContainer container) {
     64                // we only accept a selection: nothing to do here               
     65        }
     66
    6367
    6468}
  • applications/editors/josm/plugins/AddressEdit/src/org/openstreetmap/josm/plugins/addressEdit/gui/GuessAddressDataAction.java

    r23923 r23924  
    2424import org.openstreetmap.josm.plugins.addressEdit.AddressNode;
    2525
     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
    2633@SuppressWarnings("serial")
    2734public class GuessAddressDataAction extends AbstractAddressEditAction {
     
    3340        }
    3441
     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
    3563        @Override
    3664        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());
    3769        }
    3870       
    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
    4174         */
    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
    4777                for (int i = 0; i < threads.length; i++) {
    4878                        threads[i] = new AddressFinderThread();
    4979                }
    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);
    5383                for (AddressNode aNode : addrNodes) {
    5484                        if (aNode.hasStreetName()) continue;
     
    76106        }
    77107
    78         /* (non-Javadoc)
    79          * @see org.openstreetmap.josm.plugins.addressEdit.gui.AbstractAddressEditAction#updateEnabledState(org.openstreetmap.josm.plugins.addressEdit.gui.AddressEditSelectionEvent)
    80          */
    81         @Override
    82         public void updateEnabledState(AddressEditSelectionEvent ev) {
    83                 // do nothing here
    84         }
    85 
    86         @Override
    87         protected void updateEnabledState(AddressEditContainer container) {
    88                 setEnabled(container != null && container.getNumberOfIncompleteAddresses() > 0);
    89         }
    90 
    91        
    92108}
Note: See TracChangeset for help on using the changeset viewer.