Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [platform-swt-dev] RE: Making a composite to listen to bothDroplistener and Mouse listener for drop support andmovementrepectively.

Title: Message

Duong Nguyen has posted a response to my query on the swt mailing list that should at least partially work for me.  The others on this email thread might want to take a look at it and see if it will satisfy some of their requirements as well.

 

Duong’s Post for Posterity:

 

You should be able to send a DragDetect event any time you want. All you
have to do is create an event and notify your listeners of a DragDetect
event.

Event event = new Event();
event.button = e.button;
event.x = e.x;
event.y = e.y;
canvas.notifyListeners(SWT.DragDetect, event);

The only problem that I can see in your case is that once the real
drag-and-drop is started, you can't terminate it prematurely (and revert
back to your fake drag-move). Personally, I think your canvas should
always perform the drag-and-drop even when you're moving the painted
"objects" within your canvas area. Then, you don't have this problem.

Below is an (unrealistic) example that demonstrates how you can send a
DragDetect event.

Good luck!

package swt.examples.dnd;
/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/


/*
 * Drag and Drop example : drag text between two text widgets using
DragDetect.
 */
import org.eclipse.swt.*;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class DragDetectExample {

public static void main (String [] args) {

Display display = new Display ();
final Shell shell = new Shell (display);
shell.setLayout(new FillLayout());

Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK;

final Text text1 = new Text (shell, SWT.BORDER);
text1.setText ("SOURCE");
DragSource source = new DragSource (text1, operations);
source.setTransfer(types);
source.addDragListener (new DragSourceListener () {
public void dragStart(DragSourceEvent event) {
event.doit = (text1.getText ().length () != 0);
}
public void dragSetData (DragSourceEvent event) {
event.data = "" ();
}
public void dragFinished(DragSourceEvent event) {
}
});

final Label label = new Label (shell, SWT.BORDER);
label.setText("Press here to start drag");
label.addMouseListener(new MouseListener() {
public void mouseDoubleClick(MouseEvent e) {
}
public void mouseDown(MouseEvent e) {
Event event = new Event();
event.button = e.button;
event.x = e.x;
event.y = e.y;
text1.notifyListeners(SWT.DragDetect, event);
}
public void mouseUp(MouseEvent e) {
}
});

final Text text2 = new Text (shell, SWT.BORDER);
text2.setText ("DESTINATION");
DropTarget target = new DropTarget(text2, operations);
target.setTransfer(types);
target.addDropListener (new DropTargetAdapter() {
public void drop(DropTargetEvent event) {
if (event.data == null) {
event.detail = DND.DROP_NONE;
return;
}
text2.setText((String) event.data);
}
});

shell.setSize (400, 50);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
public static void setDragDrop (final Text text) {

}
}

 

Trip Gilman

Eclipse Voice Tools Project Lead

OpenMethods

4741 Central Street  |  Suite 285  |  Kansas City, MO  |  64112-1533

o| +1.816.283.VXML (8965) x102  c| +1.816.729.0672  f| +1.816.817.0643

trip@xxxxxxxxxxxxxxx  |  www.openmethods.com

 

 

This message (including any attachments) contains confidential information intended for a specific individual and purpose, and is protected by law.  If you are not the intended recipient, you should delete this message and are hereby notified that any disclosure, copying, or distribution of this message, or the taking of any action based on it, is strictly prohibited.


From: platform-swt-dev-bounces@xxxxxxxxxxx [mailto:platform-swt-dev-bounces@xxxxxxxxxxx] On Behalf Of Trip Gilman
Sent: Thursday, April 05, 2007 12:18 PM
To: Eclipse Platform SWT component developers list.
Subject: RE: [platform-swt-dev] RE: Making a composite to listen to bothDroplistener and Mouse listener for drop support andmovementrepectively.

 

Hi,

 

This sounds very similar to the situation I described in my post yesterday.  I’ve dug through the event system and found the proper event to post into the event queue, but I haven’t found a way to post this “fake” drag detect event into the queue without modifying the SWT source and forking it into my own custom build which is definitely not an option for the voice tools project.  I’m not sure if we have described the desired behavior very

well, so if you have any questions please do not hesitate to ask.

 

Trip Gilman

Eclipse Voice Tools Project Lead

OpenMethods

4741 Central Street  |  Suite 285  |  Kansas City, MO  |  64112-1533

o| +1.816.283.VXML (8965) x102  c| +1.816.729.0672  f| +1.816.817.0643

trip@xxxxxxxxxxxxxxx  |  www.openmethods.com

 

 

This message (including any attachments) contains confidential information intended for a specific individual and purpose, and is protected by law.  If you are not the intended recipient, you should delete this message and are hereby notified that any disclosure, copying, or distribution of this message, or the taking of any action based on it, is strictly prohibited.


From: platform-swt-dev-bounces@xxxxxxxxxxx [mailto:platform-swt-dev-bounces@xxxxxxxxxxx] On Behalf Of Kumar, Saurav
Sent: Thursday, April 05, 2007 10:20 AM
To: platform-swt-dev@xxxxxxxxxxx
Subject: [platform-swt-dev] RE: Making a composite to listen to both Droplistener and Mouse listener for drop support and movementrepectively.

 

 

Child1

 

Child2

  

 

Parent composite

 

 

 

 

 

 

 

 

 

 

 

We want move the children inside parent freely as well as allowing child to drop something inside child.

Problem is only one listener is working at time.

 

How to deal with such situation


From: Lakhanpal, Srikant
Sent: Thursday, April 05, 2007 8:38 PM
To: 'platform-swt-dev@xxxxxxxxxxx'
Subject: Making a composite to listen to both Drop listener and Mouse listener for drop support and movement repectively.

 

Dear All,

 

I have problem regarding the DND support and mouse listener.

We have a situation that we need to make a composite (which is the child of another parent composite) a drop target and also

allow it movement (using mouse listener mechanism ) within the parent composite.

 

I have to make that child composite (which behave like Drop target) setEnabled(true)... to listen to Drop event.

But at the same time to make it moveable we have to setEnabled(false) for the respective child.

 

So, is there any suggession available for get out of the problem.

any snippet or sample.

 

plzzzz reply soon it's very urgent!!!!!!!!!!!!

 

Thanks n Regards,

Srikant Lakhanpal 
Software Development Engineer
Barco | Control Rooms
A-5, Sector-5
Noida, India 
Tel      +91 120 4020000

Dir      +91 120 4020266

Fax     +91 120 4020100

mailto: srikant.lakhanpal@xxxxxxxxx 
http://www.barcocontrolrooms.com

 

DISCLAIMER:
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.


Back to the top