List Info

Thread: drag and drop PopupPanel




drag and drop PopupPanel
user name
2006-07-29 16:46:57
i made my own class to make a non-modal popuppanel. i just
used the
code of class PopupPanel and commented out some of its lines
of code
which were making it modal. now i was having a problem with
dragging
it. as some of other people have mentioned in the forum that
when u try
to drag and drop an object using onmousedown and onmouseup
events, it
doesnt work. mouse moves faster than the object being
dragged and when
object is left behind, it stops dragging. the technique used
is here:

public void onMouseDown(Widget sender, int x, int y) {
	  if(dragging==false)
	   dragging = true;

                   dragStartX = x;
	   dragStartY = y;
 }


public void onMouseMove(Widget sender, int x, int y) {
    if (dragging==true) {

      int absX = x + pPanel.getAbsoluteLeft();
      int absY = y + pPanel.getAbsoluteTop();
      pPanel.setPopupPosition(absX - dragStartX, absY -
dragStartY);
    }
  }

  public void onMouseUp(Widget sender, int x, int y) {
    if(dragging==true)
	dragging = false;
  }


but it doesnt work properly. when u click on an object, u
cant drag it
until u leave the mouse button (mouseup event is not
triggered when u
click on that object and move it a little bit). then object
moves with
the object. u need to click again to stop dragging (clicking
again
triggers the mouseup event). and as i mentioned, if u move
mouse fast,
object being dragged is left behind. The simple solution is
to use the
setCaputure(Element)  of DOM class on mousedown event and
releaseCaputre(Element) method on mouseup event. and drag n
drop works
fine. here is the updated  code that i am giving here to
save others'
time. i spent my whole day on it :(


public void onMouseDown(Widget sender, int x, int y) {
          if(dragging==false)
	   dragging = true;

	   DOM.setCapture(sender.getElement());
	   dragStartX = x;
	   dragStartY = y;
	 }


public void onMouseMove(Widget sender, int x, int y) {
    if (dragging==true) {
      int absX = x + pPanel.getAbsoluteLeft();
      int absY = y + pPanel.getAbsoluteTop();
      pPanel.setPopupPosition(absX - dragStartX, absY -
dragStartY);
    }
  }

  public void onMouseUp(Widget sender, int x, int y) {
    if(dragging==true)
	dragging = false;
    DOM.releaseCapture(sender.getElement());
  }


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "JavaScript Forum" group.
To post to this group, send email to
JavaScript-Informationgooglegroups.com
To unsubscribe from this group, send email to
JavaScript-Information-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/JavaScript-Information
-~----------~----~----~----~------~----~------~--~---

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )