Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Drawing scenario in SWT
Drawing scenario in SWT [message #444442] Tue, 12 October 2004 19:14 Go to next message
Bill Skrypnyk is currently offline Bill SkrypnykFriend
Messages: 2
Registered: July 2009
Junior Member
Hi all,

I have the following requirement: I need to create a way of providing a
consistent form feedback to the user, which includes drawing special red
halos around controls on validation failures and also on focus gain.

I have solved this problem in a less than elegant manner by hosting each
control in a composite with a bit of margin right around and painting
the halo in the composite. I wonder if there are better solutions.

I have come up with 3 possibilities:
1. Create a custom counterpart for each control with the sufficient
margin around the hosting control to allow the drawing -- this is
similar to my current solution.
2. Always create an invisible top-level control in the form to be drawn
last which will draw outside of its clipping region around the controls
that need to halo-ed.
3. Create an overlay window which will paint the halos in itself and be
completely transparent.

My preference lies with number 3, but I need to find out how to pass all
the events through to the underlying window.

Any comments or suggestions?

--Bill
Re: Drawing scenario in SWT [message #444444 is a reply to message #444442] Tue, 12 October 2004 21:09 Go to previous message
Veronika Irvine is currently offline Veronika IrvineFriend
Messages: 1272
Registered: July 2009
Senior Member
2 and 3 are not possible.

4. Create one composite that is the parent of the controls that need to be
drawn with halos. This composite lays out the children (could be done using
an existing layout) and draws a halo around the children as required:

public static void main(String[] args) {
Display display = new Display();
final Color red = display.getSystemColor(SWT.COLOR_RED);
Shell shell = new Shell(display);
GridLayout layout = new GridLayout(3, false);
layout.horizontalSpacing = layout.verticalSpacing = 10;
shell.setLayout(layout);

for (int i = 0; i < 20; i++) {
Button b = new Button(shell, SWT.PUSH);
if (i % 5 == 0) {
b.setText("has a halo");
b.setData("Halo", new byte[1]);
} else {
b.setText("plain");
}
}
shell.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
e.gc.setForeground(red);
Control[] children =
((Composite)e.widget).getChildren();
for (int i = 0; i < children.length; i++) {
Rectangle rect = children[i].getBounds();
boolean hasHalo =
children[i].getData("Halo") != null;
if (hasHalo) {
e.gc.drawRoundRectangle(rect.x - 3,
rect.y - 3, rect.width + 4, rect.height + 4, 10, 10);
}
}

}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}

"Bill" <vas@skrypnyk.net> wrote in message news:ckha5f$kdo$1@eclipse.org...
> Hi all,
>
> I have the following requirement: I need to create a way of providing a
> consistent form feedback to the user, which includes drawing special red
> halos around controls on validation failures and also on focus gain.
>
> I have solved this problem in a less than elegant manner by hosting each
> control in a composite with a bit of margin right around and painting the
> halo in the composite. I wonder if there are better solutions.
>
> I have come up with 3 possibilities:
> 1. Create a custom counterpart for each control with the sufficient margin
> around the hosting control to allow the drawing -- this is similar to my
> current solution.
> 2. Always create an invisible top-level control in the form to be drawn
> last which will draw outside of its clipping region around the controls
> that need to halo-ed.
> 3. Create an overlay window which will paint the halos in itself and be
> completely transparent.
>
> My preference lies with number 3, but I need to find out how to pass all
> the events through to the underlying window.
>
> Any comments or suggestions?
>
> --Bill
Previous Topic:ComboboxPropertyDescriptor
Next Topic:Double click event in "Combo"
Goto Forum:
  


Current Time: Wed Oct 28 20:41:26 GMT 2020

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

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

Back to the top