use of org.cytoscape.view.model.VisualLexiconNode in project cytoscape-impl by cytoscape.
the class ApplyToNetworkHandler method applyDefaultsInParallel.
private void applyDefaultsInParallel(final CyNetworkView netView, final VisualLexiconNode rootNode) {
final ExecutorService exe = Executors.newCachedThreadPool();
final Deque<VisualLexiconNode> deque = new ArrayDeque<>();
deque.addAll(rootNode.getChildren());
while (!deque.isEmpty()) {
final VisualLexiconNode node = deque.pop();
final VisualProperty<?> vp = node.getVisualProperty();
if (vp.getTargetDataType() != rootNode.getVisualProperty().getTargetDataType())
continue;
final Collection<VisualLexiconNode> children = node.getChildren();
if (children.isEmpty()) {
Object defaultValue = style.getDefaultValue(vp);
if (defaultValue == null) {
((VisualStyleImpl) style).getStyleDefaults().put(vp, vp.getDefault());
defaultValue = style.getDefaultValue(vp);
}
exe.submit(new ApplyDefaultTask(netView, vp, defaultValue));
}
deque.addAll(children);
}
try {
exe.shutdown();
exe.awaitTermination(10, TimeUnit.MINUTES);
} catch (Exception ex) {
logger.warn("Create apply default failed", ex);
} finally {
}
}
use of org.cytoscape.view.model.VisualLexiconNode in project cytoscape-api by cytoscape.
the class AbstractVisualLexiconTest method testTree.
protected void testTree(VisualLexicon lexicon) throws Exception {
final VisualProperty<NullDataType> root = lexicon.getRootVisualProperty();
assertNotNull(root);
assertEquals(lexicon.getRootVisualProperty(), root);
// test common methods
try {
Collection<VisualProperty<?>> result = lexicon.getAllDescendants(null);
} catch (Exception e) {
assertTrue(e instanceof NullPointerException);
}
try {
Collection<VisualProperty<?>> result = lexicon.getAllDescendants(new DefaultVisualizableVisualProperty("test", "Test Visual Property", CyNode.class));
} catch (Exception e) {
assertTrue(e instanceof IllegalArgumentException);
}
final VisualLexiconNode rootNode = lexicon.getVisualLexiconNode(root);
assertNotNull(rootNode);
assertEquals(root, rootNode.getVisualProperty());
final Collection<VisualLexiconNode> children = rootNode.getChildren();
assertFalse(0 == children.size());
traverse(children, lexicon);
// Test adding
final DoubleVisualProperty dummyVP = new DoubleVisualProperty(new Double(10), BasicVisualLexicon.ARBITRARY_DOUBLE_RANGE, "DUMMY", "Dummy VP", CyNode.class);
try {
((BasicVisualLexicon) lexicon).addVisualProperty(BasicVisualLexicon.NODE_FILL_COLOR, root);
} catch (Exception e) {
assertTrue(e instanceof IllegalStateException);
}
try {
((BasicVisualLexicon) lexicon).addVisualProperty(dummyVP, null);
} catch (Exception e) {
assertTrue(e instanceof NullPointerException);
}
try {
((BasicVisualLexicon) lexicon).addVisualProperty(dummyVP, dummyVP);
} catch (Exception e) {
assertTrue(e instanceof IllegalArgumentException);
}
((BasicVisualLexicon) lexicon).addVisualProperty(dummyVP, root);
}
use of org.cytoscape.view.model.VisualLexiconNode in project cytoscape-api by cytoscape.
the class AbstractVisualLexiconTest method traverse.
private void traverse(final Collection<VisualLexiconNode> vpSet, VisualLexicon lexicon) {
Collection<VisualLexiconNode> children = vpSet;
Collection<VisualLexiconNode> nextChildren = new HashSet<VisualLexiconNode>();
for (VisualLexiconNode child : children) {
final VisualLexiconNode parent = child.getParent();
System.out.println(parent.getVisualProperty().getDisplayName() + "\thas_child\t" + child.getVisualProperty().getDisplayName());
for (final VisualLexiconNode nextCh : child.getChildren()) assertEquals(child, nextCh.getParent());
nextChildren.addAll(child.getChildren());
}
if (nextChildren.size() == 0)
return;
else
traverse(nextChildren, lexicon);
}
use of org.cytoscape.view.model.VisualLexiconNode in project cytoscape-impl by cytoscape.
the class AbstractDViewModel method clearValueLock.
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void clearValueLock(final VisualProperty<?> vp) {
synchronized (getDGraphView().m_lock) {
directLocks.remove(vp);
VisualLexiconNode root = lexicon.getVisualLexiconNode(vp);
LinkedList<VisualLexiconNode> nodes = new LinkedList<VisualLexiconNode>();
nodes.add(root);
while (!nodes.isEmpty()) {
VisualLexiconNode node = nodes.pop();
VisualProperty visualProperty = node.getVisualProperty();
allLocks.remove(visualProperty);
// Re-apply the regular visual property value
if (visualProperties.containsKey(visualProperty)) {
applyVisualProperty(visualProperty, visualProperties.get(visualProperty));
// TODO else: reset to the visual style default if visualProperties map doesn't contain this vp
} else {
// Apply default if necessary.
final Object newValue = getVisualProperty(visualProperty);
applyVisualProperty(visualProperty, newValue);
}
for (VisualLexiconNode child : node.getChildren()) {
if (!isDirectlyLocked(child.getVisualProperty())) {
nodes.add(child);
}
}
nodes.addAll(node.getChildren());
}
}
fireViewChangedEvent(vp, null, true);
}
use of org.cytoscape.view.model.VisualLexiconNode in project cytoscape-impl by cytoscape.
the class GenericXGMMLWriter method writeGraphics.
/**
* Writes a graphics tag under graph, node, edge.
* @param view
* @param groupLockedProperties Whether or not locked visual properties must be grouped under a list-type att tag.
* @throws IOException
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void writeGraphics(View<? extends CyIdentifiable> view, final boolean groupLockedProperties) throws IOException {
if (view == null)
return;
writeElement("<graphics");
CyIdentifiable element = view.getModel();
final VisualProperty<?> root;
if (element instanceof CyNode)
root = BasicVisualLexicon.NODE;
else if (element instanceof CyEdge)
root = BasicVisualLexicon.EDGE;
else
root = BasicVisualLexicon.NETWORK;
final VisualLexicon visualLexicon = getVisualLexicon();
final Collection<VisualProperty<?>> visualProperties = visualLexicon.getAllDescendants(root);
// To be written as att tags
final List<VisualProperty<?>> attProperties = new ArrayList<VisualProperty<?>>();
final List<VisualProperty<?>> lockedProperties = new ArrayList<VisualProperty<?>>();
final Set<String> writtenKeys = new HashSet<String>();
for (VisualProperty vp : visualProperties) {
// because they are also returned as NETWORK's descendants
if (root == BasicVisualLexicon.NETWORK && vp.getTargetDataType() != CyNetwork.class)
continue;
// It doesn't have to write the property if the value is null
Object value = view.getVisualProperty(vp);
if (value == null)
continue;
if (groupLockedProperties && view.isDirectlyLocked(vp)) {
lockedProperties.add(vp);
continue;
} else {
// If not a bypass, write only leaf nodes
final VisualLexiconNode node = visualLexicon.getVisualLexiconNode(vp);
if (!node.getChildren().isEmpty())
continue;
}
// Use XGMML graphics attribute names for some visual properties
final String[] keys = getGraphicsKey(vp);
if (keys != null && keys.length > 0) {
// XGMML graphics attributes...
try {
value = vp.toSerializableString(value);
} catch (ClassCastException ex) {
System.err.println(vp.getDisplayName() + " causes ClassCastEx: " + value.getClass() + ", expected: " + vp.getDefault().getClass().getSimpleName());
value = null;
}
if (value != null) {
for (int i = 0; i < keys.length; i++) {
final String k = keys[i];
if (!writtenKeys.contains(k) && !ignoreGraphicsAttribute(element, k)) {
writeAttributePair(k, value);
// to avoid writing the same key twice, because of dependencies!
writtenKeys.add(k);
}
}
}
} else if (!ignoreGraphicsAttribute(element, vp.getIdString())) {
// So it can be written as nested att tags
attProperties.add(vp);
}
}
Map<String, String> unrecognizedMap = unrecognizedVisualPropertyMgr.getUnrecognizedVisualProperties(networkView, view);
if (attProperties.isEmpty() && lockedProperties.isEmpty() && unrecognizedMap.isEmpty()) {
write("/>\n");
} else {
write(">\n");
depth++;
// write Cy3-specific properties
for (VisualProperty vp : attProperties) {
writeVisualPropertyAtt(view, vp);
}
// also save unrecognized visual properties
for (Map.Entry<String, String> entry : unrecognizedMap.entrySet()) {
String k = entry.getKey();
String v = entry.getValue();
if (v != null)
writeAttributeXML(k, ObjectType.STRING, v, false, true);
}
// serialize locked properties as <att> tags inside <graphics>
if (!lockedProperties.isEmpty()) {
writeAttributeXML("lockedVisualProperties", ObjectType.LIST, null, false, false);
depth++;
for (VisualProperty vp : lockedProperties) {
writeVisualPropertyAtt(view, vp);
}
depth--;
writeElement("</att>\n");
}
depth--;
writeElement("</graphics>\n");
}
}
Aggregations