Changeset 22719 in osm for applications/editors
- Timestamp:
- 2010-08-21T17:46:16+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSAdjustAction.java
r22677 r22719 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.Component;6 5 import java.awt.Cursor; 7 import java.awt.GridBagLayout;8 6 import java.awt.event.MouseEvent; 9 7 import java.awt.event.MouseListener; 10 8 import 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;21 9 22 10 import org.openstreetmap.josm.Main; 23 11 import org.openstreetmap.josm.actions.mapmode.MapMode; 24 12 import org.openstreetmap.josm.data.coor.EastNorth; 25 import org.openstreetmap.josm.gui.ExtendedDialog;26 13 import org.openstreetmap.josm.gui.MapFrame; 27 14 import org.openstreetmap.josm.gui.layer.Layer; 28 import org.openstreetmap.josm.tools.GBC;29 15 import org.openstreetmap.josm.tools.ImageProvider; 30 16 … … 48 34 @Override public void enterMode() { 49 35 super.enterMode(); 50 if (!hasWMSLayersToAdjust()) { 51 warnNoWMSLayers(); 36 if (!Main.isDisplayingMapView() || !(Main.map.mapView.getActiveLayer() instanceof WMSLayer)) { 52 37 return; 53 38 } 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(); 62 40 if (!adjustingLayer.isVisible()) { 63 41 adjustingLayer.setVisible(true); … … 126 104 // provided there aren't any other means to activate this tool 127 105 @Override public boolean layerIsSupported(Layer l) { 128 return (l instanceof WMSLayer) && l.isVisible();106 return l instanceof WMSLayer; 129 107 } 130 108 131 /**132 * the list cell renderer used to render layer list entries133 *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 @Override146 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 adjusted160 *161 * @param adjustableLayers the list of adjustable layers162 * @return the selected layer; null, if no layer was selected163 */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 adjust192 *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_MESSAGE200 );201 }202 203 /**204 * Replies true if there is at least one WMS layer205 *206 * @return true if there is at least one WMS layer207 */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 @Override215 protected void updateEnabledState() {216 setEnabled(hasWMSLayersToAdjust());217 }218 109 }
Note:
See TracChangeset
for help on using the changeset viewer.