Changeset 24308 in osm for applications/editors/josm


Ignore:
Timestamp:
2010-11-18T23:30:20+01:00 (14 years ago)
Author:
ocroquette
Message:

PicLayer: Get supported file formats from ImageIO instead of using hard coded values (adds GIF support for free)

Location:
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/NewLayerFromFileAction.java

    r24300 r24308  
    2727import java.io.IOException;
    2828
     29import javax.imageio.ImageIO;
    2930import javax.swing.JFileChooser;
    3031import javax.swing.JOptionPane;
     
    5051        @Override
    5152        public boolean accept(File f) {
     53            if ( f.isDirectory() )
     54                return true;
    5255
    53             String ext3 = ( f.getName().length() > 4 ) ?  f.getName().substring( f.getName().length() - 4 ).toLowerCase() : "";
    54             String ext4 = ( f.getName().length() > 5 ) ?  f.getName().substring( f.getName().length() - 5 ).toLowerCase() : "";
     56            String fileExtension = f.getName().substring(f.getName().lastIndexOf('.')+1);
     57            String[] supportedExtensions = ImageIO.getReaderFormatNames();
    5558
    56             // TODO: check what is supported by Java :)
    57             return ( f.isDirectory()
    58                 ||  ext3.equals( ".jpg" )
    59                 ||  ext4.equals( ".jpeg" )
    60                 ||  ext3.equals( ".png" )
    61                 );
     59            // Unfortunately, getReaderFormatNames does not always return ALL extensions in
     60            // both lower and upper case, so we can not do a search in the array
     61            for (String e: supportedExtensions)
     62                if ( e.toLowerCase().equals(fileExtension) ) {
     63                    return true;
     64                }
     65                   
     66            return false;
    6267        }
    6368
     
    6570        @Override
    6671        public String getDescription() {
    67             return tr("Image files");
     72            return tr("Supported image files");
    6873        }
    6974
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerAbstract.java

    r24300 r24308  
    129129        Image image = createImage();
    130130        if ( image == null ) {
    131             throw new IOException(tr("Image not created properly."));
     131            throw new IOException(tr("PicLayer failed to load or import the image."));
    132132        }
    133133        // Convert to Buffered Image - not sure if this is the right way...
Note: See TracChangeset for help on using the changeset viewer.