Re: Request for comments – interface Rectangular

Randahl Fink Isaksen randahl at rockit.dk
Sun Dec 2 04:15:32 PST 2012


Richard,

In that case, I think we should consider if Rectangulars are always resizable. If they are not, I would suggest this hierarchy

class Region     ----- implements ----->     interface Resizable     ----- extends ----->     interface Rectangular

You also touch on the problem with the brittleness of interfaces. If you ensure that all relevant JavaFX node classes implement Resizable and Rectangular, you can easily add methods to theses interfaces as long as you add default implementations in the JavaFX node classes. E.g.

com.mycompany.MyOwnControl      ----- extends ----->      Region     ----- implements ----->      Resizable 

– I would never be affected by you adding methods to interface Resizable as long as you add a default implementation in class Region.
 
Randahl



On Dec 2, 2012, at 3:38 , Richard Bair <Richard.Bair at oracle.com> wrote:

> 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