Login | Register
My pages Projects Community openCollabNet

Discussions > dev > Fix for Bug # 292 in GEF

Discussion topic

Back to topic list

Fix for Bug # 292 in GEF


Author "Edward J dot Lyons Jr dot " <ed at netnumina dot com>
Full name "Edward J dot Lyons Jr dot " <ed at netnumina dot com>
Date 2001-01-04 22:10:30 PST
Message OK -

Here is the fix for selections being dragged off the screen permanently (GEF
Bug # 292).

I have tested the modified files and it works great - even for multiple
figure selection.

There are two files that must be changed:


(I have attached both modified files)

SelectionManager needs a new method called "getLocation()" This method
already exists in Selection and just provides the upper left coordinate for
the figure. I needed to have it for the whole selection so I could have the
absolute coordinate for the upper left hand coordinate of the bounding box.
Why? Because I only have access to the SelectionManager from ModeModify,
where the checking needs to take place.

Here is the new method for SelectionManager


   * This method will return the upper-left coordinate point
   * of the entire selection by iterating through the figs
   * @return Point - the point for that upper left corner
  public Point getLocation() {

     int size = _selections.size();

     if (size < 1) return new Point(0,0);

     Selection sel = null;

     // I just set these to two unbelievably big numbers

     int lowestX = 32000;
     int lowestY = 32000;

     Point pt = null;

     for (int i = 0; i < size; i++) {
      sel = (Selection) _selections.elementAt(i);
      pt = sel.getLocation();
      if (pt.getX() < lowestX)
        { lowestX = (int) pt.getX(); }
      if (pt.getY() < lowestY)
        { lowestY = (int) pt.getY(); }

    pt = null;
    sel = null;

    return new Point(lowestX,lowestY);


ModeModify needs two changes. In mouseDragged(), it needs to check to see
if the move would bring any part of the selection out of bounds. So on line
162, we need to change it to:

if (legal(dx, dy, sm, me) && !outOfBounds(dx,dy,me,sm)) {

Then we need to have the new method, outOfBounds...

   * This method will check to see if the selection bein moved will end up
   * off the screen and off the diagram. There is just no easy way to do
   * especially because there could be more than one fig selected!
   * @param dx - horizontal distance to move
   * @param dy - vertical distance to move
   * @param me - the mouse event
   * @param sm - the selection manager
   * @returns boolean - is it out of bounds? ( T / F )
  protected boolean outOfBounds(int dx, int dy, MouseEvent me,
SelectionManager sm) {

   Rectangle selectionBox = sm.getContentBounds();

   int selectionHeight = (int)selectionBox.getHeight();
   int selectionWidth = (int)selectionBox.getWidth();

   // Get top-left most point of the whole selection
   Point selectionOrigin = sm.getLocation();

   int selectionOriginX = (int)selectionOrigin.getX();
   int selectionOriginY = (int)selectionOrigin.getY();

   int targetY = me.getY();
   int targetX = me.getX();

   // These offsets tell us where the drag point is in relation to
   // the selection it is in. We need this information so that we don't
   // let varying parts of the selection go outside the bounds just because
   // the drag point was in different parts of the selection

   int topVerticalOffset = _lastY - selectionOriginY;
   int bottomVerticalOffset = selectionOriginY + selectionHeight - _lastY;

   int leftHorizontalOffset = _lastX - selectionOriginX;
   int rightHorizontalOffset = selectionOriginX + selectionWidth - _lastX;

    * OK, what we're saying here is that if the destination point is less
    * zero, forget it. But if you move less than zero, but part of your
    * would be in the negative zone, you cannot do that either.

   // Check top
   if ((targetY < 0 ) || (targetY < topVerticalOffset) ) return true;

   // Check bottom

   int canvasBottomEdge = me.getComponent().getHeight();

   if ((targetY > canvasBottomEdge ) ||
      ((targetY + bottomVerticalOffset) > canvasBottomEdge ) ) return true;

   // Check left
   if ((targetX < 0 ) || (targetX < leftHorizontalOffset) ) return true;

   // Check right

   int canvasRightEdge = me.getComponent().getWidth();

   if ((targetX > canvasRightEdge ) ||
      ((targetX + rightHorizontalOffset) > canvasRightEdge ) ) return true;

   // Otherwise we're ok!
    return false;


Well, that's it. Please let me know if you have any questions.


 <<SelectionMan​ager.java>> <<ModeModify.java>>

« Previous message in topic | 1 of 3 | Next message in topic »


Show all messages in topic

Fix for Bug # 292 in GEF "Edward J dot Lyons Jr dot " <ed at netnumina dot com> "Edward J dot Lyons Jr dot " <ed at netnumina dot com> 2001-01-04 22:10:30 PST
     Re: [argouml-dev] Fix for Bug # 292 in GEF carnold Curt Arnold 2001-01-04 22:59:58 PST
     Re: Fix for Bug # 292 in GEF Thorsten Sturm <1sturm at informatik dot uni-hamburg dot de> Thorsten Sturm <1sturm at informatik dot uni-hamburg dot de> 2001-01-05 05:27:18 PST
Messages per page: