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

Last change on this file since 5429 was 5429, checked in by Don-vip, 12 years ago

fix #7917 - Control the number of items displayed at once in all comboboxes (20 by default, configurable with gui.combobox.maximum-row-count)

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