Request for comments – interface Rectangular (original) (raw)

Randahl Fink Isaksen randahl at rockit.dk
Sat Dec 1 12🔞22 PST 2012


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