Re: Request for comments – interface Rectangular
Richard Bair
richard.bair at oracle.com
Sat Dec 1 18:38:43 PST 2012
I think that is a great question. Another thing that is always bothering me is that I want to be able to resize rectangular things in a regular manner. That would imply the interface should have more than just getters. That also gives another reason why interfaces are difficult to work with -- if we'd have just shipped such an interface (with only getters) and then realized we wanted setters, we'd be stuck (if we can't take advantage of default methods in 8, anyway). Anyway, I digress.
If Java had mixins, we'd have used them to great effect in many of these cases. Unfortunately it doesn't, and interfaces are poor for API evolution (they're great for defining the boundaries between systems, but not so great for defining the characteristics of something). There are a couple JIRAs actually (at least one or two I filed) that say something to the effect of "add such and such an interface when we know what it should look like".
So, we should list the use cases for when you want to work with something as though it is rectangular. I'm assuming in your case boundsInLocal doesn't cut it (because you want to know the width / height before the clip is applied)?
Richard
On Dec 1, 2012, at 12:18 PM, Randahl Fink Isaksen <randahl at rockit.dk> wrote:
> I have on a few occasions had to determine the width and height of a Node. It turns out, that this is not that easy, because JavaFX does not yet have a common interface for all nodes that have a width and a height. Consequently, I suggest an interface Rectangular to be added:
>
> interface Rectangular {
> double getWidth();
> double getHeight();
> }
>
> This interface would have the benefit of making measuring node size considerably simpler. Before:
>
> if(node instanceof Region || node instanceof Control || node instanceof Rectangle […]) {
> double width = -1;
> double height = -1;
> if(node instanceof Region) {
> width = ((Region) node).getWidth();
> height = ((Region) node).getHeight();
> }
> else if(node instanceof Control) {
> width = ((Control) node).getWidth();
> height = ((Control) node).getHeight();
> }
> else if(node instanceof Rectangle) {
> width = ((Rectangle) node).getWidth();
> height = ((Rectangle) node).getHeight();
> }
> // do something with the width and height
> }
>
> And after
>
> if(node instanceof of Rectangular) {
> double width = ((Rectangular) node).getWidth();
> double height = ((Rectangular) node).getHeight();
> // do something with the width and height
> }
>
> I would very much like to discuss if this concept could be helpful for all of us.
>
> Thanks
>
> Randahl
More information about the openjfx-dev
mailing list