Changeset 22719 in osm for applications


Ignore:
Timestamp:
2010-08-21T17:46:16+02:00 (14 years ago)
Author:
jttt
Message:

Fix #5356 WMS adjustment button is disabled when there is more than one data layer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSAdjustAction.java

    r22677 r22719  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
    5 import java.awt.Component;
    65import java.awt.Cursor;
    7 import java.awt.GridBagLayout;
    86import java.awt.event.MouseEvent;
    97import java.awt.event.MouseListener;
    108import java.awt.event.MouseMotionListener;
    11 import java.util.List;
    12 
    13 import javax.swing.DefaultComboBoxModel;
    14 import javax.swing.DefaultListCellRenderer;
    15 import javax.swing.Icon;
    16 import javax.swing.JComboBox;
    17 import javax.swing.JLabel;
    18 import javax.swing.JList;
    19 import javax.swing.JOptionPane;
    20 import javax.swing.JPanel;
    219
    2210import org.openstreetmap.josm.Main;
    2311import org.openstreetmap.josm.actions.mapmode.MapMode;
    2412import org.openstreetmap.josm.data.coor.EastNorth;
    25 import org.openstreetmap.josm.gui.ExtendedDialog;
    2613import org.openstreetmap.josm.gui.MapFrame;
    2714import org.openstreetmap.josm.gui.layer.Layer;
    28 import org.openstreetmap.josm.tools.GBC;
    2915import org.openstreetmap.josm.tools.ImageProvider;
    3016
     
    4834        @Override public void enterMode() {
    4935                super.enterMode();
    50                 if (!hasWMSLayersToAdjust()) {
    51                         warnNoWMSLayers();
     36                if (!Main.isDisplayingMapView() || !(Main.map.mapView.getActiveLayer() instanceof WMSLayer)) {
    5237                        return;
    5338                }
    54                 List<WMSLayer> wmsLayers = Main.map.mapView.getLayersOfType(WMSLayer.class);
    55                 if (wmsLayers.size() == 1) {
    56                         adjustingLayer = wmsLayers.get(0);
    57                 } else {
    58                         adjustingLayer = (WMSLayer)askAdjustLayer(Main.map.mapView.getLayersOfType(WMSLayer.class));
    59                 }
    60                 if (adjustingLayer == null)
    61                         return;
     39                adjustingLayer = (WMSLayer) Main.map.mapView.getActiveLayer();
    6240                if (!adjustingLayer.isVisible()) {
    6341                        adjustingLayer.setVisible(true);
     
    126104        // provided there aren't any other means to activate this tool
    127105        @Override public boolean layerIsSupported(Layer l) {
    128                 return (l instanceof WMSLayer) && l.isVisible();
     106                return l instanceof WMSLayer;
    129107        }
    130108
    131         /**
    132          * the list cell renderer used to render layer list entries
    133          *
    134          */
    135         static public class LayerListCellRenderer extends DefaultListCellRenderer {
    136 
    137                 protected boolean isActiveLayer(Layer layer) {
    138                         if (Main.map == null)
    139                                 return false;
    140                         if (Main.map.mapView == null)
    141                                 return false;
    142                         return Main.map.mapView.getActiveLayer() == layer;
    143                 }
    144 
    145                 @Override
    146                 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
    147                                 boolean cellHasFocus) {
    148                         Layer layer = (Layer) value;
    149                         JLabel label = (JLabel) super.getListCellRendererComponent(list, layer.getName(), index, isSelected,
    150                                         cellHasFocus);
    151                         Icon icon = layer.getIcon();
    152                         label.setIcon(icon);
    153                         label.setToolTipText(layer.getToolTipText());
    154                         return label;
    155                 }
    156         }
    157 
    158         /**
    159          * Prompts the user with a list of WMS layers which can be adjusted
    160          *
    161          * @param adjustableLayers the list of adjustable layers
    162          * @return  the selected layer; null, if no layer was selected
    163          */
    164         protected Layer askAdjustLayer(List<? extends Layer> adjustableLayers) {
    165                 JComboBox layerList = new JComboBox();
    166                 layerList.setRenderer(new LayerListCellRenderer());
    167                 layerList.setModel(new DefaultComboBoxModel(adjustableLayers.toArray()));
    168                 layerList.setSelectedIndex(0);
    169 
    170                 JPanel pnl = new JPanel();
    171                 pnl.setLayout(new GridBagLayout());
    172                 pnl.add(new JLabel(tr("Please select the WMS layer to adjust.")), GBC.eol());
    173                 pnl.add(layerList, GBC.eol());
    174 
    175                 ExtendedDialog diag = new ExtendedDialog(
    176                                 Main.parent,
    177                                 tr("Select WMS layer"),
    178                                 new String[] { tr("Start adjusting"),tr("Cancel") }
    179                 );
    180                 diag.setContent(pnl);
    181                 diag.setButtonIcons(new String[] { "mapmode/adjustwms", "cancel" });
    182                 diag.showDialog();
    183                 int decision = diag.getValue();
    184                 if (decision != 1)
    185                         return null;
    186                 Layer adjustLayer = (Layer) layerList.getSelectedItem();
    187                 return adjustLayer;
    188         }
    189 
    190         /**
    191          * Displays a warning message if there are no WMS layers to adjust
    192          *
    193          */
    194         protected void warnNoWMSLayers() {
    195                 JOptionPane.showMessageDialog(
    196                                 Main.parent,
    197                                 tr("There are currently no WMS layer to adjust."),
    198                                 tr("No layers to adjust"),
    199                                 JOptionPane.WARNING_MESSAGE
    200                 );
    201         }
    202 
    203         /**
    204          * Replies true if there is at least one WMS layer
    205          *
    206          * @return true if there is at least one WMS layer
    207          */
    208         protected boolean hasWMSLayersToAdjust() {
    209                 if (Main.map == null) return false;
    210                 if (Main.map.mapView == null) return false;
    211                 return ! Main.map.mapView.getLayersOfType(WMSLayer.class).isEmpty();
    212         }
    213 
    214         @Override
    215         protected void updateEnabledState() {
    216                 setEnabled(hasWMSLayersToAdjust());
    217         }
    218109}
Note: See TracChangeset for help on using the changeset viewer.