Ignore:
Timestamp:
2010-11-07T16:11:58+01:00 (14 years ago)
Author:
oliverw
Message:

Added selection action to "incomplete addresses dialog" , extended SelectAddressesInMapAction to support incomplete addresses.

Location:
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/AddressEditDialog.java

    r24109 r24114  
    293293               
    294294                AddressEditSelectionEvent ev = new AddressEditSelectionEvent(e.getSource(),
    295                                 streetTable, unresolvedTable, editContainer);
     295                                streetTable, unresolvedTable, null, editContainer);
    296296               
    297297                for (AbstractAddressEditAction action : actions) {
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/AddressEditSelectionEvent.java

    r24093 r24114  
    3131        private JTable streetTable;
    3232        private JTable unresolvedAddressTable;
     33        private JTable incompleteAddressTable;
    3334        private AddressEditContainer addressContainer;
    3435       
     
    3738         * @param source The event source.
    3839         * @param selStreet The street table component.
    39          * @param unresolvedAddr The unresolved addresses table component.
     40         * @param unresolvedAddresses The unresolved addresses table component.
    4041         * @param incomplete The incomplete addresses table component.
    4142         * @param container The address container instance holding the entities for streets and addresses.
    4243         */
    43         public AddressEditSelectionEvent(Object source, JTable selStreet, JTable unresolvedAddr, AddressEditContainer container) {
     44        public AddressEditSelectionEvent(Object source, JTable selStreet, JTable unresolvedAddresses, JTable incompleteAddresses, AddressEditContainer container) {
    4445                super(source, -1, "");
    4546                this.streetTable = selStreet;
    46                 this.unresolvedAddressTable = unresolvedAddr;
     47                this.unresolvedAddressTable = unresolvedAddresses;
     48                this.incompleteAddressTable = incompleteAddresses;
    4749                this.addressContainer = container;
    4850        }
     
    6365                return unresolvedAddressTable;
    6466        }
     67       
     68        /**
     69         * @return the incompleteAddressTable
     70         */
     71        protected JTable getIncompleteAddressTable() {
     72                return incompleteAddressTable;
     73        }
    6574
     75        /**
     76         * Gets the address container.
     77         *
     78         * @return the address container
     79         */
    6680        public AddressEditContainer getAddressContainer() {
    6781                return addressContainer;
     
    106120                return null;
    107121        }
     122       
     123        /**
     124         * Gets the selected incomplete addresses.
     125         *
     126         * @return the selected incomplete addresses
     127         */
     128        public List<OSMAddress> getSelectedIncompleteAddresses() {
     129                if (incompleteAddressTable != null &&
     130                                addressContainer != null &&
     131                                addressContainer.getUnresolvedAddresses() != null) {
     132                       
     133                        int[] selRows = incompleteAddressTable.getSelectedRows();
     134                       
     135                        List<OSMAddress> nodes = new ArrayList<OSMAddress>();
     136                        for (int i = 0; i < selRows.length; i++) {
     137                                if (selRows[i] >= 0 && selRows[i] < addressContainer.getNumberOfIncompleteAddresses()) {
     138                                        nodes.add(addressContainer.getIncompleteAddresses().get(selRows[i]));
     139                                }
     140                        }
     141                        return nodes;
     142                }
     143                return null;
     144        }
    108145}
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/IncompleteAddressesDialog.java

    r24112 r24114  
    2121import javax.swing.JScrollPane;
    2222import javax.swing.JTable;
     23import javax.swing.event.ListSelectionEvent;
     24import javax.swing.event.ListSelectionListener;
    2325
    2426import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
     
    3335import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
    3436import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
     37import org.openstreetmap.josm.gui.SideButton;
    3538import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
    3639import org.openstreetmap.josm.plugins.fixAddresses.AddressEditContainer;
     40import org.openstreetmap.josm.plugins.fixAddresses.IAddressEditContainerListener;
     41import org.openstreetmap.josm.plugins.fixAddresses.IOSMEntity;
     42import org.openstreetmap.josm.plugins.fixAddresses.gui.actions.AbstractAddressEditAction;
     43import org.openstreetmap.josm.plugins.fixAddresses.gui.actions.SelectAddressesInMapAction;
    3744
    3845@SuppressWarnings("serial")
    39 public class IncompleteAddressesDialog extends ToggleDialog implements DataSetListener {
     46public class IncompleteAddressesDialog extends ToggleDialog implements DataSetListener, ListSelectionListener, IAddressEditContainerListener {
     47        private static final String FIXED_DIALOG_TITLE = tr("Incomplete Addresses");
     48
     49
    4050        private AddressEditContainer container;
    4151
     52       
     53        private SelectAddressesInMapAction selectAction = new SelectAddressesInMapAction();
     54       
     55        private AbstractAddressEditAction[] actions = new AbstractAddressEditAction[]{
     56                        selectAction
     57        };
     58
     59
     60        private JTable incompleteAddr;
     61       
    4262        /**
    43          * @param name
    44          * @param iconName
    45          * @param tooltip
    46          * @param shortcut
    47          * @param preferredHeight
    48          * @param container
     63         * Instantiates a new "incomplete addresses" dialog.
     64         *
    4965         */
    5066        public IncompleteAddressesDialog() {
    51                 super(tr("Incomplete Addresses"), "incompleteaddress_24", tr("Show incomplete addresses"), null, 150);
     67                super(FIXED_DIALOG_TITLE, "incompleteaddress_24", tr("Show incomplete addresses"), null, 150);
     68               
    5269                this.container = new AddressEditContainer();
     70                container.addChangedListener(this);
    5371               
    5472                JPanel p = new JPanel(new BorderLayout());
    5573               
    56                 JTable incompleteAddr = new JTable(new IncompleteAddressesTableModel(container));
     74                incompleteAddr = new JTable(new IncompleteAddressesTableModel(container));
     75                incompleteAddr.getSelectionModel().addListSelectionListener(this);
     76               
    5777                JScrollPane sp = new JScrollPane(incompleteAddr);
    5878                p.add(sp, BorderLayout.CENTER);
    5979                this.add(p);
     80               
     81                JPanel buttonPanel = getButtonPanel(5);
     82               
     83                SideButton sb = new SideButton(selectAction);
     84                buttonPanel.add(sb);
     85               
     86                this.add(buttonPanel, BorderLayout.SOUTH);
     87               
     88                for (AbstractAddressEditAction action : actions) {
     89                        action.setContainer(container);
     90                }
    6091        }
    6192       
     
    124155                container.invalidate();         
    125156        }
     157
     158        /* (non-Javadoc)
     159         * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
     160         */
     161        @Override
     162        public void valueChanged(ListSelectionEvent e) {
     163                AddressEditSelectionEvent event = new AddressEditSelectionEvent(e, null, null, incompleteAddr, container);
     164               
     165                for (AbstractAddressEditAction action : actions) {
     166                        action.setEvent(event);
     167                }               
     168        }
     169
     170        @Override
     171        public void containerChanged(AddressEditContainer container) {
     172                if (container != null && container.getNumberOfIncompleteAddresses() > 0) {
     173                        setTitle(String.format("%s (%d %s)", FIXED_DIALOG_TITLE, container.getNumberOfIncompleteAddresses(), tr("items")));
     174                } else {
     175                        setTitle(String.format("%s (%s)", FIXED_DIALOG_TITLE, tr("no items")));                 
     176                }
     177        }
     178
     179        @Override
     180        public void entityChanged(IOSMEntity node) {
     181                // TODO Auto-generated method stub
     182               
     183        }
    126184       
    127185       
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/AbstractAddressEditAction.java

    r24106 r24114  
    113113                        if (container != null) {
    114114                                addressEditActionPerformed(container);
    115                         } else { // call super class hook
    116                                 actionPerformed(arg0);
     115                        } else {
     116                                throw new RuntimeException("AbstractAddressEditAction has no container or event");
    117117                        }
    118118                }
  • applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/gui/actions/SelectAddressesInMapAction.java

    r24105 r24114  
    6060                if (ev == null) return;
    6161               
    62                 internalSelectAddresses(ev.getSelectedUnresolvedAddresses());
     62                if (ev.getSelectedUnresolvedAddresses() != null) {
     63                        internalSelectAddresses(ev.getSelectedUnresolvedAddresses());
     64                } else if (ev.getSelectedIncompleteAddresses() != null) {
     65                        internalSelectAddresses(ev.getSelectedIncompleteAddresses());
     66                }
    6367        }
    6468
    6569        @Override
    6670        public void addressEditActionPerformed(AddressEditContainer container) {
    67                 internalSelectAddresses(container.getUnresolvedAddresses());           
     71                // do nothing           
    6872        }
    6973
     
    7377        @Override
    7478        protected void updateEnabledState(AddressEditContainer container) {
    75                 setEnabled(container != null && container.getNumberOfIncompleteAddresses() > 0);
     79                setEnabled(false);
    7680        }
    7781
     
    8185        @Override
    8286        protected void updateEnabledState(AddressEditSelectionEvent event) {
    83                 setEnabled(event != null && event.getSelectedUnresolvedAddresses() != null);
     87                setEnabled(event != null && (event.getSelectedUnresolvedAddresses() != null || event.getSelectedIncompleteAddresses() != null));
    8488        }
    8589
Note: See TracChangeset for help on using the changeset viewer.