Search in sources :

Example 1 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle in project EnrichmentMapApp by BaderLab.

the class EMStyleBuilder method setEdgeLineType.

private void setEdgeLineType(VisualStyle vs, EMStyleOptions options) {
    String col = CyEdge.INTERACTION;
    DiscreteMapping<String, LineType> dm = (DiscreteMapping<String, LineType>) dmFactory.createVisualMappingFunction(col, String.class, EDGE_LINE_TYPE);
    // Silence events fired by this mapping to prevent unnecessary style and view updates
    eventHelper.silenceEventSource(dm);
    try {
        LineType sigLineType = LineTypeVisualProperty.DOT;
        if (EDGE_LINE_TYPE.getRange().isDiscrete()) {
            DiscreteRange<LineType> range = (DiscreteRange<LineType>) EDGE_LINE_TYPE.getRange();
            Optional<LineType> first = range.values().stream().filter(v -> "MARQUEE_EQUAL".equalsIgnoreCase(v.getSerializableString())).findFirst();
            if (first.isPresent())
                sigLineType = first.get();
        }
        dm.putMapValue(Columns.EDGE_DATASET_VALUE_COMPOUND, LineTypeVisualProperty.SOLID);
        dm.putMapValue(Columns.EDGE_INTERACTION_VALUE_SIG, sigLineType);
    } finally {
        eventHelper.unsilenceEventSource(dm);
    }
    vs.addVisualMappingFunction(dm);
}
Also used : Color(java.awt.Color) NODE_SHAPE(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_SHAPE) RECTANGLE(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.RECTANGLE) NODE_BORDER_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_TRANSPARENCY) NodeShape(org.cytoscape.view.presentation.property.values.NodeShape) Inject(com.google.inject.Inject) EDGE_UNSELECTED_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_UNSELECTED_PAINT) LineType(org.cytoscape.view.presentation.property.values.LineType) ColorBrewer(org.jcolorbrewer.ColorBrewer) View(org.cytoscape.view.model.View) CyCustomGraphics2(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics2) NODE_TOOLTIP(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_TOOLTIP) Discrete(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Discrete) CyNetwork(org.cytoscape.model.CyNetwork) NODE_SIZE(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_SIZE) NODE_FILL_COLOR(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_FILL_COLOR) VisualStyleChangedEvent(org.cytoscape.view.vizmap.events.VisualStyleChangedEvent) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) VisualLexicon(org.cytoscape.view.model.VisualLexicon) Collectors(java.util.stream.Collectors) AbstractDataSet(org.baderlab.csplugins.enrichmentmap.model.AbstractDataSet) List(java.util.List) NETWORK_BACKGROUND_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.NETWORK_BACKGROUND_PAINT) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) Paint(java.awt.Paint) DIAMOND(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.DIAMOND) Optional(java.util.Optional) NODE_LABEL(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_LABEL) LineTypeVisualProperty(org.cytoscape.view.presentation.property.LineTypeVisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) Passthrough(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Passthrough) EDGE_LINE_TYPE(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_LINE_TYPE) EDGE_STROKE_UNSELECTED_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT) CyNode(org.cytoscape.model.CyNode) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) EDGE_LABEL_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_LABEL_TRANSPARENCY) EDGE_WIDTH(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_WIDTH) ELLIPSE(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.ELLIPSE) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) NODE_BORDER_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_PAINT) NODE_BORDER_WIDTH(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_WIDTH) Continuous(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Continuous) NODE_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_TRANSPARENCY) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) CyEventHelper(org.cytoscape.event.CyEventHelper) DiscreteRange(org.cytoscape.view.model.DiscreteRange) NODE_LABEL_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_LABEL_TRANSPARENCY) EDGE_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_TRANSPARENCY) VisualProperty(org.cytoscape.view.model.VisualProperty) ContinuousMappingPoint(org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) CyNetworkView(org.cytoscape.view.model.CyNetworkView) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) EMSignatureDataSet(org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet) CyEdge(org.cytoscape.model.CyEdge) VisualStyleChangeRecord(org.cytoscape.view.vizmap.events.VisualStyleChangeRecord) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) LineType(org.cytoscape.view.presentation.property.values.LineType) DiscreteRange(org.cytoscape.view.model.DiscreteRange)

Example 2 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle in project EnrichmentMapApp by BaderLab.

the class ControlPanelMediator method setCurrentView.

private void setCurrentView(CyNetworkView netView) {
    ForkJoinPool.commonPool().submit(() -> {
        // Work around a bug in Cytoscape.
        // When the current network view is changed it can lose its style, so set it back.
        CyNetworkView prevNetView = applicationManager.getCurrentNetworkView();
        VisualStyle visualStyle = visualMappingManager.getVisualStyle(prevNetView);
        applicationManager.setCurrentNetworkView(netView);
        visualMappingManager.setVisualStyle(visualStyle, prevNetView);
    });
}
Also used : VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 3 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.

the class AddEdgeTask method run.

