Search in sources :

Example 1 with View

use of org.cytoscape.view.model.View 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 View

use of org.cytoscape.view.model.View in project cytoscape-impl by cytoscape.

the class SIFInterpreterTask method run.

@Override
public void run(TaskMonitor tm) {
    if (sifString == null)
        throw new NullPointerException("SIF input string is null");
    String[] terms = sifString.split("\\s");
    if (terms != null) {
        if (terms.length > 0) {
            String name1 = terms[0].trim();
            if (!name1.equals(null)) {
                CyNode node1 = findNode(terms[0]);
                if (node1 == null) {
                    node1 = network.addNode();
                    network.getRow(node1).set("name", terms[0]);
                // nv1 = view.getNodeView(node1);
                // double[] nextLocn = new double[2];
                // nextLocn[0] = p.getX();
                // nextLocn[1] = p.getY();
                // view.xformComponentToNodeCoords(nextLocn);
                // nv1.setOffset(nextLocn[0], nextLocn[1]);
                } else {
                // nv1 = view.getNodeView(node1);
                }
                if (terms.length == 3) {
                    // simple case of 'A interaction B'
                    CyNode node2 = findNode(terms[2]);
                    if (node2 == null) {
                        node2 = network.addNode();
                        network.getRow(node2).set("name", terms[2]);
                    // nv2 = view.getNodeView(node2);
                    // nv2.setOffset(nv1.getXPosition() + spacing, nv1.getYPosition());
                    }
                    CyEdge edge = network.addEdge(node1, node2, true);
                    network.getRow(edge).set("name", terms[1]);
                } else if (terms.length > 3) {
                    // process multiple targets and one source
                    List<View<CyNode>> nodeViews = new ArrayList<View<CyNode>>();
                    String interactionType = terms[1];
                    for (int i = 2; i < terms.length; i++) {
                        CyNode node2 = findNode(terms[i]);
                        if (node2 == null) {
                            node2 = network.addNode();
                            network.getRow(node2).set("name", terms[i]);
                        // nv2 = view.getNodeView(node2);
                        // nv2.setOffset(nv1.getXPosition() + spacing, nv1
                        // .getYPosition());
                        }
                        CyEdge edge = network.addEdge(node1, node2, true);
                        network.getRow(edge).set("name", terms[1]);
                    // doCircleLayout(nodeViews, nv1);
                    }
                }
            }
            // Apply visual style
            final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
            // To make sure the edge view is created before applying the style
            eventHelper.flushPayloadEvents();
            final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
            VisualStyle vs = vmMgr.getVisualStyle(view);
            vs.apply(view);
            view.updateView();
        }
    }
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) CyNode(org.cytoscape.model.CyNode) ArrayList(java.util.ArrayList) List(java.util.List) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyEdge(org.cytoscape.model.CyEdge) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 3 with View

use of org.cytoscape.view.model.View in project cytoscape-impl by cytoscape.

the class NetworkViewMediator method updateView.

private void updateView(final CyNetworkView view, final VisualStyle style) {
    if (view == null)
        return;
    if (getNetworkViewMainPanel().isGridVisible() || view.equals(getNetworkViewMainPanel().getCurrentNetworkView())) {
        Timer timer = null;
        synchronized (lock) {
            timer = viewUpdateTimers.get(view);
        }
        if (timer == null) {
            timer = new Timer(0, evt -> {
                VisualStyle vs = style != null ? style : serviceRegistrar.getService(VisualMappingManager.class).getVisualStyle(view);
                vs.apply(view);
                view.updateView();
            });
            timer.setRepeats(false);
            timer.setCoalesce(true);
            synchronized (lock) {
                viewUpdateTimers.put(view, timer);
            }
        } else {
            timer.stop();
        }
        timer.setInitialDelay(120);
        timer.start();
    } else {
        viewUpdateRequired.add(view);
    }
}
Also used : VisualStyleSetListener(org.cytoscape.view.vizmap.events.VisualStyleSetListener) LoggerFactory(org.slf4j.LoggerFactory) UpdateNetworkPresentationListener(org.cytoscape.view.model.events.UpdateNetworkPresentationListener) View(org.cytoscape.view.model.View) SetCurrentVisualStyleListener(org.cytoscape.view.vizmap.events.SetCurrentVisualStyleListener) SessionAboutToBeLoadedListener(org.cytoscape.session.events.SessionAboutToBeLoadedListener) VisualStyleSetEvent(org.cytoscape.view.vizmap.events.VisualStyleSetEvent) CyNetwork(org.cytoscape.model.CyNetwork) Map(java.util.Map) MouseAdapter(java.awt.event.MouseAdapter) SetCurrentNetworkViewEvent(org.cytoscape.application.events.SetCurrentNetworkViewEvent) CyProperty(org.cytoscape.property.CyProperty) ViewChangedEvent(org.cytoscape.view.model.events.ViewChangedEvent) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) ColumnNameChangedEvent(org.cytoscape.model.events.ColumnNameChangedEvent) MouseListener(java.awt.event.MouseListener) Timer(javax.swing.Timer) VisualStyleChangedEvent(org.cytoscape.view.vizmap.events.VisualStyleChangedEvent) RenderingEngineFactory(org.cytoscape.view.presentation.RenderingEngineFactory) ViewChangedListener(org.cytoscape.view.model.events.ViewChangedListener) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) NetworkViewAboutToBeDestroyedListener(org.cytoscape.view.model.events.NetworkViewAboutToBeDestroyedListener) ViewChangeRecord(org.cytoscape.view.model.events.ViewChangeRecord) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) VisualStyleChangedListener(org.cytoscape.view.vizmap.events.VisualStyleChangedListener) ColumnDeletedEvent(org.cytoscape.model.events.ColumnDeletedEvent) Collection(java.util.Collection) SetCurrentNetworkViewListener(org.cytoscape.application.events.SetCurrentNetworkViewListener) Set(java.util.Set) VisualLexicon(org.cytoscape.view.model.VisualLexicon) CyNetworkManager(org.cytoscape.model.CyNetworkManager) Component(java.awt.Component) SessionLoadedListener(org.cytoscape.session.events.SessionLoadedListener) RowsSetEvent(org.cytoscape.model.events.RowsSetEvent) RowsSetListener(org.cytoscape.model.events.RowsSetListener) List(java.util.List) CyApplicationManager(org.cytoscape.application.CyApplicationManager) ThumbnailPanel(org.cytoscape.internal.view.NetworkViewGrid.ThumbnailPanel) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) SessionLoadedEvent(org.cytoscape.session.events.SessionLoadedEvent) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer) ActionListener(java.awt.event.ActionListener) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) Mode(org.cytoscape.internal.view.GridViewToggleModel.Mode) ExportNetworkViewTaskFactory(org.cytoscape.task.write.ExportNetworkViewTaskFactory) NetworkViewAboutToBeDestroyedEvent(org.cytoscape.view.model.events.NetworkViewAboutToBeDestroyedEvent) HashMap(java.util.HashMap) RowSetRecord(org.cytoscape.model.events.RowSetRecord) HashSet(java.util.HashSet) DestroyNetworkViewTaskFactory(org.cytoscape.task.destroy.DestroyNetworkViewTaskFactory) ExportNetworkImageTaskFactory(org.cytoscape.task.write.ExportNetworkImageTaskFactory) JMenuItem(javax.swing.JMenuItem) NetworkViewAddedListener(org.cytoscape.view.model.events.NetworkViewAddedListener) CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) SetCurrentVisualStyleEvent(org.cytoscape.view.vizmap.events.SetCurrentVisualStyleEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) LinkedHashSet(java.util.LinkedHashSet) WeakHashMap(java.util.WeakHashMap) CyTable(org.cytoscape.model.CyTable) VisualProperty(org.cytoscape.view.model.VisualProperty) UpdateNetworkPresentationEvent(org.cytoscape.view.model.events.UpdateNetworkPresentationEvent) NetworkViewAddedEvent(org.cytoscape.view.model.events.NetworkViewAddedEvent) SessionAboutToBeLoadedEvent(org.cytoscape.session.events.SessionAboutToBeLoadedEvent) Properties(java.util.Properties) Logger(org.slf4j.Logger) JPopupMenu(javax.swing.JPopupMenu) CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier) MappableVisualPropertyValue(org.cytoscape.view.presentation.property.values.MappableVisualPropertyValue) ViewUtil(org.cytoscape.internal.util.ViewUtil) ActionEvent(java.awt.event.ActionEvent) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) MouseEvent(java.awt.event.MouseEvent) DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager) ColumnDeletedListener(org.cytoscape.model.events.ColumnDeletedListener) ColumnNameChangedListener(org.cytoscape.model.events.ColumnNameChangedListener) CyNetworkView(org.cytoscape.view.model.CyNetworkView) RenderingEngine(org.cytoscape.view.presentation.RenderingEngine) CyColumnIdentifierFactory(org.cytoscape.view.presentation.property.values.CyColumnIdentifierFactory) ViewUtil.invokeOnEDT(org.cytoscape.internal.util.ViewUtil.invokeOnEDT) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) Collections(java.util.Collections) Timer(javax.swing.Timer) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager)

