PDA

View Full Version : DND - Status Proxy



peternorman
23 Mar 2009, 1:45 PM
I'm currently trying to position some text on a panel with an absolute layout via drag and drop. It is working fine besides the fact that the drag proxy ( I believe that is the correct term ) appears very far way from the 'Ok' check mark. Sometimes, it appears just to the lower right just like the example and other times it is very far lower right. Is there a way of changing this behavior or changing my code if it is incorrect? Any help would be appreciated, thanks.

Here is the code in question


viewPanel = new ContentPanel ();
viewPanel.setLayout ( new CenterLayout () );
viewPanel.setHeaderVisible ( false );
viewPanel.setBorders ( true );
viewPanel.setWidth ( 740 );
viewPanel.setHeight ( 500 );

final ContentPanel cp = new ContentPanel ( new AbsoluteLayout () );
cp.setHeaderVisible ( false );
cp.setBorders ( true );
cp.setStyleAttribute ( "borderStyle", "dashed" );
cp.setSize ( 725, 485 );
cp.add ( new Image ( "images/720x380-oreillyfootball.jpg" ), new AbsoluteData ( 0, 0 ));

DropTarget target = new DropTarget ( cp )
{
protected void onDragDrop ( DNDEvent event )
{
super.onDragDrop ( event );
Html html = ( Html ) event.data;
int x = event.getClientX ();
int y = event.getClientY ();
cp.add ( html, new AbsoluteData ( x, y ) );
cp.layout ();
}
};
target.setGroup ( "test" );
target.setOverStyle ( "drag-ok" );

final Html html = new Html ( "<p><span style=\"font-size: 40px; color: #000000;\">Drag me</span></p>" );
html.sinkEvents ( Event.MOUSEEVENTS );
html.sinkEvents ( Event.ONDBLCLICK );
html.addListener ( Events.OnMouseOver, new Listener<DomEvent> ()
{
public void handleEvent ( DomEvent de )
{
html.setStyleAttribute ( "border", "1px solid red" );
}
});
html.addListener ( Events.OnMouseOut, new Listener<DomEvent> ()
{
public void handleEvent ( DomEvent de )
{
html.setStyleAttribute ( "border", "none" );
}
});
html.addListener ( Events.OnDoubleClick, new Listener<DomEvent> ()
{
public void handleEvent ( DomEvent de )
{
final Window w = new Window ();
w.setLayout ( new FitLayout () );
w.setPosition ( de.getClientX (), de.getClientY () );
w.setSize ( 400, 400 );
editor = new TinyMCE( 100, 100 );
w.add ( editor );

Button okButton = new Button ( "Ok" );
okButton.setIconStyle ( "ok" );
okButton.addSelectionListener ( new SelectionListener<ComponentEvent> ()
{
public void componentSelected ( ComponentEvent ce )
{
w.hide ();
html.setHtml ( editor.getText () );
}
});

w.addButton ( okButton );
w.setCloseAction ( Window.CloseAction.HIDE );
w.show ();
}
});
cp.add ( html, new AbsoluteData ( 20, 20 ) );

DragSource source = new DragSource ( html )
{
protected void onDragStart ( DNDEvent event )
{
event.data = html;
event.status.update ( El.fly ( html.getElement () ).cloneNode ( true ) );
}
};
source.setGroup ( "test" );

viewPanel.add ( cp );

return viewPanel;

peternorman
23 Mar 2009, 7:54 PM
Well since there are not any replies at this point I'm going to assume this is super simple and I'm overlooking something or something more difficult without a simple answer. I have been poking around since I posted my original question and found the StatusProxy object. I guess this is the actual object that is displayed while dragging. Is there a way of creating our own proxy class or modifying the behavior of the existing one?