Search in sources :

Example 1 with Node

use of org.cytoscape.io.internal.util.vizmap.model.Node in project cytoscape-impl by cytoscape.

the class CalculatorConverterTest method setUp.

@Before
public void setUp() throws Exception {
    props = new Properties();
    props.setProperty("globalAppearanceCalculator.My style.defaultBackgroundColor", "255,255,255");
    vs = new VisualStyle();
    vs.setNetwork(new Network());
    vs.setNode(new Node());
    vs.setEdge(new Edge());
}
Also used : Network(org.cytoscape.io.internal.util.vizmap.model.Network) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) Node(org.cytoscape.io.internal.util.vizmap.model.Node) VisualStyle(org.cytoscape.io.internal.util.vizmap.model.VisualStyle) Properties(java.util.Properties) Edge(org.cytoscape.io.internal.util.vizmap.model.Edge) CyEdge(org.cytoscape.model.CyEdge) Before(org.junit.Before)

Example 2 with Node

use of org.cytoscape.io.internal.util.vizmap.model.Node in project cytoscape-impl by cytoscape.

the class VisualStyleSerializer method createVizmap.

/**
 * This method creates a serializable Vizmap object based on the provided collection of visual styles.
 * @param styles The collection of VisualStyles that you wish to convert into a serializable object.
 * @return A Vizmap object that contains a representation of the collection of visual styles.
 */
public Vizmap createVizmap(final Collection<VisualStyle> styles) {
    final Vizmap vizmap = new Vizmap();
    final RenderingEngineManager renderingEngineManager = serviceRegistrar.getService(RenderingEngineManager.class);
    lexicon = renderingEngineManager.getDefaultVisualLexicon();
    if (styles != null) {
        for (VisualStyle style : styles) {
            org.cytoscape.io.internal.util.vizmap.model.VisualStyle vsModel = new org.cytoscape.io.internal.util.vizmap.model.VisualStyle();
            vizmap.getVisualStyle().add(vsModel);
            vsModel.setName(style.getTitle());
            vsModel.setNetwork(new Network());
            vsModel.setNode(new Node());
            vsModel.setEdge(new Edge());
            createVizmapProperties(style, BasicVisualLexicon.NETWORK, vsModel.getNetwork().getVisualProperty());
            createVizmapProperties(style, BasicVisualLexicon.NODE, vsModel.getNode().getVisualProperty());
            createVizmapProperties(style, BasicVisualLexicon.EDGE, vsModel.getEdge().getVisualProperty());
            // Create Dependencies
            createDependencies(style, vsModel);
        }
    }
    return vizmap;
}
Also used : RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) CyNode(org.cytoscape.model.CyNode) Node(org.cytoscape.io.internal.util.vizmap.model.Node) Vizmap(org.cytoscape.io.internal.util.vizmap.model.Vizmap) CyNetwork(org.cytoscape.model.CyNetwork) Network(org.cytoscape.io.internal.util.vizmap.model.Network) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) Edge(org.cytoscape.io.internal.util.vizmap.model.Edge) CyEdge(org.cytoscape.model.CyEdge)

Example 3 with Node

use of org.cytoscape.io.internal.util.vizmap.model.Node in project cytoscape-impl by cytoscape.

the class VisualStyleSerializer method restoreDependencies.

private void restoreDependencies(final VisualStyle visualStyle, org.cytoscape.io.internal.util.vizmap.model.VisualStyle vsModel) {
    final Node nodeSection = vsModel.getNode();
    final Edge edgeSection = vsModel.getEdge();
    final Network networkSection = vsModel.getNetwork();
    final Set<Dependency> dependencyStates = new HashSet<>();
    if (nodeSection != null)
        dependencyStates.addAll(nodeSection.getDependency());
    if (edgeSection != null)
        dependencyStates.addAll(edgeSection.getDependency());
    if (networkSection != null)
        dependencyStates.addAll(networkSection.getDependency());
    final Set<VisualPropertyDependency<?>> availableDependencies = visualStyle.getAllVisualPropertyDependencies();
    for (final Dependency dep : dependencyStates) {
        final String depName = dep.getName();
        final Boolean enabled = dep.isValue();
        for (final VisualPropertyDependency<?> vsDependency : availableDependencies) {
            if (vsDependency.getIdString().equalsIgnoreCase(depName))
                vsDependency.setDependency(enabled);
        }
    }
}
Also used : CyNode(org.cytoscape.model.CyNode) Node(org.cytoscape.io.internal.util.vizmap.model.Node) CyNetwork(org.cytoscape.model.CyNetwork) Network(org.cytoscape.io.internal.util.vizmap.model.Network) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) Dependency(org.cytoscape.io.internal.util.vizmap.model.Dependency) Edge(org.cytoscape.io.internal.util.vizmap.model.Edge) CyEdge(org.cytoscape.model.CyEdge) HashSet(java.util.HashSet)

