Search in sources :

Example 6 with PreviewController

use of org.gephi.preview.api.PreviewController in project gephi by gephi.

the class PNGExporter method execute.

@Override
public boolean execute() {
    Progress.start(progress);
    PreviewController ctrl = Lookup.getDefault().lookup(PreviewController.class);
    PreviewModel m = ctrl.getModel(workspace);
    setExportProperties(m);
    ctrl.refreshPreview(workspace);
    target = (G2DTarget) ctrl.getRenderTarget(RenderTarget.G2D_TARGET, workspace);
    if (target instanceof LongTask) {
        ((LongTask) target).setProgressTicket(progress);
    }
    try {
        target.refresh();
        Progress.switchToIndeterminate(progress);
        Image sourceImg = target.getImage();
        BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        img.getGraphics().drawImage(sourceImg, 0, 0, null);
        ImageIO.write(img, "png", stream);
        stream.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    discardExportProperties(m);
    Progress.finish(progress);
    return !cancel;
}
Also used : PreviewModel(org.gephi.preview.api.PreviewModel) LongTask(org.gephi.utils.longtask.spi.LongTask) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) PreviewController(org.gephi.preview.api.PreviewController) BufferedImage(java.awt.image.BufferedImage)

Example 7 with PreviewController

use of org.gephi.preview.api.PreviewController in project gephi by gephi.

the class SVGExporter method execute.

@Override
public boolean execute() {
    PreviewController controller = Lookup.getDefault().lookup(PreviewController.class);
    controller.getModel(workspace).getProperties().putValue(PreviewProperty.VISIBILITY_RATIO, 1.0);
    controller.refreshPreview(workspace);
    PreviewProperties props = controller.getModel(workspace).getProperties();
    props.putValue(SVGTarget.SCALE_STROKES, scaleStrokes);
    props.putValue(PreviewProperty.MARGIN, new Float((float) margin));
    target = (SVGTarget) controller.getRenderTarget(RenderTarget.SVG_TARGET, workspace);
    if (target instanceof LongTask) {
        ((LongTask) target).setProgressTicket(progress);
    }
    try {
        controller.render(target, workspace);
        // creates SVG-to-SVG transcoder
        SVGTranscoder t = new SVGTranscoder();
        t.addTranscodingHint(SVGTranscoder.KEY_XML_DECLARATION, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        // sets transcoder input and output
        TranscoderInput input = new TranscoderInput(target.getDocument());
        // performs transcoding
        try {
            TranscoderOutput output = new TranscoderOutput(writer);
            t.transcode(input, output);
        } finally {
            writer.close();
            props.removeSimpleValue(PreviewProperty.MARGIN);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    Progress.finish(progress);
    return !cancel;
}
Also used : PreviewProperties(org.gephi.preview.api.PreviewProperties) TranscoderOutput(org.apache.batik.transcoder.TranscoderOutput) LongTask(org.gephi.utils.longtask.spi.LongTask) TranscoderInput(org.apache.batik.transcoder.TranscoderInput) PreviewController(org.gephi.preview.api.PreviewController) SVGTranscoder(org.apache.batik.transcoder.svg2svg.SVGTranscoder)

Example 8 with PreviewController

use of org.gephi.preview.api.PreviewController in project gephi by gephi.

the class PreviewWorkspaceDuplicateProvider method duplicate.

@Override
public void duplicate(Workspace source, Workspace destination) {
    PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class);
    PreviewModel sourceModel = previewController.getModel(source);
    PreviewModel destModel = previewController.getModel(destination);
    destModel.setManagedRenderers(sourceModel.getManagedRenderers());
    for (PreviewProperty property : sourceModel.getProperties().getProperties()) {
        destModel.getProperties().putValue(property.getName(), property.getValue());
    }
    for (Entry<String, Object> property : sourceModel.getProperties().getSimpleValues()) {
        destModel.getProperties().putValue(property.getKey(), property.getValue());
    }
}
Also used : PreviewModel(org.gephi.preview.api.PreviewModel) PreviewProperty(org.gephi.preview.api.PreviewProperty) PreviewController(org.gephi.preview.api.PreviewController)

Aggregations

PreviewController (org.gephi.preview.api.PreviewController)8 PreviewModel (org.gephi.preview.api.PreviewModel)5 PreviewProperties (org.gephi.preview.api.PreviewProperties)4 LongTask (org.gephi.utils.longtask.spi.LongTask)3 Color (java.awt.Color)2 BufferedImage (java.awt.image.BufferedImage)2 BaseColor (com.itextpdf.text.BaseColor)1 Document (com.itextpdf.text.Document)1 DocumentException (com.itextpdf.text.DocumentException)1 Rectangle (com.itextpdf.text.Rectangle)1 PdfContentByte (com.itextpdf.text.pdf.PdfContentByte)1 PdfWriter (com.itextpdf.text.pdf.PdfWriter)1 Dimension (java.awt.Dimension)1 Graphics2D (java.awt.Graphics2D)1 Image (java.awt.Image)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 JPanel (javax.swing.JPanel)1 TranscoderInput (org.apache.batik.transcoder.TranscoderInput)1 TranscoderOutput (org.apache.batik.transcoder.TranscoderOutput)1 SVGTranscoder (org.apache.batik.transcoder.svg2svg.SVGTranscoder)1