Ignore:
Timestamp:
2009-07-19T19:04:49+02:00 (15 years ago)
Author:
Gubaer
Message:

removed dependencies to Main.ds, removed Main.ds
removed AddVisitor, NameVisitor, DeleteVisitor - unnecessary double dispatching for these simple cases

File:
1 edited

Legend:

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

    r1722 r1814  
    4343import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
    4444import org.openstreetmap.josm.gui.SideButton;
     45import org.openstreetmap.josm.gui.layer.Layer;
     46import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     47import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
    4548import org.openstreetmap.josm.tools.Shortcut;
    4649
     
    5255 * @author imi
    5356 */
    54 public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener {
     57public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener, LayerChangeListener {
    5558
    5659    private static final int SELECTION_HISTORY_SIZE = 10;
     
    8083    public SelectionListDialog() {
    8184        super(tr("Current Selection"), "selectionlist", tr("Open a selection list window."),
    82         Shortcut.registerShortcut("subwindow:selection", tr("Toggle: {0}", tr("Current Selection")), KeyEvent.VK_T, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150);
     85                Shortcut.registerShortcut("subwindow:selection", tr("Toggle: {0}", tr("Current Selection")), KeyEvent.VK_T, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150);
    8386
    8487        selectionHistory = new LinkedList<Collection<? extends OsmPrimitive>>();
     
    8992            @Override
    9093            public void mouseClicked(MouseEvent e) {
    91                 if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1)
     94                if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
    9295                    updateMap();
     96                }
    9397            }
    9498
     
    112116                tr("Set the selected elements on the map to the selected items in the list above."),
    113117                new ActionListener() {
    114                     public void actionPerformed(ActionEvent e) {
    115                         updateMap();
    116                     }
    117                 });
     118            public void actionPerformed(ActionEvent e) {
     119                updateMap();
     120            }
     121        });
    118122        buttonPanel.add(selectButton);
    119123        BasicArrowButton selectionHistoryMenuButton = createArrowButton(selectButton);
     
    134138        buttonPanel.add(new SideButton(marktr("Reload"), "refresh", "SelectionList", tr("Refresh the selection list."),
    135139                new ActionListener() {
    136                     public void actionPerformed(ActionEvent e) {
    137                         selectionChanged(Main.ds.getSelected());
    138                     }
    139                 }));
     140            public void actionPerformed(ActionEvent e) {
     141                selectionChanged(Main.main.getCurrentDataSet().getSelected());
     142            }
     143        }));
    140144
    141145        searchButton = new SideButton(marktr("Search"), "search", "SelectionList", tr("Search for objects."),
     
    159163        popupMenu.add(zoomToSelection);
    160164
    161         selectionChanged(Main.ds.getSelected());
     165        if (Main.main.getCurrentDataSet() != null) {
     166            selectionChanged(Main.main.getCurrentDataSet().getSelected());
     167        }
    162168
    163169        DataSet.selListeners.add(this);
     170        Layer.listeners.add(this);
    164171    }
    165172
     
    179186    public void setVisible(boolean b) {
    180187        super.setVisible(b);
    181         if (b)
    182             selectionChanged(Main.ds.getSelected());
     188        if (b && Main.main.getCurrentDataSet() != null) {
     189            selectionChanged(Main.main.getCurrentDataSet().getSelected());
     190        }
    183191    }
    184192
     
    204212        for (int i = 0; i < selected.length; i++) {
    205213            Object o = list.get(selected[i]);
    206             if (o instanceof OsmPrimitive)
     214            if (o instanceof OsmPrimitive) {
    207215                ((OsmPrimitive) o).visit(box);
     216            }
    208217        }
    209218        if (box.getBounds() == null)
     
    247256        list.setSize(selArr.length);
    248257        int i = 0;
    249         for (OsmPrimitive osm : selArr)
     258        for (OsmPrimitive osm : selArr) {
    250259            list.setElementAt(osm, i++);
     260        }
    251261        if (selectionHistory != null && newSelection.size() > 0 && !newSelection.equals(historyIgnoreSelection)) {
    252262            historyIgnoreSelection = null;
     
    259269            }
    260270            selectionHistory.addFirst(newSelection);
    261             while (selectionHistory.size() > SELECTION_HISTORY_SIZE)
     271            while (selectionHistory.size() > SELECTION_HISTORY_SIZE) {
    262272                selectionHistory.removeLast();
     273            }
    263274        }
    264275
     
    267278        int relations = 0;
    268279        for (OsmPrimitive o : newSelection) {
    269             if (o instanceof Way)
     280            if (o instanceof Way) {
    270281                ways++;
    271             else if (o instanceof Node)
     282            } else if (o instanceof Node) {
    272283                nodes++;
    273             else if (o instanceof Relation)
     284            } else if (o instanceof Relation) {
    274285                relations++;
     286            }
    275287        }
    276288
     
    288300        Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>();
    289301        for (int i = 0; i < list.getSize(); ++i)
    290             if (displaylist.isSelectedIndex(i))
     302            if (displaylist.isSelectedIndex(i)) {
    291303                sel.add((OsmPrimitive) list.get(i));
    292         Main.ds.setSelected(sel);
     304            }
     305        Main.main.getCurrentDataSet().setSelected(sel);
    293306    }
    294307
     
    308321            int relations = 0;
    309322            for (OsmPrimitive o : sel) {
    310                 if (o instanceof Way)
     323                if (o instanceof Way) {
    311324                    ways++;
    312                 else if (o instanceof Node)
     325                } else if (o instanceof Node) {
    313326                    nodes++;
    314                 else if (o instanceof Relation)
     327                } else if (o instanceof Relation) {
    315328                    relations++;
     329                }
    316330            }
    317331            String text = "";
    318             if(ways != 0)
     332            if(ways != 0) {
    319333                text += (text.length() > 0 ? ", " : "")
    320334                + trn("{0} way", "{0} ways", ways, ways);
    321             if(nodes != 0)
     335            }
     336            if(nodes != 0) {
    322337                text += (text.length() > 0 ? ", " : "")
    323338                + trn("{0} node", "{0} nodes", nodes, nodes);
    324             if(relations != 0)
     339            }
     340            if(relations != 0) {
    325341                text += (text.length() > 0 ? ", " : "")
    326342                + trn("{0} relation", "{0} relations", relations, relations);
     343            }
    327344            setText(tr("Selection: {0}", text));
    328345            addActionListener(this);
     
    331348        public void actionPerformed(ActionEvent e) {
    332349            historyIgnoreSelection = sel;
    333             Main.ds.setSelected(sel);
     350            Main.main.getCurrentDataSet().setSelected(sel);
    334351        }
    335352
     
    355372
    356373    }
     374
     375    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     376        if (newLayer instanceof OsmDataLayer) {
     377            OsmDataLayer dataLayer = (OsmDataLayer)newLayer;
     378            selectionChanged(dataLayer.data.getSelected());
     379
     380        }
     381
     382    }
     383
     384    public void layerAdded(Layer newLayer) {
     385        // do nothing
     386
     387    }
     388
     389    public void layerRemoved(Layer oldLayer) {
     390        // do nothing
     391
     392    }
    357393}
Note: See TracChangeset for help on using the changeset viewer.