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;
}
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);
}
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);
}
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);
}
Aggregations