Search in sources :

Example 41 with CyGroup

use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.

the class GroupIO method handleEvent.

@Override
public void handleEvent(final SessionAboutToBeSavedEvent event) {
    final CyNetworkManager netMgr = groupMgr.getService(CyNetworkManager.class);
    final Set<CyNetwork> networkSet = netMgr.getNetworkSet();
    final Set<CyGroup> allGroups = new LinkedHashSet<>();
    for (final CyNetwork net : networkSet) {
        final Set<CyGroup> groupSet = groupMgr.getGroupSet(net);
        if (groupSet != null)
            allGroups.addAll(groupSet);
    }
    if (allGroups.isEmpty())
        return;
    final List<File> files = new ArrayList<File>();
    try {
        final File root = File.createTempFile(NAMESPACE, ".temp");
        root.delete();
        root.mkdir();
        root.deleteOnExit();
        final File file = new File(root, FILENAME);
        writeLockedVisualPropertiesMap(file, allGroups);
        files.add(file);
        file.deleteOnExit();
        event.addAppFiles(NAMESPACE, files);
    } catch (Exception e) {
        logger.error("Unexpected error", e);
    }
}
Also used : CyGroup(org.cytoscape.group.CyGroup) LinkedHashSet(java.util.LinkedHashSet) CyNetworkManager(org.cytoscape.model.CyNetworkManager) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) File(java.io.File) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 42 with CyGroup

use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.

the class CyGroupSettingsImpl method handleEvent.

