You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Przemek Więch <pw...@gmail.com> on 2011/03/23 15:29:59 UTC

Image editor canvas

Hi!

I'm trying to create a simple vector image editor using Pivot. I have a
problem in creating a canvas component, on which I will be able to draw
shapes. So the questions are:

1. Which class should I subclass to create my canvas component? Component?
Image?

2. How does the idea of a canvas on which I can click and draw relate to the
concept of component skins?

Cheers,
Przemek

Re: Image editor canvas

Posted by Greg Brown <gk...@verizon.net>.
> On Thu, Mar 24, 2011 at 14:07, Greg Brown <gk...@verizon.net> wrote:
>> 1. Which class should I subclass to create my canvas component? Component? Image?
> 
> Component
> 
>> 2. How does the idea of a canvas on which I can click and draw relate to the concept of component skins?
> 
> ComponentSkin (abstract) registers to receive mouse events from its component. You can create a concrete subclass that responds to those events in whatever way is appropriate for your component.
> 
> 
> Thanks for the answer. I finally subclassed the Panel class and I'm receiving mouse events in this class. When I tried to subclass Component, I had to implement several methods such as getWidth which referred to the skin, which I don't have.
> 
> It works for me but I'm not sure if it's the right approach. Perhaps I should subclass Container and attach a subclass of Skin. I still don't know how I should divide my code between Component and Skin.

There's nothing wrong with subclassing Panel. However, the recommended approach would be to subclass Component and ComponentSkin. In your component's constructor, you can call setSkin(new MyComponentSkin()). That will install the skin and cause mouse, keyboard, etc. events to be directed to the skin. You'd implement your drawing code in your skin's paint() method rather than overriding Component#paint().

G



Re: Image editor canvas

Posted by Przemek Więch <pw...@gmail.com>.
On Thu, Mar 24, 2011 at 14:07, Greg Brown <gk...@verizon.net> wrote:

> 1. Which class should I subclass to create my canvas component? Component?
> Image?
>
>
> Component
>
> 2. How does the idea of a canvas on which I can click and draw relate to
> the concept of component skins?
>
>
> ComponentSkin (abstract) registers to receive mouse events from its
> component. You can create a concrete subclass that responds to those events
> in whatever way is appropriate for your component.
>
>
Thanks for the answer. I finally subclassed the Panel class and I'm
receiving mouse events in this class. When I tried to subclass Component, I
had to implement several methods such as getWidth which referred to the
skin, which I don't have.

It works for me but I'm not sure if it's the right approach. Perhaps I
should subclass Container and attach a subclass of Skin. I still don't know
how I should divide my code between Component and Skin.

Cheers,
Przemek

Re: Image editor canvas

Posted by Greg Brown <gk...@verizon.net>.
> 1. Which class should I subclass to create my canvas component? Component? Image?

Component

> 2. How does the idea of a canvas on which I can click and draw relate to the concept of component skins?

ComponentSkin (abstract) registers to receive mouse events from its component. You can create a concrete subclass that responds to those events in whatever way is appropriate for your component.