[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 | */
|
---|
[6889] | 30 | public static class LayerListCellRenderer extends DefaultListCellRenderer {
|
---|
[2512] | 31 |
|
---|
| 32 | @Override
|
---|
[7001] | 33 | public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
---|
[2512] | 34 | Layer layer = (Layer) value;
|
---|
[7001] | 35 | JLabel label = (JLabel) super.getListCellRendererComponent(list, layer.getName(), index, isSelected, cellHasFocus);
|
---|
[2512] | 36 | Icon icon = layer.getIcon();
|
---|
| 37 | label.setIcon(icon);
|
---|
| 38 | label.setToolTipText(layer.getToolTipText());
|
---|
| 39 | return label;
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[6792] | 43 | /**
|
---|
| 44 | * Constructs a new {@code AbstractMergeAction}.
|
---|
| 45 | */
|
---|
[2512] | 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 |
|
---|
[4851] | 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 |
|
---|
[2512] | 59 | protected Layer askTargetLayer(List<Layer> targetLayers) {
|
---|
[7017] | 60 | JosmComboBox<Layer> layerList = new JosmComboBox<>(targetLayers.toArray(new Layer[0]));
|
---|
[2512] | 61 | layerList.setRenderer(new LayerListCellRenderer());
|
---|
| 62 | layerList.setSelectedIndex(0);
|
---|
| 63 |
|
---|
[5450] | 64 | JPanel pnl = new JPanel(new GridBagLayout());
|
---|
[2512] | 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"),
|
---|
[8443] | 70 | new String[] {tr("Merge"), tr("Cancel")});
|
---|
| 71 | ed.setButtonIcons(new String[] {"dialogs/mergedown", "cancel"});
|
---|
[2512] | 72 | ed.setContent(pnl);
|
---|
| 73 | ed.showDialog();
|
---|
| 74 | if (ed.getValue() != 1)
|
---|
| 75 | return null;
|
---|
| 76 |
|
---|
[6792] | 77 | return (Layer) layerList.getSelectedItem();
|
---|
[2512] | 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 | }
|
---|