Ignore:
Timestamp:
2011-10-17T01:40:35+02:00 (13 years ago)
Author:
donvip
Message:

JOSM plugin imagery XML bounds version 1.2: allow to open imagery XML files with Ctrl-L

Location:
applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds
Files:
4 added
2 edited
3 moved

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/ImageryXmlBoundsPlugin.java

    r26808 r26896  
    2525import org.openstreetmap.josm.plugins.imageryxmlbounds.actions.ShowBoundsPropertiesAction;
    2626import org.openstreetmap.josm.plugins.imageryxmlbounds.actions.ShowBoundsSelectionAction;
     27import org.openstreetmap.josm.plugins.imageryxmlbounds.actions.downloadtask.DownloadXmlBoundsTask;
     28import org.openstreetmap.josm.plugins.imageryxmlbounds.io.XmlBoundsExporter;
     29import org.openstreetmap.josm.plugins.imageryxmlbounds.io.XmlBoundsImporter;
    2730
    2831/**
    2932 * Main class of Imagery XML bounds plugin.
    3033 * @author Don-vip
    31  * @version 1.1
     34 * @version 1.2
    3235 * History:
     36 * 1.2 17-Oct-2011 Update for #6960 and JOSM 4523 (allow to download imagery XML bounds with Ctrl-L)
    3337 * 1.1 08-Oct-2011 Update for #6934 and JOSM 4506, code refactorisation, removing debug code
    3438 * 1.0 03-Oct-2011 first version
     
    6973                DataSet.addSelectionListener(selectionAction);
    7074                Main.toolbar.register(selectionAction);
     75                // Allow JOSM to download *.imagery.xml files
     76                Main.main.menu.openLocation.addDownloadTaskClass(DownloadXmlBoundsTask.class);
    7177        }
    7278
  • applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/XmlBoundsConstants.java

    r26808 r26896  
    3333         * Plugin version.
    3434         */
    35         public static final String PLUGIN_VERSION = "1.1";
     35        public static final String PLUGIN_VERSION = "1.2";
    3636       
    3737        /**
     
    3939         */
    4040        public static final String XML_NAMESPACE = "http://josm.openstreetmap.de/maps-1.0";
    41        
     41
     42    /**
     43     * XML file location.
     44     */
     45    public static final String XML_LOCATION = "http://josm.openstreetmap.de/maps";
     46
    4247        /**
    4348         * XML Schema
  • applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/io/ValidatingImageryReader.java

    r26892 r26896  
    22 *
    33 */
    4 package org.openstreetmap.josm.plugins.imageryxmlbounds;
     4package org.openstreetmap.josm.plugins.imageryxmlbounds.io;
    55
    66import java.io.IOException;
     
    1313import org.openstreetmap.josm.io.MirroredInputStream;
    1414import org.openstreetmap.josm.io.imagery.ImageryReader;
     15import org.openstreetmap.josm.plugins.imageryxmlbounds.XmlBoundsConstants;
    1516import org.xml.sax.SAXException;
    1617
  • applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/io/XmlBoundsExporter.java

    r26892 r26896  
    1414//    You should have received a copy of the GNU General Public License
    1515//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16 package org.openstreetmap.josm.plugins.imageryxmlbounds;
     16package org.openstreetmap.josm.plugins.imageryxmlbounds.io;
    1717
    1818import java.io.BufferedWriter;
     
    2626import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2727import org.openstreetmap.josm.io.FileExporter;
     28import org.openstreetmap.josm.plugins.imageryxmlbounds.XmlBoundsConstants;
    2829import org.openstreetmap.josm.plugins.imageryxmlbounds.actions.ComputeBoundsAction;
    2930
  • applications/editors/josm/plugins/imagery-xml-bounds/src/org/openstreetmap/josm/plugins/imageryxmlbounds/io/XmlBoundsImporter.java

    r26892 r26896  
    1414//    You should have received a copy of the GNU General Public License
    1515//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16 package org.openstreetmap.josm.plugins.imageryxmlbounds;
     16package org.openstreetmap.josm.plugins.imageryxmlbounds.io;
    1717
    1818import static org.openstreetmap.josm.tools.I18n.tr;
     
    4444import org.openstreetmap.josm.io.IllegalDataException;
    4545import org.openstreetmap.josm.io.imagery.ImageryReader;
     46import org.openstreetmap.josm.plugins.imageryxmlbounds.XmlBoundsConstants;
     47import org.openstreetmap.josm.plugins.imageryxmlbounds.XmlBoundsLayer;
    4648import org.xml.sax.SAXException;
    4749
     
    163165        }
    164166       
     167        public DataSet parseDataSet(final String source) throws IOException, SAXException {
     168            return parseDataSet(source, null);
     169        }
     170
     171        public DataSet parseDataSet(final File file) throws IOException, SAXException {
     172        return parseDataSet(null, file);
     173    }
     174       
     175        protected DataSet parseDataSet(final String source, final File file) throws IOException, SAXException {
     176        ImageryReader reader = null;
     177       
     178        try {
     179            reader = new ValidatingImageryReader(source != null ? source : file.getAbsolutePath());
     180        } catch (SAXException e)  {
     181            if (JOptionPane.showConfirmDialog(
     182                    Main.parent,
     183                    tr("Validating error in file {0}:\n{1}\nDo you want to continue without validating the file ?",
     184                            source != null ? source : file.getPath(), e.getLocalizedMessage()),
     185                    tr("Open Imagery XML file"),
     186                    JOptionPane.YES_NO_CANCEL_OPTION) != JOptionPane.YES_OPTION) {
     187                return null;
     188            }
     189
     190            reader = new ImageryReader(source != null ? source : file.getAbsolutePath());
     191        }
     192       
     193        return convertImageryEntries(reader.parse());
     194        }
     195       
     196    protected void importData(final String source, final String layerName, final File file, ProgressMonitor progressMonitor)
     197            throws IOException, IllegalDataException {
     198        try {
     199            final DataSet dataSet = parseDataSet(source, file);
     200            final XmlBoundsLayer layer = new XmlBoundsLayer(dataSet, source != null ? layerName : file.getName(), file);
     201            Runnable uiStuff = new Runnable() {
     202                @Override
     203                public void run() {
     204                    if (dataSet.allPrimitives().isEmpty()) {
     205                        JOptionPane.showMessageDialog(
     206                                Main.parent, tr("No data found in file {0}.", source != null ? source : file.getPath()),
     207                                tr("Open Imagery XML file"), JOptionPane.INFORMATION_MESSAGE);
     208                    }
     209                    Main.main.addLayer(layer);
     210                    layer.onPostLoadFromFile();
     211                }
     212            };
     213            if (SwingUtilities.isEventDispatchThread()) {
     214                uiStuff.run();
     215            } else {
     216                SwingUtilities.invokeLater(uiStuff);
     217            }
     218        } catch (SAXException e) {
     219            e.printStackTrace();
     220        }
     221    }
     222       
    165223        /* (non-Javadoc)
    166224         * @see org.openstreetmap.josm.io.FileImporter#importData(java.io.File, org.openstreetmap.josm.gui.progress.ProgressMonitor)
     
    169227        public void importData(final File file, ProgressMonitor progressMonitor)
    170228                        throws IOException, IllegalDataException {
    171                 try {
    172                         ImageryReader reader = null;
    173                        
    174                         try {
    175                                 reader = new ValidatingImageryReader(file.getAbsolutePath());
    176                         } catch (SAXException e)  {
    177                 if (JOptionPane.showConfirmDialog(
    178                         Main.parent,
    179                         tr("Validating error in file {0}:\n{1}\nDo you want to continue without validating the file ?", file.getPath(), e.getLocalizedMessage()),
    180                         tr("Open Imagery XML file"),
    181                         JOptionPane.YES_NO_CANCEL_OPTION) != JOptionPane.YES_OPTION) {
    182                         return;
    183                 }
    184 
    185                                 reader = new ImageryReader(file.getAbsolutePath());
    186                         }
    187                        
    188                         final DataSet dataSet = convertImageryEntries(reader.parse());
    189                                
    190                 final XmlBoundsLayer layer = new XmlBoundsLayer(dataSet, file.getName(), file);
    191                 Runnable uiStuff = new Runnable() {
    192                     @Override
    193                     public void run() {
    194                         if (dataSet.allPrimitives().isEmpty()) {
    195                             JOptionPane.showMessageDialog(
    196                                     Main.parent,
    197                                     tr("No data found in file {0}.", file.getPath()),
    198                                     tr("Open Imagery XML file"),
    199                                     JOptionPane.INFORMATION_MESSAGE);
    200                         }
    201                         Main.main.addLayer(layer);
    202                         layer.onPostLoadFromFile();
    203                     }
    204                 };
    205                 if (SwingUtilities.isEventDispatchThread()) {
    206                     uiStuff.run();
    207                 } else {
    208                     SwingUtilities.invokeLater(uiStuff);
    209                 }
    210                 } catch (SAXException e) {
    211                         e.printStackTrace();
    212                 }
    213         }
     229                importData(null, null, file, progressMonitor);
     230        }
     231       
     232        public void importData(final String source, final String layerName, ProgressMonitor progressMonitor)
     233                throws IOException, IllegalDataException {
     234            importData(source, layerName, null, progressMonitor);
     235    }
    214236
    215237        /* (non-Javadoc)
Note: See TracChangeset for help on using the changeset viewer.