@Override
public void run(final TaskMonitor taskMonitor) {
    if (network == null) {
        network = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetwork();
        if (network == null) {
            taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Network must be specified for add command");
            return;
        }
    }
    if (sourceName == null) {
        taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Source node name must be specified for add command");
        return;
    }
    if (targetName == null) {
        taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Target node name must be specified for add command");
        return;
    }
    // Find the source and target nodes
    CyNode source = null;
    CyNode target = null;
    for (CyNode node : network.getNodeList()) {
        String nodeName = network.getRow(node).get(CyNetwork.NAME, String.class);
        if (sourceName.equals(nodeName))
            source = node;
        else if (targetName.equals(nodeName))
            target = node;
        if (source != null && target != null)
            break;
    }
    if (source == null) {
        taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Can't find source node named '" + sourceName + "'");
        return;
    }
    if (target == null) {
        taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Can't find target node named '" + targetName + "'");
        return;
    }
    newEdge = network.addEdge(source, target, isDirected);
    if (name != null) {
        network.getRow(newEdge).set(CyNetwork.NAME, name);
        network.getRow(newEdge).set(CyRootNetwork.SHARED_NAME, name);
    }
    cyEventHelper.flushPayloadEvents();
    if (networkViewManager.viewExists(network)) {
        for (CyNetworkView view : networkViewManager.getNetworkViews(network)) {
            View<CyEdge> edgeView = view.getEdgeView(newEdge);
            VisualStyle style = visualMappingManager.getVisualStyle(view);
            if (style != null) {
                style.apply(network.getRow(newEdge), edgeView);
            }
            // Not sure why we need to refresh the view for edges and not nodes, but apparently we do
            view.updateView();
        }
    }
    cyEventHelper.flushPayloadEvents();
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Added edge " + newEdge.toString() + " to network");
}
Also used : CyNode(org.cytoscape.model.CyNode) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge)

Example 4 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.

the class AddNodeTask method run.

@Override
public void run(final TaskMonitor taskMonitor) {
    if (network == null) {
        network = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetwork();
        if (network == null) {
            taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Network must be specified for add command");
            return;
        }
    }
    newNode = network.addNode();
    if (name != null) {
        network.getRow(newNode).set(CyNetwork.NAME, name);
        network.getRow(newNode).set(CyRootNetwork.SHARED_NAME, name);
    }
    cyEventHelper.flushPayloadEvents();
    if (networkViewManager.viewExists(network)) {
        for (CyNetworkView view : networkViewManager.getNetworkViews(network)) {
            View<CyNode> nodeView = view.getNodeView(newNode);
            VisualStyle style = visualMappingManager.getVisualStyle(view);
            if (style != null) {
                style.apply(network.getRow(newNode), nodeView);
            }
        }
    }
    cyEventHelper.flushPayloadEvents();
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Added node " + newNode.toString() + " to network");
}
Also used : CyNode(org.cytoscape.model.CyNode) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 5 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.

the class PasteEdit method redo.

@Override
public void redo() {
    List<CyIdentifiable> pastedObjects = null;
    if (this.xformPt == null)
        pastedObjects = clipboard.paste(view, 0.0, 0.0);
    else
        pastedObjects = clipboard.paste(view, xformPt.getX(), xformPt.getY());
    // Apply visual style
    final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
    VisualStyle vs = vmMgr.getVisualStyle(view);
    for (CyIdentifiable element : pastedObjects) {
        View<? extends CyIdentifiable> elementView = null;
        if (element instanceof CyNode)
            elementView = view.getNodeView((CyNode) element);
        else if (element instanceof CyEdge)
            elementView = view.getEdgeView((CyEdge) element);
        else
            continue;
        vs.apply(view.getModel().getRow(element), elementView);
    }
    view.updateView();
}
Also used : CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyEdge(org.cytoscape.model.CyEdge) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Aggregations

VisualStyle (org.cytoscape.view.vizmap.VisualStyle)100 CyNetworkView (org.cytoscape.view.model.CyNetworkView)42 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)37 CyNetwork (org.cytoscape.model.CyNetwork)35 CyNode (org.cytoscape.model.CyNode)30 CyEdge (org.cytoscape.model.CyEdge)24 CyEventHelper (org.cytoscape.event.CyEventHelper)14 HashSet (java.util.HashSet)13 VisualProperty (org.cytoscape.view.model.VisualProperty)12 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)12 Paint (java.awt.Paint)11 HashMap (java.util.HashMap)11 CyApplicationManager (org.cytoscape.application.CyApplicationManager)11 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)11 Color (java.awt.Color)10 ArrayList (java.util.ArrayList)10 RenderingEngineManager (org.cytoscape.view.presentation.RenderingEngineManager)9 BasicVisualLexicon (org.cytoscape.view.presentation.property.BasicVisualLexicon)9 ContinuousMapping (org.cytoscape.view.vizmap.mappings.ContinuousMapping)9 View (org.cytoscape.view.model.View)8