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