Search in sources :

Example 1 with PreviewModel

use of org.gephi.preview.api.PreviewModel 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 2 with PreviewModel

use of org.gephi.preview.api.PreviewModel 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 3 with PreviewModel

use of org.gephi.preview.api.PreviewModel 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 4 with PreviewModel

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

the class PreviewUIControllerImpl method savePreset.

@Override
public void savePreset(String name) {
    if (model != null) {
        PreviewModel previewModel = previewController.getModel();
        Map<String, Object> map = new HashMap<>();
        for (PreviewProperty p : previewModel.getProperties().getProperties()) {
            map.put(p.getName(), p.getValue());
        }
        for (Entry<String, Object> p : previewModel.getProperties().getSimpleValues()) {
            map.put(p.getKey(), p.getValue());
        }
        PreviewPreset preset = new PreviewPreset(name, map);
        presetUtils.savePreset(preset);
        model.setCurrentPreset(preset);
    }
}
Also used : PreviewModel(org.gephi.preview.api.PreviewModel) HashMap(java.util.HashMap) PreviewProperty(org.gephi.preview.api.PreviewProperty) PreviewPreset(org.gephi.preview.api.PreviewPreset)

Example 5 with PreviewModel

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

the class PreviewUIControllerImpl method setCurrentPreset.

@Override
public void setCurrentPreset(PreviewPreset preset) {
    if (model != null) {
        model.setCurrentPreset(preset);
        PreviewModel previewModel = previewController.getModel();
        previewModel.getProperties().applyPreset(preset);
    }
}
Also used : PreviewModel(org.gephi.preview.api.PreviewModel)

Aggregations

PreviewModel (org.gephi.preview.api.PreviewModel)11 PreviewController (org.gephi.preview.api.PreviewController)5 ManagedRenderer (org.gephi.preview.api.ManagedRenderer)3 PreviewPreset (org.gephi.preview.api.PreviewPreset)2 PreviewProperty (org.gephi.preview.api.PreviewProperty)2 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 Image (java.awt.Image)1 BufferedImage (java.awt.image.BufferedImage)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 JPanel (javax.swing.JPanel)1 PreviewUIController (org.gephi.desktop.preview.api.PreviewUIController)1 Column (org.gephi.graph.api.Column)1 Node (org.gephi.graph.api.Node)1 Item (org.gephi.preview.api.Item)1 PreviewProperties (org.gephi.preview.api.PreviewProperties)1 PreviewUI (org.gephi.preview.spi.PreviewUI)1 Renderer (org.gephi.preview.spi.Renderer)1