Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] Regarding Highlighting drop target in swt

Hi All,

I am new to SWT/eclipse environment and I have a requirement to highlight the drop target which is a ScrolledForm.

Following is the part of code that I have written.

 

// added drop support

@Override

protected void addDropSupport()

    {

        // getting control from viewer. This is scrolled form

       Control control = ssViewer.getControl();

        int operations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_DEFAULT;

        Transfer[] transferTypes = { ComponentTransfer.getInstance(),FileTransfer.getInstance() };

        myDropTargetEffect mdte=null;

        int operations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_DEFAULT;

        Transfer[] transferTypes = { ComponentTransfer.getInstance(),FileTransfer.getInstance() };

                                DropTarget dropTarget = new DropTarget(control, operations);

        MyDropTargetEffect mdte= new MyDropTargetEffect(control);

        dropTarget.setDropTargetEffect( mdte );

        dropTarget.setTransfer(transferTypes);

        dropTarget.addDropListener(listener);

   

    }

// created class MyDropTargetEffect

class MyDropTargetEffect extends DropTargetEffect

    {

       Control ctrl;

        public MyDropTargetEffect(Control control) {

            super(control);

                                                this.ctrl=control;

        }

        @Override

        public void dragEnter(DropTargetEvent event)

        {

            // getting GC

            GC gc= new GC(ctrl);

            Color color = ctrl.getDisplay().getSystemColor(SWT.COLOR_BLUE);

            gc.setForeground(color);

            gc.setLineWidth(4);

            Rectangle rect = ctrl.getBounds();

            // drawing rectangle

            gc.drawRectangle(rect.x, rect.y,rect.width,

                    rect.height);

            gc.dispose();

           ctrl.redraw();

        }

     }

 

Even after this I am not seeing any desired effect.

Am I missing something here? Any help is appreciated.

 

 

Thanks and Regards,

Mahesh


Back to the top