Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Drag and Drop Questions

There's nothing special but here it is (works for me on Windows Xp):


public static void main (String[] args) {
        final Display  display = new Display ();
        Shell shell = new Shell ();
        final StyledText text = new StyledText (shell, SWT.BORDER);
        text.setBounds(10, 10, 200, 200);
        DragSource dragSource = new DragSource(shell, DND.DROP_MOVE | 
DND.DROP_COPY | DND.DROP_LINK);
        dragSource.setTransfer(new Transfer[] 
{TextTransfer.getInstance()});
        dragSource.addDragListener(new DragSourceAdapter() {
                public void dragSetData(DragSourceEvent event) {   
                        event.data = "Felipe";
                }
        });
        DropTarget dropTarget = new DropTarget (text, DND.DROP_MOVE | 
DND.DROP_COPY | DND.DROP_LINK);
        dropTarget.setTransfer(new Transfer[] 
{TextTransfer.getInstance()});
        dropTarget.addDropListener(new DropTargetAdapter() {
                public void drop(DropTargetEvent event) {
                        text.setCaretOffset(text.getCharCount()); 
                        text.insert((String)event.data);
                }
        }); 
        shell.open ();
        while (!shell.isDisposed()) {
                if (!display.readAndDispatch()) {
                        display.sleep ();
                }
        }
        display.dispose ();
}

Felipe



"Brian Sam-Bodden" <bsbodden@xxxxxxxxxxxxxxx> 
Sent by: platform-swt-dev-admin@xxxxxxxxxxx
07/26/2004 04:06 PM
Please respond to
platform-swt-dev


To
platform-swt-dev@xxxxxxxxxxx
cc

Subject
Re: [platform-swt-dev] Drag and Drop Questions






Felipe,
  Thanks for the quick reply. Could you post that code
snippet you used to get the a Shell to work as a
DragSource. I've tried but I could not get it to work.

For the drag over effect I want to draw something on
the receiving control (which is a custom control of
mine, descendant of Composite). I was just looking for
an official way to handle customization of the DragOver
effects. I currently using the dragEnter and dragLeave
events so that works just fine.

Thanks,
  Brian

> 
> Veronika is our DND guru but she won't be back till
> second week of August 
> so I going to try to give you some answers.
> 
> 1) Can a Shell be a DragSource? 
> I don't see way not, I just tried it on Windows and it
> worked fine.
> 
> 2) Can the DragOver effect be customized?
> What do you exactly need ? Change the cursor, change
> the widget selection, 
> draw something, etc ?
> TreeDragUnderEffect and TableDragUnderEffect are
> examples of drag over 
> effect. Unfortunately they are internal and can't be
> accessed. Anyhow, you 
> can use dragEnter, dragLeave, dragOver, and drop
events
> to implement your 
> own, in a way, that is what TreeDragUnderEffect and
> TableDragUnderEffect 
> do.
> 
> The swt newgroups is right place for user question,
you
> can probably get 
> better answer there.
> Thanks,
> Felipe
> 
> 
> 
> 
> "Brian Sam-Bodden" <bsbodden@xxxxxxxxxxxxxxx> 
> Sent by: platform-swt-dev-admin@xxxxxxxxxxx
> 07/26/2004 10:04 AM
> Please respond to
> platform-swt-dev
> 
> 
> To
> platform-swt-dev@xxxxxxxxxxx
> cc
> 
> Subject
> [platform-swt-dev] Drag and Drop Questions
> 
> 
> 
> 
> 
> 
> I got a couple of questions for the DND gurus:
> 1) Can a Shell be a DragSource? 
> 2) Can the DragOver effect be customized?
> 
> Thanks,
>   Brian
> _______________________________________________
> platform-swt-dev mailing list
> platform-swt-dev@xxxxxxxxxxx
>
http://dev.eclipse.org/mailman/listinfo/platform-swt-dev
> 
> 
> _______________________________________________
> platform-swt-dev mailing list
> platform-swt-dev@xxxxxxxxxxx
>
http://dev.eclipse.org/mailman/listinfo/platform-swt-dev
_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/platform-swt-dev




Back to the top