How to show selection when a figure is selected by mouse click [message #142021] |
Wed, 07 July 2004 11:15 |
Eclipse User |
|
|
|
Originally posted by: sibin.exorindia.com
Dear fellows working in GEF,
this is my first mail to this group.My problem is regarding draw2D
I have created one lightweight system and added a parent figure.
I also added child figures for the parent figure.Up on Mouse click on a
particular figure ,I want to show selection on that figure.I have used the
MouseListener class of the Draw2D for listening the mouse click on a
particular figure.What code should I write inside the mousePressed(event)
method to show the figure on which I clicked selected?
Is there any APIs to make a Figure slelected in the canvas ?
How the selection is managed in the view in GEF?
Please let me know........
Thanks in advance
|
|
|
Re: How to show selection when a figure is selected by mouse click [message #142039 is a reply to message #142021] |
Wed, 07 July 2004 14:38 |
Eclipse User |
|
|
|
Originally posted by: rlemaigr.ulb.ac.be
Hello,
If you only know about draw2d, an explanation about how GEF manages =
selection will probably be quite hard to understand to you, so I will on=
ly =
explain how to implement the same mechanism as the one used in GEF to sh=
ow =
seletion, without all the GEF-related details (DragTracker, =
EditParts,...). If you are interested in these details, look at the =
classes AbstractHandle and NonResizableEditPolicy.
I am not a genius in GEF so what follows could not be very reliable.
Typically, selection is shown with decorations outside of the bounds of =
=
the selected Figure and you want that these decorations move with the =
selected Figure.
To achieve this goal, the first idea you could have is to add children t=
o =
the selected Figure. But there will be two problems: the selected Figure=
=
probably has a LayoutManager, so you can't place the children as you wou=
ld =
like, and you can't place the children outside of the bounds of their =
parent Figure because if you do so they won't be visible. So you can't u=
se =
this method.
The good idea (it is the one implemented in GEF) is to add on top of =
everything a special draw2d Layer ( =3D a panel transparent to mouse eve=
nts =
) which will contains all the selection decorations.
The benefits of this are:
- now you can add the selection feedback outside of the bounds of the =
selected Figure, it will be visible,
- the selection feedback is always visible and accessible because it is =
on =
top of everything.
The drawback is:
- as the selection decorations are no more children of the selected =
figure, they won't move with it. So you have to find a way to have them =
=
move with the selected figure.
Here is such a way :
You create a special Figure subclass for your selection decoration. This=
=
Figure subclass will have two properties: an associated figure (the =
selected figure), and a draw2d Locator (to place the decoration based on=
=
the position of the selected Figure). It will listen as an =
AncestorListener to the selected Figure to know about its movements (met=
h. =
ancestorMoved(IFigure)) and when the selected figure moves, it will call=
=
this.revalidate(). You redefine the validate() method to use the Locator=
=
to set the bounds of "this". You can find useful Locators in draw2d.
For examples of how to do that, look at the org.eclipse.gef.handles =
package for the class AbstractHandle. There are a lot of types of handle=
s, =
maybe you could adapt one of them to make your own selection decoration =
=
class (maybe NonResizableHandle).
When a Figure is selected, you add your decorations to the decoration =
layer, and you remove them when the figure is deselected.
Maybe there is a simple way to do it but I don't know it. You will have =
to =
wait for better answers.
Hope this will help,
r=E9gis
On Wed, 7 Jul 2004 16:45:02 +0530, sibin <sibin@exorindia.com> wrote:
> Dear fellows working in GEF,
>
> this is my first mail to this group.My problem is regarding draw2D=
> I have created one lightweight system and added a parent figure.
> I also added child figures for the parent figure.Up on Mouse click on=
a
> particular figure ,I want to show selection on that figure.I have used=
=
> the
> MouseListener class of the Draw2D for listening the mouse click on a
> particular figure.What code should I write inside the mousePressed(eve=
nt)
> method to show the figure on which I clicked selected?
>
> Is there any APIs to make a Figure slelected in the canvas ?
>
> How the selection is managed in the view in GEF?
>
> Please let me know........
> Thanks in advance
>
>
-- =
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
|
|
|
Re: How to show selection when a figure is selected by mouse click [message #142048 is a reply to message #142021] |
Wed, 07 July 2004 15:08 |
Allen C Wong Messages: 9 Registered: July 2009 |
Junior Member |
|
|
can't you just extend the your figure with Clickable class?
FYI: this is the paintBorder method inside Clickable
/**
* If this Clickable has focus, this method paints a focus rectangle.
*
* @param graphics Graphics handle for painting
*/
protected void paintBorder(Graphics graphics) {
super.paintBorder(graphics);
if (hasFocus()) {
graphics.setForegroundColor(ColorConstants.black);
graphics.setBackgroundColor(ColorConstants.white);
Rectangle area = getClientArea();
if (isStyle(STYLE_BUTTON))
graphics.drawFocus(area.x, area.y, area.width, area.height);
else
graphics.drawFocus(area.x, area.y, area.width - 1, area.height - 1);
}
}
sibin wrote:
> Dear fellows working in GEF,
> this is my first mail to this group.My problem is regarding draw2D
> I have created one lightweight system and added a parent figure.
> I also added child figures for the parent figure.Up on Mouse click on a
> particular figure ,I want to show selection on that figure.I have used the
> MouseListener class of the Draw2D for listening the mouse click on a
> particular figure.What code should I write inside the mousePressed(event)
> method to show the figure on which I clicked selected?
> Is there any APIs to make a Figure slelected in the canvas ?
> How the selection is managed in the view in GEF?
> Please let me know........
> Thanks in advance
|
|
|
|
Powered by
FUDForum. Page generated in 0.03021 seconds