1 | package cadastre_fr;
|
---|
2 |
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 |
|
---|
5 | import java.awt.event.ActionEvent;
|
---|
6 | import java.awt.image.BufferedImage;
|
---|
7 | import java.io.File;
|
---|
8 | import java.io.IOException;
|
---|
9 |
|
---|
10 | import javax.imageio.ImageIO;
|
---|
11 | import javax.swing.JFileChooser;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.Main;
|
---|
14 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
15 |
|
---|
16 | public class MenuActionSaveRasterAs extends JosmAction {
|
---|
17 |
|
---|
18 | public static String name = "Save image as PNG";
|
---|
19 |
|
---|
20 | private static final long serialVersionUID = 1L;
|
---|
21 |
|
---|
22 | private WMSLayer wmsLayer;
|
---|
23 |
|
---|
24 | public MenuActionSaveRasterAs(WMSLayer wmsLayer) {
|
---|
25 | super(tr(name), "save", tr("Export as PNG format (only raster images)"), null, false);
|
---|
26 | this.wmsLayer = wmsLayer;
|
---|
27 | }
|
---|
28 |
|
---|
29 | public void actionPerformed(ActionEvent arg0) {
|
---|
30 | File file;
|
---|
31 | JFileChooser fc = new JFileChooser();
|
---|
32 | int returnVal = fc.showSaveDialog(Main.parent);
|
---|
33 | if (returnVal == JFileChooser.APPROVE_OPTION) {
|
---|
34 | file = fc.getSelectedFile();
|
---|
35 | BufferedImage bi = wmsLayer.images.get(0).image;
|
---|
36 | try {
|
---|
37 | ImageIO.write(bi, "png", file);
|
---|
38 | } catch (IOException e) {
|
---|
39 | e.printStackTrace();
|
---|
40 | }
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | }
|
---|