Author: pwang
Date: 2009-08-04 17:41:53 -0700 (Tue, 04 Aug 2009)
New Revision: 17689
Modified:
csplugins/trunk/ucsd/mes/groupResults/src/org/cytoscape/groups/results/GroupHandler.java
csplugins/trunk/ucsd/mes/groupResults/src/org/cytoscape/groups/results/LayoutRegion.java
Log:
Expand a box, if a node is dragged outside the box
Modified:
csplugins/trunk/ucsd/mes/groupResults/src/org/cytoscape/groups/results/GroupHandler.java
===================================================================
---
csplugins/trunk/ucsd/mes/groupResults/src/org/cytoscape/groups/results/GroupHandler.java
2009-08-05 00:30:06 UTC (rev 17688)
+++
csplugins/trunk/ucsd/mes/groupResults/src/org/cytoscape/groups/results/GroupHandler.java
2009-08-05 00:41:53 UTC (rev 17689)
@@ -238,6 +238,38 @@
if ( LayoutRegionManager.getNumRegionsForView
(Cytoscape.getCurrentNetworkView()) < 1) { return; }
+ CyNode node = dragOnNode(e);
+ if ( node != null){
+ // drag on a node,
+ List groupList = node.getGroups();
+ if (groupList == null || groupList.size() == 0){
+ // The node does not belong to a group, do
nothing
+ return;
+ }
+ // The group belong to one or more groups
+ //System.out.println("drag on a node belong to group,
expand their boxes");
+
+ List<LayoutRegion> regionList =
LayoutRegionManager.getRegionListForView(Cytoscape.getCurrentNetworkView());
+ List<LayoutRegion> regions = new
ArrayList<LayoutRegion>();
+
+ for (int i=0; i< groupList.size(); i++){
+ for (int j=0; j< regionList.size(); j++){
+ if (groupList.get(i)==
regionList.get(j).getMyGroup()){
+ regions.add(regionList.get(j));
+ }
+ }
+ }
+
+ // expand boxes if the nodeView moves outside the box
+ for (int i=0; i< regions.size(); i++){
+ System.out.println("region to be expand: "+
regions.get(i).getMyGroup().getGroupName());
+
regions.get(i).expand(Cytoscape.getCurrentNetworkView().getNodeView(node));
+ }
+
+ return;
+ }
+
+
onEdge = calculateOnEdge(e.getPoint(), pickedRegion);
if (!dragging) {
@@ -437,6 +469,10 @@
List regionList =
LayoutRegionManager.getRegionListForView(Cytoscape
.getCurrentNetworkView());
+ if (regionList == null || regionList.size() == 0){
+ return;
+ }
+
for (int i=0; i< regionList.size(); i++){
LayoutRegion theRegion = (LayoutRegion)
regionList.get(i);
if (theRegion.isSelected()){
@@ -586,6 +622,15 @@
System.out.println("groupChanged()");
}
+
+ private CyNode dragOnNode(MouseEvent e){
+ DGraphView cView =
(DGraphView)Cytoscape.getCurrentNetworkView();
+ NodeView nv = cView.getPickedNodeView(e.getPoint());
+ if (nv == null){
+ return null;
+ }
+ return (CyNode) nv.getNode();
+ }
/**
* Determines which edge of region the cursor is over
Modified:
csplugins/trunk/ucsd/mes/groupResults/src/org/cytoscape/groups/results/LayoutRegion.java
===================================================================
---
csplugins/trunk/ucsd/mes/groupResults/src/org/cytoscape/groups/results/LayoutRegion.java
2009-08-05 00:30:06 UTC (rev 17688)
+++
csplugins/trunk/ucsd/mes/groupResults/src/org/cytoscape/groups/results/LayoutRegion.java
2009-08-05 00:41:53 UTC (rev 17689)
@@ -790,4 +790,70 @@
private void setMyGroup(CyGroup group) {
myGroup = group;
}
+
+ // if a nodeView is moved outside the box, expand the box
+ public void expand(NodeView nv){
+ if (!nodeViews.contains(nv)){
+ return;
+ }
+
+ boolean shouldExpand = false;
+
+ // Get the screen coordinate of the nodeView
+ double[] screenXY = getScreenCoordinates(nv);
+
+ if (screenXY[0] < this.getX1()){
+ this.setW1(this.getW1()+ (this.x1 - screenXY[0]));
+ this.setX1(screenXY[0]);
+ shouldExpand = true;
+ }
+ if (screenXY[1]< this.getY1()){
+ this.setH1(this.getH1() + (this.getY1() - screenXY[1]));
+ this.setY1(screenXY[1]);
+ shouldExpand = true;
+ }
+ if (screenXY[2] > this.getX1() + this.getW1()){
+ this.setW1(screenXY[2] - this.getX1());
+ shouldExpand = true;
+ }
+ if (screenXY[3] > this.getY1() + this.getH1()){
+ this.setH1(screenXY[3]-this.getY1());
+ shouldExpand = true;
+ }
+
+ if (shouldExpand){
+ this.setBounds(this.getX1(), this.getY1(),
this.getW1(), this.getH1());
+ }
+ }
+
+
+ private double[] getScreenCoordinates(NodeView nv){
+ // determine the min and max screen coordinates of the nodeView
+ DGraphView theView = (DGraphView)
Cytoscape.getCurrentNetworkView();
+ double scaleFactor =
Cytoscape.getCurrentNetworkView().getZoom();
+
+ double w = theView.getComponent().getBounds().getWidth();
+ double h = theView.getComponent().getBounds().getHeight();
+
+ double xCenter = theView.getCenter().getX();
+ double yCenter = theView.getCenter().getY();
+
+ Double xMin = nv.getXPosition() - nv.getWidth()/2 -
nv.getBorderWidth();
+ Double yMin = nv.getYPosition() - nv.getHeight()/2 -
nv.getBorderWidth();
+ Double xMax = nv.getXPosition() + nv.getWidth()/2 +
nv.getBorderWidth();
+ Double yMax = nv.getYPosition() + nv.getHeight()/2 +
nv.getBorderWidth();
+
+ double xMin_screen = w/2 - (xCenter - xMin)*scaleFactor;
+ double yMin_screen = h/2 - (yCenter - yMin)*scaleFactor;
+ double xMax_screen = w/2 + (xMax - xCenter)*scaleFactor;
+ double yMax_screen = h/2 + (yMax - yCenter)*scaleFactor;
+
+ double[] xy = new double[4];
+ xy[0] = xMin_screen;
+ xy[1] = yMin_screen;
+ xy[2] = xMax_screen;
+ xy[3] = yMax_screen;
+
+ return xy;
+ }
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en
-~----------~----~----~----~------~----~------~--~---