use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class NetworkMainPanel method maybeShowViewPopup.
private void maybeShowViewPopup(final SubNetworkPanel item) {
final CySubNetwork network = item.getModel().getNetwork();
if (viewDialog != null) {
if (// Clicking the same item--will probably never happen
viewDialog.getNetwork().equals(network))
return;
viewDialog.dispose();
}
if (item.getModel().getViewCount() > 0) {
final Window windowAncestor = SwingUtilities.getWindowAncestor(item);
final CyNetworkView currentView = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetworkView();
viewDialog = new NetworkViewPreviewDialog(network, currentView, windowAncestor, serviceRegistrar);
viewDialog.addWindowFocusListener(new WindowFocusListener() {
@Override
public void windowLostFocus(WindowEvent e) {
viewDialog.dispose();
}
@Override
public void windowGainedFocus(WindowEvent e) {
}
});
viewDialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
viewDialog = null;
}
});
viewDialog.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
viewDialog.dispose();
}
});
viewDialog.addPropertyChangeListener("currentNetworkView", (PropertyChangeEvent evt) -> {
// TODO Move to NetworkSelectionMediator
serviceRegistrar.getService(CyApplicationManager.class).setCurrentNetworkView((CyNetworkView) evt.getNewValue());
});
final Point screenPt = item.getViewIconLabel().getLocationOnScreen();
final Point compPt = item.getViewIconLabel().getLocation();
int xOffset = screenPt.x - compPt.x - item.getViewIconLabel().getWidth() / 2;
int yOffset = screenPt.y - compPt.y + item.getViewIconLabel().getBounds().height - 2;
final Point pt = item.getViewIconLabel().getBounds().getLocation();
pt.translate(xOffset, yOffset);
viewDialog.setLocation(pt);
viewDialog.setVisible(true);
viewDialog.requestFocusInWindow();
}
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class RootNetworkPanel method getDepth.
private int getDepth(final CySubNetwork net) {
int depth = -1;
CySubNetwork parent = net;
do {
parent = ViewUtil.getParent(parent, serviceRegistrar);
depth++;
} while (parent != null);
return depth;
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class RootNetworkPanel method addItem.
public SubNetworkPanel addItem(final CySubNetwork network) {
if (!getItems().containsKey(network)) {
final SubNetworkPanelModel model = new SubNetworkPanelModel(network, serviceRegistrar);
final SubNetworkPanel subNetPanel = new SubNetworkPanel(model, showIndentation, serviceRegistrar);
subNetPanel.setAlignmentX(LEFT_ALIGNMENT);
final CySubNetwork parentNet = ViewUtil.getParent(network, serviceRegistrar);
if (parentNet == null) {
// No parent network? So just add it to the end of the list...
getSubNetListPanel().add(subNetPanel);
getItems().put(network, subNetPanel);
} else {
// It has a parent network, so let's find the position where it must be inserted...
final LinkedHashMap<CySubNetwork, SubNetworkPanel> newItems = new LinkedHashMap<>();
// New item added to the map?
boolean newItemAdded = false;
boolean parentItemFound = false;
for (Entry<CySubNetwork, SubNetworkPanel> entry : getItems().entrySet()) {
if (!newItemAdded) {
if (!parentItemFound && entry.getKey().equals(parentNet)) {
// We found the parent of the new item
parentItemFound = true;
} else if (parentItemFound) {
// we know this is the position where the new item must be inserted
if (!entry.getValue().isDescendantOf(parentNet)) {
newItems.put(network, subNetPanel);
newItemAdded = true;
}
}
}
newItems.put(entry.getKey(), entry.getValue());
}
if (!newItemAdded) {
// Just add the new item to the end...
getSubNetListPanel().add(subNetPanel);
getItems().put(network, subNetPanel);
} else {
// Rebuild the whole list...
getSubNetListPanel().removeAll();
getItems().clear();
for (Entry<CySubNetwork, SubNetworkPanel> entry : newItems.entrySet()) {
getSubNetListPanel().add(entry.getValue());
getItems().put(entry.getKey(), entry.getValue());
}
}
}
updateRootPanel();
}
return getItems().get(network);
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class NetworkMediator method handleEvent.
@Override
public void handleEvent(final NetworkAddedEvent e) {
if (loadingSession)
return;
final CyNetwork net = e.getNetwork();
invokeOnEDT(() -> {
if (net instanceof CySubNetwork) {
networkMainPanel.addNetwork((CySubNetwork) net);
networkMainPanel.updateNodeEdgeCount();
}
});
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class NetworkLineParser method createNode.
private CyNode createNode(final String[] parts, final Integer nodeIndex) {
CyNode node = null;
if (nodeIndex.equals(-1) == false && (nodeIndex <= (parts.length - 1)) && (parts[nodeIndex] != null)) {
if (this.nMap.get(parts[nodeIndex]) == null) {
// Node does not exist yet, create it
node = network.addNode();
network.getRow(node).set("name", parts[nodeIndex]);
nMap.put(parts[nodeIndex], rootNetwork.getNode(node.getSUID()));
nodeList.add(node.getSUID());
} else {
// Node already exists in parent network
CyNode parentNode = this.nMap.get(parts[nodeIndex]);
CySubNetwork subnet = (CySubNetwork) network;
subnet.addNode(parentNode);
node = subnet.getNode(parentNode.getSUID());
}
}
return node;
}
Aggregations