You'll have to blaze the trail for the rest of us.
Of course, it has only been four days, two of which were weekend days, and we are right at the major holiday boundary. Might want to let this simmer a bit more.
You'll have to blaze the trail for the rest of us.
Of course, it has only been four days, two of which were weekend days, and we are right at the major holiday boundary. Might want to let this simmer a bit more.
Maybe you can "just" have your component implement Bounds2DComponent
?
Would you have an example of Bounds2DComponent being used?
Nope. You're on uncharted territory. But implementing the interface directly might be easier than subclassing one of the existing Vision shapes, which are currently the one things that implement the interface.
I got it mostly figured out now using AbstractVisionShape
. My component automatically resizes depending on the properties entered.
The one issue I still have is that when I grab the component from the Palette and drop it on the screen, it initially goes to a predefined x,y location. I want it to show up wherever I click with the mouse instead. How do I access the mouse coordinates from within the component java code?
I hope the video is visible to everyone.
So defining the component's outline based on properties is possible with the AbstractVisionShape
class.
Thanks to @pturmel for pointing me towards vision shapes!
The three key functions under that class are:
setBoundingRect(Rectangle2D rd)
/* rd is the bounding rectangle that is sent down from ignition, either when
* the component is initially dropped on the window or when it is resized or moved.
* Define the component's area in here by using the given rectangle and then modifying
* it as needed.
*/
getShapeBounds(Rectangle2D rd)
/* this function determines the size of the boundary to show around the component.
* Use a clone of the component's area that was created under setBoundingRect()
*/
getArea()
/* this function determines the area of the component that will allow the component to be
* selected by the mouse.
*/
Hi Mathias,
I am trying to implement something similar to this in some components I am creating. Thankyou for documenting everything so well. Though may I ask though how you resolved:
Looking forward to your response!
Thanks!
Hi Max,
I'm not sure what my code looked like back in January, that would have caused the component to go to predefined x, y coordinates when first dropped onto the container. As stated in my comment under the setBoundingRect(Rectangle2D rd)
function, rd gives you x, y, width
and height
of your component when it is first placed onto a container and when it is moved or resized.
Here is what I currently do and it works:
public void setBoundingRect(Rectangle2D rd) {
double newX = rd.getX();
double newY = rd.getY();
double newWidth = rd.getWidth();
double newHeight = rd.getHeight();
boundingRect.setFrame(newX, newY, newWidth, newHeight);
}
Of course you can manipulate rd
whichever way you want. Just make sure that boundingRect
is a property in the BeanInfo
class for your component. That's how the location and size of the component gets saved.
And here is what you want under getShapeBounds(Rectangle2D rd)
. This code is based on the JComponent's getBounds(Rectangle rv)
method:
public Rectangle2D getShapeBounds(Rectangle2D rd) {
if (boundingRect == null) {
return new Rectangle2D.Double( getLocation().x,
getLocation().y,
getPreferredSize().width,
getPreferredSize().height);
} else if (rd == null) {
return boundingRect.getBounds2D();
} else {
rd.setRect(boundingRect.getBounds2D());
return rd;
}
}
I hope this helps!
Hi Mathias,
Could you please have a look at:
Error-When-Saving-Bounds2DComponent (Serialization error)
It is related to what Max is trying to do too. I am asking you since you mentioned about need of boundingRect
property... something I suspect I am doing wrong (any particular flags must be set for it to work, e.g. when using addProp(..)
in the BeanInfo
?). Any chance you can advice how exactly that property needs to be added and if you aware of anything else needed for such component to be saved?
Thank you.
See reply over here: