You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Thomas Grimaud <tg...@gmail.com> on 2011/02/17 03:30:41 UTC

Drag&Drop using Object

Hi,



I’m just starting with Pivot, which is really impressive by the way, and I’m
just trying to be more familiar with the Drag&Drop.



I’ve just made a Split panel, and I want to be able to move a text from one
panel to the other using drag and drop.

For that I have one label on each side and I have implemented the Drag& drop
on both of them.



I started by just putting the Text in the manifest and everything is working
fine.

But now I would like to put the Label in the manifest by using the putValue
in my DragSource,

but I can’t get the value from my DragTarget.



Am I doing something wrong?

Below the code of my Drag and Drop for one of my panel,



splitPane.getRight().setDropTarget(*new* DropTarget() {



             @Override

             *public* DropAction dragEnter(Component component, Manifest
dragContent,

                         *int* supportedDropActions, DropAction
userDropAction) {



                   DropAction dropAction = *null*;



                 *if* (dragContent.containsText()

                     && DropAction.*MOVE*.isSelected(supportedDropActions))
{

                     dropAction = DropAction.*MOVE*;

                 }



                 *return* dropAction;

             }



             @Override

             *public* *void* dragExit(Component component) {

             }



             @Override

             *public* DropAction dragMove(Component component, Manifest
dragContent,

                 *int* supportedDropActions, *int* x, *int* y, DropAction
userDropAction) {

                 *return* (dragContent.containsText() ? DropAction.*MOVE* :
*null*);

             }



             @Override

             *public* DropAction userDropActionChange(Component component,
Manifest dragContent,

                 *int* supportedDropActions, *int* x, *int* y, DropAction
userDropAction) {

                 *return* (dragContent.containsText() ? DropAction.*MOVE* :
*null*);

             }



             @Override

             *public* DropAction drop(Component component, Manifest
dragContent,

                 *int* supportedDropActions, *int* x, *int* y, DropAction
userDropAction) {

                 DropAction dropAction = *null*;

                 *try* {

                       *if* ((dragContent.containsValue("source"))) {

                         ((Label)splitPane
.getRight()).setText(((Label)(dragContent.getValue("source"))).getText());

                         *if* ((dragContent.getValue("source").equals(
splitPane.getLeft()))&& (userDropAction == DropAction.*MOVE*)){

                               ((Label)splitPane.getLeft()).setText("");

                         }

                       }

                 }

                 *catch*(IOException e){

                 }

                 dragExit(component);



                 *return* dropAction;

             }

         });



         splitPane.getRight().setDragSource(*new* DragSource() {



             *private* LocalManifest content = *null*;



             @Override

             *public* *boolean* beginDrag(Component component, *int* x, *int
* y) {

                   String text = ((Label)splitPane.getRight()).getText();



                 *if* (text != *null*) {

                     content = *new* LocalManifest();

                     content.putText(text);

                     content.putValue("source", splitPane.getRight());

                 }

                   *return* (content != *null*);

             }



             @Override

             *public* *void* endDrag(Component component, DropAction
dropAction) {

                   content = *null*;

             }



             @Override

             *public* *boolean* isNative() {

                 *return* *true*;

             }



             @Override

             *public* LocalManifest getContent() {

                 *return* content;

             }



             @Override

             *public* Visual getRepresentation() {

                 *return* *null*;

             }



             @Override

             *public* Point getOffset() {

                 *return* *null*;

             }



             @Override

             *public* *int* getSupportedDropActions() {

                 *return* DropAction.*MOVE*.getMask();

             }

         });





Thanks for your answer,

Rgds,


Tom

Re: Drag&Drop using Object

Posted by Thomas Grimaud <tg...@gmail.com>.
That works well,
Thanks



2011/2/18 Greg Brown <gk...@verizon.net>

> Try returning false from isNative(). Not 100% sure if that is the problem,
> but it is possible - unfortunately, native drags only support image, text,
> and file list (AWT limitation).
>
> G
>
>
> On Feb 16, 2011, at 9:30 PM, Thomas Grimaud wrote:
>
> Hi,
>
>
> I’m just starting with Pivot, which is really impressive by the way, and
> I’m just trying to be more familiar with the Drag&Drop.
>
>
> I’ve just made a Split panel, and I want to be able to move a text from one
> panel to the other using drag and drop.
> For that I have one label on each side and I have implemented the Drag&
> drop on both of them.
>
>
> I started by just putting the Text in the manifest and everything is
> working fine.
> But now I would like to put the Label in the manifest by using the putValue
> in my DragSource,
> but I can’t get the value from my DragTarget.
>
>
> Am I doing something wrong?
> Below the code of my Drag and Drop for one of my panel,
>
>
> splitPane.getRight().setDropTarget(*new* DropTarget() {
>
>
>              @Override
>              *public* DropAction dragEnter(Component component, Manifest
> dragContent,
>                          *int* supportedDropActions, DropAction
> userDropAction) {
>
>
>                    DropAction dropAction = *null*;
>
>
>                  *if* (dragContent.containsText()
>                      && DropAction.*MOVE*.isSelected(supportedDropActions))
> {
>                      dropAction = DropAction.*MOVE*;
>                  }
>
>
>                  *return* dropAction;
>              }
>
>
>              @Override
>              *public* *void* dragExit(Component component) {
>              }
>
>
>              @Override
>              *public* DropAction dragMove(Component component, Manifest
> dragContent,
>                  *int* supportedDropActions, *int* x, *int* y, DropAction
> userDropAction) {
>                  *return* (dragContent.containsText() ? DropAction.*MOVE*
>  : *null*);
>              }
>
>
>              @Override
>              *public* DropAction userDropActionChange(Component component,
> Manifest dragContent,
>                  *int* supportedDropActions, *int* x, *int* y, DropAction
> userDropAction) {
>                  *return* (dragContent.containsText() ? DropAction.*MOVE*
>  : *null*);
>              }
>
>
>              @Override
>              *public* DropAction drop(Component component, Manifest
> dragContent,
>                  *int* supportedDropActions, *int* x, *int* y, DropAction
> userDropAction) {
>                  DropAction dropAction = *null*;
>                  *try* {
>                        *if* ((dragContent.containsValue("source"))) {
>                          ((Label)splitPane
> .getRight()).setText(((Label)(dragContent.getValue("source"))).getText());
>                          *if* ((dragContent.getValue("source").equals(
> splitPane.getLeft()))&& (userDropAction == DropAction.*MOVE*)){
>                                ((Label)splitPane.getLeft()).setText("");
>                          }
>                        }
>                  }
>                  *catch*(IOException e){
>                  }
>                  dragExit(component);
>
>
>                  *return* dropAction;
>              }
>          });
>
>
>          splitPane.getRight().setDragSource(*new* DragSource() {
>
>
>              *private* LocalManifest content = *null*;
>
>
>              @Override
>              *public* *boolean* beginDrag(Component component, *int* x, *
> int* y) {
>                    String text = ((Label)splitPane.getRight()).getText();
>
>
>                  *if* (text != *null*) {
>                      content = *new* LocalManifest();
>                      content.putText(text);
>                      content.putValue("source", splitPane.getRight());
>                  }
>                    *return* (content != *null*);
>              }
>
>
>              @Override
>              *public* *void* endDrag(Component component, DropAction
> dropAction) {
>                    content = *null*;
>              }
>
>
>              @Override
>              *public* *boolean* isNative() {
>                  *return* *true*;
>              }
>
>
>              @Override
>              *public* LocalManifest getContent() {
>                  *return* content;
>              }
>
>
>              @Override
>              *public* Visual getRepresentation() {
>                  *return* *null*;
>              }
>
>
>              @Override
>              *public* Point getOffset() {
>                  *return* *null*;
>              }
>
>
>              @Override
>              *public* *int* getSupportedDropActions() {
>                  *return* DropAction.*MOVE*.getMask();
>              }
>          });
>
>
>
>
> Thanks for your answer,
> Rgds,
>
> Tom
>
>
>

