You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by Noel Grandin <no...@gmail.com> on 2009/04/13 12:28:41 UTC

outline decorator

Hi

I'm trying to implement a Decorator that will add a red border around
a component. I've got the following, which seems to work sometimes,
but not always.

What am I doing wrong?

Thanks, Noel.

	/** draws a red border around a component */
	private final class OutlineDecorator implements Decorator {
		private Component component = null;
		private Graphics2D graphics = null;

		public Graphics2D prepare(Component component, Graphics2D graphics) {
			this.component = component;
			this.graphics = graphics;

			return graphics;
		}

		public void update() {
			graphics.setColor(Color.RED);
			graphics.drawRect(-1, -1, component.getWidth() + 1, component
					.getHeight() + 1);
		}

		public Bounds getBounds(Component component) {
			return new Bounds(-1, -1, component.getWidth() + 1, component
					.getHeight() + 1);
		}

		public AffineTransform getTransform(Component component) {
			return new AffineTransform();
		}
	}

Re: outline decorator

Posted by Noel Grandin <no...@gmail.com>.
Thanks, I wasn't aware of that limitation in Decorator.
Yes, a ShadeDecorator works much better.

On Mon, Apr 13, 2009 at 16:59, Todd Volkert <tv...@gmail.com> wrote:
> If this is the case, and if you're using this for your builder app (as
> the user selects a component in the hierarchy, for example) maybe a
> shade decorator would suit your needs more.
>

Re: outline decorator

Posted by Todd Volkert <tv...@gmail.com>.
If this is the case, and if you're using this for your builder app (as
the user selects a component in the hierarchy, for example) maybe a
shade decorator would suit your needs more.

On Mon, Apr 13, 2009 at 10:57 AM, Greg Brown <gk...@mac.com> wrote:
> OK. Are you trying to use it to paint outside the bounds of the component's parent? For example, is your component's location set to 0, 0? If so, that would explain it. Decorators can paint outside of their components' bounds, but not their components' parents' bounds.
>
> On Monday, April 13, 2009, at 09:49AM, "Noel Grandin" <no...@gmail.com> wrote:
>>I'm applying it to various components.
>>On some components, it works, on others, not.
>>The attached image is a "not working" case
>>
>>the code looks like this:
>>   this.selectedComponent.getDecorators().add(outlineDecorator);
>>so nothing special.
>>
>>On Mon, Apr 13, 2009 at 15:02, Greg Brown <gk...@mac.com> wrote:
>>>>I'm trying to implement a Decorator that will add a red border around
>>>>a component. I've got the following, which seems to work sometimes,
>>>>but not always.
>>>
>>> At a quick glance, it seems OK. Under what circumstances does it not work properly? Do you have some sample code that demonstrates how you are using this decorator?
>>>
>>>
>>>
>>
>>
>

Re: outline decorator

Posted by Greg Brown <gk...@mac.com>.
OK. Are you trying to use it to paint outside the bounds of the component's parent? For example, is your component's location set to 0, 0? If so, that would explain it. Decorators can paint outside of their components' bounds, but not their components' parents' bounds.
 
On Monday, April 13, 2009, at 09:49AM, "Noel Grandin" <no...@gmail.com> wrote:
>I'm applying it to various components.
>On some components, it works, on others, not.
>The attached image is a "not working" case
>
>the code looks like this:
>   this.selectedComponent.getDecorators().add(outlineDecorator);
>so nothing special.
>
>On Mon, Apr 13, 2009 at 15:02, Greg Brown <gk...@mac.com> wrote:
>>>I'm trying to implement a Decorator that will add a red border around
>>>a component. I've got the following, which seems to work sometimes,
>>>but not always.
>>
>> At a quick glance, it seems OK. Under what circumstances does it not work properly? Do you have some sample code that demonstrates how you are using this decorator?
>>
>>
>>
>
>

Re: outline decorator

Posted by Noel Grandin <no...@gmail.com>.
I'm applying it to various components.
On some components, it works, on others, not.
The attached image is a "not working" case

the code looks like this:
   this.selectedComponent.getDecorators().add(outlineDecorator);
so nothing special.

On Mon, Apr 13, 2009 at 15:02, Greg Brown <gk...@mac.com> wrote:
>>I'm trying to implement a Decorator that will add a red border around
>>a component. I've got the following, which seems to work sometimes,
>>but not always.
>
> At a quick glance, it seems OK. Under what circumstances does it not work properly? Do you have some sample code that demonstrates how you are using this decorator?
>
>
>

Re: outline decorator

Posted by Greg Brown <gk...@mac.com>.
>I'm trying to implement a Decorator that will add a red border around
>a component. I've got the following, which seems to work sometimes,
>but not always.

At a quick glance, it seems OK. Under what circumstances does it not work properly? Do you have some sample code that demonstrates how you are using this decorator?