Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to give a user feedback during a Tracker drag(Tracker uses its own event loop apparently. How can I shows users feedback?)
icon5.gif  How to give a user feedback during a Tracker drag [message #514572] Mon, 15 February 2010 19:40 Go to next message
Mark Mising name is currently offline Mark Mising nameFriend
Messages: 73
Registered: July 2009
Location: Ohio, USA
Member
My program uses the "Tracker" widget to let users drag a box around the window. The software lacks a means of providing feedback to the user as to the exact location of the box they are dragging. In the Tracker's ControlMoved handler/listener, I can write out these coordinates to the console, but when I try to update the GUI, say through a ToolTip or through a table cell, the update is blocked until the user releases the mouse button (i.e., "drops" the Tracker).

I tried putting the Tracker object in a new Runnable using "syncExec()", but that provided no improvement over the problem. What must I do to have GUI elements update on-the-fly while a Tracker widget is being dragged by the user?

Mark
Re: How to give a user feedback during a Tracker drag [message #514660 is a reply to message #514572] Tue, 16 February 2010 09:12 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
Can you modify the below snippet for printing it on console...

*
 * Drag and Drop example snippet: define a default operation (in this example, Copy)
 *
 * For a list of all SWT example snippets see
 * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets
 */
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DragSource;
import org.eclipse.swt.dnd.DragSourceAdapter;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DropTarget;
import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class Snippet84
{

    public static void main(String[] args)
    {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new GridLayout(2, false));

        final Label label = new Label(shell, SWT.BORDER);
        label.setText("Drag Source");
        DragSource source = new DragSource(label, DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK);
        source.setTransfer(new Transfer[] { TextTransfer.getInstance() });
        source.addDragListener(new DragSourceAdapter()
        {
            @Override
            public void dragSetData(DragSourceEvent event)
            {
                event.data = "Text Transferred";
            }

            @Override
            public void dragFinished(DragSourceEvent event)
            {
                if (event.doit)
                {
                    String operation = null;
                    switch (event.detail)
                    {
                        case DND.DROP_MOVE:
                            operation = "moved";
                            break;
                        case DND.DROP_COPY:
                            operation = "copied";
                            break;
                        case DND.DROP_LINK:
                            operation = "linked";
                            break;
                        case DND.DROP_NONE:
                            operation = "disallowed";
                            break;
                        default:
                            operation = "unknown";
                            break;
                    }
                    label.setText("Drag Source (data " + operation + ")");
                }
                else
                {
                    label.setText("Drag Source (drag cancelled)");
                }
            }
        });

        final Text text = new Text(shell, SWT.BORDER | SWT.MULTI);
        text.setText("Drop Target");
        DropTarget target = new DropTarget(text, DND.DROP_DEFAULT | DND.DROP_COPY | DND.DROP_MOVE
                | DND.DROP_LINK);
        target.setTransfer(new Transfer[] { TextTransfer.getInstance() });
        target.addDropListener(new DropTargetAdapter()
        {
            @Override
            public void dragEnter(DropTargetEvent event)
            {
                if (event.detail == DND.DROP_DEFAULT) event.detail = DND.DROP_COPY;
            }

            @Override
            public void dragOperationChanged(DropTargetEvent event)
            {
                if (event.detail == DND.DROP_DEFAULT) event.detail = DND.DROP_COPY;
            }

            @Override
            public void drop(DropTargetEvent event)
            {
                String operation = null;
                switch (event.detail)
                {
                    case DND.DROP_MOVE:
                        operation = "moved";
                        break;
                    case DND.DROP_COPY:
                        operation = "copied";
                        break;
                    case DND.DROP_LINK:
                        operation = "linked";
                        break;
                    case DND.DROP_NONE:
                        operation = "disallowed";
                        break;
                    default:
                        operation = "unknown";
                        break;
                }
                text.append("\n" + operation + (String) event.data);
            }
        });

        shell.setSize(400, 400);
        final Label label1 = new Label(shell, SWT.BORDER);
        label1.setText("TEST");
        shell.addMouseMoveListener(new MouseMoveListener()
        {

            @Override
            public void mouseMove(MouseEvent e)
            {
                label1.setText(e.x + " " + e.y);
                System.out.println(e.x + " " + e.y);
            }
        });

        shell.open();
        while (!shell.isDisposed())
        {
            if (!display.readAndDispatch()) display.sleep();
        }
        display.dispose();
    }
}


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: How to give a user feedback during a Tracker drag [message #514782 is a reply to message #514572] Tue, 16 February 2010 15:55 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi Mark,

You should not have to do anything special here, I think you're seeing a
bug. The snippet below updates a Label and a TableItem with the Tracker's x
value. On win32 and OSX both of these controls update successfully, but on
GTK only the Label updates, the TableItem does not. I assume you're using
Linux or Solaris?

I've logged https://bugs.eclipse.org/bugs/show_bug.cgi?id=302961 . In the
meantime, maybe you could work around this by using a Control like Label
that stays responsive while the Tracker is open?

public static void main (String [] args) {
Display display = new Display ();
final Shell shell = new Shell (display);
final Label label = new Label(shell, SWT.NONE);
label.setBounds(10,10,100,30);
label.setText("label");
Table table = new Table(shell, SWT.NONE);
table.setBounds(10,50,100,50);
final TableItem item = new TableItem(table, SWT.NONE);
shell.open ();
shell.addListener (SWT.MouseDown, new Listener () {
public void handleEvent (Event e) {
Tracker tracker = new Tracker (shell, SWT.NONE);
tracker.setRectangles (new Rectangle [] {
new Rectangle (e.x, e.y, 100, 100),
});
tracker.addListener(SWT.Move, new Listener() {
public void handleEvent(Event event) {
System.out.println(event.x);
String string = String.valueOf(event.x);
label.setText(string);
item.setText(string);
}
});
tracker.open ();
}
});
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}

Grant


"Mark" <Mark.Fenbers@noaa.gov> wrote in message
news:hlc7vj$gn1$1@build.eclipse.org...
> My program uses the "Tracker" widget to let users drag a box around the
window. The software lacks a means of providing feedback to the user as to
the exact location of the box they are dragging. In the Tracker's
ControlMoved handler/listener, I can write out these coordinates to the
console, but when I try to update the GUI, say through a ToolTip or through
a table cell, the update is blocked until the user releases the mouse button
(i.e., "drops" the Tracker).
>
> I tried putting the Tracker object in a new Runnable using "syncExec()",
but that provided no improvement over the problem. What must I do to have
GUI elements update on-the-fly while a Tracker widget is being dragged by
the user?
>
> Mark
Re: How to give a user feedback during a Tracker drag [message #514902 is a reply to message #514782] Wed, 17 February 2010 05:47 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
But Grant...

With drag and drop operation the problem does happen...

Lets suppose user performs a drag and drop operation and tracker mechanism is used to show that drag operation...

In that case the GUI update does freez...


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: How to give a user feedback during a Tracker drag [message #515422 is a reply to message #514782] Thu, 18 February 2010 17:54 Go to previous message
Mark Mising name is currently offline Mark Mising nameFriend
Messages: 73
Registered: July 2009
Location: Ohio, USA
Member
Thanks, Grant. I have not tried updating a label -- only a tool-tip and a table cell. I verified that the code was at least being reached because it outputs to System.err just fine during a Tracker drag. So I will try a label as a possible means as a temporary work-around until the apparent bug gets fixed.

Thanks for opening a ticket...
Mark
Previous Topic:SWT Toggle Button mousehover
Next Topic:Sockets,Streams and Threads
Goto Forum:
  


Current Time: Thu Dec 26 22:39:09 GMT 2024

Powered by FUDForum. Page generated in 0.03618 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top