Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 185075 Details for
Bug 327893
[UI] Implement DnD for Toolbars / TrimControls
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
SWT Snippet for hosting a 'drag shell'
Snippet31.java (text/java), 6.56 KB, created by
Eric Moffatt
on 2010-12-13 11:14:43 EST
(
hide
)
Description:
SWT Snippet for hosting a 'drag shell'
Filename:
MIME Type:
Creator:
Eric Moffatt
Created:
2010-12-13 11:14:43 EST
Size:
6.56 KB
patch
obsolete
>package zz; > >/* > * Tracker example snippet: create a tracker (drag when "torn off") > * > * For a list of all SWT example snippets see > * http://www.eclipse.org/swt/snippets/ > */ >import java.util.ArrayList; > >import org.eclipse.swt.*; >import org.eclipse.swt.graphics.*; >import org.eclipse.swt.layout.RowLayout; >import org.eclipse.swt.widgets.*; >import org.eclipse.ui.internal.DragHandle; > >public class Snippet31 { > static String CanDragKey = "Can Drag"; > static String CanDropKey = "Can Drop"; > > static Tracker tracker = null; > > static class DragManager { > private Display display; > private Shell dndShell; > private Shell dragShell; > > Control dragCtrl; > int offsetX; > int offsetY; > > Composite dropCandidate = null; > private Point downPoint = null; > > Listener moveListener = new Listener() { > @Override > public void handleEvent(Event event) { > if (downPoint == null || dragCtrl == null) > return; > > int dx = event.x - downPoint.x; > int dy = event.y - downPoint.y; > if (dx > 5 || dx < -5 || dy > 5 || dy < 5) { > doDrag(dragCtrl, 10, 10); > } > } > }; > > Listener buttonListener = new Listener() { > @Override > public void handleEvent(Event event) { > if (event.type == SWT.MouseDown) { > downPoint = new Point(event.x, event.y); > dragCtrl = getDragControl(); > } else if (event.type == SWT.MouseUp) { > downPoint = null; > dragCtrl = null; > } > } > }; > private Composite dragParent; > > public DragManager(Shell shell) { > dndShell = shell; > display = shell.getDisplay(); > > display.addFilter(SWT.MouseMove, moveListener); > display.addFilter(SWT.MouseDown, buttonListener); > display.addFilter(SWT.MouseUp, buttonListener); > } > > public void dispose() { > dndShell.getDisplay().removeListener(SWT.MouseMove, moveListener); > dndShell.getDisplay().removeListener(SWT.MouseDown, buttonListener); > dndShell.getDisplay().removeListener(SWT.MouseUp, buttonListener); > } > > protected Control getDragControl() { > Control ctrl = dndShell.getDisplay().getCursorControl(); > if (ctrl == null) > return null; > > Boolean canDrag = (Boolean) ctrl.getData(CanDragKey); > if (canDrag != null && canDrag.booleanValue()) > return ctrl; > > return null; > } > > public boolean doDrag(Control dragCtrl, final int offsetX, final int offsetY) { > dragParent = dragCtrl.getParent(); > dndShell.setCapture(true); > > dragShell = new Shell(dndShell, SWT.NO_TRIM); > dragShell.setAlpha(140); > > dragCtrl.setParent(dragShell); > dragParent.layout(); > dragParent.update(); > dragCtrl.setLocation(0,0); > > Point curPos = display.getCursorLocation(); > dragShell.setLocation(curPos.x-offsetX, curPos.y-offsetY); > dragShell.setSize(dragCtrl.getSize()); > Region rgn = new Region(); > rgn.add(dragShell.getClientArea()); > rgn.subtract(offsetX,offsetY,1,1); > dragShell.setRegion(rgn); > dragShell.open(); > > tracker = new Tracker(display, SWT.NONE); > tracker.addListener(SWT.Move, new Listener() { > Color curDropColor = null; > > @Override > public void handleEvent(Event event) { > switch (event.type) { > case SWT.Move: > dragShell.setLocation(event.x-offsetX, event.y-offsetY); > dropCandidate = getDropControl(); > if (dropCandidate != null) > dndShell.setCursor(display.getSystemCursor(SWT.CURSOR_HAND)); > else > dndShell.setCursor(display.getSystemCursor(SWT.CURSOR_NO)); > break; > } > } > > private Composite getDropControl() { > Control dropCandidate = display.getCursorControl(); > if (dropCandidate == null || !(dropCandidate instanceof Composite)) > return null; > > Boolean canDrag = (Boolean) dropCandidate.getData(CanDropKey); > if (canDrag != null && canDrag.booleanValue()) > return (Composite) dropCandidate; > > return null; > } > }); > > boolean result = tracker.open(); > > if (result && dropCandidate != null) { > dragCtrl.setParent(dropCandidate); > dropCandidate.layout(); > } else { > dragCtrl.setParent(dragParent); > dragParent.layout(); > } > > dndShell.setCapture(false); > > tracker.dispose(); > downPoint = null; > dragCtrl = null; > dragShell.dispose(); > > dndShell.setCursor(null); > > return result; > } > } > > private static void fillShell(Shell newShell, String prefix) { > Composite comp = new Composite(newShell, SWT.BORDER); > comp.setLayout(new RowLayout(SWT.VERTICAL)); > comp.setData(CanDropKey, true); > comp.setBounds(10,10,150,150); > Button b = new Button(comp, SWT.PUSH); > b.setText(prefix + ": AAAA"); > b.setLocation(10,10); > b.setSize(b.computeSize(SWT.DEFAULT, SWT.DEFAULT)); > b.setData(CanDragKey, true); > > comp = new Composite(newShell, SWT.BORDER); > comp.setLayout(new RowLayout(SWT.VERTICAL)); > comp.setData(CanDropKey, true); > comp.setBounds(160,10,150,150); > b = new Button(comp, SWT.PUSH); > b.setText(prefix + ": BBBB"); > b.setLocation(10,10); > b.setSize(b.computeSize(SWT.DEFAULT, SWT.DEFAULT)); > b.setData(CanDragKey, true); > > comp = new Composite(newShell, SWT.BORDER); > comp.setLayout(new RowLayout(SWT.VERTICAL)); > comp.setData(CanDropKey, true); > comp.setBounds(10,160,150,150); > b = new Button(comp, SWT.PUSH); > b.setText(prefix + ": CCCC"); > b.setLocation(10,10); > b.setSize(b.computeSize(SWT.DEFAULT, SWT.DEFAULT)); > b.setData(CanDragKey, true); > > comp = new Composite(newShell, SWT.BORDER); > comp.setLayout(new RowLayout(SWT.VERTICAL)); > comp.setData(CanDropKey, true); > comp.setBounds(160,160,150,150); > final ProgressBar p = new ProgressBar(comp, SWT.SMOOTH | SWT.HORIZONTAL); > p.setLocation(10,10); > p.setSize(120, 20); > p.setMinimum(0); > p.setMaximum(100); > p.setSelection(30); > p.setData(CanDragKey, true); > > Runnable timer = new Runnable() { > int value = 0; > @Override > public void run() { > if (!Display.getCurrent().isDisposed()) { > if (!p.isDisposed()) > p.setSelection(value); > value += 10; > if (value > 100) > value = 0; > Display.getCurrent().timerExec(100, this); > } > } > }; > > newShell.getDisplay().timerExec(100, timer); > } > > > public static void main(String[] args) { > final Display display = new Display(); > final Shell shell = new Shell(display); > shell.setSize(400,400); > fillShell(shell, "Main"); > > final DragManager dndManager = new DragManager(shell); > > shell.open(); > while (!shell.isDisposed()) { > if (!display.readAndDispatch()) > display.sleep(); > } > display.dispose(); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 327893
:
180959
| 185075