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

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

fix #7917 - Control the number of items displayed at once in all comboboxes (replaced configurable method with a dynamic method based on screen height and look and feel)

  • 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 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
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
58 protected Layer askTargetLayer(List<Layer> targetLayers) {
59 JosmComboBox layerList = new JosmComboBox(targetLayers.toArray());
60 layerList.setRenderer(new LayerListCellRenderer());
61 layerList.setSelectedIndex(0);
62
63 JPanel pnl = new JPanel(new GridBagLayout());
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,
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.