How can I create and set a custom UI Delegate for a component that can take any orientation?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Abey_Mullassery
Posted On:   Thursday, August 2, 2001 11:58 PM

How is it possible to have a visual component which can take any orientation(ie., that can be rotated)? Should I write a custom UI delegate? If yes, How?


I want to use a component which has an image on it to function as a movable (translate & rotate) tile, in a tile based game. I want this tile to be a component since it has to respond to mouse events and display the image. It also has to support grouping, etc.


How can I modify the UI to support rotation of components (on a component with no (null) layout).

Re: How can I create and set a custom UI Delegate for a component that can take any orientation?

Posted By:   Abey_Mullassery  
Posted On:   Tuesday, August 21, 2001 02:48 AM

Solved the problem to an extent.


I maintain a shape and an AffineTransform object. All transform are done onthe affineTransform object. The shape is then updated accordingly.


This shape is used to override the contains method for catching the mouse clicks and to set a new clip area while painting.



public void paintComponent(java.awt.Graphics graphics) {
Graphics2D g2d = (Graphics2D) graphics;

//imageBounds is the rectangle representing the image
s = affineTransform.createTransformedShape(imageBounds);
g2d.setClip(s);
if(img!=null) g2d.drawImage(img,affineTransform,this);
}

public void rotate(double theta, double x, double y){
affineTransform.rotate(theta, x, y);
}



I also planning to "group" these components such that transformation can be done to the component based on Group co-ordinates.


Any design or code related suggestions??

Re: How can I create and set a custom UI Delegate for a component that can take any orientation?

Posted By:   Amit_Bohara  
Posted On:   Friday, August 3, 2001 11:50 AM

if you have access to graphics2d, use an affine transformation with a rotation matrix. Increase the angle of rotation like you want. To translate or do anything else you can create an appropriate matrix and implement it using an affineTransformation into your graphics object and then paint the object with it. You can have this done inside the paint() method of your delegate.

Hope that helps.
About | Sitemap | Contact