Example 4 with View

use of org.cytoscape.view.model.View in project cytoscape-impl by cytoscape.

the class SelectFirstNeighborsNodeViewTaskTest method testRun.

@Test
public void testRun() throws Exception {
    // more setup
    List<CyNode> nl = new ArrayList<CyNode>();
    nl.add(e4);
    when(net.getNeighborList(e3, CyEdge.Type.ANY)).thenReturn(nl);
    View<CyNode> nv = (View<CyNode>) mock(View.class);
    when(nv.getModel()).thenReturn(e3);
    CyNetworkView netView = mock(CyNetworkView.class);
    when(netView.getModel()).thenReturn(net);
    // run the task
    Task t = new SelectFirstNeighborsNodeViewTask(nv, netView, CyEdge.Type.ANY, eventHelper);
    t.run(tm);
    // check that the expected rows were set
    verify(r4, times(1)).set("selected", true);
}
Also used : Task(org.cytoscape.work.Task) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyNetworkView(org.cytoscape.view.model.CyNetworkView) Test(org.junit.Test)

Example 5 with View

use of org.cytoscape.view.model.View in project cytoscape-impl by cytoscape.

the class AbstractPropertyTask method getPropertyValue.

public Object getPropertyValue(CyNetwork network, CyIdentifiable target, VisualProperty vp) {
    CyNetworkView networkView = getViewForNetwork(network);
    Class<? extends CyIdentifiable> vpTargetType = vp.getTargetDataType();
    if (target instanceof CyNetwork) {
        if (vpTargetType != CyNetwork.class)
            throw new RuntimeException("Property '" + vp.getDisplayName() + "' not available for networks");
        return networkView.getVisualProperty(vp);
    } else if (target instanceof CyNode) {
        if (vpTargetType != CyNode.class)
            throw new RuntimeException("Property '" + vp.getDisplayName() + "' not available for nodes");
        View<CyNode> nodeView = networkView.getNodeView((CyNode) target);
        return nodeView.getVisualProperty(vp);
    } else if (target instanceof CyEdge) {
        if (vpTargetType != CyEdge.class)
            throw new RuntimeException("Property '" + vp.getDisplayName() + "' not available for edges");
        View<CyEdge> edgeView = networkView.getEdgeView((CyEdge) target);
        return edgeView.getVisualProperty(vp);
    }
    return null;
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge)

Aggregations

CyNetworkView (org.cytoscape.view.model.CyNetworkView)35 View (org.cytoscape.view.model.View)35 CyNode (org.cytoscape.model.CyNode)24 CyEdge (org.cytoscape.model.CyEdge)17 CyNetwork (org.cytoscape.model.CyNetwork)15 ArrayList (java.util.ArrayList)12 HashSet (java.util.HashSet)11 VisualProperty (org.cytoscape.view.model.VisualProperty)8 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)8 List (java.util.List)7 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)6 HashMap (java.util.HashMap)5 Set (java.util.Set)5 CyEventHelper (org.cytoscape.event.CyEventHelper)5 BasicVisualLexicon (org.cytoscape.view.presentation.property.BasicVisualLexicon)5 Paint (java.awt.Paint)4 CyApplicationManager (org.cytoscape.application.CyApplicationManager)4 CyIdentifiable (org.cytoscape.model.CyIdentifiable)4 VisualLexicon (org.cytoscape.view.model.VisualLexicon)4 Collectors (java.util.stream.Collectors)3