Search in sources :

Example 1 with Renderer

use of org.gephi.preview.spi.Renderer in project gephi by gephi.

the class PreviewModelImpl method initProperties.

private synchronized void initProperties() {
    if (properties == null) {
        properties = new PreviewProperties();
        //Properties from renderers
        for (Renderer renderer : getManagedEnabledRenderers()) {
            PreviewProperty[] props = renderer.getProperties();
            for (PreviewProperty p : props) {
                properties.addProperty(p);
            }
        }
        //Default preset
        properties.applyPreset(new DefaultPreset());
        //Defaut values
        properties.putValue(PreviewProperty.VISIBILITY_RATIO, 1f);
    }
}
Also used : MouseResponsiveRenderer(org.gephi.preview.spi.MouseResponsiveRenderer) Renderer(org.gephi.preview.spi.Renderer) DefaultPreset(org.gephi.preview.presets.DefaultPreset)

Example 2 with Renderer

use of org.gephi.preview.spi.Renderer in project gephi by gephi.

the class PreviewModelImpl method prepareManagedListeners.

private void prepareManagedListeners() {
    ArrayList<PreviewMouseListener> listeners = new ArrayList<>();
    for (PreviewMouseListener listener : Lookup.getDefault().lookupAll(PreviewMouseListener.class)) {
        for (Renderer renderer : getManagedEnabledRenderers()) {
            if (renderer instanceof MouseResponsiveRenderer) {
                if (((MouseResponsiveRenderer) renderer).needsPreviewMouseListener(listener) && !listeners.contains(listener)) {
                    listeners.add(listener);
                }
            }
        }
    }
    //First listeners to receive events will be the ones coming from last called renderers.
    Collections.reverse(listeners);
    enabledMouseListeners = listeners.toArray(new PreviewMouseListener[0]);
}
Also used : PreviewMouseListener(org.gephi.preview.spi.PreviewMouseListener) MouseResponsiveRenderer(org.gephi.preview.spi.MouseResponsiveRenderer) Renderer(org.gephi.preview.spi.Renderer) MouseResponsiveRenderer(org.gephi.preview.spi.MouseResponsiveRenderer)

Example 3 with Renderer

use of org.gephi.preview.spi.Renderer in project gephi by gephi.

the class PreviewModelImpl method getGraphicsCanvasSize.

@Override
public CanvasSize getGraphicsCanvasSize() {
    float x1 = Float.MAX_VALUE;
    float y1 = Float.MAX_VALUE;
    float x2 = Float.MIN_VALUE;
    float y2 = Float.MIN_VALUE;
    for (Renderer r : getManagedEnabledRenderers()) {
        for (String type : getItemTypes()) {
            for (Item item : getItems(type)) {
                if (r.isRendererForitem(item, getProperties())) {
                    CanvasSize cs = r.getCanvasSize(item, getProperties());
                    x1 = Math.min(x1, cs.getX());
                    y1 = Math.min(y1, cs.getY());
                    x2 = Math.max(x2, cs.getMaxX());
                    y2 = Math.max(y2, cs.getMaxY());
                }
            }
        }
    }
    return new CanvasSize(x1, y1, x2 - x1, y2 - y1);
}
Also used : MouseResponsiveRenderer(org.gephi.preview.spi.MouseResponsiveRenderer) Renderer(org.gephi.preview.spi.Renderer)

Example 4 with Renderer

use of org.gephi.preview.spi.Renderer in project gephi by gephi.

the class PreviewModelImpl method completeManagedRenderersListIfNecessary.

/**
     * Makes sure that managedRenderers contains every renderer existing implementations. If some renderers are not in the list, they are added in default implementation order at the end of the list
     * and not enabled.
     */
private void completeManagedRenderersListIfNecessary() {
    if (managedRenderers != null) {
        Set<String> existing = new HashSet<>();
        for (ManagedRenderer mr : managedRenderers) {
            existing.add(mr.getRenderer().getClass().getName());
        }
        List<ManagedRenderer> completeManagedRenderersList = new ArrayList<>();
        completeManagedRenderersList.addAll(Arrays.asList(managedRenderers));
        for (Renderer renderer : previewController.getRegisteredRenderers()) {
            if (!existing.contains(renderer.getClass().getName())) {
                completeManagedRenderersList.add(new ManagedRenderer(renderer, false));
            }
        }
        managedRenderers = completeManagedRenderersList.toArray(new ManagedRenderer[0]);
    }
}
Also used : MouseResponsiveRenderer(org.gephi.preview.spi.MouseResponsiveRenderer) Renderer(org.gephi.preview.spi.Renderer)

