Changeset 18109 in osm for applications/editors/josm


Ignore:
Timestamp:
2009-10-13T12:22:54+02:00 (15 years ago)
Author:
pieren
Message:

add a file filter in selector

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionSaveRasterAs.java

    r17089 r18109  
    55import java.awt.event.ActionEvent;
    66import java.awt.image.BufferedImage;
     7import java.io.BufferedOutputStream;
    78import java.io.File;
     9import java.io.FileOutputStream;
    810import java.io.IOException;
    911
    1012import javax.imageio.ImageIO;
    1113import javax.swing.JFileChooser;
     14import javax.swing.filechooser.FileFilter;
    1215
    1316import org.openstreetmap.josm.Main;
    1417import org.openstreetmap.josm.actions.JosmAction;
     18
     19import com.sun.image.codec.jpeg.JPEGCodec;
     20import com.sun.image.codec.jpeg.JPEGImageEncoder;
    1521
    1622public class MenuActionSaveRasterAs extends JosmAction {
     
    2127   
    2228    private WMSLayer wmsLayer;
     29   
     30    public class FiltrePng extends FileFilter {
     31        @Override
     32        public boolean accept(File file) {
     33            if (file.isDirectory()) {
     34                return true;
     35            }
     36            return file.getName().toLowerCase().endsWith(".png");
     37        }
     38
     39        @Override
     40        public String getDescription() {
     41            return tr("PNG files (*.png)");
     42        }
     43       
     44    }
     45   
     46    FiltrePng filtrePng = new FiltrePng();
    2347
    2448    public MenuActionSaveRasterAs(WMSLayer wmsLayer) {
     
    3054        File file;
    3155        JFileChooser fc = new JFileChooser();
     56        fc.setFileFilter(filtrePng);
    3257        int returnVal = fc.showSaveDialog(Main.parent);
    3358        if (returnVal == JFileChooser.APPROVE_OPTION) {
    3459            file = fc.getSelectedFile();
     60            if (!file.getName().endsWith(".png"))
     61                file = new File(file.getParent(), file.getName()+".png");
    3562            BufferedImage bi = wmsLayer.images.get(0).image;
    3663            try {
    3764                ImageIO.write(bi, "png", file);
     65/*
     66                FileOutputStream flux = new FileOutputStream(file);
     67                BufferedOutputStream fluxBuf = new BufferedOutputStream(flux);
     68                JPEGImageEncoder codec = JPEGCodec.createJPEGEncoder(fluxBuf, JPEGCodec.getDefaultJPEGEncodeParam(bi));
     69                codec.encode(bi);
     70                fluxBuf.close();
     71*/
    3872            } catch (IOException e) {
    3973                e.printStackTrace();
Note: See TracChangeset for help on using the changeset viewer.