Logo Search packages:      
Sourcecode: josm version File versions  Download package

org::openstreetmap::josm::gui::dialogs::LayerListDialog::LayerListDialog ( MapFrame  mapFrame  )  [inline]

Create an layerlist and attach it to the given mapView.

Definition at line 145 of file LayerListDialog.java.

References deleteAction, downButton, org::openstreetmap::josm::gui::MapView::getActiveLayer(), org::openstreetmap::josm::gui::MapView::getAllLayers(), org::openstreetmap::josm::gui::layer::Layer::getIcon(), org::openstreetmap::josm::gui::layer::Layer::getToolTipText(), instance, org::openstreetmap::josm::gui::MapFrame::mapView, mergeButton, org::openstreetmap::josm::gui::layer::Layer::mergeFrom(), model, org::openstreetmap::josm::gui::MapView::moveLayer(), org::openstreetmap::josm::gui::layer::Layer::name, org::openstreetmap::josm::gui::MapView::removeLayer(), org::openstreetmap::josm::gui::MapView::setActiveLayer(), upButton, updateButtonEnabled(), and org::openstreetmap::josm::gui::layer::Layer::visible.

                                                {
            super(tr("Layers"), "layerlist", tr("Open a list of all loaded layers."), KeyEvent.VK_L, 100);
            instance = new JList(model);
            listScrollPane = new JScrollPane(instance);
            add(listScrollPane, BorderLayout.CENTER);
            instance.setBackground(UIManager.getColor("Button.background"));
            instance.setCellRenderer(new DefaultListCellRenderer(){
                  @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                        Layer layer = (Layer)value;
                        JLabel label = (JLabel)super.getListCellRendererComponent(list,
                                    layer.name, index, isSelected, cellHasFocus);
                        Icon icon = layer.getIcon();
                        if (!layer.visible)
                              icon = ImageProvider.overlay(icon, "overlay/invisible", OverlayPosition.SOUTHEAST);
                        label.setIcon(icon);
                        label.setToolTipText(layer.getToolTipText());
                        return label;
                  }
            });

            final MapView mapView = mapFrame.mapView;

            Collection<Layer> data = mapView.getAllLayers();
            for (Layer l : data)
                  model.addElement(l);

            instance.setSelectedValue(mapView.getActiveLayer(), true);
            instance.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            instance.addListSelectionListener(new ListSelectionListener(){
                  public void valueChanged(ListSelectionEvent e) {
                        if (instance.getModel().getSize() == 0)
                              return;
                        if (instance.getSelectedIndex() == -1)
                              instance.setSelectedIndex(e.getFirstIndex());
                        mapView.setActiveLayer((Layer)instance.getSelectedValue());
                  }
            });
            Layer.listeners.add(this);

            instance.addMouseListener(new MouseAdapter(){
                  private void openPopup(MouseEvent e) {
                        Point p = listScrollPane.getMousePosition();
                        if (p == null)
                              return; // user is faster than swing with mouse movement
                        int index = instance.locationToIndex(e.getPoint());
                        Layer layer = (Layer)instance.getModel().getElementAt(index);
                        LayerListPopup menu = new LayerListPopup(instance, layer);
                        menu.show(listScrollPane, p.x, p.y-3);
                  }
                  @Override public void mousePressed(MouseEvent e) {
                        if (e.isPopupTrigger())
                              openPopup(e);
                  }
                  @Override public void mouseReleased(MouseEvent e) {
                        if (e.isPopupTrigger())
                              openPopup(e);
                  }
                  @Override public void mouseClicked(MouseEvent e) {
                        if (e.getClickCount() == 2) {
                              int index = instance.locationToIndex(e.getPoint());
                              Layer layer = (Layer)instance.getModel().getElementAt(index);
                              String current = Main.pref.get("marker.show "+layer.name,"show");
                              Main.pref.put("marker.show "+layer.name, current.equalsIgnoreCase("show") ? "hide" : "show");
                              layer.visible = !layer.visible;
                              Main.map.mapView.repaint();
                              instance.repaint();
                        }
                  }
            });


            // Buttons
            JPanel buttonPanel = new JPanel(new GridLayout(1, 5));

            ActionListener upDown = new ActionListener(){
                  public void actionPerformed(ActionEvent e) {
                        Layer l = (Layer)instance.getSelectedValue();
                        int sel = instance.getSelectedIndex();
                        int selDest = e.getActionCommand().equals("up") ? sel-1 : sel+1;
                        mapView.moveLayer(l, selDest);
                        model.set(sel, model.get(selDest));
                        model.set(selDest, l);
                        instance.setSelectedIndex(selDest);
                        updateButtonEnabled();
                        mapView.repaint();
                  }
            };

            upButton.setToolTipText(tr("Move the selected layer one row up."));
            upButton.addActionListener(upDown);
            upButton.setActionCommand("up");
            upButton.putClientProperty("help", "Dialog/LayerList/Up");
            buttonPanel.add(upButton);

            downButton.setToolTipText(tr("Move the selected layer one row down."));
            downButton.addActionListener(upDown);
            downButton.setActionCommand("down");
            downButton.putClientProperty("help", "Dialog/LayerList/Down");
            buttonPanel.add(downButton);

            JButton showHideButton = new JButton(new ShowHideLayerAction(null));
            showHideButton.setText("");
            buttonPanel.add(showHideButton);

            JButton deleteButton = new JButton(deleteAction);
            deleteButton.setText("");
            buttonPanel.add(deleteButton);

            mergeButton.setToolTipText(tr("Merge the layer directly below into the selected layer."));
            mergeButton.addActionListener(new ActionListener(){
                  public void actionPerformed(ActionEvent e) {
                        Layer lTo = (Layer)instance.getSelectedValue();
                        Layer lFrom = (Layer)model.get(instance.getSelectedIndex()+1);
                        lTo.mergeFrom(lFrom);
                        mapView.removeLayer(lFrom);
                        updateButtonEnabled();
                        mapView.repaint();
                  }
            });
            mergeButton.putClientProperty("help", "Dialog/LayerList/Merge");
            buttonPanel.add(mergeButton);

            add(buttonPanel, BorderLayout.SOUTH);

            updateButtonEnabled();
      }


Generated by  Doxygen 1.6.0   Back to index