Skip to main content

RE: [JAVA2D] Moving Shape

1 reply [Last post]
Anonymous

you could also use
AffineTransform.getTranslateInstance(x,y)

to get an AffineTransform, then use createTransformedShape() on your Shape...

doesn't that do the job?

> -----Original Message-----
> From: Discussion list for Java 2D API
> [mailto:JAVA2D-INTEREST@JAVA.SUN.COM] On Behalf Of "Jan
> Bösenberg (INCORS GmbH)"
> Sent: Monday, October 23, 2006 11:56 AM
> To: JAVA2D-INTEREST@JAVA.SUN.COM
> Subject: Re: [JAVA2D] Moving Shape
>
>
> You could implement this with a class like this:
>
>
> public class ShapeObject implements Shape {
> private final Shape shape;
> private float x = 0;
> private float y = 0;
>
> public ShapeObject(Shape shape) {
> this.shape = shape;
> }
>
> public float getX() {
> return x;
> }
>
> public void setX(float x) {
> this.x = x;
> }
>
> public float getY() {
> return y;
> }
>
> public void setY(float y) {
> this.y = y;
> }
>
> public boolean *contains*(double x, double y) {
> return shape.contains(x - this.x, y - this.y);
> }
>
> public Rectangle2D *getBounds2D*() {
> Rectangle2D bounds2D = shape.getBounds2D();
> bounds2D.setRect(bounds2D.getX() + x, bounds2D.getY() +
> y, bounds2D.getWidth(), bounds2D.getHeight());
> return bounds2D;
> }
>
> public PathIterator *getPathIterator*(AffineTransform at) {
> AffineTransform at2 = new AffineTransform(at);
> at2.translate(x, y);
> return shape.getPathIterator(at2);
> }
>
>
> // You have to implement the other Shape methods yourself
>
>
> }
>
>
> This class is more or less all you need. Put each of your
> shapes into a ShapeObject class and move the ShapeObjects
> around using the setX() and
> setY() methods.
>
> BTW, the questions was not too stupid to be answered, but
> most people have quite a lot to do so answers sometimes take
> a bit longer or never come.
>
>
> Cheers
> Jan
>
>
>
>
>
> Danilo Costa wrote:
>
> > No body has any idea? Or is the question too much stupid to be
> > answered?
> >
> > On 10/22/06, *Danilo Costa* > > wrote:
> >
> > I think it is a dummy question, but I cant find its
> answer easily.
> >
> > I have a collection of Shapes that are rendered in a
> canvas and I
> > have to let the user to interact with it, dragging it.
> > I've found this example
> > http://java.sun.com/docs/books/tutorial/2d/display/user.html
> > called Shape mover, but actually it works only with Rectangle
> > class, which has convenient methods for that, such as
> setLocation
> > and translate. I am wondering why Shape interface does
> not define
> > those methods? How can I implement such methods when I
> am working
> > with generic shapes? Any help is appreciate.
> >
> > Tahanks
> > Danilo
> > --
> > "...YOU CANNOT KNOW THE MEANING OF YOUR LIFE UNTIL YOU ARE
> > CONNECTED WITH THE POWER THAT CREATED YOU..."
> > Shri Mataji Nirmala Devi
> >
> >
> >
> >
> > --
> > "...YOU CANNOT KNOW THE MEANING OF YOUR LIFE UNTIL YOU ARE
> CONNECTED
> > WITH THE POWER THAT CREATED YOU..." Shri Mataji Nirmala Devi
> >
> ==============================================================
> =============
> > To unsubscribe, send email to listserv@java.sun.com and
> include in the
> > body of the message "signoff JAVA2D-INTEREST". For general
> help, send
> > email to listserv@java.sun.com and include in the body of
> the message
> > "help".
>
> ==============================================================
> =============
> To unsubscribe, send email to listserv@java.sun.com and
> include in the body of the message "signoff JAVA2D-INTEREST".
> For general help, send email to listserv@java.sun.com and
> include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Danilo Costa

Thank you guys!

I was just thinking about creating myCustomShape implementing Shape as Jan
suggested! And Thank you Nidel, I was trying something using
AffineTransform, but I didn't know about
AffineTransform.createTransformedShape(), sounds good also!

Thank you very much!! I am sorry I was a little bit anxious, because I was
searching for 3 days and nothing!

