source: osm/applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/MenuActionSaveRasterAs.java@ 18408

Last change on this file since 18408 was 18278, checked in by pieren, 16 years ago

fix some warnings and easier selection of WMSlayer in WMSAdjustAction

File size: 2.3 KB
Line 
1package cadastre_fr;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.event.ActionEvent;
6import java.awt.image.BufferedImage;
7import java.io.File;
8import java.io.IOException;
9
10import javax.imageio.ImageIO;
11import javax.swing.JFileChooser;
12import javax.swing.filechooser.FileFilter;
13
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.actions.JosmAction;
16
17public class MenuActionSaveRasterAs extends JosmAction {
18
19 public static String name = "Save image as PNG";
20
21 private static final long serialVersionUID = 1L;
22
23 private WMSLayer wmsLayer;
24
25 public class FiltrePng extends FileFilter {
26 @Override
27 public boolean accept(File file) {
28 if (file.isDirectory()) {
29 return true;
30 }
31 return file.getName().toLowerCase().endsWith(".png");
32 }
33
34 @Override
35 public String getDescription() {
36 return tr("PNG files (*.png)");
37 }
38
39 }
40
41 FiltrePng filtrePng = new FiltrePng();
42
43 public MenuActionSaveRasterAs(WMSLayer wmsLayer) {
44 super(tr(name), "save", tr("Export as PNG format (only raster images)"), null, false);
45 this.wmsLayer = wmsLayer;
46 }
47
48 public void actionPerformed(ActionEvent arg0) {
49 File file;
50 JFileChooser fc = new JFileChooser();
51 fc.setFileFilter(filtrePng);
52 int returnVal = fc.showSaveDialog(Main.parent);
53 if (returnVal == JFileChooser.APPROVE_OPTION) {
54 file = fc.getSelectedFile();
55 if (!file.getName().endsWith(".png"))
56 file = new File(file.getParent(), file.getName()+".png");
57 BufferedImage bi = wmsLayer.images.get(0).image;
58 try {
59 ImageIO.write(bi, "png", file);
60/*
61 FileOutputStream flux = new FileOutputStream(file);
62 BufferedOutputStream fluxBuf = new BufferedOutputStream(flux);
63 JPEGImageEncoder codec = JPEGCodec.createJPEGEncoder(fluxBuf, JPEGCodec.getDefaultJPEGEncodeParam(bi));
64 codec.encode(bi);
65 fluxBuf.close();
66*/
67 } catch (IOException e) {
68 e.printStackTrace();
69 }
70 }
71 }
72
73}
Note: See TracBrowser for help on using the repository browser.