Changeset 16872 in osm for applications/editors/josm


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

fixing

Location:
applications/editors/josm/plugins/wmsplugin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/build.xml

    r16860 r16872  
     1<!--
     2** This is a template build file for a JOSM  plugin.
     3**
     4** Maintaining versions
     5** ====================
     6** see README.template
     7**
     8** Usage
     9** =====
     10** To build it run
     11**
     12**    > ant  dist
     13**
     14** To install the generated plugin locally (in your default plugin directory) run
     15**
     16**    > ant  install
     17**
     18** To build against the core in ../../core, create a correct manifest and deploy to
     19** SVN, run
     20**    - set the property commit.message
     21**    - set the property josm.reference.release to lowest JOSM release number this
     22**      plugin build is compatible with
     23**    > ant  deploy
     24**
     25**
     26-->
    127<project name="wmsplugin" default="dist" basedir=".">
    228    <property name="josm"                   location="../../core/dist/josm-custom.jar"/>
     
    531    <property name="plugin.jar"             value="${plugin.dist.dir}/${ant.project.name}.jar"/>
    632    <property name="ant.build.javac.target" value="1.5"/>
     33        <property name="commit.message"         value="fixing JOSM issue #3186" />
     34        <property name="josm.reference.release" value="1914" />
     35       
    736    <target name="init">
    837        <mkdir dir="${plugin.build.dir}"/>
     
    1645    </target>
    1746    <target name="dist" depends="compile,revision">
     47        <echo message="building ${plugin.jar} with version ${version.entry.commit.revision} for JOSM version ${josm.reference.release} "/>
    1848        <copy todir="${plugin.build.dir}/images">
    1949            <fileset dir="images"/>
     
    2656                <attribute name="Plugin-Description" value="Display georeferenced images as background in JOSM (WMS servers, Yahoo, ...)."/>
    2757                <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/WMSPlugin"/>
    28                 <attribute name="Plugin-Mainversion" value="1908"/>
     58                <attribute name="Plugin-Mainversion" value="${josm.reference.release}"/>
    2959                <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
    3060                <attribute name="de_Plugin-Link" value="http://wiki.openstreetmap.org/wiki/DE:JOSM/Plugins/WMSPlugin"/>
     
    5585        <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/>
    5686    </target>
     87       
     88        <target name="core-info">
     89                <exec append="false" output="core.info.xml" executable="svn" failifexecutionfails="false">
     90                            <env key="LANG" value="C"/>
     91                            <arg value="info"/>
     92                            <arg value="--xml"/>
     93                            <arg value="../../core"/>
     94                </exec>
     95                <xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true"/>
     96                        <echo>Building against core revision ${coreversion.info.entry.revision} ...</echo>
     97                        <delete file="core.info.xml" />
     98                </target>
     99
     100               
     101                <target name="commit-current">
     102                        <echo>Commiting the plugin source ...</echo>
     103                    <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
     104                                    <env key="LANG" value="C"/>
     105                                    <arg value="commit"/>
     106                                    <arg value="-m &quot;${commit.message}&quot;"/>
     107                                    <arg value="."/>
     108                    </exec>         
     109                </target>
     110
     111               
     112                <target name="update-current">
     113                        <echo>Updating basedir ...</echo>
     114                    <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
     115                                    <env key="LANG" value="C"/>
     116                                    <arg value="up"/>
     117                                    <arg value="."/>
     118                    </exec>         
     119                        <echo>Updating ${plugin.jar} ...</echo>
     120                    <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
     121                                    <env key="LANG" value="C"/>
     122                                    <arg value="up"/>
     123                                    <arg value="${plugin.jar}"/>
     124                    </exec>         
     125                </target>
     126               
     127                <target name="commit-dist">
     128                                <echo>Commiting ${plugin.jar} ...</echo>
     129                            <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
     130                                            <env key="LANG" value="C"/>
     131                                            <arg value="commit"/>
     132                                                <arg value="-m &quot;${commit.message}&quot;"/>
     133                                            <arg value="${plugin.jar}"/>
     134                            </exec>         
     135                </target>
     136               
     137                <target name="deploy" depends="core-info,commit-current,update-current,clean,dist,commit-dist">
     138                </target>
    57139</project>
  • 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.