Changeset 22761 in osm for applications
- Timestamp:
- 2010-08-25T07:57:58+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSAdjustAction.java
r22719 r22761 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.Component; 5 6 import java.awt.Cursor; 7 import java.awt.GridBagLayout; 6 8 import java.awt.event.MouseEvent; 7 9 import java.awt.event.MouseListener; 8 10 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; 9 21 10 22 import org.openstreetmap.josm.Main; 11 23 import org.openstreetmap.josm.actions.mapmode.MapMode; 12 24 import org.openstreetmap.josm.data.coor.EastNorth; 25 import org.openstreetmap.josm.gui.ExtendedDialog; 13 26 import org.openstreetmap.josm.gui.MapFrame; 14 27 import org.openstreetmap.josm.gui.layer.Layer; 28 import org.openstreetmap.josm.tools.GBC; 15 29 import org.openstreetmap.josm.tools.ImageProvider; 16 30 … … 34 48 @Override public void enterMode() { 35 49 super.enterMode(); 36 if (!Main.isDisplayingMapView() || !(Main.map.mapView.getActiveLayer() instanceof WMSLayer)) { 50 if (!hasWMSLayersToAdjust()) { 51 warnNoWMSLayers(); 37 52 return; 38 53 } 39 adjustingLayer = (WMSLayer) Main.map.mapView.getActiveLayer(); 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; 40 62 if (!adjustingLayer.isVisible()) { 41 63 adjustingLayer.setVisible(true); … … 101 123 } 102 124 103 // This only makes the buttons look disabled, but since no keyboard shortcut is104 // provided there aren't any other means to activate this tool105 125 @Override public boolean layerIsSupported(Layer l) { 106 return l instanceof WMSLayer; 107 } 108 126 return hasWMSLayersToAdjust(); 127 } 128 129 /** 130 * the list cell renderer used to render layer list entries 131 * 132 */ 133 static public class LayerListCellRenderer extends DefaultListCellRenderer { 134 135 protected boolean isActiveLayer(Layer layer) { 136 if (Main.map == null) 137 return false; 138 if (Main.map.mapView == null) 139 return false; 140 return Main.map.mapView.getActiveLayer() == layer; 141 } 142 143 @Override 144 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, 145 boolean cellHasFocus) { 146 Layer layer = (Layer) value; 147 JLabel label = (JLabel) super.getListCellRendererComponent(list, layer.getName(), index, isSelected, 148 cellHasFocus); 149 Icon icon = layer.getIcon(); 150 label.setIcon(icon); 151 label.setToolTipText(layer.getToolTipText()); 152 return label; 153 } 154 } 155 156 /** 157 * Prompts the user with a list of WMS layers which can be adjusted 158 * 159 * @param adjustableLayers the list of adjustable layers 160 * @return the selected layer; null, if no layer was selected 161 */ 162 protected Layer askAdjustLayer(List<? extends Layer> adjustableLayers) { 163 JComboBox layerList = new JComboBox(); 164 layerList.setRenderer(new LayerListCellRenderer()); 165 layerList.setModel(new DefaultComboBoxModel(adjustableLayers.toArray())); 166 layerList.setSelectedIndex(0); 167 168 JPanel pnl = new JPanel(); 169 pnl.setLayout(new GridBagLayout()); 170 pnl.add(new JLabel(tr("Please select the WMS layer to adjust.")), GBC.eol()); 171 pnl.add(layerList, GBC.eol()); 172 173 ExtendedDialog diag = new ExtendedDialog( 174 Main.parent, 175 tr("Select WMS layer"), 176 new String[] { tr("Start adjusting"),tr("Cancel") } 177 ); 178 diag.setContent(pnl); 179 diag.setButtonIcons(new String[] { "mapmode/adjustwms", "cancel" }); 180 diag.showDialog(); 181 int decision = diag.getValue(); 182 if (decision != 1) 183 return null; 184 Layer adjustLayer = (Layer) layerList.getSelectedItem(); 185 return adjustLayer; 186 } 187 188 /** 189 * Displays a warning message if there are no WMS layers to adjust 190 * 191 */ 192 protected void warnNoWMSLayers() { 193 JOptionPane.showMessageDialog( 194 Main.parent, 195 tr("There are currently no WMS layer to adjust."), 196 tr("No layers to adjust"), 197 JOptionPane.WARNING_MESSAGE 198 ); 199 } 200 201 /** 202 * Replies true if there is at least one WMS layer 203 * 204 * @return true if there is at least one WMS layer 205 */ 206 protected boolean hasWMSLayersToAdjust() { 207 if (Main.map == null) return false; 208 if (Main.map.mapView == null) return false; 209 return ! Main.map.mapView.getLayersOfType(WMSLayer.class).isEmpty(); 210 } 211 212 @Override 213 protected void updateEnabledState() { 214 setEnabled(hasWMSLayersToAdjust()); 215 } 109 216 }
Note:
See TracChangeset
for help on using the changeset viewer.