Search in sources :

Example 1 with Vizmap

use of org.cytoscape.io.internal.util.vizmap.model.Vizmap 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 2 with Vizmap

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

the class VizmapWriterImpl method run.

@Override
public void run(TaskMonitor taskMonitor) throws Exception {
    taskMonitor.setProgress(0.0);
    final JAXBContext jc = JAXBContext.newInstance(Vizmap.class.getPackage().getName(), this.getClass().getClassLoader());
    Marshaller m = jc.createMarshaller();
    taskMonitor.setProgress(0.2);
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    final DateFormat df = new SimpleDateFormat("yyyy_MM_dd-HH_mm");
    String now = df.format(new Date());
    String vizmapDocId = "VizMap-" + now;
    taskMonitor.setProgress(0.2);
    Vizmap vizmap = visualStyleSerializer.createVizmap(visualStyles);
    vizmap.setId(vizmapDocId);
    vizmap.setDocumentVersion(VIZMAP_VERSION);
    taskMonitor.setProgress(0.4);
    m.marshal(vizmap, outputStream);
    taskMonitor.setProgress(1.0);
}
Also used : Marshaller(javax.xml.bind.Marshaller) Vizmap(org.cytoscape.io.internal.util.vizmap.model.Vizmap) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) JAXBContext(javax.xml.bind.JAXBContext) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 3 with Vizmap

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

the class VizmapXMLReader method run.

public void run(TaskMonitor tm) throws Exception {
    tm.setProgress(0.0);
    // No idea why, but ObjectFactory doesn't get picked up in the default
    // Thread.currentThread().getContextClassLoader() classloader, whereas
    // that approach works fine for bookmarks.  Anyway, just force the issue
    // by getting this classloader.
    final JAXBContext jaxbContext = JAXBContext.newInstance(VIZMAP_PACKAGE, getClass().getClassLoader());
    tm.setProgress(0.1);
    final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    tm.setProgress(0.2);
    Vizmap vizmap = (Vizmap) unmarshaller.unmarshal(inputStream);
    tm.setProgress(0.7);
    this.visualStyles = visualStyleSerializer.createVisualStyles(vizmap);
    tm.setProgress(1.0);
}
Also used : Vizmap(org.cytoscape.io.internal.util.vizmap.model.Vizmap) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 4 with Vizmap

use of org.cytoscape.io.internal.util.vizmap.model.Vizmap 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

Vizmap (org.cytoscape.io.internal.util.vizmap.model.Vizmap)4 JAXBContext (javax.xml.bind.JAXBContext)2 Edge (org.cytoscape.io.internal.util.vizmap.model.Edge)2 Network (org.cytoscape.io.internal.util.vizmap.model.Network)2 Node (org.cytoscape.io.internal.util.vizmap.model.Node)2 CyEdge (org.cytoscape.model.CyEdge)2 CyNetwork (org.cytoscape.model.CyNetwork)2 CyNode (org.cytoscape.model.CyNode)2 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 RenderingEngineManager (org.cytoscape.view.presentation.RenderingEngineManager)1