Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DragRepositionStop has previous position values

    I have a draggable label and I want to use the new position (left, top) when the drag ends. However I dont get the latest position, instead I get the previous location. For eg, when I drag for the first time, I see no change in the original left, right value. The label is moved to the new position, say p2.
    The second drag moves from p2 to p3. However the DragRepositionStop handler still has the p2 values.

    Is there a way to get the latest value in the handler? Should I use a different handler?

    Env
    eclipse 3.6
    gwt 2.0.6
    smartgwt 2.4
    ie 7

    Code:
    package com.test.client;
    
    
    import com.smartgwt.client.types.Alignment;
    import com.smartgwt.client.types.DragAppearance;
    import com.smartgwt.client.types.Overflow;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.Label;
    import com.smartgwt.client.widgets.Window;
    import com.smartgwt.client.widgets.events.DragRepositionStopEvent;
    import com.smartgwt.client.widgets.events.DragRepositionStopHandler;
    import com.google.gwt.core.client.EntryPoint;
    
    /**
     * Entry point classes define <code>onModuleLoad()</code>.
     */
    public class TestGwt implements EntryPoint {
    
    	public void onModuleLoad() {
    		Window window = new Window();
    		window.setHeight(300);
    		window.setWidth(300);
    		Canvas canvas = new Canvas();
    		window.addItem(canvas);
    		canvas.addChild(getLabel());		
    		window.show();
    	}
    
    	private Canvas getLabel() {
    		Label label = new Label();
    		label.setWidth(50);
    		label.setHeight(50);
    		label.setLeft(100);
    		label.setTop(40);
    		label.setBackgroundColor("yellow");
    		label.setAlign(Alignment.CENTER);
            label.setShowEdges(true);   
            label.setOverflow(Overflow.HIDDEN);
            displayLabelPosition(label);
            
            label.setCanDragReposition(true);
            label.setDragAppearance(DragAppearance.OUTLINE);
    		label.addDragRepositionStopHandler(getDragRepositionStopHandler());
    	
    		
    		return label;
    	}
    
    	private DragRepositionStopHandler getDragRepositionStopHandler() {
    		return new DragRepositionStopHandler() {
    			
    			public void onDragRepositionStop(DragRepositionStopEvent event) {
    				displayLabelPosition((Label) event.getSource());
    			}
    		};
    	}
    
    	private void displayLabelPosition(Label label) {
    		label.setContents("l=" + label.getLeft() + " t=" + label.getTop());
    	}
    	
    	
    	
    }

    #2
    I tried monitoring event.getX() and getY()
    Thou these values seems to be different from the label position. I guess they follow the cursor position instead of the label left and top.

    Comment


      #3
      Is there an alternate way to get the final position of drag movement?

      Thanks
      Balaji

      Comment


        #4
        Found a work around. I deferred executing my code and then I see updated label position.

        Comment


          #5
          Originally posted by jbalaji
          Found a work around. I deferred executing my code and then I see updated label position.
          Hi,

          I'm struggling with the same issue. Would you care to share your workaround please?

          TIA
          Graham

          Comment


            #6
            Thanks, found a solution

            Comment


              #7
              Hi everyone,

              I'm new to this forum and just found it by googling for the same problem as the thread-creator
              (getting the previuos values at DragRepositionStop) - and seemingly jbalaji and gsasmurf found a solution to this problem.

              Well, it's nice to read that you have overcome your problems, but wouldn't it be nicer if everyone knew how you did it?

              Because I have not found a workaround until now - and would appreciate it very much, if you shared your solution(s).

              Thank you very much,
              castar.

              ---
              As it happens, I found a solution/workaround in this forum - thanks to jbalaji:

              Code:
              public void onDragRepositionStart(DragRepositionStartEvent event) {
              	oldPositionX = event.getX();
              	oldPositionY = event.getY();
              	...
              
              }
              
              public void onDragRepositionStop(DragRepositionStopEvent event) {
              	Canvas canvas = (Canvas) event.getSource();
              			
              	int displaceX = event.getX() - oldPositionX;
              	int displaceY = event.getY() - oldPositionY;
              	canvas.setLeft(canvas.getLeft() + displaceX);
              	canvas.setTop(canvas.getTop() + displaceY);
              	...
              }
              ---

              But there's a problem with this approach: it takes the position of the mouse and stores it -
              that does only work, if the relative position of mouse cursor and canvas does not change;
              but it can change if the canvas is kept in a parent rectangle... so this approach does not work
              properly.
              Last edited by castar; 27 Sep 2011, 03:41. Reason: found a solution

              Comment

              Working...
              X