Example 5 with Renderer

use of org.gephi.preview.spi.Renderer in project gephi by gephi.

the class PreviewModelImpl method readXML.

public void readXML(XMLStreamReader reader) throws XMLStreamException {
    PreviewProperties props = getProperties();
    String propName = null;
    boolean isSimpleValue = false;
    String simpleValueClass = null;
    List<ManagedRenderer> managedRenderersList = new ArrayList<>();
    Map<String, Renderer> availableRenderers = new HashMap<>();
    for (Renderer renderer : Lookup.getDefault().lookupAll(Renderer.class)) {
        availableRenderers.put(renderer.getClass().getName(), renderer);
        Class superClass = renderer.getClass().getSuperclass();
        if (superClass != null && superClass.getName().startsWith("org.gephi.preview.plugin.renderers.")) {
            //For plugins replacing a default renderer
            availableRenderers.put(superClass.getName(), renderer);
        }
    }
    boolean end = false;
    while (reader.hasNext() && !end) {
        int type = reader.next();
        switch(type) {
            case XMLStreamReader.START_ELEMENT:
                String name = reader.getLocalName();
                if ("previewproperty".equalsIgnoreCase(name)) {
                    propName = reader.getAttributeValue(null, "name");
                    isSimpleValue = false;
                } else if ("previewsimplevalue".equalsIgnoreCase(name)) {
                    propName = reader.getAttributeValue(null, "name");
                    simpleValueClass = reader.getAttributeValue(null, "class");
                    isSimpleValue = true;
                } else if ("managedrenderer".equalsIgnoreCase(name)) {
                    String rendererClass = reader.getAttributeValue(null, "class");
                    if (availableRenderers.containsKey(rendererClass)) {
                        managedRenderersList.add(new ManagedRenderer(availableRenderers.get(rendererClass), Boolean.parseBoolean(reader.getAttributeValue(null, "enabled"))));
                    }
                }
                break;
            case XMLStreamReader.CHARACTERS:
                if (!reader.isWhiteSpace()) {
                    if (propName != null) {
                        if (!isSimpleValue) {
                            //Read PreviewProperty:
                            PreviewProperty p = props.getProperty(propName);
                            if (p != null) {
                                Object value = Serialization.readValueFromText(reader.getText(), p.getType());
                                if (value != null) {
                                    p.setValue(value);
                                }
                            }
                        } else {
                            //Read preview simple value:
                            if (simpleValueClass != null) {
                                if (!propName.equals("width") && !propName.equals("height")) {
                                    Object value = Serialization.readValueFromText(reader.getText(), simpleValueClass);
                                    if (value != null) {
                                        props.putValue(propName, value);
                                    }
                                }
                            }
                        }
                    }
                }
                break;
            case XMLStreamReader.END_ELEMENT:
                if ("previewmodel".equalsIgnoreCase(reader.getLocalName())) {
                    end = true;
                }
                propName = null;
                break;
        }
    }
    if (!managedRenderersList.isEmpty()) {
        setManagedRenderers(managedRenderersList.toArray(new ManagedRenderer[0]));
    }
}
Also used : MouseResponsiveRenderer(org.gephi.preview.spi.MouseResponsiveRenderer) Renderer(org.gephi.preview.spi.Renderer)

Aggregations

Renderer (org.gephi.preview.spi.Renderer)8 MouseResponsiveRenderer (org.gephi.preview.spi.MouseResponsiveRenderer)6 ManagedRenderer (org.gephi.preview.api.ManagedRenderer)1 PreviewModel (org.gephi.preview.api.PreviewModel)1 DefaultPreset (org.gephi.preview.presets.DefaultPreset)1 PreviewMouseListener (org.gephi.preview.spi.PreviewMouseListener)1 PropertySheet (org.openide.explorer.propertysheet.PropertySheet)1 AbstractNode (org.openide.nodes.AbstractNode)1 Node (org.openide.nodes.Node)1 Sheet (org.openide.nodes.Sheet)1