Search in sources :

Example 6 with VisualLexiconNode

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 {
    }
}
Also used : VisualLexiconNode(org.cytoscape.view.model.VisualLexiconNode) ExecutorService(java.util.concurrent.ExecutorService) ArrayDeque(java.util.ArrayDeque)

Example 7 with VisualLexiconNode

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);
}
Also used : VisualLexiconNode(org.cytoscape.view.model.VisualLexiconNode) NullDataType(org.cytoscape.view.model.NullDataType) VisualProperty(org.cytoscape.view.model.VisualProperty) CyNode(org.cytoscape.model.CyNode)

Example 8 with VisualLexiconNode

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);
}
Also used : VisualLexiconNode(org.cytoscape.view.model.VisualLexiconNode) HashSet(java.util.HashSet)

Example 9 with VisualLexiconNode

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);
}
Also used : VisualLexiconNode(org.cytoscape.view.model.VisualLexiconNode) VisualProperty(org.cytoscape.view.model.VisualProperty) LinkedList(java.util.LinkedList)

Example 10 with VisualLexiconNode

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");
    }
}
Also used : BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualLexicon(org.cytoscape.view.model.VisualLexicon) VisualLexiconNode(org.cytoscape.view.model.VisualLexiconNode) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) DoubleVisualProperty(org.cytoscape.view.presentation.property.DoubleVisualProperty) VisualProperty(org.cytoscape.view.model.VisualProperty) IntegerVisualProperty(org.cytoscape.view.presentation.property.IntegerVisualProperty) CyNode(org.cytoscape.model.CyNode) Map(java.util.Map) ObjectTypeMap(org.cytoscape.io.internal.read.xgmml.ObjectTypeMap) WeakHashMap(java.util.WeakHashMap) CyIdentifiable(org.cytoscape.model.CyIdentifiable) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

VisualLexiconNode (org.cytoscape.view.model.VisualLexiconNode)12 VisualProperty (org.cytoscape.view.model.VisualProperty)6 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)3 VisualLexicon (org.cytoscape.view.model.VisualLexicon)3 Map (java.util.Map)2 Dimension (java.awt.Dimension)1 Font (java.awt.Font)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 Collator (java.text.Collator)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1