Changeset 2194 in josm for trunk


Ignore:
Timestamp:
2009-09-26T13:54:06+02:00 (15 years ago)
Author:
Gubaer
Message:

fixed #3528: Cannot select multiple relations and apply some preset to them

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r2126 r2194  
    7777        displaylist = new JList(model);
    7878        displaylist.setCellRenderer(new OsmPrimitivRenderer());
    79         displaylist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     79        displaylist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    8080        displaylist.addMouseListener(new DoubleClickAdapter());
    8181        add(new JScrollPane(displaylist), BorderLayout.CENTER);
     
    9797        buttonPanel.add(new SideButton(editAction), GBC.std());
    9898
    99         // the edit action
     99        // the duplicate action
    100100        //
    101101        DuplicateAction duplicateAction = new DuplicateAction();
     
    108108        displaylist.addListSelectionListener(deleteAction);
    109109        buttonPanel.add(new SideButton(deleteAction), GBC.eol());
     110
     111        // the select action
     112        //
     113        SelectAction selectAction = new SelectAction();
     114        displaylist.addListSelectionListener(selectAction);
     115        buttonPanel.add(new SideButton(selectAction), GBC.eol());
     116
     117
    110118        add(buttonPanel, BorderLayout.SOUTH);
    111119
     
    275283        public EditAction() {
    276284            putValue(SHORT_DESCRIPTION,tr( "Open an editor for the selected relation"));
    277             putValue(NAME, tr("Edit"));
     285            //putValue(NAME, tr("Edit"));
    278286            putValue(SMALL_ICON, ImageProvider.get("dialogs", "edit"));
    279287            setEnabled(false);
     
    303311
    304312        public void valueChanged(ListSelectionEvent e) {
    305             setEnabled(displaylist.getSelectedIndices() != null && displaylist.getSelectedIndices().length > 0);
     313            setEnabled(displaylist.getSelectedIndices() != null && displaylist.getSelectedIndices().length == 1);
    306314        }
    307315    }
     
    311319     *
    312320     */
    313     class DeleteAction extends AbstractAction implements ListSelectionListener, Runnable {
     321    class DeleteAction extends AbstractAction implements ListSelectionListener {
    314322        class AbortException extends Exception {}
    315323
    316324        public DeleteAction() {
    317325            putValue(SHORT_DESCRIPTION,tr("Delete the selected relation"));
    318             putValue(NAME, tr("Delete"));
     326            //putValue(NAME, tr("Delete"));
    319327            putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete"));
    320328            setEnabled(false);
    321329        }
    322330
    323         public void run() {
    324             if (!isEnabled()) return;
    325             Relation toDelete = getSelected();
     331        protected void deleteRelation(Relation toDelete) {
    326332            if (toDelete == null)
    327333                return;
     
    333339
    334340        public void actionPerformed(ActionEvent e) {
    335             run();
     341            if (!isEnabled()) return;
     342            int [] idx  = displaylist.getSelectedIndices();
     343            ArrayList<Relation> toDelete = new ArrayList<Relation>(idx.length);
     344            for (int i: idx) {
     345                toDelete.add(model.getRelation(i));
     346            }
     347            for (Relation r: toDelete) {
     348                deleteRelation(r);
     349            }
    336350        }
    337351
     
    348362        public NewAction() {
    349363            putValue(SHORT_DESCRIPTION,tr("Create a new relation"));
    350             putValue(NAME, tr("New"));
     364            //putValue(NAME, tr("New"));
    351365            putValue(SMALL_ICON, ImageProvider.get("dialogs", "addrelation"));
    352366            setEnabled(false);
     
    385399        public DuplicateAction() {
    386400            putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window"));
    387             // FIXME provide an icon
    388401            putValue(SMALL_ICON, ImageProvider.get("duplicate"));
    389             putValue(NAME, tr("Duplicate"));
     402            //putValue(NAME, tr("Duplicate"));
    390403            updateEnabledState();
    391404        }
     
    419432    }
    420433
     434    /**
     435     * Sets the current selection to the list of relations selected in this dialog
     436     *
     437     */
     438    class SelectAction extends AbstractAction implements ListSelectionListener{
     439        public SelectAction() {
     440            putValue(SHORT_DESCRIPTION,tr("Set the current selection to the list of selected relations"));
     441            //putValue(NAME, tr("Select"));
     442            putValue(SMALL_ICON, ImageProvider.get("dialogs", "select"));
     443            setEnabled(false);
     444        }
     445
     446        public void actionPerformed(ActionEvent e) {
     447            if (!isEnabled()) return;
     448            int [] idx = displaylist.getSelectedIndices();
     449            if (idx == null || idx.length == 0) return;
     450            ArrayList<OsmPrimitive> selection = new ArrayList<OsmPrimitive>(idx.length);
     451            for (int i: idx) {
     452                selection.add(model.getRelation(i));
     453            }
     454            Main.map.mapView.getEditLayer().data.setSelected(selection);
     455            DataSet.fireSelectionChanged(selection);
     456        }
     457
     458        public void valueChanged(ListSelectionEvent e) {
     459            setEnabled(displaylist.getSelectedIndices() != null && displaylist.getSelectedIndices().length > 0);
     460        }
     461    }
     462
    421463    private static  class RelationListModel extends AbstractListModel {
    422464        private ArrayList<Relation> relations;
     
    424466        public ArrayList<Relation> getRelations() {
    425467            return relations;
     468        }
     469
     470        public Relation getRelation(int idx) {
     471            return relations.get(idx);
    426472        }
    427473
Note: See TracChangeset for help on using the changeset viewer.