Package org.gephi.preview.api

Examples of org.gephi.preview.api.PreviewProperties


        //Get the current preview model, little hack to get the current workspace from the graph
        PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class);
        PreviewModel previewModel = previewController.getModel(graph.getGraphModel().getWorkspace());
       
        //Get the sort column from the properties, if any
        PreviewProperties previewProperties = previewModel.getProperties();
        final AttributeColumn sortColumn = previewProperties.getValue(SORT_COLUMN);
       
        //Get the standard node items from the node builder
        Item[] nodeItems = super.getItems(graph, attributeModel);
        if (sortColumn != null) {
            //Sort by column
View Full Code Here


        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("width", width);
        props.putValue("height", height);
        target = (ProcessingTarget) controller.getRenderTarget(RenderTarget.PROCESSING_TARGET, workspace);

        try {
            target.refresh();
View Full Code Here

        Progress.start(progress);

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

        Rectangle size = new Rectangle(pageSize);
        if (landscape) {
            size = new Rectangle(pageSize.rotate());
        }
        Color col = props.getColorValue(PreviewProperty.BACKGROUND_COLOR);
        size.setBackgroundColor(new BaseColor(col.getRed(), col.getGreen(), col.getBlue()));

        Document document = new Document(size);
        PdfWriter pdfWriter = null;
        try {
            pdfWriter = PdfWriter.getInstance(document, stream);
            pdfWriter.setPdfVersion(PdfWriter.PDF_VERSION_1_5);
            pdfWriter.setFullCompression();

        } catch (DocumentException ex) {
            Exceptions.printStackTrace(ex);
        }
        document.open();
        PdfContentByte cb = pdfWriter.getDirectContent();
        cb.saveState();

        props.putValue(PDFTarget.LANDSCAPE, landscape);
        props.putValue(PDFTarget.PAGESIZE, size);
        props.putValue(PDFTarget.MARGIN_TOP, new Float((float) marginTop));
        props.putValue(PDFTarget.MARGIN_LEFT, new Float((float) marginLeft));
        props.putValue(PDFTarget.MARGIN_BOTTOM, new Float((float) marginBottom));
        props.putValue(PDFTarget.MARGIN_RIGHT, new Float((float) marginRight));
        props.putValue(PDFTarget.PDF_CONTENT_BYTE, cb);
        target = (PDFTarget) controller.getRenderTarget(RenderTarget.PDF_TARGET, workspace);
        if (target instanceof LongTask) {
            ((LongTask) target).setProgressTicket(progress);
        }

        try {
            controller.render(target, workspace);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        cb.restoreState();
        document.close();

        Progress.finish(progress);

        props.putValue(PDFTarget.PDF_CONTENT_BYTE, null);
        props.putValue(PDFTarget.PAGESIZE, null);

        return !cancel;
    }
View Full Code Here

        Progress.start(progress);

        PreviewController controller = Lookup.getDefault().lookup(PreviewController.class);
        controller.getModel(workspace).getProperties().putValue(PreviewProperty.VISIBILITY_RATIO, 1.0);

        PreviewProperties props = controller.getModel(workspace).getProperties();
        props.putValue("width", width);
        props.putValue("height", height);
        Color oldColor = props.getColorValue(PreviewProperty.BACKGROUND_COLOR);
        if (transparentBackground) {
            props.putValue(PreviewProperty.BACKGROUND_COLOR, new Color(255, 255, 255, 0));//White transparent
        }
        props.putValue(PreviewProperty.MARGIN, new Float((float) margin));
        controller.refreshPreview(workspace);
        target = (G2DTarget) controller.getRenderTarget(RenderTarget.G2D_TARGET, workspace);
        if (target instanceof LongTask) {
            ((LongTask) target).setProgressTicket(progress);
        }
        //Fix bug caused by keeping width and height in the workspace preview properties.
        //When a .gephi file is loaded later with these properties PGraphics will be created instead of a PApplet
        props.removeSimpleValue("width");
        props.removeSimpleValue("height");
        props.removeSimpleValue(PreviewProperty.MARGIN);

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

            props.putValue(PreviewProperty.BACKGROUND_COLOR, oldColor);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        Progress.finish(progress);
View Full Code Here

    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);
        }
View Full Code Here

        double height = previewModel.getDimensions().getHeight();
        width = Math.max(1, width);
        height = Math.max(1, height);
        int topLeftX = previewModel.getTopLeftPosition().x;
        int topLeftY = previewModel.getTopLeftPosition().y;
        PreviewProperties properties = previewModel.getProperties();
        float marginBottom = properties.getFloatValue(PDFTarget.MARGIN_BOTTOM);
        float marginLeft = properties.getFloatValue(PDFTarget.MARGIN_LEFT);
        float marginRight = properties.getFloatValue(PDFTarget.MARGIN_RIGHT);
        float marginTop = properties.getFloatValue(PDFTarget.MARGIN_TOP);
        Rectangle pageSize = properties.getValue(PDFTarget.PAGESIZE);
        boolean landscape = properties.getBooleanValue(PDFTarget.LANDSCAPE);
        PdfContentByte cb = properties.getValue(PDFTarget.PDF_CONTENT_BYTE);
        PDFRenderTargetImpl renderTarget = new PDFRenderTargetImpl(cb, width, height, topLeftX, topLeftY,
                pageSize, marginLeft, marginRight, marginTop, marginBottom, landscape);
        return renderTarget;
    }
View Full Code Here

TOP

Related Classes of org.gephi.preview.api.PreviewProperties

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.