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

Last change on this file since 2032 was 2032, checked in by stoecker, 15 years ago

fix #3377 - patch by xeen - removed deprecated calls

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.layer.Layer;
22import org.openstreetmap.josm.tools.GBC;
23import org.openstreetmap.josm.tools.Shortcut;
24
25public abstract class AbstractMergeAction extends JosmAction {
26
27
28 /**
29 * the list cell renderer used to render layer list entries
30 *
31 */
32 static public class LayerListCellRenderer extends DefaultListCellRenderer {
33
34 protected boolean isActiveLayer(Layer layer) {
35 if (Main.map == null)
36 return false;
37 if (Main.map.mapView == null)
38 return false;
39 return Main.map.mapView.getActiveLayer() == layer;
40 }
41
42 @Override
43 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
44 boolean cellHasFocus) {
45 Layer layer = (Layer) value;
46 JLabel label = (JLabel) super.getListCellRendererComponent(list, layer.getName(), index, isSelected,
47 cellHasFocus);
48 Icon icon = layer.getIcon();
49 label.setIcon(icon);
50 label.setToolTipText(layer.getToolTipText());
51 return label;
52 }
53 }
54
55 public AbstractMergeAction() {
56 super();
57 }
58
59 public AbstractMergeAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean register) {
60 super(name, iconName, tooltip, shortcut, register);
61 }
62
63 protected Layer askTargetLayer(List<Layer> targetLayers) {
64 JComboBox layerList = new JComboBox();
65 layerList.setRenderer(new LayerListCellRenderer());
66 layerList.setModel(new DefaultComboBoxModel(targetLayers.toArray()));
67 layerList.setSelectedIndex(0);
68
69 JPanel pnl = new JPanel();
70 pnl.setLayout(new GridBagLayout());
71 pnl.add(new JLabel(tr("Please select the target layer.")), GBC.eol());
72 pnl.add(layerList, GBC.eol());
73
74 ExtendedDialog ed = new ExtendedDialog(Main.parent,
75 tr("Select target layer"),
76 new String[] { tr("Merge"), tr("Cancel") });
77 ed.setButtonIcons(new String[] { "dialogs/mergedown", "cancel" });
78 ed.setContent(pnl);
79 ed.showDialog();
80 if (ed.getValue() != 1)
81 return null;
82
83 Layer targetLayer = (Layer) layerList.getSelectedItem();
84 return targetLayer;
85 }
86
87 protected void warnNoTargetLayersForSourceLayer(Layer sourceLayer) {
88 JOptionPane.showMessageDialog(Main.parent,
89 tr("<html>There are no layers the source layer<br>''{0}''<br>could be merged to.</html>"),
90 tr("No target layers"), JOptionPane.WARNING_MESSAGE);
91 }
92}
Note: See TracBrowser for help on using the repository browser.