// Update all of our maps when we add a new group
public void handleEvent(GroupAddedEvent e) {
    CyGroup addedGroup = e.getGroup();
    Map<Class<?>, Aggregator<?>> defMap = new HashMap<>();
    Map<Class<?>, Aggregator<?>> defListMap = new HashMap<>();
    CyNetwork network = appMgr.getCurrentNetwork();
    if (network == null || !addedGroup.isInNetwork(network)) {
        for (CyNetwork net : addedGroup.getNetworkSet()) {
            network = net;
            break;
        }
    }
    synchronized (lock) {
        for (Class<?> cKey : allGroupDefaultMap.keySet()) defMap.put(cKey, allGroupDefaultMap.get(cKey));
        for (Class<?> cKey : allGroupListDefaultMap.keySet()) defListMap.put(cKey, allGroupListDefaultMap.get(cKey));
        Map<CyColumn, Aggregator<?>> ovMap = new HashMap<CyColumn, Aggregator<?>>();
        for (CyColumn cKey : allGroupOverrideMap.keySet()) ovMap.put(cKey, allGroupOverrideMap.get(cKey));
        groupMap.put(addedGroup, new GroupSpecificMaps(defMap, defListMap, ovMap));
    }
    // Now override these with any settings from the table
    // Flag to indicate that we don't want to trigger visualization changes
    loadingNewGroup = true;
    try {
        loadSettingsFromTable(addedGroup, network);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    loadingNewGroup = false;
}
Also used : CyGroup(org.cytoscape.group.CyGroup) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CyColumn(org.cytoscape.model.CyColumn) Aggregator(org.cytoscape.group.data.Aggregator) CyNetwork(org.cytoscape.model.CyNetwork)

Example 43 with CyGroup

use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.

the class ViewUtils method styleCompoundNode.

// Careful!  In Cytoscape the X and Y locations are actually the
// center of the node!
public static void styleCompoundNode(CyGroup group, CyNetworkView view, CyGroupManager groupManager, VisualMappingManager cyStyleManager, GroupViewType viewType) {
    double z = Z_OFFSET;
    if (viewType.equals(GroupViewType.SINGLENODE))
        z = -Z_OFFSET;
    List<CyGroup> restyleList = new ArrayList<>();
    // First find out if any of our members are compound nodes
    for (CyNode node : group.getNodeList()) {
        if (groupManager.isGroup(node, view.getModel())) {
            // Yes -- git it's Z value
            View<CyNode> nv = view.getNodeView(node);
            if (nv != null) {
                z = nv.getVisualProperty(BasicVisualLexicon.NODE_Z_LOCATION) + Z_OFFSET;
                // Add it to the list to restyle
                restyleList.add(groupManager.getGroup(node, view.getModel()));
            }
        }
    }
    // TODO: Go through the list of our children and update z?
    // for (CyNode node: group.getNodeList()) {
    // View<CyNode> nv = view.getNodeView(group.getGroupNode());
    // 
    // }
    View<CyNode> groupView = view.getNodeView(group.getGroupNode());
    // Get the visual lexicon
    VisualLexicon lex = getVisualLexicon((CyGroupManagerImpl) groupManager, view);
    VisualProperty<?> paddingProperty = lex.lookup(CyNode.class, "COMPOUND_NODE_PADDING");
    double padding = 5.0;
    if (paddingProperty != null)
        padding = (Double) groupView.getVisualProperty(paddingProperty);
    VisualProperty<?> shapeProperty = lex.lookup(CyNode.class, "COMPOUND_NODE_SHAPE");
    NodeShape shape = NodeShapeVisualProperty.ROUND_RECTANGLE;
    if (shapeProperty != null)
        shape = (NodeShape) groupView.getVisualProperty(shapeProperty);
    if (groupView != null) {
        // System.out.println("styleCompoundNode: group "+group+" currently at: "+
        // groupView.getVisualProperty(xLoc)+","+
        // groupView.getVisualProperty(yLoc));
        Rectangle2D bounds = calculateBounds(group.getNodeList(), view, padding);
        double height = bounds.getHeight();
        double width = bounds.getWidth();
        // System.out.println("styleCompoundNode: bounds = "+bounds);
        // 
        double xLocation = bounds.getX() + width / 2.0;
        double yLocation = bounds.getY() + height / 2.0;
        // Adjust bounds for some of the shapes
        if (shape.equals(NodeShapeVisualProperty.ELLIPSE) || shape.equals(NodeShapeVisualProperty.HEXAGON) || shape.equals(NodeShapeVisualProperty.OCTAGON)) {
            // Note that in general, the correct forumla is height * Math.sqrt(2), but
            // I'm fudging a little since the correct formula only applies when the
            // nodes are at the bounding box
            height = height * Math.sqrt(1.5);
            width = width * Math.sqrt(1.5);
        } else if (shape.equals(NodeShapeVisualProperty.DIAMOND)) {
            height = height * Math.sqrt(2);
            width = width * Math.sqrt(2);
        }
        // System.out.println("Moving to "+xLocation+","+yLocation);
        // System.out.println("Resizing to "+bounds.getWidth()+"x"+bounds.getHeight());
        groupView.setVisualProperty(xLoc, xLocation);
        groupView.setVisualProperty(yLoc, yLocation);
        groupView.setLockedValue(BasicVisualLexicon.NODE_HEIGHT, height);
        groupView.setLockedValue(BasicVisualLexicon.NODE_WIDTH, width);
        if (!viewType.equals(GroupViewType.SINGLENODE)) {
            groupView.setLockedValue(BasicVisualLexicon.NODE_SHAPE, shape);
            groupView.setLockedValue(BasicVisualLexicon.NODE_TRANSPARENCY, COMPOUND_NODE_TRANSPARENCY);
        } else {
            groupView.setLockedValue(BasicVisualLexicon.NODE_TRANSPARENCY, 10);
            groupView.setLockedValue(BasicVisualLexicon.NODE_SHAPE, NodeShapeVisualProperty.RECTANGLE);
            groupView.setLockedValue(BasicVisualLexicon.NODE_BORDER_WIDTH, 1.0);
        }
        groupView.setLockedValue(BasicVisualLexicon.NODE_Z_LOCATION, z);
        updateGroupLocation(view.getModel(), group, xLocation, yLocation);
    }
// OK, now restyle any child compound nodes
/*
		for (CyGroup childGroup: restyleList) {
			styleCompoundNode(childGroup, view, groupManager, cyStyleManager);
		}
		*/
}
Also used : CyGroup(org.cytoscape.group.CyGroup) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualLexicon(org.cytoscape.view.model.VisualLexicon) ArrayList(java.util.ArrayList) NodeShape(org.cytoscape.view.presentation.property.values.NodeShape) Rectangle2D(java.awt.geom.Rectangle2D) CyNode(org.cytoscape.model.CyNode)

Example 44 with CyGroup

use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.

the class CyGroupNodeSettingsTaskFactory method createTaskIterator.

@Override
public TaskIterator createTaskIterator(View<CyNode> nodeView, CyNetworkView netView) {
    CyGroup group = cyGroupManager.getGroup(nodeView.getModel(), netView.getModel());
    CyGroupSettingsTask task = new CyGroupSettingsTask(cyGroupManager, cyAggManager, settings, group);
    return new TaskIterator(task);
}
Also used : CyGroup(org.cytoscape.group.CyGroup) TaskIterator(org.cytoscape.work.TaskIterator)

Example 45 with CyGroup

use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.

the class CyGroupManagerImpl method handleEvent.

public void handleEvent(AboutToRemoveEdgesEvent removedEdgesEvent) {
    CyNetwork net = removedEdgesEvent.getSource();
    Collection<CyEdge> edges = removedEdgesEvent.getEdges();
    Set<CyGroup> groups = getGroupSet(net);
    if (groups == null || groups.size() == 0)
        return;
    for (CyGroup group : groups) {
        CyGroupImpl gImpl = (CyGroupImpl) group;
        if (gImpl.isCollapsing() || gImpl.isExpanding())
            return;
    }
    List<CyEdge> edgesToRemove = new ArrayList<>();
    for (CyGroup group : groups) {
        for (CyEdge edge : edges) {
            edgesToRemove.add(edge);
        }
        group.removeEdges(edgesToRemove);
    }
}
Also used : CyGroup(org.cytoscape.group.CyGroup) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge)

Aggregations

CyGroup (org.cytoscape.group.CyGroup)60 CyNode (org.cytoscape.model.CyNode)33 CyNetwork (org.cytoscape.model.CyNetwork)26 ArrayList (java.util.ArrayList)22 CyEdge (org.cytoscape.model.CyEdge)12 CyNetworkView (org.cytoscape.view.model.CyNetworkView)10 HashSet (java.util.HashSet)8 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)7 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)7 List (java.util.List)6 GroupViewType (org.cytoscape.group.CyGroupSettingsManager.GroupViewType)6 CyGroupManager (org.cytoscape.group.CyGroupManager)5 CyRow (org.cytoscape.model.CyRow)5 TaskIterator (org.cytoscape.work.TaskIterator)5 CyGroupImpl (org.cytoscape.group.internal.CyGroupImpl)4 Dimension (java.awt.Dimension)3 LinkedHashSet (java.util.LinkedHashSet)3 CyEventHelper (org.cytoscape.event.CyEventHelper)3 GroupCollapsedEvent (org.cytoscape.group.events.GroupCollapsedEvent)3 FuzzyNodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster)2