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

Last change on this file since 29194 was 26382, checked in by pieren, 13 years ago

improved i18n with patches #6624 #6625

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