Ignore:
Timestamp:
2009-12-29T23:31:57+01:00 (14 years ago)
Author:
bastiK
Message:

fixed #4100 - unable to simply load already referenced images
Added 'jpg' to the list of available formats for 'File' > 'Open...'

Location:
trunk/src/org/openstreetmap/josm/io
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/FileImporter.java

    r2181 r2702  
    66import java.io.File;
    77import java.io.IOException;
     8import java.util.List;
    89
     10import javax.swing.JOptionPane;
     11
     12import org.openstreetmap.josm.Main;
    913import org.openstreetmap.josm.actions.ExtensionFileFilter;
    1014
    11 public abstract class FileImporter {
     15public abstract class FileImporter implements Comparable<FileImporter> {
    1216
    1317    public ExtensionFileFilter filter;
     
    2125    }
    2226
     27    /**
     28     * A batch importer is a file importer that preferes to read multiple files at the same time.
     29     */
     30    public boolean isBatchImporter() {
     31        return false;
     32    }
     33   
     34    /**
     35     * Needs to be implemented if isBatchImporter() returns false.
     36     */
    2337    public void importData(File file) throws IOException, IllegalDataException {
    24         throw new IOException(tr("Could not read ''{0}''.", file.getName()));
     38        throw new IOException(tr("Could not import ''{0}''.", file.getName()));
    2539    }
    2640
     41    /**
     42     * Needs to be implemented if isBatchImporter() returns true.
     43     */
     44    public void importData(List<File> files) throws IOException, IllegalDataException {
     45        throw new IOException(tr("Could not import Files."));
     46    }
     47
     48    /**
     49     * Wrapper to give meaningful output if things go wrong.
     50     */
     51    public void importDataHandleExceptions(File f) {
     52        try {
     53            System.out.println("Open file: " + f.getAbsolutePath() + " (" + f.length() + " bytes)");
     54            importData(f);
     55        } catch (Exception e) {
     56            e.printStackTrace();
     57            JOptionPane.showMessageDialog(
     58                    Main.parent,
     59                    tr("<html>Could not read file ''{0}\''.<br> Error is: <br>{1}</html>", f.getName(), e.getMessage()),
     60                    tr("Error"),
     61                    JOptionPane.ERROR_MESSAGE
     62            );
     63        }
     64    }
     65    public void importDataHandleExceptions(List<File> files) {
     66        try {
     67            System.out.println("Open "+files.size()+" files");
     68            importData(files);
     69        } catch (Exception e) {
     70            e.printStackTrace();
     71            JOptionPane.showMessageDialog(
     72                    Main.parent,
     73                    tr("<html>Could not read files.<br> Error is: <br>{0}</html>", e.getMessage()),
     74                    tr("Error"),
     75                    JOptionPane.ERROR_MESSAGE
     76            );
     77        }
     78    }
     79
     80    /**
     81     * If multiple files (with multiple file formats) are selected,
     82     * they are opened in the order of their priorities.
     83     * Highest priority comes first.
     84     */
     85    public double getPriority() {
     86        return 0;
     87    }
     88
     89    public int compareTo(FileImporter other) {
     90        return (new Double(this.getPriority())).compareTo(other.getPriority());
     91    }
    2792}
Note: See TracChangeset for help on using the changeset viewer.