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

Last change on this file since 19424 was 18544, checked in by pieren, 15 years ago

Add licence in headers for GPL compliance.

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