r4206 - in trunk: . src/main/java/fr/ifremer/isisfish/ui src/main/resources/i18n src/main/resources/icons
Author: echatellier Date: 2015-04-24 08:34:43 +0000 (Fri, 24 Apr 2015) New Revision: 4206 Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/4206 Log: Add screenshot tool Added: trunk/src/main/java/fr/ifremer/isisfish/ui/StatusBarHandler.java trunk/src/main/resources/icons/camera.png Modified: trunk/pom.xml trunk/src/main/java/fr/ifremer/isisfish/ui/StatusBarUI.jaxx trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java trunk/src/main/resources/i18n/isis-fish_en_GB.properties trunk/src/main/resources/i18n/isis-fish_fr_FR.properties Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2015-04-22 15:09:18 UTC (rev 4205) +++ trunk/pom.xml 2015-04-24 08:34:43 UTC (rev 4206) @@ -524,9 +524,9 @@ <redmine.statusIds>3,10,11,18,19</redmine.statusIds> <!-- Dependencies version --> - <jaxxVersion>2.23.1</jaxxVersion> + <jaxxVersion>2.24</jaxxVersion> <eugeneVersion>2.14</eugeneVersion> - <topiaVersion>2.9.5.1</topiaVersion> + <topiaVersion>2.9.5.3</topiaVersion> <hibernateVersion>4.3.9.Final</hibernateVersion> <nuitonI18nVersion>3.3</nuitonI18nVersion> <nuitonWidgetsVersion>1.1.1</nuitonWidgetsVersion> Added: trunk/src/main/java/fr/ifremer/isisfish/ui/StatusBarHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/StatusBarHandler.java (rev 0) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/StatusBarHandler.java 2015-04-24 08:34:43 UTC (rev 4206) @@ -0,0 +1,101 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2015 Ifremer, Codelutin, Chatellier Eric + * %% + * 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 + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ +package fr.ifremer.isisfish.ui; + +import java.awt.Component; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.Toolkit; +import java.awt.image.BufferedImage; +import java.io.File; +import javax.imageio.ImageIO; +import javax.swing.JFileChooser; +import javax.swing.SwingUtilities; +import jaxx.runtime.JAXXContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Status bar UI handler. + * + * @author chatellier + */ +public class StatusBarHandler { + + /** Class logger. */ + private static Log log = LogFactory.getLog(StatusBarHandler.class); + + /** Attribute used to remember screenshot last directory. */ + protected JFileChooser screenshotFileChooser; + + /** + * Ask user for screenshot save file and take screenshot to that file. + */ + public void screenshot(Component parent) { + if (screenshotFileChooser == null) { + screenshotFileChooser = new JFileChooser(); + screenshotFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + screenshotFileChooser.setMultiSelectionEnabled(false); + } + + // reset + File previousFile = screenshotFileChooser.getSelectedFile(); + if (previousFile != null) { + screenshotFileChooser.setSelectedFile(new File("")); // hack alert + screenshotFileChooser.setCurrentDirectory(previousFile.getParentFile()); + } + + // find parent + while (!(parent instanceof WelcomeUI)) { + parent = parent.getParent(); + } + final Component realParent = parent; + + // ask user for file + int opt = screenshotFileChooser.showSaveDialog(realParent); + if (opt == JFileChooser.APPROVE_OPTION) { + File file = screenshotFileChooser.getSelectedFile(); + + // add "png" if not yet set + if (!file.getName().endsWith(".png")) { + file = new File(file.getAbsolutePath() + ".png"); + } + final File realFile = file; + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + // take screenshot + try { + Rectangle screenRect = realParent.getBounds(); + BufferedImage capture = new Robot().createScreenCapture(screenRect); + ImageIO.write(capture, "png", realFile); + } catch (Exception ex) { + if (log.isErrorEnabled()) { + log.error("Can't show help", ex); + } + } + } + }); + } + } +} Property changes on: trunk/src/main/java/fr/ifremer/isisfish/ui/StatusBarHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/StatusBarUI.jaxx =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/StatusBarUI.jaxx 2015-04-22 15:09:18 UTC (rev 4205) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/StatusBarUI.jaxx 2015-04-24 08:34:43 UTC (rev 4206) @@ -5,7 +5,7 @@ $Id$ $HeadURL$ %% - Copyright (C) 2006 - 2010 Ifremer, Code Lutin + Copyright (C) 2006 - 2015 Ifremer, Code Lutin, Chatellier Eric %% This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -23,8 +23,11 @@ #L% --> <Table> + <StatusBarHandler id="handler" /> <script><![CDATA[ - + protected void $afterCompleteSetup() { + //getHandler().postInit(this); + } /** * Change status message and stop progress bar if running. * @@ -58,6 +61,9 @@ <JButton id="stopCommand" actionCommand="stopCommand" visible="false" text="isisfish.common.stop" toolTipText="Stop the process" /> </cell> --> + <cell> + <JLabel icon="camera.png" toolTipText="isisfish.status.screenshot" onMouseClicked="handler.screenshot(this)" /> + </cell> <cell fill="both"> <jaxx.runtime.swing.StatusMessagePanel /> </cell> Modified: trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java 2015-04-22 15:09:18 UTC (rev 4205) +++ trunk/src/main/java/fr/ifremer/isisfish/ui/WelcomeHandler.java 2015-04-24 08:34:43 UTC (rev 4206) @@ -95,7 +95,7 @@ public void postInit(WelcomeUI welcomeUI) { welcomeUI.setContextValue(verifier); - allFrameOpened = new java.util.HashMap<JFrame, WelcomePanelUI>(); + allFrameOpened = new HashMap<JFrame, WelcomePanelUI>(); welcomeUI.getWelcomePanelUI().setContent(new WelcomeTabUI(new JAXXInitialContext().add(verifier))); // increase tooltip display time Modified: trunk/src/main/resources/i18n/isis-fish_en_GB.properties =================================================================== --- trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2015-04-22 15:09:18 UTC (rev 4205) +++ trunk/src/main/resources/i18n/isis-fish_en_GB.properties 2015-04-24 08:34:43 UTC (rev 4206) @@ -1028,6 +1028,7 @@ isisfish.ssh.askpassphrase.message=Enter passphrase for key '%s' \: isisfish.ssh.askpassphrase.title=SSH key unlocking isisfish.ssh.askpassphrase.wrongpassphrase=Wrong passphrase, enter a new one for key '%s' \: +isisfish.status.screenshot=Take screenshot isisfish.strategy.comments=Comments isisfish.strategy.inactivity=Inactivity equation isisfish.strategy.inactivityEquationUsed=Use inactivity equation Modified: trunk/src/main/resources/i18n/isis-fish_fr_FR.properties =================================================================== --- trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2015-04-22 15:09:18 UTC (rev 4205) +++ trunk/src/main/resources/i18n/isis-fish_fr_FR.properties 2015-04-24 08:34:43 UTC (rev 4206) @@ -1026,6 +1026,7 @@ isisfish.ssh.askpassphrase.message=Entrez la passphrase pour la clé '%s' \: isisfish.ssh.askpassphrase.title=Déverrouillage de clé SSH isisfish.ssh.askpassphrase.wrongpassphrase=Mauvaise clé, entrez une nouvelle passphrase '%s' \: +isisfish.status.screenshot=Prendre une captures d'écran isisfish.strategy.comments=Commentaires isisfish.strategy.inactivity=Equation d'inactivité isisfish.strategy.inactivityEquationUsed=Utiliser une équation d'inactivité Added: trunk/src/main/resources/icons/camera.png =================================================================== (Binary files differ) Property changes on: trunk/src/main/resources/icons/camera.png ___________________________________________________________________ Added: svn:mime-type + image/png
participants (1)
-
echatellier@users.forge.codelutin.com