fr.ird.observe.client.action.tripMap.ExportPngUIAction Maven / Gradle / Ivy
package fr.ird.observe.client.action.tripMap;
/*-
* #%L
* ObServe Toolkit :: Common Client
* %%
* Copyright (C) 2008 - 2017 IRD, Ultreia.io
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* .
* #L%
*/
import fr.ird.observe.client.MainUI;
import fr.ird.observe.client.ObserveClientTechnicalException;
import fr.ird.observe.client.util.tripMap.TripMapUI;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.KeyStroke;
import org.nuiton.jaxx.widgets.file.JaxxFileChoosers;
import static org.nuiton.i18n.I18n.t;
/**
* Created by tchemit on 25/08/17.
*
* @author Tony Chemit - [email protected]
*/
public class ExportPngUIAction extends TripMapActionSupport {
public static final String ACTION_NAME = ExportPngUIAction.class.getName();
public ExportPngUIAction(MainUI mainUI) {
super(mainUI,
ACTION_NAME,
t("observe.content.map.action.exportPng"),
t("observe.content.map.action.exportPng.tip"),
"save",
KeyStroke.getKeyStroke("ctrl pressed S"));
}
@Override
protected void actionPerformed(TripMapUI view) {
File file = JaxxFileChoosers.chooseFile(
view,
t("observe.content.map.export.chooseFile.title"),
t("observe.content.map.export.chooseFile.ok"),
null,
"^.+\\.png|.+\\.PNG$",
t("observe.content.map.export.chooseFile.png"));
if (file != null && JaxxFileChoosers.confirmOverwriteFileIfExist(view, file)) {
BufferedImage im = new BufferedImage(view.getWidth(), view.getHeight(), BufferedImage.TYPE_INT_ARGB);
view.paint(im.getGraphics());
try {
ImageIO.write(im, "PNG", file);
} catch (IOException e) {
throw new ObserveClientTechnicalException("unable to export map ", e);
}
displayInfo(t("observe.content.map.export.success", file));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy