From 015719b9deb0ece6685a724dfc2c1e7aa6966bc2 Mon Sep 17 00:00:00 2001 From: philippe lhardy Date: Tue, 12 Dec 2017 22:43:01 +0100 Subject: [PATCH] add svg save --- java/org/artisanlogiciel/games/Display.java | 69 +++++++++++++++++++-- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/java/org/artisanlogiciel/games/Display.java b/java/org/artisanlogiciel/games/Display.java index 30158ce..e0cb2c3 100644 --- a/java/org/artisanlogiciel/games/Display.java +++ b/java/org/artisanlogiciel/games/Display.java @@ -48,6 +48,7 @@ import org.artisanlogiciel.util.UTF8Control; import org.artisanlogiciel.graphics.Drawing; import org.artisanlogiciel.graphics.DrawingLine; +import org.artisanlogiciel.graphics.SvgWriter; /** * Display is Main JFrame for this tool @@ -250,6 +251,18 @@ public class Display extends JFrame return d; } + // to allow to log / write somewher into screen... + void writeSentence(String pSentence) + { + // TODO + System.out.println( pSentence); + } + + void writeError(String pError) + { + System.err.println(pError); + } + void saveImc() { Drawing d = createDrawing(); @@ -257,14 +270,14 @@ public class Display extends JFrame if ( d != null ) { File outfile = new File(params.getSaveDir(), params.getName() + ".imc"); - System.out.println("Saving to " + outfile + " ..."); + writeSentence("Saving to " + outfile + " ..."); try { DataOutputStream out = new DataOutputStream(new FileOutputStream(outfile)); d.saveLinesKompressed(out); out.flush(); out.close(); - System.out.println("... Done."); + writeSentence("... Done."); } catch (IOException io) { @@ -273,6 +286,36 @@ public class Display extends JFrame } } + void saveSvg() + { + Drawing d = createDrawing(); + + if ( d != null ) + { + File outfile = new File(params.getSaveDir(), params.getName() + ".svg"); + writeSentence("Saving to " + outfile + " ..."); + try + { + DataOutputStream out = new DataOutputStream(new FileOutputStream(outfile)); + SvgWriter writer = new SvgWriter(d.getInternLines()); + writer.writeTo(out); + out.flush(); + out.close(); + writeSentence("... Done."); + } + catch (IOException io) + { + io.printStackTrace(System.err); + } + } + else + { + writeError("drawing creation failed"); + } + } + + + void savePng() { File file = new File("snapshot.png"); @@ -546,6 +589,15 @@ public class Display extends JFrame } }; savePngButton.addActionListener(savePngAction); + final JButton saveSvgButton = new JButton(labels.getString("save") +" svg"); + Action saveSvgAction = new AbstractAction() { + public void actionPerformed(ActionEvent evt) + { + writeSentence("save png"); + saveSvg(); + } + }; + saveSvgButton.addActionListener(saveSvgAction); final JButton saveButton = new JButton(labels.getString("save") +" raw"); Action saveAction = new AbstractAction() { public void actionPerformed(ActionEvent evt) @@ -589,10 +641,15 @@ public class Display extends JFrame resizecontrol.add(showAll); resizecontrol.add(slider); resizecontrol.add(autoSlide); - resizecontrol.add(saveName); - resizecontrol.add(savePngButton); - resizecontrol.add(saveButton); - resizecontrol.add(saveImcButton); + + // todo dedicate a panel for save + JPanel savePanel = resizecontrol; + savePanel.add(saveName); + savePanel.add(saveSvgButton); + savePanel.add(savePngButton); + savePanel.add(saveButton); + savePanel.add(saveImcButton); + resizecontrol.add(quitButton); add(controlDisplayPanel, BorderLayout.SOUTH);