Example 4 with Node

use of org.cytoscape.io.internal.util.vizmap.model.Node in project cytoscape-impl by cytoscape.

the class VisualStyleSerializer method createVisualStyles.

/**
 * This method creates a collection of VisualStyle objects based on the provided Properties object.
 * Used to convert old (2.x) vizmap.props format to visual styles.
 * @param vizmap A Properties object containing a representation of VisualStyles.
 * @return A collection of VisualStyle objects.
 */
public Set<VisualStyle> createVisualStyles(final Properties props) {
    // Convert properties to Vizmap:
    Vizmap vizmap = new Vizmap();
    List<org.cytoscape.io.internal.util.vizmap.model.VisualStyle> vizmapStyles = vizmap.getVisualStyle();
    // Group properties keys/values by visual style name:
    Map<String, Map<String, String>> styleNamesMap = new HashMap<>();
    Set<String> propNames = props.stringPropertyNames();
    for (String key : propNames) {
        String value = props.getProperty(key);
        String styleName = CalculatorConverter.parseStyleName(key);
        if (styleName != null) {
            // Add each style name and its properties to a map
            Map<String, String> keyValueMap = styleNamesMap.get(styleName);
            if (keyValueMap == null) {
                keyValueMap = new HashMap<String, String>();
                styleNamesMap.put(styleName, keyValueMap);
            }
            keyValueMap.put(key, value);
        }
    }
    // Create a Visual Style for each style name:
    for (Entry<String, Map<String, String>> entry : styleNamesMap.entrySet()) {
        String styleName = entry.getKey();
        org.cytoscape.io.internal.util.vizmap.model.VisualStyle vs = new org.cytoscape.io.internal.util.vizmap.model.VisualStyle();
        vs.setName(styleName);
        vs.setNetwork(new Network());
        vs.setNode(new Node());
        vs.setEdge(new Edge());
        // Create and set the visual properties and mappings:
        Map<String, String> vsProps = entry.getValue();
        for (Entry<String, String> p : vsProps.entrySet()) {
            String key = p.getKey();
            String value = p.getValue();
            Set<CalculatorConverter> convs = calculatorConverterFactory.getConverters(key);
            for (CalculatorConverter c : convs) {
                c.convert(vs, value, props);
            }
        }
        vizmapStyles.add(vs);
    }
    return createVisualStyles(vizmap);
}
Also used : HashMap(java.util.HashMap) CyNode(org.cytoscape.model.CyNode) Node(org.cytoscape.io.internal.util.vizmap.model.Node) CyNetwork(org.cytoscape.model.CyNetwork) Network(org.cytoscape.io.internal.util.vizmap.model.Network) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) Vizmap(org.cytoscape.io.internal.util.vizmap.model.Vizmap) HashMap(java.util.HashMap) Map(java.util.Map) Edge(org.cytoscape.io.internal.util.vizmap.model.Edge) CyEdge(org.cytoscape.model.CyEdge)

Aggregations

Edge (org.cytoscape.io.internal.util.vizmap.model.Edge)4 Network (org.cytoscape.io.internal.util.vizmap.model.Network)4 Node (org.cytoscape.io.internal.util.vizmap.model.Node)4 CyEdge (org.cytoscape.model.CyEdge)4 CyNetwork (org.cytoscape.model.CyNetwork)4 CyNode (org.cytoscape.model.CyNode)4 Vizmap (org.cytoscape.io.internal.util.vizmap.model.Vizmap)2 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Dependency (org.cytoscape.io.internal.util.vizmap.model.Dependency)1 VisualStyle (org.cytoscape.io.internal.util.vizmap.model.VisualStyle)1 RenderingEngineManager (org.cytoscape.view.presentation.RenderingEngineManager)1 VisualPropertyDependency (org.cytoscape.view.vizmap.VisualPropertyDependency)1 Before (org.junit.Before)1