Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Trackers / Rubber bands
Trackers / Rubber bands [message #447254] Fri, 10 December 2004 17:58 Go to next message
Mani Ghamari is currently offline Mani GhamariFriend
Messages: 33
Registered: July 2009
Member
Hi All,

I am developing an FTP client (SWT, Stand alone).
I used a ScrolledComposite to implement an "Icon View" of the files just
like the Icons View in windows explorer.

My custom widget (IconListComposite extends Composite) has a
ScrolledComposite inside. The content of the ScrolledComposite is another
Composite (RowLayout) which is the actual parent of each IconComposite.

The IconComposite class (which extends Composite, of course) has a Canvas
(style: SWT.NO_FOCUS) which paints the icon image and a label for the
filename. The IconComposite has a setSelected(boolean selected) method which
just changes the background (/ foreground) of the composite, the canvas and
the label, when the Icon is selected or deselected.

So far so good...

I need to implement the rubber band functionallity for selections
(everything withing the drag rectangle is selected).

My first approach was to draw the selection rectabgle manally on iconList,
the Composite which holds the Icons (which is the content of the
ScrolledComposite), using addPaintListener(). Yet as you probably already
know, Contorls (IconComposites) are painted OVER the rectangle ( ie: my
paintConrol() is called AFTER the Icons are painted (?)).
So after a couple of days of trying and struggling, I decided to go with a
Tracker Control.

I want to know, whether it is possible to implement this WITHOUT using the
Tracker control. If it is not possible, are there any workarounds for the
following problems?:

The code below almost works but I have a coule of problems:
- The "Sticky" behavoir (and the change of mouse pointer) of the tracker
control is very undesirable for my application.

- The Tracker has a low performance, especially when there are a lot of
icons (The manual painting apporach to the rubberband did not display
correctly, yet the performace was way better)

- BIG ISSUE:
(See the screenshots in the attachments).
If I select a number of icons (att: drag_select.jpg), and the downsize the
tracker again so that some of the selected Icons are deselected again
(drag_deselect.jpg), the Tracker leaves its trace on the IconComposites!

The faster the deselection is occured, the more "trace marks" I get. The
traces remain until the Composite is redrawn by the OS (Scrolling out of and
back to visible area, minimizing/resotring the shell, etc).
I have already tried all the combinations of explicit .redraw(), .update(),
layout() and layout(boolean) calls on iconList ( & scroller.getContent() ),
on individual
IconComposites, on the IconListComposite and even on
IconListComposite.getParent() (both during (in controlResized()) and after
the tracker is visible).
Yet none of above mentioned metohd calls seem to have an effect!

I would be thankfull for any comments / ideas on this....

here is some of the code:

void dragDetected(int x. int y) // x, y = mouse location
{
trackIt(x, y);
}

private void trackIt(int x, int y)
{

Tracker tracker = new Tracker(iconList, SWT.RESIZE);
tracker.setRectangles (new Rectangle [] {new Rectangle (x, y, 1, 1)});
tracker.setStippled(true);
final boolean[] selection = getIsSelectedForAll(); //save initial
selection (for CTRL+drag)
tracker.addControlListener(new ControlAdapter()
{
public void controlResized(ControlEvent e)
{
changeSelections(((Tracker)e.getSource()).getRectangles()[0] ,
selection);
// iconList.update(); //Has no effect
}
});
tracker.open ();
//set the selections again after the tracker was closed
changeSelections(tracker.getRectangles()[0], selection);
tracker.dispose();
isDragging = false;
iconList.update();
}

private void changeSelections(Rectangle selection, boolean[]
initialSelection)
{
// System.out.println("changeSelection()");
Control[] icons = iconList.getChildren();
IconComposite ic;
for (int i=0; i<icons.length; i++)
{
if (icons[i].getClass().equals(IconComposite.class))
{
ic = (IconComposite) thumbs[i];
if (selection.intersects(ic.getBounds()) ||
ic.getBounds().contains(selection.x, selection.y))
{
// Intersection with tracker
if (isDragControlDown)
{
//CTRL is down, Reverse Selection
ic.setSelected(!initialSelection[i]);
}
else
{
//No CTRL, Select Icon
ic.setSelected(true);
}
}
else
{
// NO Intersection with tracker

if (!isDragControlDown)
{
// NO CTRL, Deselect Icon.
t.setSelected(false);
}
else
{
// CTRL is dwon, Dont change selection
t.setSelected(initialSelection[i]);
}
}
ic.update(); // has no effect
}
}
}


Thanks,

Mani Ghamari
Re: Trackers / Rubber bands - Attachments [message #447255 is a reply to message #447254] Fri, 10 December 2004 18:00 Go to previous message
Mani Ghamari is currently offline Mani GhamariFriend
Messages: 33
Registered: July 2009
Member
Oops, I forgot the attachments ;)
here they go...

"Mani Ghamari" <mani.ghamari@linkast.com> wrote in message
news:cpco4d$d53$1@www.eclipse.org...
> Hi All,
>
> I am developing an FTP client (SWT, Stand alone).
> I used a ScrolledComposite to implement an "Icon View" of the files just
> like the Icons View in windows explorer.
>
> My custom widget (IconListComposite extends Composite) has a
> ScrolledComposite inside. The content of the ScrolledComposite is another
> Composite (RowLayout) which is the actual parent of each IconComposite.
>
> The IconComposite class (which extends Composite, of course) has a Canvas
> (style: SWT.NO_FOCUS) which paints the icon image and a label for the
> filename. The IconComposite has a setSelected(boolean selected) method
> which
> just changes the background (/ foreground) of the composite, the canvas
> and
> the label, when the Icon is selected or deselected.
>
> So far so good...
>
> I need to implement the rubber band functionallity for selections
> (everything withing the drag rectangle is selected).
>
> My first approach was to draw the selection rectabgle manally on iconList,
> the Composite which holds the Icons (which is the content of the
> ScrolledComposite), using addPaintListener(). Yet as you probably already
> know, Contorls (IconComposites) are painted OVER the rectangle ( ie: my
> paintConrol() is called AFTER the Icons are painted (?)).
> So after a couple of days of trying and struggling, I decided to go with a
> Tracker Control.
>
> I want to know, whether it is possible to implement this WITHOUT using the
> Tracker control. If it is not possible, are there any workarounds for the
> following problems?:
>
> The code below almost works but I have a coule of problems:
> - The "Sticky" behavoir (and the change of mouse pointer) of the tracker
> control is very undesirable for my application.
>
> - The Tracker has a low performance, especially when there are a lot of
> icons (The manual painting apporach to the rubberband did not display
> correctly, yet the performace was way better)
>
> - BIG ISSUE:
> (See the screenshots in the attachments).
> If I select a number of icons (att: drag_select.jpg), and the downsize the
> tracker again so that some of the selected Icons are deselected again
> (drag_deselect.jpg), the Tracker leaves its trace on the IconComposites!
>
> The faster the deselection is occured, the more "trace marks" I get. The
> traces remain until the Composite is redrawn by the OS (Scrolling out of
> and
> back to visible area, minimizing/resotring the shell, etc).
> I have already tried all the combinations of explicit .redraw(),
> .update(),
> layout() and layout(boolean) calls on iconList ( &
> scroller.getContent() ),
> on individual
> IconComposites, on the IconListComposite and even on
> IconListComposite.getParent() (both during (in controlResized()) and after
> the tracker is visible).
> Yet none of above mentioned metohd calls seem to have an effect!
>
> I would be thankfull for any comments / ideas on this....
>
> here is some of the code:
>
> void dragDetected(int x. int y) // x, y = mouse location
> {
> trackIt(x, y);
> }
>
> private void trackIt(int x, int y)
> {
>
> Tracker tracker = new Tracker(iconList, SWT.RESIZE);
> tracker.setRectangles (new Rectangle [] {new Rectangle (x, y, 1, 1)});
> tracker.setStippled(true);
> final boolean[] selection = getIsSelectedForAll(); //save initial
> selection (for CTRL+drag)
> tracker.addControlListener(new ControlAdapter()
> {
> public void controlResized(ControlEvent e)
> {
> changeSelections(((Tracker)e.getSource()).getRectangles()[0] ,
> selection);
> // iconList.update(); //Has no effect
> }
> });
> tracker.open ();
> //set the selections again after the tracker was closed
> changeSelections(tracker.getRectangles()[0], selection);
> tracker.dispose();
> isDragging = false;
> iconList.update();
> }
>
> private void changeSelections(Rectangle selection, boolean[]
> initialSelection)
> {
> // System.out.println("changeSelection()");
> Control[] icons = iconList.getChildren();
> IconComposite ic;
> for (int i=0; i<icons.length; i++)
> {
> if (icons[i].getClass().equals(IconComposite.class))
> {
> ic = (IconComposite) thumbs[i];
> if (selection.intersects(ic.getBounds()) ||
> ic.getBounds().contains(selection.x, selection.y))
> {
> // Intersection with tracker
> if (isDragControlDown)
> {
> //CTRL is down, Reverse Selection
> ic.setSelected(!initialSelection[i]);
> }
> else
> {
> //No CTRL, Select Icon
> ic.setSelected(true);
> }
> }
> else
> {
> // NO Intersection with tracker
>
> if (!isDragControlDown)
> {
> // NO CTRL, Deselect Icon.
> t.setSelected(false);
> }
> else
> {
> // CTRL is dwon, Dont change selection
> t.setSelected(initialSelection[i]);
> }
> }
> ic.update(); // has no effect
> }
> }
> }
>
>
> Thanks,
>
> Mani Ghamari
>
>



Previous Topic:Dolphin Web Browser, based on org.eclipse.swt.browser.Browser
Next Topic:long menus: what to do?
Goto Forum:
  


Current Time: Fri Apr 26 05:56:29 GMT 2024

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

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

Back to the top