Re: Drag&Drop using Object

Posted by Greg Brown <gk...@verizon.net>.
Try returning false from isNative(). Not 100% sure if that is the problem, but it is possible - unfortunately, native drags only support image, text, and file list (AWT limitation).

G

On Feb 16, 2011, at 9:30 PM, Thomas Grimaud wrote:

> Hi,
>  
> I’m just starting with Pivot, which is really impressive by the way, and I’m just trying to be more familiar with the Drag&Drop.
>  
> I’ve just made a Split panel, and I want to be able to move a text from one panel to the other using drag and drop.
> For that I have one label on each side and I have implemented the Drag& drop on both of them.
>  
> I started by just putting the Text in the manifest and everything is working fine.
> But now I would like to put the Label in the manifest by using the putValue in my DragSource,
> but I can’t get the value from my DragTarget.
>  
> Am I doing something wrong?
> Below the code of my Drag and Drop for one of my panel,
>  
> splitPane.getRight().setDropTarget(new DropTarget() {
>              
>              @Override
>              public DropAction dragEnter(Component component, Manifest dragContent,
>                          int supportedDropActions, DropAction userDropAction) {
>                 
>                    DropAction dropAction = null;
>  
>                  if (dragContent.containsText()
>                      && DropAction.MOVE.isSelected(supportedDropActions)) {
>                      dropAction = DropAction.MOVE;
>                  }
>  
>                  return dropAction;
>              }
>  
>              @Override
>              public void dragExit(Component component) {
>              }
>  
>              @Override
>              public DropAction dragMove(Component component, Manifest dragContent,
>                  int supportedDropActions, int x, int y, DropAction userDropAction) {
>                  return (dragContent.containsText() ? DropAction.MOVE : null);
>              }
>  
>              @Override
>              public DropAction userDropActionChange(Component component, Manifest dragContent,
>                  int supportedDropActions, int x, int y, DropAction userDropAction) {
>                  return (dragContent.containsText() ? DropAction.MOVE : null);
>              }
>  
>              @Override
>              public DropAction drop(Component component, Manifest dragContent,
>                  int supportedDropActions, int x, int y, DropAction userDropAction) {
>                  DropAction dropAction = null;
>                  try {
>                        if ((dragContent.containsValue("source"))) {
>                          ((Label)splitPane.getRight()).setText(((Label)(dragContent.getValue("source"))).getText());
>                          if ((dragContent.getValue("source").equals(splitPane.getLeft()))&& (userDropAction == DropAction.MOVE)){
>                                ((Label)splitPane.getLeft()).setText("");
>                          }
>                        }
>                  }
>                  catch(IOException e){
>                  }
>                  dragExit(component);
>  
>                  return dropAction;
>              }
>          });
>         
>          splitPane.getRight().setDragSource(new DragSource() {
>             
>              private LocalManifest content = null;
>  
>              @Override
>              public boolean beginDrag(Component component, int x, int y) {
>                    String text = ((Label)splitPane.getRight()).getText();
>  
>                  if (text != null) {
>                      content = new LocalManifest();
>                      content.putText(text);
>                      content.putValue("source", splitPane.getRight());
>                  }
>                    return (content != null);
>              }
>  
>              @Override
>              public void endDrag(Component component, DropAction dropAction) {
>                    content = null;     
>              }
>  
>              @Override
>              public boolean isNative() {
>                  return true;
>              }
>  
>              @Override
>              public LocalManifest getContent() {
>                  return content;
>              }
>  
>              @Override
>              public Visual getRepresentation() {
>                  return null;
>              }
>  
>              @Override
>              public Point getOffset() {
>                  return null;
>              }
>  
>              @Override
>              public int getSupportedDropActions() {
>                  return DropAction.MOVE.getMask();
>              }
>          });
>  
>  
> Thanks for your answer,
> Rgds,
> 
> Tom