Search in sources :

Example 1 with DefaultPreset

use of org.gephi.preview.presets.DefaultPreset in project gephi by gephi.

the class PresetUtils method readXML.

private PreviewPreset readXML(Document document) {
    // For retrieving property class if it is not in the xml (old serialization)
    DefaultPreset defaultPreset = new DefaultPreset();
    Element presetE = document.getDocumentElement();
    Map<String, Object> propertiesMap = new HashMap<>();
    String presetName = presetE.getAttribute("name");
    NodeList propertyList = presetE.getElementsByTagName("previewproperty");
    for (int i = 0; i < propertyList.getLength(); i++) {
        Node n = propertyList.item(i);
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            Element propertyE = (Element) n;
            String name = propertyE.getAttribute("name");
            String valueClassName = propertyE.hasAttribute(name) ? propertyE.getAttribute("class") : null;
            String stringValue = propertyE.getTextContent();
            Class valueClass = null;
            if (valueClassName != null) {
                try {
                    valueClass = Class.forName(valueClassName);
                } catch (ClassNotFoundException ex) {
                    Exceptions.printStackTrace(ex);
                }
            } else {
                Object defaultValue = defaultPreset.getProperties().get(name);
                if (defaultValue != null) {
                    valueClass = defaultValue.getClass();
                }
            }
            if (valueClass != null) {
                Object value = PreviewProperties.readValueFromText(stringValue, valueClass);
                if (value != null) {
                    propertiesMap.put(name, value);
                }
            }
        }
    }
    return new PreviewPreset(presetName, propertiesMap);
}
Also used : HashMap(java.util.HashMap) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) DefaultPreset(org.gephi.preview.presets.DefaultPreset) FileObject(org.openide.filesystems.FileObject) PreviewPreset(org.gephi.preview.api.PreviewPreset)

Example 2 with DefaultPreset

use of org.gephi.preview.presets.DefaultPreset 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)

Aggregations

DefaultPreset (org.gephi.preview.presets.DefaultPreset)2 HashMap (java.util.HashMap)1 PreviewPreset (org.gephi.preview.api.PreviewPreset)1 MouseResponsiveRenderer (org.gephi.preview.spi.MouseResponsiveRenderer)1 Renderer (org.gephi.preview.spi.Renderer)1 FileObject (org.openide.filesystems.FileObject)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1