Search in sources :

Example 1 with PreviewController

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

the class PreviewTopComponent method initTarget.

public void initTarget(PreviewUIModel previewUIModel) {
    // inits the preview applet
    if (previewUIModel != null && target == null) {
        PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class);
        PreviewModel previewModel = previewUIModel.getPreviewModel();
        Color background = previewModel.getProperties().getColorValue(PreviewProperty.BACKGROUND_COLOR);
        if (background != null) {
            setBackgroundColor(background);
        }
        Dimension dimensions = getSketchDimensions();
        previewModel.getProperties().putValue("width", (int) dimensions.getWidth());
        previewModel.getProperties().putValue("height", (int) dimensions.getHeight());
        target = (G2DTarget) previewController.getRenderTarget(RenderTarget.G2D_TARGET);
        if (target != null) {
            sketch = new PreviewSketch(target);
            sketchPanel.add(sketch, BorderLayout.CENTER);
        }
    } else if (previewUIModel == null) {
        sketchPanel.remove(sketch);
        target = null;
    }
}
Also used : PreviewModel(org.gephi.preview.api.PreviewModel) Color(java.awt.Color) Dimension(java.awt.Dimension) PreviewController(org.gephi.preview.api.PreviewController)

Example 2 with PreviewController

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

the class PDFExporter method execute.

@Override
public boolean execute() {
    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;
}
Also used : PreviewProperties(org.gephi.preview.api.PreviewProperties) PdfWriter(com.itextpdf.text.pdf.PdfWriter) Color(java.awt.Color) BaseColor(com.itextpdf.text.BaseColor) Rectangle(com.itextpdf.text.Rectangle) Document(com.itextpdf.text.Document) PreviewController(org.gephi.preview.api.PreviewController) DocumentException(com.itextpdf.text.DocumentException) BaseColor(com.itextpdf.text.BaseColor) LongTask(org.gephi.utils.longtask.spi.LongTask) DocumentException(com.itextpdf.text.DocumentException) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte)

Example 3 with PreviewController

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

the class PreviewSettingsTopComponent method setup.

public void setup(PreviewUIModel previewModel) {
    propertySheet.setNodes(new Node[] { new PreviewNode(propertySheet) });
    PreviewUIController previewUIController = Lookup.getDefault().lookup(PreviewUIController.class);
    if (previewModel != null) {
        ratioSlider.setValue((int) (previewModel.getVisibilityRatio() * 100));
    }
    // Presets
    if (previewModel == null) {
        saveButton.setEnabled(false);
        labelPreset.setEnabled(false);
        presetComboBox.setEnabled(false);
        presetComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---" }));
    } else {
        saveButton.setEnabled(true);
        labelPreset.setEnabled(true);
        presetComboBox.setEnabled(true);
        DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
        defaultPresetLimit = 0;
        for (PreviewPreset preset : previewUIController.getDefaultPresets()) {
            comboBoxModel.addElement(preset);
            defaultPresetLimit++;
        }
        PreviewPreset[] userPresets = previewUIController.getUserPresets();
        if (userPresets.length > 0) {
            comboBoxModel.addElement(NO_SELECTION);
            for (PreviewPreset preset : userPresets) {
                comboBoxModel.addElement(preset);
            }
        }
        presetComboBox.setSelectedItem(previewModel.getCurrentPreset());
        presetComboBox.setModel(comboBoxModel);
    }
    // Refresh tabs
    int tabCount = tabbedPane.getTabCount();
    for (int i = 2; i < tabCount; i++) {
        // Start at 2, not removing settings and renderer manager tabs
        tabbedPane.removeTabAt(i);
    }
    for (PreviewUI pui : Lookup.getDefault().lookupAll(PreviewUI.class)) {
        pui.unsetup();
    }
    if (previewModel != null) {
        PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class);
        PreviewModel pModel = previewController.getModel();
        // Add new tabs
        for (PreviewUI pui : Lookup.getDefault().lookupAll(PreviewUI.class)) {
            pui.setup(pModel);
            JPanel pluginPanel = pui.getPanel();
            if (UIUtils.isAquaLookAndFeel()) {
                pluginPanel.setBackground(UIManager.getColor("NbExplorerView.background"));
            }
            if (pui.getIcon() != null) {
                tabbedPane.addTab(pui.getPanelTitle(), pui.getIcon(), pluginPanel);
            } else {
                tabbedPane.addTab(pui.getPanelTitle(), pluginPanel);
            }
        }
    }
}
Also used : JPanel(javax.swing.JPanel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) PreviewUI(org.gephi.preview.spi.PreviewUI) PreviewController(org.gephi.preview.api.PreviewController) PreviewPreset(org.gephi.preview.api.PreviewPreset) PreviewModel(org.gephi.preview.api.PreviewModel) PreviewUIController(org.gephi.desktop.preview.api.PreviewUIController) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 4 with PreviewController

use of org.gephi.preview.api.PreviewController in project gephi-plugins-bootcamp by gephi.

the class NodesZOrdering method getItems.

@Override
public Item[] getItems(Graph graph) {
    // 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();
    // Get the sort column from the properties, if any
    PreviewProperties previewProperties = previewModel.getProperties();
    final Column sortColumn = previewProperties.getValue(SORT_COLUMN);
    // Get the standard node items from the node builder
    Item[] nodeItems = super.getItems(graph);
    if (sortColumn != null) {
        // Sort by column
        Arrays.sort(nodeItems, new Comparator<Item>() {

            @Override
            public int compare(Item o1, Item o2) {
                Node n1 = (Node) o1.getSource();
                Node n2 = (Node) o2.getSource();
                Number s1 = (Number) n1.getAttribute(sortColumn);
                Number s2 = (Number) n2.getAttribute(sortColumn);
                double size1 = s1 == null ? Double.NEGATIVE_INFINITY : s1.doubleValue();
                double size2 = s2 == null ? Double.NEGATIVE_INFINITY : s2.doubleValue();
                return size1 > size2 ? 1 : size1 < size2 ? -1 : 0;
            }
        });
    } else {
        // Sort by node size
        Arrays.sort(nodeItems, new Comparator<Item>() {

            @Override
            public int compare(Item o1, Item o2) {
                Node n1 = (Node) o1.getSource();
                Node n2 = (Node) o2.getSource();
                float size1 = n1.size();
                float size2 = n2.size();
                return size1 > size2 ? 1 : size1 < size2 ? -1 : 0;
            }
        });
    }
    return nodeItems;
}
Also used : Item(org.gephi.preview.api.Item) PreviewModel(org.gephi.preview.api.PreviewModel) PreviewProperties(org.gephi.preview.api.PreviewProperties) Column(org.gephi.graph.api.Column) Node(org.gephi.graph.api.Node) PreviewController(org.gephi.preview.api.PreviewController)

Example 5 with PreviewController

use of org.gephi.preview.api.PreviewController in project gephi-plugins-bootcamp by gephi.

the class JPGExporter 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("width", width);
    props.putValue("height", height);
    target = (G2DTarget) controller.getRenderTarget(RenderTarget.G2D_TARGET, workspace);
    try {
        target.refresh();
        Graphics2D pg2 = (Graphics2D) target.getGraphics();
        BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        pg2.drawImage(img, null, 0, 0);
        ImageIO.write(img, "jpg", stream);
        stream.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return true;
}
Also used : PreviewProperties(org.gephi.preview.api.PreviewProperties) PreviewController(org.gephi.preview.api.PreviewController) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

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