Ignore:
Timestamp:
2009-08-05T11:56:29+02:00 (16 years ago)
Author:
guggis
Message:

fixing

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  
    11package wmsplugin;
    22
    3 import java.awt.Color;
    43import java.awt.Dimension;
    54import java.awt.Graphics;
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSAdjustAction.java

    r16781 r16872  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
     5import java.awt.Component;
    56import java.awt.Cursor;
     7import java.awt.GridBagLayout;
    68import java.awt.event.MouseEvent;
    79import java.awt.event.MouseListener;
    810import java.awt.event.MouseMotionListener;
     11import java.util.List;
     12
     13import javax.swing.DefaultComboBoxModel;
     14import javax.swing.DefaultListCellRenderer;
     15import javax.swing.Icon;
     16import javax.swing.JComboBox;
     17import javax.swing.JLabel;
     18import javax.swing.JList;
     19import javax.swing.JOptionPane;
     20import javax.swing.JPanel;
    921
    1022import org.openstreetmap.josm.Main;
    11 import org.openstreetmap.josm.gui.MapFrame;
    1223import org.openstreetmap.josm.actions.mapmode.MapMode;
    1324import org.openstreetmap.josm.data.coor.EastNorth;
     25import org.openstreetmap.josm.gui.ExtendedDialog;
     26import org.openstreetmap.josm.gui.MapFrame;
     27import org.openstreetmap.josm.gui.OptionPaneUtil;
     28import org.openstreetmap.josm.gui.layer.Layer;
     29import org.openstreetmap.josm.tools.GBC;
    1430import org.openstreetmap.josm.tools.ImageProvider;
    15 import org.openstreetmap.josm.gui.layer.Layer;
    1631
    1732
     
    2035
    2136    GeorefImage selectedImage;
    22     WMSLayer selectedLayer;
    2337    boolean mouseDown;
    2438    EastNorth prevEastNorth;
     39    private WMSLayer adjustingLayer;
    2540
    2641    public WMSAdjustAction(MapFrame mapFrame) {
     
    3045    }
    3146
     47   
     48   
    3249    @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        }
    3466        Main.map.mapView.addMouseListener(this);
    3567        Main.map.mapView.addMouseMotionListener(this);
     
    4072        Main.map.mapView.removeMouseListener(this);
    4173        Main.map.mapView.removeMouseMotionListener(this);
     74        adjustingLayer = null;
    4275    }
    4376
     
    4679            return;
    4780
    48         Layer layer=Main.map.mapView.getActiveLayer();
    49         if (layer.isVisible() && layer instanceof WMSLayer) {
     81        if (adjustingLayer.isVisible()) {
    5082            prevEastNorth=Main.map.mapView.getEastNorth(e.getX(),e.getY());
    51             selectedLayer = ((WMSLayer)layer);
    52             selectedImage = selectedLayer.findImage(prevEastNorth);
     83            selectedImage = adjustingLayer.findImage(prevEastNorth);
    5384            if(selectedImage!=null) {
    5485                Main.map.mapView.setCursor
     
    6293            EastNorth eastNorth=
    6394                    Main.map.mapView.getEastNorth(e.getX(),e.getY());
    64             selectedLayer.displace(
     95            adjustingLayer.displace(
    6596                eastNorth.east()-prevEastNorth.east(),
    6697                eastNorth.north()-prevEastNorth.north()
     
    76107        selectedImage = null;
    77108        prevEastNorth = null;
    78         selectedLayer = null;
    79109    }
    80110   
     
    99129        return (l instanceof WMSLayer) && l.isVisible();
    100130    }
     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        }   
    101214}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSGrabber.java

    r16781 r16872  
    1414import java.text.DecimalFormat;
    1515import java.text.DecimalFormatSymbols;
    16 import java.text.MessageFormat;
    1716import java.text.NumberFormat;
    1817import java.util.Locale;
     
    2726import org.openstreetmap.josm.data.coor.EastNorth;
    2827import org.openstreetmap.josm.data.coor.LatLon;
    29 import org.openstreetmap.josm.data.projection.Epsg4326;
    3028import org.openstreetmap.josm.data.projection.Mercator;
    3129import org.openstreetmap.josm.gui.MapView;
Note: See TracChangeset for help on using the changeset viewer.