use of org.cytoscape.io.internal.util.vizmap.model.Edge 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());
}
use of org.cytoscape.io.internal.util.vizmap.model.Edge 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.Edge 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);
}
}
}
use of org.cytoscape.io.internal.util.vizmap.model.Edge 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