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);
}
}
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;
}
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);
}
*/
}
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);
}
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);
}
}
Aggregations