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

Last change on this file since 9303 was 8443, checked in by Don-vip, 9 years ago

remove extra whitespaces

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