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 223156 Details for
Bug 393514
DND feedback and a drag event with image cause repaint issues on Windows
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Pure SWT test case
DNDRepaintBug.java (text/x-java), 5.94 KB, created by
Peter Severin
on 2012-11-04 23:35:38 EST
(
hide
)
Description:
Pure SWT test case
Filename:
MIME Type:
Creator:
Peter Severin
Created:
2012-11-04 23:35:38 EST
Size:
5.94 KB
patch
obsolete
>package org.eclipse.swt.snippets; > >import org.eclipse.swt.SWT; >import org.eclipse.swt.dnd.DND; >import org.eclipse.swt.dnd.DragSource; >import org.eclipse.swt.dnd.DragSourceEvent; >import org.eclipse.swt.dnd.DragSourceListener; >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.PaintEvent; >import org.eclipse.swt.events.PaintListener; >import org.eclipse.swt.graphics.GC; >import org.eclipse.swt.graphics.Point; >import org.eclipse.swt.graphics.Rectangle; >import org.eclipse.swt.layout.GridData; >import org.eclipse.swt.layout.GridLayout; >import org.eclipse.swt.widgets.Canvas; >import org.eclipse.swt.widgets.Composite; >import org.eclipse.swt.widgets.Control; >import org.eclipse.swt.widgets.Display; >import org.eclipse.swt.widgets.Label; >import org.eclipse.swt.widgets.Shell; >import org.eclipse.swt.widgets.Tree; >import org.eclipse.swt.widgets.TreeItem; > >/** > * A test case that demonstrates repaint issues on drag over. The test case > * consist of a drag source on the left and 2 drag targets on the right. Drag > * source creates a source image in drag source event. Drop targets paint a red > * rectangle under the cursor when an item is dragged over. One drag target uses > * redraw calls to invalidate and force repaint. The other additionally calls > * {@link Control#update()} to force an immediate repaint. This results in a > * repaint issue under the mouse. > */ >public class DNDRepaintBug { > public static void main(String[] args) { > final Display display = new Display(); > final Shell shell = new Shell(display); > shell.setLayout(new GridLayout(3, true)); > > new Label(shell, SWT.NONE).setText("Drag items from here"); > new Label(shell, SWT.NONE).setText("Drag over works OK"); > new Label(shell, SWT.NONE).setText("Drag over has repaint issues"); > > final Tree tree = new Tree(shell, SWT.BORDER | SWT.MULTI); > tree.setLayoutData(new GridData(GridData.FILL_BOTH)); > for (int i = 0; i < 10; i++) { > TreeItem item = new TreeItem(tree, SWT.NONE); > item.setText("item " + i); > } > > Transfer[] types = new Transfer[] { TextTransfer.getInstance() }; > int operations = DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK; > > final DragSource source = new DragSource(tree, operations); > source.setTransfer(types); > final TreeItem[] dragSourceItem = new TreeItem[1]; > source.addDragListener(new DragSourceListener() { > public void dragStart(DragSourceEvent event) { > TreeItem[] selection = tree.getSelection(); > if (selection.length > 0 && selection[0].getItemCount() == 0) { > event.doit = true; > dragSourceItem[0] = selection[0]; > } else { > event.doit = false; > } > }; > > public void dragSetData(DragSourceEvent event) { > event.data = dragSourceItem[0].getText(); > } > > public void dragFinished(DragSourceEvent event) { > if (event.detail == DND.DROP_MOVE) > dragSourceItem[0].dispose(); > dragSourceItem[0] = null; > } > }); > > // Create drop area that only calls Control#redraw > createDropArea(shell, types, operations, false); > // Create a second drop area that also calls Control#update > createDropArea(shell, types, operations, true); > > shell.setSize(600, 400); > shell.open(); > while (!shell.isDisposed()) { > if (!display.readAndDispatch()) > display.sleep(); > } > display.dispose(); > } > > private static void createDropArea(Composite parent, Transfer[] types, > int operations, boolean forceUpdate) { > final DropArea dropArea = new DropArea(parent, SWT.BORDER); > dropArea.setForceUpdate(forceUpdate); > dropArea.setLayoutData(new GridData(GridData.FILL_BOTH)); > DropTarget target = new DropTarget(dropArea, operations); > target.setTransfer(types); > target.addDropListener(new DropTargetAdapter() { > @Override > public void dragOver(DropTargetEvent event) { > paintHotspot(event); > } > > private void paintHotspot(DropTargetEvent event) { > Point pt = dropArea.toControl(new Point(event.x, event.y)); > pt.x -= pt.x % 50; > pt.y -= pt.y % 50; > dropArea.setHotSpot(new Rectangle(pt.x, pt.y, 50, 50)); > } > > @Override > public void dragEnter(DropTargetEvent event) { > paintHotspot(event); > } > > @Override > public void dragOperationChanged(DropTargetEvent event) { > paintHotspot(event); > } > > @Override > public void dragLeave(DropTargetEvent event) { > eraseHotspot(); > } > > @Override > public void drop(DropTargetEvent event) { > eraseHotspot(); > } > > private void eraseHotspot() { > dropArea.setHotSpot(null); > } > }); > } > > private static class DropArea extends Canvas { > private Rectangle hotSpot; > > private boolean forceUpdate; > > public DropArea(Composite parent, int style) { > super(parent, style); > addPaintListener(new PaintListener() { > @Override > public void paintControl(PaintEvent e) { > paint(e); > } > }); > } > > public void setForceUpdate(boolean forceUpdate) { > this.forceUpdate = forceUpdate; > } > > public void setHotSpot(Rectangle hotSpot) { > if (!eq(hotSpot, this.hotSpot)) { > Rectangle oldHotSpot = this.hotSpot; > this.hotSpot = hotSpot; > if (oldHotSpot != null) > redrawRect(oldHotSpot); > if (hotSpot != null) > redrawRect(hotSpot); > > if (forceUpdate) > update(); > } > } > > private void redrawRect(Rectangle r) { > redraw(r.x, r.y, r.width, r.height, false); > } > > private boolean eq(Rectangle a, Rectangle b) { > if (a == null) > return b == null; > else > return a.equals(b); > } > > private void paint(PaintEvent e) { > GC gc = e.gc; > Rectangle area = getClientArea(); > gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE)); > gc.fillRectangle(area); > if (hotSpot != null) { > gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_RED)); > gc.fillRectangle(hotSpot); > } > } > } >}
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 393514
:
223155
| 223156 |
223157
|
223158