Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Draw2d paint problem when dragging with image in Eclipse 3.3
Draw2d paint problem when dragging with image in Eclipse 3.3 [message #238025] Mon, 20 August 2007 14:24
Eclipse UserFriend
Originally posted by: liziwen.yahoo.com

In Eclipse3.3 SWT DND supports image dragsource effects. But when I try it
in draw2d I met some problems which draw2d can not update the dirty
region. I have tried the performUpdate but it does not work. Did I miss
some function call or other solutions? thanks.
The following is the snippet of example:

public class Test {

private IFigure sourceFigure;

Image image;

/**
* @param args
*/
public static void main(String[] args) {
new Test();
}

public Test(){
final Display d = new Display();
Shell s = new Shell(d);
s.setLayout(new FillLayout());
Transfer[] types = new Transfer[] {TextTransfer.getInstance()};
final FigureCanvas canvas1 = createContents(s);
DragSource ds = new DragSource(canvas1, DND.DROP_COPY | DND.DROP_MOVE);
ds.setTransfer(types);
ds.addDragListener(new DragSourceListener(){

public void dragFinished(DragSourceEvent event) {

}

public void dragSetData(DragSourceEvent event) {
event.data = "";
}

public void dragStart(DragSourceEvent event) {
IFigure dot = canvas1.getContents().findFigureAt(event.x, event.y);
if(image != null) image.dispose();
image = new Image(d, dot.getBounds().width, dot.getBounds().height);
GC gc = new GC(canvas1);
gc.copyArea(image, dot.getBounds().x, dot.getBounds().y);
gc.dispose();
event.image = image;
}

});

final FigureCanvas canvas2 = createContents(s);
DropTarget dt = new DropTarget(canvas2, DND.DROP_COPY | DND.DROP_MOVE);
dt.setTransfer(types);
dt.addDropListener(new DropTargetListener(){

public void dragEnter(DropTargetEvent event) {
}

public void dragLeave(DropTargetEvent event) {
}

public void dragOperationChanged(DropTargetEvent event) {
}

public void dragOver(DropTargetEvent event) {
Point pt = d.map(null, canvas2, new Point(event.x, event.y));
IFigure figure = canvas2.getContents().findFigureAt(pt.x, pt.y);

if(sourceFigure == null){
figure.setBackgroundColor(d.getSystemColor(SWT.COLOR_RED));
figure.repaint();
}
else{
if(!figure.equals(sourceFigure)){
figure.setBackgroundColor(d.getSystemColor(SWT.COLOR_RED));
sourceFigure.setBackgroundColor(d.getSystemColor(SWT.COLOR_B LUE));
}
}
sourceFigure = figure;
}

public void drop(DropTargetEvent event) {
event.data = "";
}

public void dropAccept(DropTargetEvent event) {

}

});
s.open();
while(!s.isDisposed()){
if(!d.readAndDispatch()){
d.sleep();
}
}
d.dispose();
}

FigureCanvas createContents(Shell s){
FigureCanvas canvas = new FigureCanvas(s, SWT.DOUBLE_BUFFERED);
Figure panel = new Figure();
int y = 0;
for(int i = 0; i < 10; i++){
Figure rf = new Figure();
rf.setBackgroundColor(canvas.getDisplay().getSystemColor(SWT .COLOR_BLUE));
rf.setOpaque(true);
rf.setBounds(new Rectangle(0, y + 40 * i, 100, 40));
panel.add(rf);
}
canvas.setContents(panel);
return canvas;
}

}
Previous Topic:Shift Click event
Next Topic:Paint Polyline iterative
Goto Forum:
  


Current Time: Fri Apr 26 12:15:38 GMT 2024

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

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

Back to the top