1 package org.enhydra.jawe.actions; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 import java.io.*; 6 7 import javax.swing.*; 8 import org.apache.batik.dom.*; 9 import org.apache.batik.svggen.*; 10 import org.w3c.dom.*; 11 12 import org.enhydra.jawe.*; 13 14 public class SaveAsSVG extends ActionBase { 15 16 public SaveAsSVG (AbstractEditor editor) { 17 super(editor); 18 } 19 20 public void actionPerformed(ActionEvent e) { 21 try { 23 String file = 24 JaWE.getInstance().saveDialog( 25 ResourceManager.getLanguageDependentString("SaveAsSVGLabel"),2, 26 editor.getGraph().get("Id").toString()); 27 if (file!=null && file.length()>0) { 28 saveGraphAsSVG(file,editor.getGraph()); 29 } 30 } catch (Exception ex) { 31 String msg=ResourceManager.getLanguageDependentString("ErrorSVGSavingFailed"); 32 JaWE.getInstance().message(msg,JOptionPane.WARNING_MESSAGE); 33 } 34 } 35 36 public static void saveGraphAsSVG (String file,AbstractGraph graph) throws Exception { 37 FileOutputStream fos=new FileOutputStream(new File(file)); 38 Writer out = new OutputStreamWriter(fos,JaWEConfig.getInstance().getEncoding()); 40 DOMImplementation domImpl = 42 GenericDOMImplementation.getDOMImplementation(); 43 Document document=domImpl.createDocument(null,"svg",null); 45 SVGGraphics2D svgGenerator=new SVGGraphics2D(document); 47 graph.paint(svgGenerator); 49 boolean useCSS=true; 51 svgGenerator.stream(out,useCSS); 53 fos.flush(); 55 fos.close(); 56 } 57 58 } 59 | Popular Tags |