diff --git a/src/main/java/ui/interactivesimulation/InteractiveSimulationActions.java b/src/main/java/ui/interactivesimulation/InteractiveSimulationActions.java index c15a6a0364ec72304a16643ff6eccbbebaf054e5..63ab392022ab44a05e4c4bd000890f852601f3e0 100755 --- a/src/main/java/ui/interactivesimulation/InteractiveSimulationActions.java +++ b/src/main/java/ui/interactivesimulation/InteractiveSimulationActions.java @@ -109,8 +109,8 @@ public class InteractiveSimulationActions extends AbstractAction { public static final int ACT_QUIT_SD_WINDOW = 37; public static final int ACT_SAVE_SD_SVG = 38; - - public static final int NB_ACTION = 39; + public static final int ACT_SAVE_SD_PNG = 39; + public static final int NB_ACTION = 40; private static final TAction [] actions = new TAction[NB_ACTION]; @@ -198,7 +198,7 @@ public class InteractiveSimulationActions extends AbstractAction { actions[ACT_QUIT_SD_WINDOW] = new TAction("close-sdpanel", "Close Window", IconManager.imgic27, IconManager.imgic27, "Close window", "Close this window", 'Q'); actions[ACT_SAVE_SD_SVG] = new TAction("svg-sdpanel", "Save in SVG Format", IconManager.imgic1310, IconManager.imgic1310, "Save in SVG Format", "Save as SVG file", 'S'); - + actions[ACT_SAVE_SD_PNG] = new TAction("png-sdpanel", "Save in PNG Format", IconManager.imgic1310, IconManager.imgic1310, "Save in PNG Format", "Save as PNG file", 'S'); } diff --git a/src/main/java/ui/interactivesimulation/JFrameTMLSimulationPanel.java b/src/main/java/ui/interactivesimulation/JFrameTMLSimulationPanel.java index d20126925f3c039a5e11a2621e9be1bb2bfcb398..ff8e2a9772e0d785006c06fbadfc4f45d7d54eff 100644 --- a/src/main/java/ui/interactivesimulation/JFrameTMLSimulationPanel.java +++ b/src/main/java/ui/interactivesimulation/JFrameTMLSimulationPanel.java @@ -56,7 +56,7 @@ import java.awt.event.ComponentEvent; import java.io.BufferedReader; import java.io.File; - +import java.awt.image.BufferedImage; /** * Class JFrameSimulationSDPanel * Creation: 26/05/2011 @@ -113,6 +113,8 @@ public class JFrameTMLSimulationPanel extends JFrame implements ActionListener { topPanel.add(buttonClose); JButton buttonSVG = new JButton(actions[InteractiveSimulationActions.ACT_SAVE_SD_SVG]); topPanel.add(buttonSVG); + JButton buttonPNG = new JButton(actions[InteractiveSimulationActions.ACT_SAVE_SD_PNG]); + topPanel.add(buttonPNG); /*topPanel.add(new JLabel(" time unit:")); units = new JComboBox<>(unitTab); units.setSelectedIndex(1); @@ -187,6 +189,32 @@ public class JFrameTMLSimulationPanel extends JFrame implements ActionListener { gen.saveInSVG(sdpanel, file.getAbsolutePath()); //newSVGSave(fileName); } + + private void savePNG() { + TraceManager.addDev("Saving in png format"); + File file = mgui.selectFileForCapture(); + + BufferedImage bi; + bi = sdpanel.performCapture(); + boolean ok = true; + + try { + ok = FileUtils.checkFileForSave(file); + } catch (Exception e) { + ok = false; + } + + if (!ok) { + JOptionPane.showMessageDialog(this, + "The capture could not be performed: the specified file is not valid", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + + mgui.writeImageCapture(bi, file, true); + //newSVGSave(fileName); + } public void actionPerformed(ActionEvent evt) { String command = evt.getActionCommand(); @@ -196,6 +224,8 @@ public class JFrameTMLSimulationPanel extends JFrame implements ActionListener { close(); } else if (command.equals(actions[InteractiveSimulationActions.ACT_SAVE_SD_SVG].getActionCommand())) { saveSVG(); + } else if (command.equals(actions[InteractiveSimulationActions.ACT_SAVE_SD_PNG].getActionCommand())) { + savePNG(); } }