Search in sources :

Example 81 with VisualStyle

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

the class ConnectSelectedNodesTask method run.

@Override
public void run(TaskMonitor taskMonitor) throws Exception {
    taskMonitor.setProgress(0.0);
    taskMonitor.setTitle("Connecting Selected Nodes");
    taskMonitor.setStatusMessage("Connecting nodes.  Please wait...");
    if (network == null) {
        taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Network must be specified");
        return;
    }
    List<CyNode> selectedNodes;
    if (nodes.getValue() == null || nodes.getValue().isEmpty())
        selectedNodes = CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true);
    else
        selectedNodes = nodes.getValue();
    taskMonitor.setProgress(0.1);
    int selectedNodesCount = selectedNodes.size();
    int i = 0;
    newEdges = new ArrayList<CyEdge>();
    eventHelper.silenceEventSource(network);
    for (final CyNode source : selectedNodes) {
        for (final CyNode target : selectedNodes) {
            if (source != target) {
                final List<CyNode> sourceNeighborList = network.getNeighborList(source, Type.ANY);
                if (!sourceNeighborList.contains(target)) {
                    // connect it
                    final CyEdge newEdge = network.addEdge(source, target, false);
                    newEdges.add(newEdge);
                    String name = network.getRow(source).get(CyNetwork.NAME, String.class) + " (" + DEFAULT_INTERACTION + ") " + network.getRow(target).get(CyNetwork.NAME, String.class);
                    network.getRow(newEdge).set(CyNetwork.NAME, name);
                    // System.out.println("Added edge "+name);
                    network.getRow(newEdge).set(CyEdge.INTERACTION, DEFAULT_INTERACTION);
                }
            }
        }
        i++;
        taskMonitor.setProgress(0.1 + i / (double) selectedNodesCount * 0.9);
    }
    eventHelper.unsilenceEventSource(network);
    undoSupport.postEdit(new ConnectSelectedNodesEdit(network, newEdges));
    for (CyEdge edge : newEdges) {
        eventHelper.addEventPayload(network, edge, AddedEdgesEvent.class);
    }
    // To make sure the edge views are created before applying the style
    eventHelper.flushPayloadEvents();
    // Apply visual style
    for (final CyNetworkView view : netViewMgr.getNetworkViews(network)) {
        VisualStyle vs = vmm.getVisualStyle(view);
        vs.apply(view);
        view.updateView();
    }
    taskMonitor.setProgress(1.0);
}
Also used : CyNode(org.cytoscape.model.CyNode) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyEdge(org.cytoscape.model.CyEdge) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 82 with VisualStyle

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

the class CloneNetworkTask method run.

public void run(TaskMonitor tm) {
    tm.setProgress(0.0);
    // nogui?
    if (network != null)
        parentNetwork = network;
    if (parentNetwork == null) {
        tm.showMessage(TaskMonitor.Level.ERROR, "No network to clone");
        return;
    }
    // Create copied network model
    final CyNetwork newNet = cloneNetwork(parentNetwork);
    tm.setProgress(0.5);
    final Collection<CyNetworkView> views = networkViewManager.getNetworkViews(parentNetwork);
    // TODO What if the network has more than one view
    final CyNetworkView origView = views.size() != 0 ? views.iterator().next() : null;
    if (origView != null) {
        final VisualStyle style = vmm.getVisualStyle(origView);
        final CyNetworkView newView = netViewFactory.createNetworkView(newNet);
        tm.setProgress(0.6);
        // Let the CopyExistingViewTask respond to the Observer (if any)
        final CopyExistingViewTask copyExistingViewTask = new CopyExistingViewTask(renderingEngineMgr, newView, origView, style, new2OrigNodeMap, new2OrigEdgeMap, false);
        final RegisterNetworkTask registerNetworkTask = new RegisterNetworkTask(newView, style, networkManager, vmm, appMgr, networkViewManager);
        insertTasksAfterCurrentTask(copyExistingViewTask, registerNetworkTask);
    } else {
        final RegisterNetworkTask registerNetworkTask = new RegisterNetworkTask(newNet, networkManager, vmm, appMgr, networkViewManager);
        insertTasksAfterCurrentTask(registerNetworkTask);
        result = nullNetworkViewFactory.createNetworkView(newNet);
    }
    tm.setProgress(1.0);
}
Also used : CopyExistingViewTask(org.cytoscape.task.internal.view.CopyExistingViewTask) CyNetwork(org.cytoscape.model.CyNetwork) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 83 with VisualStyle

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

the class UnHideCommandTask method run.

@Override
public void run(TaskMonitor e) {
    e.setProgress(0.0);
    edges = tunable.getEdgeList();
    nodes = tunable.getNodeList();
    network = tunable.getNetwork();
    if ((edges == null || edges.size() == 0) && (nodes == null || nodes.size() == 0)) {
        e.showMessage(TaskMonitor.Level.ERROR, "Must specify nodes or edges to show");
        return;
    }
    Collection<CyNetworkView> views = serviceRegistrar.getService(CyNetworkViewManager.class).getNetworkViews(network);
    if (views == null || views.size() == 0) {
        e.showMessage(TaskMonitor.Level.ERROR, "Network " + network.toString() + " doesn't have a view");
        return;
    }
    // We only handle a single view at this point.  At some point, we'll
    // have to come up with a way to name views...
    int nodeCount = 0;
    int edgeCount = 0;
    final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
    for (CyNetworkView view : views) {
        VisualStyle style = vmMgr.getVisualStyle(view);
        if (nodes != null) {
            HideUtils.setVisibleNodes(nodes, true, view);
            nodeCount = nodes.size();
            for (CyNode node : nodes) {
                View<CyNode> nodeView = view.getNodeView(node);
                style.apply(network.getRow(node), nodeView);
            }
        }
        if (edges != null) {
            HideUtils.setVisibleEdges(edges, true, view);
            edgeCount = edges.size();
            for (CyEdge edge : edges) {
                View<CyEdge> edgeView = view.getEdgeView(edge);
                style.apply(network.getRow(edge), edgeView);
            }
        }
        view.updateView();
    }
    e.showMessage(TaskMonitor.Level.INFO, "Showed " + nodeCount + " nodes and " + edgeCount + " edges");
    e.setProgress(1.0);
}
Also used : CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge)

Example 84 with VisualStyle

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

the class DeleteEdit method undo.

@Override
public void undo() {
    for (CyNode n : nodes) net.addNode(n);
    for (CyEdge e : edges) net.addEdge(e);
    eventHelper.flushPayloadEvents();
    final Collection<CyNetworkView> views = netViewMgr.getNetworkViews(net);
    CyNetworkView netView = null;
    if (views.size() != 0)
        netView = views.iterator().next();
    VisualStyle style = visualMappingManager.getVisualStyle(netView);
    if (netView != null) {
        int i = 0;
        for (final CyNode node : nodes) {
            View<CyNode> nodeView = netView.getNodeView(node);
            if (nodeView == null)
                continue;
            nodeView.setVisualProperty(NODE_X_LOCATION, xPos[i]);
            nodeView.setVisualProperty(NODE_Y_LOCATION, yPos[i]);
            setLockedValues(nodeView);
            style.apply(net.getRow(node), nodeView);
            i++;
        }
        for (final CyEdge edge : edges) {
            View<CyEdge> edgeView = netView.getEdgeView(edge);
            if (edgeView == null)
                continue;
            setLockedValues(edgeView);
            style.apply(net.getRow(edge), edgeView);
        }
    }
    netView.updateView();
}
Also used : CyNode(org.cytoscape.model.CyNode) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyEdge(org.cytoscape.model.CyEdge) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 85 with VisualStyle

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

the class AddEdgeTask method run.

@Override
public void run(TaskMonitor tm) throws Exception {
    CyNode sourceNode = AddEdgeStateMonitor.getSourceNode(netView);
    if (sourceNode == null) {
        AddEdgeStateMonitor.setSourceNode(netView, nodeView.getModel());
        double[] coords = new double[2];
        coords[0] = nodeView.getVisualProperty(BasicVisualLexicon.NODE_X_LOCATION);
        coords[1] = nodeView.getVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION);
        ((DGraphView) netView).xformNodeToComponentCoords(coords);
        Point sourceP = new Point();
        sourceP.setLocation(coords[0], coords[1]);
        AddEdgeStateMonitor.setSourcePoint(netView, sourceP);
    } else {
        // set the name attribute for the new node
        CyNetwork net = netView.getModel();
        CyNode targetNode = nodeView.getModel();
        final CyEdge newEdge = net.addEdge(sourceNode, targetNode, true);
        final String interaction = "interacts with";
        String edgeName = net.getRow(sourceNode).get(CyRootNetwork.SHARED_NAME, String.class);
        edgeName += " (" + interaction + ") ";
        edgeName += net.getRow(targetNode).get(CyRootNetwork.SHARED_NAME, String.class);
        CyRow edgeRow = net.getRow(newEdge, CyNetwork.DEFAULT_ATTRS);
        edgeRow.set(CyNetwork.NAME, edgeName);
        edgeRow.set(CyEdge.INTERACTION, interaction);
        AddEdgeStateMonitor.setSourceNode(netView, null);
        // Apply visual style
        // To make sure the edge view is created before applying the style
        serviceRegistrar.getService(CyEventHelper.class).flushPayloadEvents();
        VisualStyle vs = serviceRegistrar.getService(VisualMappingManager.class).getVisualStyle(netView);
        View<CyEdge> edgeView = netView.getEdgeView(newEdge);
        if (edgeView != null)
            vs.apply(edgeRow, edgeView);
        netView.updateView();
    }
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) Point(java.awt.Point) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge)

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