Search in sources :

Example 6 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle 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 7 with VisualStyle

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

the class NetworkViewMediator method handleEvent.

@Override
public void handleEvent(final SetCurrentVisualStyleEvent e) {
    if (loadingSession)
        return;
    final VisualStyle style = e.getVisualStyle();
    if (style != null) {
        final CyNetworkView curView = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetworkView();
        if (curView != null) {
            final VisualMappingManager vmm = serviceRegistrar.getService(VisualMappingManager.class);
            vmm.setVisualStyle(style, curView);
        }
    }
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 8 with VisualStyle

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

the class NetworkViewMediator method onColumnChanged.

private void onColumnChanged(final CyTable tbl, final String columnName) {
    if (loadingSession || getNetworkViewMainPanel().isEmpty())
        return;
    final CyNetworkTableManager netTblMgr = serviceRegistrar.getService(CyNetworkTableManager.class);
    final CyNetwork net = netTblMgr.getNetworkForTable(tbl);
    final CyNetworkViewManager netViewMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
    // And if there is no related view, nothing needs to be done
    if (net != null && netViewMgr.viewExists(net) && (tbl.equals(net.getDefaultNodeTable()) || tbl.equals(net.getDefaultEdgeTable()))) {
        // Reapply locked values that map to changed columns
        final Collection<CyNetworkView> networkViews = netViewMgr.getNetworkViews(net);
        final boolean lockedValuesApplyed = reapplyLockedValues(columnName, networkViews);
        // Find views that had their styles affected by the RowsSetEvent
        final Set<VisualStyle> styles = findStylesWithMappedColumn(columnName);
        final Set<CyNetworkView> viewsToUpdate = findNetworkViewsWithStyles(styles);
        if (lockedValuesApplyed)
            viewsToUpdate.addAll(networkViews);
        // Update views
        for (final CyNetworkView view : viewsToUpdate) updateView(view, null);
    }
}
Also used : CyNetworkTableManager(org.cytoscape.model.CyNetworkTableManager) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) CyNetwork(org.cytoscape.model.CyNetwork) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 9 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle 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 10 with VisualStyle

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

the class CreateNetworkViewTask method run.

@Override
public void run(TaskMonitor tm) throws Exception {
    tm.setProgress(0.0);
    final Collection<CyNetwork> netList = network != null ? Collections.singletonList(network) : networks;
    final int total = netList.size();
    tm.setTitle("Creating Network View" + (total == 1 ? "" : "s"));
    tm.setStatusMessage("Creating " + total + " network view" + (total == 1 ? "" : "s") + "...");
    if (viewFactory == null && viewRenderers.size() > 1) {
        // Let the user choose the network view renderer first
        final ChooseViewRendererTask chooseRendererTask = new ChooseViewRendererTask(netList);
        insertTasksAfterCurrentTask(chooseRendererTask);
    } else {
        final CyNetwork curNet = appMgr.getCurrentNetwork();
        CyNetworkView curView = appMgr.getCurrentNetworkView();
        final VisualStyle style = vmMgr.getCurrentVisualStyle();
        int i = 0;
        int viewCount = netList.size();
        for (final CyNetwork n : netList) {
            // TODO Remove this check when multiple views per network is supported
            if (netViewMgr.viewExists(n))
                continue;
            final CyNetworkView view = createView(n, style, tm);
            networkViews.add(view);
            if (curView == null && n.equals(curNet))
                curView = view;
            tm.setStatusMessage("Network view successfully created for:  " + n.getRow(n).get(CyNetwork.NAME, String.class));
            i++;
            tm.setProgress((i / (double) viewCount));
        }
        final List<CyNetwork> selectedNetworks = appMgr.getSelectedNetworks();
        final List<CyNetworkView> selectedViews = new ArrayList<>(appMgr.getSelectedNetworkViews());
        boolean setSelectedViews = false;
        if (layoutMgr == null) {
            // Create network from selection?
            insertTasksAfterCurrentTask(new RegisterNetworkTask(networkViews.get(0), style, netMgr, vmMgr, appMgr, netViewMgr));
        } else {
            insertTasksAfterCurrentTask(new RegisterNetworkTask(networkViews, style, netMgr, vmMgr, appMgr, netViewMgr));
        }
    }
    tm.setProgress(1.0);
}
Also used : ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) RegisterNetworkTask(org.cytoscape.task.internal.network.RegisterNetworkTask) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

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