Ignore:
Timestamp:
2013-07-31T19:55:26+02:00 (11 years ago)
Author:
akks
Message:

[josm/ImageWayPoint] move opening to File/Open

Location:
applications/editors/josm/plugins/imagewaypoint
Files:
2 added
2 edited

Legend:

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

    r29435 r29799  
    3030<project name="ImageWayPoint" default="dist" basedir=".">
    3131    <!-- enter the SVN commit message -->
    32     <property name="commit.message" value="Updated the constructor signature of the plugin main class"/>
     32    <property name="commit.message" value="[josm/ImageWayPoint] move opening to File/Open"/>
    3333    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    3434    <property name="plugin.main.version" value="4980"/>
    35     <property name="josm" location="../../core/dist/josm-custom.jar"/>
    36     <property name="plugin.dist.dir" value="../../dist"/>
    37     <property name="plugin.build.dir" value="build"/>
    38     <property name="plugin.jar" value="${plugin.dist.dir}/${ant.project.name}.jar"/>
    39     <property name="ant.build.javac.target" value="1.5"/>
    40     <target name="init">
    41         <mkdir dir="${plugin.build.dir}"/>
    42     </target>
    43     <target name="compile" depends="init">
    44         <echo message="creating ${plugin.jar}"/>
    45         <javac srcdir="src" classpath="${josm}" debug="true" destdir="${plugin.build.dir}">
    46             <compilerarg value="-Xlint:deprecation"/>
    47             <compilerarg value="-Xlint:unchecked"/>
    48         </javac>
    49     </target>
    50     <target name="dist" depends="compile,revision">
    51         <copy todir="${plugin.build.dir}/images">
    52             <fileset dir="images"/>
    53         </copy>
    54         <copy todir="${plugin.build.dir}/data">
    55             <fileset dir="data"/>
    56         </copy>
    57         <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}">
    58             <manifest>
    59                 <attribute name="Author" value="Flint"/>
    60                 <attribute name="Plugin-Class" value="org.insignificant.josm.plugins.imagewaypoint.ImageWayPointPlugin"/>
    61                 <attribute name="Plugin-Date" value="${version.entry.commit.date}"/>
    62                 <attribute name="Plugin-Description" value="Another plugin to match images to the waypoints in a GPX file. A match is made when the ''name'', ''cmt'' or ''desc'' attribute of a waypoint tag matches the filename of an image."/>
    63                 <attribute name="Plugin-Early" value="false"/>
    64                 <attribute name="Plugin-Icon" value="images/dialogs/imagewaypoint.png"/>
    65                 <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/>
    66                 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
    67             </manifest>
    68         </jar>
    69     </target>
    70     <target name="revision">
    71         <exec append="false" output="REVISION" executable="svn" failifexecutionfails="false">
    72             <env key="LANG" value="C"/>
    73             <arg value="info"/>
    74             <arg value="--xml"/>
    75             <arg value="."/>
    76         </exec>
    77         <xmlproperty file="REVISION" prefix="version" keepRoot="false" collapseAttributes="true"/>
    78         <delete file="REVISION"/>
    79     </target>
    80     <target name="clean">
    81         <delete dir="${plugin.build.dir}"/>
    82         <delete file="${plugin.jar}"/>
    83     </target>
    84     <target name="install" depends="dist">
    85         <property environment="env"/>
    86         <condition property="josm.plugins.dir" value="${env.APPDATA}/JOSM/plugins" else="${user.home}/.josm/plugins">
    87             <and>
    88                 <os family="windows"/>
    89             </and>
    90         </condition>
    91         <copy file="${plugin.jar}" todir="${josm.plugins.dir}"/>
    92     </target>
    93     <!--
    94     ************************** Publishing the plugin ***********************************
     35   
     36    <!-- Configure these properties (replace "..." accordingly).
     37         See http://josm.openstreetmap.de/wiki/DevelopersGuide/DevelopingPlugins
    9538    -->
    96     <!--
    97         ** extracts the JOSM release for the JOSM version in ../core and saves it in the
    98         ** property ${coreversion.info.entry.revision}
    99         **
    100         -->
    101     <target name="core-info">
    102         <exec append="false" output="core.info.xml" executable="svn" failifexecutionfails="false">
    103             <env key="LANG" value="C"/>
    104             <arg value="info"/>
    105             <arg value="--xml"/>
    106             <arg value="../../core"/>
    107         </exec>
    108         <xmlproperty file="core.info.xml" prefix="coreversion" keepRoot="true" collapseAttributes="true"/>
    109         <echo>Building against core revision ${coreversion.info.entry.revision}.</echo>
    110         <echo>Plugin-Mainversion is set to ${plugin.main.version}.</echo>
    111         <delete file="core.info.xml"/>
    112     </target>
    113     <!--
    114         ** commits the source tree for this plugin
    115         -->
    116     <target name="commit-current">
    117         <echo>Commiting the plugin source with message '${commit.message}' ...</echo>
    118         <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
    119             <env key="LANG" value="C"/>
    120             <arg value="commit"/>
    121             <arg value="-m '${commit.message}'"/>
    122             <arg value="."/>
    123         </exec>
    124     </target>
    125     <!--
    126         ** updates (svn up) the source tree for this plugin
    127         -->
    128     <target name="update-current">
    129         <echo>Updating plugin source ...</echo>
    130         <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
    131             <env key="LANG" value="C"/>
    132             <arg value="up"/>
    133             <arg value="."/>
    134         </exec>
    135         <echo>Updating ${plugin.jar} ...</echo>
    136         <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
    137             <env key="LANG" value="C"/>
    138             <arg value="up"/>
    139             <arg value="../dist/${plugin.jar}"/>
    140         </exec>
    141     </target>
    142     <!--
    143         ** commits the plugin.jar
    144         -->
    145     <target name="commit-dist">
    146         <echo>
    147     ***** Properties of published ${plugin.jar} *****
    148     Commit message    : '${commit.message}'
    149     Plugin-Mainversion: ${plugin.main.version}
    150     JOSM build version: ${coreversion.info.entry.revision}
    151     Plugin-Version    : ${version.entry.commit.revision}
    152     ***** / Properties of published ${plugin.jar} *****
     39    <property name="plugin.author" value="Flint"/>
     40    <property name="plugin.class" value="org.insignificant.josm.plugins.imagewaypoint.ImageWayPointPlugin"/>
     41    <property name="plugin.description" value="Another plugin to match images to the waypoints in a GPX file. A match is made when the ''name'', ''cmt'' or ''desc'' attribute of a waypoint tag matches the filename of an image."/>
     42    <property name="plugin.icon" value="images/dialogs/imagewaypoint.png"/>
     43    <property name="plugin.link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/ImageWayPoint"/>
    15344
    154     Now commiting ${plugin.jar} ...
    155     </echo>
    156         <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false">
    157             <env key="LANG" value="C"/>
    158             <arg value="-m '${commit.message}'"/>
    159             <arg value="commit"/>
    160             <arg value="${plugin.jar}"/>
    161         </exec>
    162     </target>
    163     <!-- ** make sure svn is present as a command line tool ** -->
    164     <target name="ensure-svn-present">
    165         <exec append="true" output="svn.log" executable="svn" failifexecutionfails="false" failonerror="false" resultproperty="svn.exit.code">
    166             <env key="LANG" value="C"/>
    167             <arg value="--version"/>
    168         </exec>
    169         <fail message="Fatal: command 'svn --version' failed. Please make sure svn is installed on your system.">
    170             <!-- return code not set at all? Most likely svn isn't installed -->
    171             <condition>
    172                 <not>
    173                     <isset property="svn.exit.code"/>
    174                 </not>
    175             </condition>
    176         </fail>
    177         <fail message="Fatal: command 'svn --version' failed. Please make sure a working copy of svn is installed on your system.">
    178             <!-- error code from SVN? Most likely svn is not what we are looking on this system -->
    179             <condition>
    180                 <isfailure code="${svn.exit.code}"/>
    181             </condition>
    182         </fail>
    183     </target>
    184     <target name="publish" depends="ensure-svn-present,core-info,commit-current,update-current,clean,dist,commit-dist">
    185     </target>
     45    <!-- ** include targets that all plugins have in common ** -->
     46    <import file="../build-common.xml"/>
    18647</project>
  • applications/editors/josm/plugins/imagewaypoint/src/org/insignificant/josm/plugins/imagewaypoint/ImageWayPointPlugin.java

    r23191 r29799  
    55import java.awt.event.ActionEvent;
    66import java.io.File;
     7import java.io.IOException;
    78import java.util.ArrayList;
    89import java.util.Collection;
     
    1415
    1516import org.openstreetmap.josm.Main;
     17import org.openstreetmap.josm.actions.ExtensionFileFilter;
    1618import org.openstreetmap.josm.actions.JosmAction;
    1719import org.openstreetmap.josm.gui.MainMenu;
    1820import org.openstreetmap.josm.gui.MapFrame;
    1921import org.openstreetmap.josm.gui.layer.Layer;
     22import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     23import org.openstreetmap.josm.gui.util.GuiHelper;
     24import org.openstreetmap.josm.io.FileImporter;
     25import org.openstreetmap.josm.io.IllegalDataException;
    2026import org.openstreetmap.josm.plugins.PluginInformation;
    2127
     
    3743    }
    3844
    39     private static final class LoadImagesAction extends JosmAction {
    40         private static final long serialVersionUID = 4480306223276347301L;
     45    private final class ImageWaypointImporter extends FileImporter {
    4146
    42         private final ImageWayPointPlugin plugin;
    43 
    44         public LoadImagesAction(final ImageWayPointPlugin plugin) {
    45             super(tr("Open images with ImageWayPoint"),
    46             "imagewaypoint-open",
    47             tr("Load set of images as a new layer."),
    48             null,
    49             false);
    50 
    51             this.plugin = plugin;
     47        public ImageWaypointImporter() {
     48            super(new ExtensionFileFilter("jpg,jpeg,png,gif", "jpg", "Image files [by ImageWayPoint plugin] (*.jpg, *.jpeg, *.png, *.gif)"));
    5249        }
    5350
    54         public final void actionPerformed(final ActionEvent actionEvent) {
    55             final JFileChooser fileChooser = new JFileChooser(Main.pref.get("tagimages.lastdirectory"));
    56             fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    57             fileChooser.setMultiSelectionEnabled(true);
    58             fileChooser.setAcceptAllFileFilterUsed(false);
    59             fileChooser.setFileFilter(new ImageFileFilter());
     51        @Override
     52        public boolean isBatchImporter() {
     53            return true;
     54        }
    6055
    61             fileChooser.showOpenDialog(Main.parent);
     56        @Override
     57        public double getPriority() {
     58            return -3;
     59        }
    6260
    63             final File[] selectedFiles = fileChooser.getSelectedFiles();
    64             if (null != selectedFiles && 0 != selectedFiles.length) {
    65                 Main.pref.put("tagimages.lastdirectory",
    66                     fileChooser.getCurrentDirectory().getPath());
    67 
     61        @Override
     62        public void importData(List<File> files, ProgressMonitor progressMonitor) throws IOException, IllegalDataException {
     63            if (null != files && !files.isEmpty()) {
     64           
    6865                // recursively find all files
    6966                final List<File> allFiles = new ArrayList<File>();
    70                 this.plugin.addFiles(allFiles, selectedFiles);
     67                addFiles(allFiles, files.toArray(new File[0]));
    7168
    7269                // add files to ImageEntries
     
    8683                }
    8784                if (!foundImageWayPointLayer) {
    88                     new ImageWayPointLayer();
     85                    GuiHelper.runInEDT(new Runnable() {
     86                        @Override
     87                        public void run() {
     88                            new ImageWayPointLayer();
     89                        }
     90                    });
    8991                }
    9092            }
     
    9799    public ImageWayPointPlugin(PluginInformation info) {
    98100        super(info);
    99 
    100         MainMenu menu = Main.main.menu;
    101         menu.add(menu.fileMenu, new LoadImagesAction(this));
     101        ExtensionFileFilter.importers.add(new ImageWaypointImporter());
    102102    }
    103103
Note: See TracChangeset for help on using the changeset viewer.