Changeset 16872 in osm for applications/editors/josm/plugins/wmsplugin/src
- Timestamp:
- 2009-08-05T11:56:29+02:00 (16 years ago)
- Location:
- applications/editors/josm/plugins/wmsplugin/src/wmsplugin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/GeorefImage.java
r16781 r16872 1 1 package wmsplugin; 2 2 3 import java.awt.Color;4 3 import java.awt.Dimension; 5 4 import java.awt.Graphics; -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSAdjustAction.java
r16781 r16872 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 import org.openstreetmap.josm.gui.MapFrame;12 23 import org.openstreetmap.josm.actions.mapmode.MapMode; 13 24 import org.openstreetmap.josm.data.coor.EastNorth; 25 import org.openstreetmap.josm.gui.ExtendedDialog; 26 import org.openstreetmap.josm.gui.MapFrame; 27 import org.openstreetmap.josm.gui.OptionPaneUtil; 28 import org.openstreetmap.josm.gui.layer.Layer; 29 import org.openstreetmap.josm.tools.GBC; 14 30 import org.openstreetmap.josm.tools.ImageProvider; 15 import org.openstreetmap.josm.gui.layer.Layer;16 31 17 32 … … 20 35 21 36 GeorefImage selectedImage; 22 WMSLayer selectedLayer;23 37 boolean mouseDown; 24 38 EastNorth prevEastNorth; 39 private WMSLayer adjustingLayer; 25 40 26 41 public WMSAdjustAction(MapFrame mapFrame) { … … 30 45 } 31 46 47 48 32 49 @Override public void enterMode() { 33 super.enterMode(); 50 super.enterMode(); 51 if (!hasWMSLayersToAdjust()) { 52 warnNoWMSLayers(); 53 return; 54 } 55 List<WMSLayer> wmsLayers = Main.map.mapView.getLayersOfType(WMSLayer.class); 56 if (wmsLayers.size() == 1) { 57 adjustingLayer = wmsLayers.get(0); 58 } else { 59 adjustingLayer = (WMSLayer)askAdjustLayer(Main.map.mapView.getLayersOfType(WMSLayer.class)); 60 } 61 if (adjustingLayer == null) 62 return; 63 if (!adjustingLayer.isVisible()) { 64 adjustingLayer.setVisible(true); 65 } 34 66 Main.map.mapView.addMouseListener(this); 35 67 Main.map.mapView.addMouseMotionListener(this); … … 40 72 Main.map.mapView.removeMouseListener(this); 41 73 Main.map.mapView.removeMouseMotionListener(this); 74 adjustingLayer = null; 42 75 } 43 76 … … 46 79 return; 47 80 48 Layer layer=Main.map.mapView.getActiveLayer(); 49 if (layer.isVisible() && layer instanceof WMSLayer) { 81 if (adjustingLayer.isVisible()) { 50 82 prevEastNorth=Main.map.mapView.getEastNorth(e.getX(),e.getY()); 51 selectedLayer = ((WMSLayer)layer); 52 selectedImage = selectedLayer.findImage(prevEastNorth); 83 selectedImage = adjustingLayer.findImage(prevEastNorth); 53 84 if(selectedImage!=null) { 54 85 Main.map.mapView.setCursor … … 62 93 EastNorth eastNorth= 63 94 Main.map.mapView.getEastNorth(e.getX(),e.getY()); 64 selectedLayer.displace(95 adjustingLayer.displace( 65 96 eastNorth.east()-prevEastNorth.east(), 66 97 eastNorth.north()-prevEastNorth.north() … … 76 107 selectedImage = null; 77 108 prevEastNorth = null; 78 selectedLayer = null;79 109 } 80 110 … … 99 129 return (l instanceof WMSLayer) && l.isVisible(); 100 130 } 131 132 /** 133 * the list cell renderer used to render layer list entries 134 * 135 */ 136 static public class LayerListCellRenderer extends DefaultListCellRenderer { 137 138 protected boolean isActiveLayer(Layer layer) { 139 if (Main.map == null) 140 return false; 141 if (Main.map.mapView == null) 142 return false; 143 return Main.map.mapView.getActiveLayer() == layer; 144 } 145 146 @Override 147 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, 148 boolean cellHasFocus) { 149 Layer layer = (Layer) value; 150 JLabel label = (JLabel) super.getListCellRendererComponent(list, layer.getName(), index, isSelected, 151 cellHasFocus); 152 Icon icon = layer.getIcon(); 153 label.setIcon(icon); 154 label.setToolTipText(layer.getToolTipText()); 155 return label; 156 } 157 } 158 159 /** 160 * Prompts the user with a list of WMS layers which can be adjusted 161 * 162 * @param adjustableLayers the list of adjustable layers 163 * @return the selected layer; null, if no layer was selected 164 */ 165 protected Layer askAdjustLayer(List<? extends Layer> adjustableLayers) { 166 JComboBox layerList = new JComboBox(); 167 layerList.setRenderer(new LayerListCellRenderer()); 168 layerList.setModel(new DefaultComboBoxModel(adjustableLayers.toArray())); 169 layerList.setSelectedIndex(0); 170 171 JPanel pnl = new JPanel(); 172 pnl.setLayout(new GridBagLayout()); 173 pnl.add(new JLabel(tr("Please select the WMS layer to adjust.")), GBC.eol()); 174 pnl.add(layerList, GBC.eol()); 175 176 int decision = new ExtendedDialog(Main.parent, tr("Select WMS layer"), pnl, new String[] { tr("Start adjusting"), 177 tr("Cancel") }, new String[] { "mapmode/adjustwms", "cancel" }).getValue(); 178 if (decision != 1) 179 return null; 180 Layer adjustLayer = (Layer) layerList.getSelectedItem(); 181 return adjustLayer; 182 } 183 184 /** 185 * Displays a warning message if there are no WMS layers to adjust 186 * 187 */ 188 protected void warnNoWMSLayers() { 189 OptionPaneUtil.showMessageDialog( 190 Main.parent, 191 tr("There are currently no WMS layer to adjust."), 192 tr("No layers to adjust"), 193 JOptionPane.WARNING_MESSAGE 194 ); 195 } 196 197 /** 198 * Replies true if there is at least one WMS layer 199 * 200 * @return true if there is at least one WMS layer 201 */ 202 protected boolean hasWMSLayersToAdjust() { 203 if (Main.map == null) return false; 204 if (Main.map.mapView == null) return false; 205 return ! Main.map.mapView.getLayersOfType(WMSLayer.class).isEmpty(); 206 } 207 208 209 210 @Override 211 protected void updateEnabledState() { 212 setEnabled(hasWMSLayersToAdjust()); 213 } 101 214 } -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSGrabber.java
r16781 r16872 14 14 import java.text.DecimalFormat; 15 15 import java.text.DecimalFormatSymbols; 16 import java.text.MessageFormat;17 16 import java.text.NumberFormat; 18 17 import java.util.Locale; … … 27 26 import org.openstreetmap.josm.data.coor.EastNorth; 28 27 import org.openstreetmap.josm.data.coor.LatLon; 29 import org.openstreetmap.josm.data.projection.Epsg4326;30 28 import org.openstreetmap.josm.data.projection.Mercator; 31 29 import org.openstreetmap.josm.gui.MapView;
Note:
See TracChangeset
for help on using the changeset viewer.