source: josm/trunk/src/org/openstreetmap/josm/actions/AbstractMergeAction.java@ 1890

Last change on this file since 1890 was 1890, checked in by Gubaer, 15 years ago

update: rewrite of layer dialog
new: allows multiple selection of layers in the dialog
new: move up, move down, toggle visibility, and delete on multiple layers
new: merge from an arbitrary layer into another layer, not only from the first into the second
new: new action for merging of the currently selected primitives on an arbitrary layer
new: make "active" layer explicit (special icon); activating a layer automatically moves it in the first position
refactoring: public fields 'name' and 'visible' on Layer are @deprecated. Use the setter/getters instead, Layer now emits PropertyChangeEvents if name or visibility are changed.

File size: 3.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Component;
7import java.awt.GridBagLayout;
8import java.util.List;
9
10import javax.swing.DefaultComboBoxModel;
11import javax.swing.DefaultListCellRenderer;
12import javax.swing.Icon;
13import javax.swing.JComboBox;
14import javax.swing.JLabel;
15import javax.swing.JList;
16import javax.swing.JOptionPane;
17import javax.swing.JPanel;
18
19import org.openstreetmap.josm.Main;
20import org.openstreetmap.josm.gui.ExtendedDialog;
21import org.openstreetmap.josm.gui.OptionPaneUtil;
22import org.openstreetmap.josm.gui.layer.Layer;
23import org.openstreetmap.josm.tools.GBC;
24import org.openstreetmap.josm.tools.Shortcut;
25
26public abstract class AbstractMergeAction extends JosmAction {
27
28
29 /**
30 * the list cell renderer used to render layer list entries
31 *
32 */
33 static public class LayerListCellRenderer extends DefaultListCellRenderer {
34
35 protected boolean isActiveLayer(Layer layer) {
36 if (Main.map == null)
37 return false;
38 if (Main.map.mapView == null)
39 return false;
40 return Main.map.mapView.getActiveLayer() == layer;
41 }
42
43 @Override
44 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
45 boolean cellHasFocus) {
46 Layer layer = (Layer) value;
47 JLabel label = (JLabel) super.getListCellRendererComponent(list, layer.getName(), index, isSelected,
48 cellHasFocus);
49 Icon icon = layer.getIcon();
50 label.setIcon(icon);
51 label.setToolTipText(layer.getToolTipText());
52 return label;
53 }
54 }
55
56 public AbstractMergeAction() {
57 super();
58 }
59
60 public AbstractMergeAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean register) {
61 super(name, iconName, tooltip, shortcut, register);
62 }
63
64 protected Layer askTargetLayer(List<Layer> targetLayers) {
65 JComboBox layerList = new JComboBox();
66 layerList.setRenderer(new LayerListCellRenderer());
67 layerList.setModel(new DefaultComboBoxModel(targetLayers.toArray()));
68 layerList.setSelectedIndex(0);
69
70 JPanel pnl = new JPanel();
71 pnl.setLayout(new GridBagLayout());
72 pnl.add(new JLabel(tr("Please select the target layer.")), GBC.eol());
73 pnl.add(layerList, GBC.eol());
74
75 int decision = new ExtendedDialog(Main.parent, tr("Select target layer"), pnl, new String[] { tr("Merge"),
76 tr("Cancel") }, new String[] { "dialogs/mergedown", "cancel" }).getValue();
77 if (decision != 1)
78 return null;
79 Layer targetLayer = (Layer) layerList.getSelectedItem();
80 return targetLayer;
81 }
82
83 protected void warnNoTargetLayersForSourceLayer(Layer sourceLayer) {
84 OptionPaneUtil.showMessageDialog(Main.parent,
85 tr("<html>There are no layers the source layer<br>''{0}''<br>could be merged to.</html>"),
86 tr("No target layers"), JOptionPane.WARNING_MESSAGE);
87 }
88}
Note: See TracBrowser for help on using the repository browser.