Search in sources :

Example 1 with SAXDocumentFactory

use of org.apache.batik.dom.util.SAXDocumentFactory in project megameklab by MegaMek.

the class PrintMech method loadPipSVG.

@Nullable
private NodeList loadPipSVG(String filename) {
    File f = new File(filename);
    if (!f.exists()) {
        return null;
    }
    Document doc;
    try (InputStream is = new FileInputStream(f)) {
        DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
        final String parser = XMLResourceDescriptor.getXMLParserClassName();
        SAXDocumentFactory df = new SAXDocumentFactory(impl, parser);
        doc = df.createDocument(f.toURI().toASCIIString(), is);
    } catch (Exception e) {
        LogManager.getLogger().error("Failed to open pip SVG file! Path: " + f.getName());
        return null;
    }
    if (doc == null) {
        LogManager.getLogger().error("Failed to open pip SVG file! Path: " + f.getName());
        return null;
    } else {
        return doc.getElementsByTagName(SVGConstants.SVG_PATH_TAG);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SVGDOMImplementation(org.apache.batik.anim.dom.SVGDOMImplementation) SAXDocumentFactory(org.apache.batik.dom.util.SAXDocumentFactory) File(java.io.File) FileInputStream(java.io.FileInputStream) Nullable(megamek.common.annotations.Nullable)

Example 2 with SAXDocumentFactory

use of org.apache.batik.dom.util.SAXDocumentFactory in project megameklab by MegaMek.

the class PrintRecordSheet method loadSVG.

/**
 * Creates a {@link Document} from an svg image file
 *
 * @param filename The name of the SVG file
 * @return The document object
 */
@Nullable
static Document loadSVG(String dirName, String filename) {
    File f = new File(dirName, filename);
    Document svgDocument = null;
    try (InputStream is = new FileInputStream(f)) {
        DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
        final String parser = XMLResourceDescriptor.getXMLParserClassName();
        SAXDocumentFactory df = new SAXDocumentFactory(impl, parser);
        svgDocument = df.createDocument(f.toURI().toASCIIString(), is);
    } catch (Exception ex) {
        LogManager.getLogger().error("", ex);
    }
    if (svgDocument == null) {
        LogManager.getLogger().error("Failed to open SVG file! Path: data/images/recordsheets/" + filename);
    }
    return svgDocument;
}
Also used : DOMImplementation(org.w3c.dom.DOMImplementation) SVGDOMImplementation(org.apache.batik.anim.dom.SVGDOMImplementation) SAXDocumentFactory(org.apache.batik.dom.util.SAXDocumentFactory) SVGDocument(org.w3c.dom.svg.SVGDocument) Document(org.w3c.dom.Document) ConfigurationException(org.apache.fop.configuration.ConfigurationException) TranscoderException(org.apache.batik.transcoder.TranscoderException) SAXException(org.xml.sax.SAXException) Nullable(megamek.common.annotations.Nullable)

Example 3 with SAXDocumentFactory

use of org.apache.batik.dom.util.SAXDocumentFactory in project megameklab by MegaMek.

the class PrintRecordSheet method print.

public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
    final String METHOD_NAME = "print(Graphics,PageFormat,int)";
    Graphics2D g2d = (Graphics2D) graphics;
    if (null != g2d) {
        File f = new File("data/images/recordsheets/" + getSVGFileName());
        svgDocument = null;
        try {
            InputStream is = new FileInputStream(f);
            DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
            final String parser = XMLResourceDescriptor.getXMLParserClassName();
            SAXDocumentFactory df = new SAXDocumentFactory(impl, parser);
            svgDocument = df.createDocument(f.toURI().toASCIIString(), is);
        } catch (Exception e) {
            MegaMekLab.getLogger().log(PrintRecordSheet.class, METHOD_NAME, e);
        }
        if (null == svgDocument) {
            MegaMekLab.getLogger().log(PrintRecordSheet.class, METHOD_NAME, LogLevel.ERROR, "Failed to open Mech SVG file! Path: data/images/recordsheets/" + getSVGFileName());
        } else {
            svgGenerator = new SVGGraphics2D(svgDocument);
            printImage(g2d, pageFormat, pageIndex - firstPage);
            GraphicsNode node = build();
            node.paint(g2d);
        }
    }
    return Printable.PAGE_EXISTS;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DOMImplementation(org.w3c.dom.DOMImplementation) SVGDOMImplementation(org.apache.batik.anim.dom.SVGDOMImplementation) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) SAXDocumentFactory(org.apache.batik.dom.util.SAXDocumentFactory) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) PrinterException(java.awt.print.PrinterException) Graphics2D(java.awt.Graphics2D) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) GraphicsNode(org.apache.batik.gvt.GraphicsNode)

Aggregations

SVGDOMImplementation (org.apache.batik.anim.dom.SVGDOMImplementation)3 SAXDocumentFactory (org.apache.batik.dom.util.SAXDocumentFactory)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Nullable (megamek.common.annotations.Nullable)2 DOMImplementation (org.w3c.dom.DOMImplementation)2 Graphics2D (java.awt.Graphics2D)1 PrinterException (java.awt.print.PrinterException)1 BufferedInputStream (java.io.BufferedInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 GraphicsNode (org.apache.batik.gvt.GraphicsNode)1 SVGGraphics2D (org.apache.batik.svggen.SVGGraphics2D)1 TranscoderException (org.apache.batik.transcoder.TranscoderException)1 ConfigurationException (org.apache.fop.configuration.ConfigurationException)1 Document (org.w3c.dom.Document)1 SVGDocument (org.w3c.dom.svg.SVGDocument)1 SAXException (org.xml.sax.SAXException)1