当前位置: 首页>>代码示例>>Java>>正文


Java SVGGraphics2D类代码示例

本文整理汇总了Java中org.apache.batik.svggen.SVGGraphics2D的典型用法代码示例。如果您正苦于以下问题:Java SVGGraphics2D类的具体用法?Java SVGGraphics2D怎么用?Java SVGGraphics2D使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SVGGraphics2D类属于org.apache.batik.svggen包,在下文中一共展示了SVGGraphics2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: exportImage

import org.apache.batik.svggen.SVGGraphics2D; //导入依赖的package包/类
public void exportImage() {
  try {
    File file = IOUtility.selectFileToSave(FileType.IMAGE);
    if (file != null) {
      Rectangle drawingArea = getDrawingArea();
      String extension = FilenameUtils.getExtension(file.getName());
      if (extension.equals("svg")) {
        SVGGraphics2D svgGenerator = IOUtility.getSVGGraphics(drawingArea.getSize());
        paintDrawing(svgGenerator, drawingArea.x, drawingArea.y);
        svgGenerator.stream(new FileWriter(file));
        svgGenerator.dispose();
      } else {
        BufferedImage bi = new BufferedImage(drawingArea.width, drawingArea.height, BufferedImage.TYPE_INT_RGB);
        Graphics g = bi.createGraphics();
        paintDrawing(g, drawingArea.x, drawingArea.y);
        ImageIO.write(bi, extension, file);
        g.dispose();
      }
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
开发者ID:onprom,项目名称:onprom,代码行数:24,代码来源:UMLDiagramPanel.java

示例2: writeSVG

import org.apache.batik.svggen.SVGGraphics2D; //导入依赖的package包/类
private void writeSVG(OutputStream stream) throws IOException {
    DOMImplementation impl = GenericDOMImplementation
            .getDOMImplementation();
    String svgNS = "http://www.w3.org/2000/svg";
    Document myFactory = impl.createDocument(svgNS, "svg", null);

    SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(myFactory);
    ctx.setEmbeddedFontsOn(Options.getBoolean("EMBEDDED_SVG_FONTS", true));
    SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, Options.getBoolean(
            "EMBEDDED_SVG_FONTS", true));

    svgGenerator.setSVGCanvasSize(size);

    paint(svgGenerator, 0, 0);

    boolean useCSS = true;
    Writer out = new OutputStreamWriter(stream, "UTF-8");
    svgGenerator.stream(out, useCSS);

}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:21,代码来源:PIDEF0painter.java

示例3: exportChartAsSVG

import org.apache.batik.svggen.SVGGraphics2D; //导入依赖的package包/类
/**
 * Exports a JFreeChart to a SVG file.
 *
 * @param chart JFreeChart to export
 * @param bounds the dimensions of the viewport
 * @param svgFile the output file.
 * @throws IOException if writing the svgFile fails.
 */
public static void exportChartAsSVG(
        JFreeChart chart,
        Rectangle bounds,
        File svgFile) throws IOException {
    // Get a DOMImplementation and create an XML document
    DOMImplementation domImpl
            = GenericDOMImplementation.getDOMImplementation();
    Document document = domImpl.createDocument(null, "svg", null);

    // Create an instance of the SVG Generator
    SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

    // draw the chart in the SVG generator
    chart.draw(svgGenerator, bounds);

    // Write svg file
    OutputStream outputStream = new FileOutputStream(svgFile);
    Writer out = new OutputStreamWriter(outputStream, "UTF-8");
    svgGenerator.stream(out, true /* use css */);
    outputStream.flush();
    outputStream.close();
}
 
开发者ID:IARC-CSU,项目名称:CanReg5,代码行数:31,代码来源:Tools.java

示例4: export

import org.apache.batik.svggen.SVGGraphics2D; //导入依赖的package包/类
@Override
public void export(Model model, OutputStream out) throws IOException, SerialisationException {
    if (!(model instanceof VisualModel)) {
        throw new SerialisationException("Non-visual model cannot be exported as SVG file.");
    }
    VisualModel visualModel = (VisualModel) model;
    try {
        Document doc = XmlUtils.createDocument();
        SVGGraphics2D g2d = new SVGGraphics2D(doc);
        g2d.setUnsupportedAttributes(null);
        g2d.scale(SCALE_FACTOR, SCALE_FACTOR);
        VisualGroup visualGroup = (VisualGroup) model.getRoot();
        Rectangle2D bounds = visualGroup.getBoundingBoxInLocalSpace();
        g2d.translate(-bounds.getMinX(), -bounds.getMinY());
        int canvasWidth = (int) (bounds.getWidth() * SCALE_FACTOR);
        int canvasHeight = (int) (bounds.getHeight() * SCALE_FACTOR);
        g2d.setSVGCanvasSize(new Dimension(canvasWidth, canvasHeight));
        visualModel.draw(g2d, Decorator.Empty.INSTANCE);
        g2d.stream(new OutputStreamWriter(out));
    } catch (ParserConfigurationException e) {
        throw new SerialisationException(e);
    }
}
 
开发者ID:workcraft,项目名称:workcraft,代码行数:24,代码来源:SvgExporter.java

示例5: exportAsSVG

import org.apache.batik.svggen.SVGGraphics2D; //导入依赖的package包/类
public static <T, U> void exportAsSVG(VennFigureParameters<T> parameters, File file, Dimension size) throws IOException {

        // Get a DOMImplementation.
        DOMImplementation domImpl =
                GenericDOMImplementation.getDOMImplementation();

        // Create an instance of org.w3c.dom.Document.
        String svgNS = "http://www.w3.org/2000/svg";
        Document document = domImpl.createDocument(svgNS, "svg", null);

        // Create an instance of the SVG Generator.
        SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
        VennDrawGraphics2D.draw(VennFigureCreator.createVennFigure(parameters), svgGenerator, size);
        try (Writer writer = new FileWriter(file)) {
            svgGenerator.stream(writer, true);
        }
    }
 
开发者ID:informationsea,项目名称:VennDraw,代码行数:18,代码来源:VennExporter.java

示例6: fullExportToStream

import org.apache.batik.svggen.SVGGraphics2D; //导入依赖的package包/类
@Override
public void fullExportToStream(ERDesignerGraph aGraph, OutputStream aStream) throws IOException {
    Object[] cells = aGraph.getRoots();
    Rectangle2D bounds = aGraph.toScreen(aGraph.getCellBounds(cells));
    if (bounds != null) {
        DOMImplementation theDomImpl = SVGDOMImplementation.getDOMImplementation();
        String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
        Document theDocument = theDomImpl.createDocument(svgNS, "svg", null);
        SVGGraphics2D theSvgGenerator = new SVGGraphics2D(theDocument);
        theSvgGenerator.translate(-bounds.getX() + 10, -bounds.getY() + 0);
        RepaintManager theRepaintManager = RepaintManager.currentManager(aGraph);
        theRepaintManager.setDoubleBufferingEnabled(false);
        boolean theDoubleBuffered = aGraph.isDoubleBuffered();
        // Disable double buffering to allow Batik to render svg elements
        // instead of images
        aGraph.setDoubleBuffered(false);
        aGraph.paint(theSvgGenerator);
        aGraph.setDoubleBuffered(theDoubleBuffered);
        Writer theWriter = new OutputStreamWriter(aStream, PlatformConfig.getXMLEncoding());
        theSvgGenerator.stream(theWriter, false);
        theRepaintManager.setDoubleBufferingEnabled(true);

        theWriter.flush();
        theWriter.close();
    }
}
 
开发者ID:mirkosertic,项目名称:ERDesignerNG,代码行数:27,代码来源:SVGExporter.java

示例7: exportToStream

import org.apache.batik.svggen.SVGGraphics2D; //导入依赖的package包/类
@Override
public void exportToStream(Component aComponent, OutputStream aStream) throws IOException {
    DOMImplementation theDomImpl = GenericDOMImplementation.getDOMImplementation();
    Document theDocument = theDomImpl.createDocument(null, "svg", null);
    SVGGraphics2D theSvgGenerator = new SVGGraphics2D(theDocument);
    RepaintManager theRepaintManager = RepaintManager.currentManager(aComponent);
    theRepaintManager.setDoubleBufferingEnabled(false);

    Dimension theSize = aComponent.getPreferredSize();
    aComponent.setSize(theSize);

    aComponent.paint(theSvgGenerator);
    Writer theWriter = new OutputStreamWriter(aStream, PlatformConfig.getXMLEncoding());
    theSvgGenerator.stream(theWriter, false);
    theRepaintManager.setDoubleBufferingEnabled(true);

    theWriter.flush();
    theWriter.close();
}
 
开发者ID:mirkosertic,项目名称:ERDesignerNG,代码行数:20,代码来源:SVGExporter.java

示例8: test2

import org.apache.batik.svggen.SVGGraphics2D; //导入依赖的package包/类
private static void test2() {

        File selecteddFile = new File("test2.svg");
         try {

             DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();


             // Create an instance of org.w3c.dom.Document.
             String svgNS = "http://www.w3.org/2000/svg";
             Document document = domImpl.createDocument(svgNS, "svg", null);


             // Create an instance of the SVG Generator.
             org.apache.batik.svggen.SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

             draw(svgGenerator);

             Writer out = new BufferedWriter(new FileWriter(selecteddFile));
             //logger.info("Writing output");
             svgGenerator.stream(out, false);
             //logger.info("Done");
         } catch (Exception e) {
             MessageUtils.showMessage("Error encountered creating SVG file: " + e.toString());
         }
     }
 
开发者ID:hyounesy,项目名称:ALEA,代码行数:27,代码来源:SVGTest.java

示例9: generateSVG

import org.apache.batik.svggen.SVGGraphics2D; //导入依赖的package包/类
/**
 * Create a SVG image. The image handler will write all images files to
 * "res/images".
 *
 * @param p the drawable component.
 * @param outStream the the output stream.
 * @throws UnsupportedEncodingException error on unsupported encoding.
 * @throws SVGGraphics2DIOException error on error to conversion.
 */
private void generateSVG(Drawable p, OutputStream outStream) throws UnsupportedEncodingException, SVGGraphics2DIOException {
    DOMImplementation domImpl
            = GenericDOMImplementation.getDOMImplementation();
    String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
    Document myFactory = domImpl.createDocument(svgNS, "svg", null);
    SVGGeneratorContext ctx
            = SVGGeneratorContext.createDefault(myFactory);
    GenericImageHandler ihandler = new CachedImageHandlerPNGEncoder("res/images", null);
    ctx.setGenericImageHandler(ihandler);

    SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);

    TurtleState ts = new TurtleState();

    p.draw(svgGenerator, ts);
    // Create the SVG DOM tree.
    Writer out = new OutputStreamWriter(outStream, "UTF-8");
    svgGenerator.stream(out, true);
}
 
开发者ID:ZenHarbinger,项目名称:torgo,代码行数:29,代码来源:LogoMenuBar.java

示例10: drawSvgGraphics

import org.apache.batik.svggen.SVGGraphics2D; //导入依赖的package包/类
/**
 * Draws the selected component (assumed to be a Component) into the
 * provided SVGGraphics2D object.
 *
 * @param component
 * @param bounds
 */
private static SVGGraphics2D drawSvgGraphics(Object component, Rectangle bounds) {

    // Get a SVGDOMImplementation and create an XML document
    DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
    String svgNS = "http://www.w3.org/2000/svg";
    SVGDocument svgDocument = (SVGDocument) domImpl.createDocument(svgNS, "svg", null);

    // Create an instance of the SVG Generator
    SVGGraphics2D svgGenerator = new SVGGraphics2D(svgDocument);
    svgGenerator.setSVGCanvasSize(bounds.getSize());

    // draw the panel in the SVG generator
    if (component instanceof JFreeChart) {
        ((JFreeChart) component).draw(svgGenerator, bounds);
    } else if (component instanceof JComponent) {
        ((JComponent) component).paintAll(svgGenerator);
    }

    return svgGenerator;
}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:28,代码来源:Export.java

示例11: exportChartAsSVG

import org.apache.batik.svggen.SVGGraphics2D; //导入依赖的package包/类
/**
    * Export chart as svg.
    *
    * @param chart the chart
    * @param bounds the bounds
    * @param svgFile the svg file
    * @throws IOException Signals that an I/O exception has occurred.
    */
   private void exportChartAsSVG(JFreeChart chart, Rectangle bounds, File svgFile) throws IOException {
       // Get a DOMImplementation and create an XML document
       DOMImplementation domImpl =
           GenericDOMImplementation.getDOMImplementation();
       Document document = domImpl.createDocument(null, "svg", null);

       // Create an instance of the SVG Generator
       SVGGraphics2D svgGenerator = new SVGGraphics2D(document);

       // draw the chart in the SVG generator
       chart.draw(svgGenerator, bounds);

       // Write svg file
       OutputStream outputStream = new FileOutputStream(svgFile);
       Writer out = new OutputStreamWriter(outputStream, "UTF-8");
       svgGenerator.stream(out, true /* use css */);						
       outputStream.flush();
       outputStream.close();
}
 
开发者ID:mattmagic149,项目名称:AnSoMia,代码行数:28,代码来源:NewsHistogram.java

示例12: createGraphicsContext

import org.apache.batik.svggen.SVGGraphics2D; //导入依赖的package包/类
public Graphics2D createGraphicsContext(int width, int height)
{
	// Get a DOMImplementation.
	DOMImplementation domImpl = GenericDOMImplementation
			.getDOMImplementation();

	// Create an instance of org.w3c.dom.Document.
	String svgNS = "http://www.w3.org/2000/svg";
	Document document = domImpl.createDocument(svgNS, "svg", null);

	// Create an instance of the SVG Generator.
	svgGenerator = new SVGGraphics2D(document);
	svgGenerator.setSVGCanvasSize(new Dimension(width, height));

	return svgGenerator;
}
 
开发者ID:donkirkby,项目名称:donkirkby,代码行数:17,代码来源:PaintWriter.java

示例13: createGraphicsContext

import org.apache.batik.svggen.SVGGraphics2D; //导入依赖的package包/类
public Graphics2D createGraphicsContext()
{
	// Get a DOMImplementation.
	DOMImplementation domImpl = GenericDOMImplementation
			.getDOMImplementation();

	// Create an instance of org.w3c.dom.Document.
	String svgNS = "http://www.w3.org/2000/svg";
	Document document = domImpl.createDocument(svgNS, "svg", null);

	// Create an instance of the SVG Generator.
	svgGenerator = new SVGGraphics2D(document);
	svgGenerator.setSVGCanvasSize(new Dimension(300, 300));

	return svgGenerator;
}
 
开发者ID:donkirkby,项目名称:donkirkby,代码行数:17,代码来源:PaintWriter.java

示例14: drawSvgGraphics

import org.apache.batik.svggen.SVGGraphics2D; //导入依赖的package包/类
/**
 * Draws the selected component (assumed to be a Component) into the provided
 * SVGGraphics2D object.
 *
 * @param component
 * @param bounds
 */
private static SVGGraphics2D drawSvgGraphics(Object component, Rectangle bounds) {

    // Get a SVGDOMImplementation and create an XML document
    DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
    String svgNS = "http://www.w3.org/2000/svg";
    SVGDocument svgDocument = (SVGDocument) domImpl.createDocument(svgNS, "svg", null);

    // Create an instance of the SVG Generator
    SVGGraphics2D svgGenerator = new SVGGraphics2D(svgDocument);
    svgGenerator.setSVGCanvasSize(bounds.getSize());

    // draw the panel in the SVG generator
    if (component instanceof JFreeChart) {
        ((JFreeChart) component).draw(svgGenerator, bounds);
    } else if (component instanceof JComponent) {
        ((JComponent) component).paintAll(svgGenerator);
    }

    return svgGenerator;
}
 
开发者ID:compomics,项目名称:mitraq,代码行数:28,代码来源:Export.java

示例15: fillSVGGraphics2D

import org.apache.batik.svggen.SVGGraphics2D; //导入依赖的package包/类
/**
 */
protected SVGGraphics2D fillSVGGraphics2D(MapView view) {
	// NodeAdapter root = (NodeAdapter) getController().getMap().getRoot();
	SVGGraphics2D g2d = createSvgGraphics2D();
	try {
		view.preparePrinting();
		Rectangle innerBounds = view.getInnerBounds();
		g2d.setSVGCanvasSize(new Dimension(innerBounds.width,
				innerBounds.height));
		g2d.translate(-innerBounds.x, -innerBounds.y);
		//
		// Generate SVG content
		//
		view.print(g2d);
	} finally {
		view.endPrinting();
	}
	// g2d.setColor(Color.BLACK);
	// g2d.setStroke(new BasicStroke(3));
	// g2d.drawRect(innerBounds.x, innerBounds.y, innerBounds.width - 2,
	// innerBounds.height - 2);
	return g2d;
}
 
开发者ID:iwabuchiken,项目名称:freemind_1.0.0_20140624_214725,代码行数:25,代码来源:ExportVectorGraphic.java


注:本文中的org.apache.batik.svggen.SVGGraphics2D类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。