On 10/23/06, Nidel, Mike wrote:
>
> you could also use
> AffineTransform.getTranslateInstance(x,y)
>
> to get an AffineTransform, then use createTransformedShape() on your
> Shape...
>
> doesn't that do the job?
>
> > -----Original Message-----
> > From: Discussion list for Java 2D API
> > [mailto:JAVA2D-INTEREST@JAVA.SUN.COM] On Behalf Of "Jan
> > Bösenberg (INCORS GmbH)"
> > Sent: Monday, October 23, 2006 11:56 AM
> > To: JAVA2D-INTEREST@JAVA.SUN.COM
> > Subject: Re: [JAVA2D] Moving Shape
> >
> >
> > You could implement this with a class like this:
> >
> >
> > public class ShapeObject implements Shape {
> > private final Shape shape;
> > private float x = 0;
> > private float y = 0;
> >
> > public ShapeObject(Shape shape) {
> > this.shape = shape;
> > }
> >
> > public float getX() {
> > return x;
> > }
> >
> > public void setX(float x) {
> > this.x = x;
> > }
> >
> > public float getY() {
> > return y;
> > }
> >
> > public void setY(float y) {
> > this.y = y;
> > }
> >
> > public boolean *contains*(double x, double y) {
> > return shape.contains(x - this.x, y - this.y);
> > }
> >
> > public Rectangle2D *getBounds2D*() {
> > Rectangle2D bounds2D = shape.getBounds2D();
> > bounds2D.setRect(bounds2D.getX() + x, bounds2D.getY() +
> > y, bounds2D.getWidth(), bounds2D.getHeight());
> > return bounds2D;
> > }
> >
> > public PathIterator *getPathIterator*(AffineTransform at) {
> > AffineTransform at2 = new AffineTransform(at);
> > at2.translate(x, y);
> > return shape.getPathIterator(at2);
> > }
> >
> >
> > // You have to implement the other Shape methods yourself
> >
> >
> > }
> >
> >
> > This class is more or less all you need. Put each of your
> > shapes into a ShapeObject class and move the ShapeObjects
> > around using the setX() and
> > setY() methods.
> >
> > BTW, the questions was not too stupid to be answered, but
> > most people have quite a lot to do so answers sometimes take
> > a bit longer or never come.
> >
> >
> > Cheers
> > Jan
> >
> >
> >
> >
> >
> > Danilo Costa wrote:
> >
> > > No body has any idea? Or is the question too much stupid to be
> > > answered?
> > >
> > > On 10/22/06, *Danilo Costa* > > > > wrote:
> > >
> > > I think it is a dummy question, but I cant find its
> > answer easily.
> > >
> > > I have a collection of Shapes that are rendered in a
> > canvas and I
> > > have to let the user to interact with it, dragging it.
> > > I've found this example
> > > http://java.sun.com/docs/books/tutorial/2d/display/user.html
> > > called Shape mover, but actually it works only with Rectangle
> > > class, which has convenient methods for that, such as
> > setLocation
> > > and translate. I am wondering why Shape interface does
> > not define
> > > those methods? How can I implement such methods when I
> > am working
> > > with generic shapes? Any help is appreciate.
> > >
> > > Tahanks
> > > Danilo
> > > --
> > > "...YOU CANNOT KNOW THE MEANING OF YOUR LIFE UNTIL YOU ARE
> > > CONNECTED WITH THE POWER THAT CREATED YOU..."
> > > Shri Mataji Nirmala Devi
> > >
> > >
> > >
> > >
> > > --
> > > "...YOU CANNOT KNOW THE MEANING OF YOUR LIFE UNTIL YOU ARE
> > CONNECTED
> > > WITH THE POWER THAT CREATED YOU..." Shri Mataji Nirmala Devi
> > >
> > ==============================================================
> > =============
> > > To unsubscribe, send email to listserv@java.sun.com and
> > include in the
> > > body of the message "signoff JAVA2D-INTEREST". For general
> > help, send
> > > email to listserv@java.sun.com and include in the body of
> > the message
> > > "help".
> >
> > ==============================================================
> > =============
> > To unsubscribe, send email to listserv@java.sun.com and
> > include in the body of the message "signoff JAVA2D-INTEREST".
> > For general help, send email to listserv@java.sun.com and
> > include in the body of the message "help".
> >
>
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the
> body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>

--
"...YOU CANNOT KNOW THE MEANING OF YOUR LIFE UNTIL YOU ARE CONNECTED WITH
THE POWER THAT CREATED YOU..."
Shri Mataji Nirmala Devi

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".
[att1.html]