add svg save

This commit is contained in:
philippe lhardy
2017-12-12 22:43:01 +01:00
parent 6066e47330
commit 015719b9de

View File

@@ -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);