[API REVIEW] RT-27883: move Size and SizeUnits to public API

David Grieve david.grieve at oracle.com
Thu Jan 24 13:57:10 PST 2013


On Jan 24, 2013, at 2:22 PM, Richard Bair <richard.bair at oracle.com> wrote:

>> Size and SizeUnit are used for CSS values and units. These currently live in the com.sun.javafx.css package. These classes need to be moved to javafx.css in order to remove raw types from generics in the CSS public API. Some methods in the com.sun.javafx.css API should be renamed to make their purpose clearer. 
> 
> OK in general.
> 
>> Size: 
>> public double getValue() - return the number part of the css value 
>> public SizeUnits getUnits() - return the units, e.g. - em, px, % 
>> public boolean isFontRelative() - return true if the units are font-relative (em or ex) 
>> public double actualValue(Font font) - calculate the actual value using the size of the given font if the units are font-relative or percentage 
>> public double actualValue(double multiplier) - calculate the actual value using the multiplier if the units are font-relative or percentage 
>> public double actualValue() - same as actualValue(1.0) 
> 
> How often is actualValue() used? Is it worth having that convenience API in there?

The convenience method is used in more places than actualValue(double). I don't have any qualms about getting rid of it, though. 

> 
>> enum SizeUnits 
>> 
>> public boolean isFontRelative() - return true if the units are font-relative (em or ex) 
> 
> Why do we have this method here and in Size? It seems like Size doesn't need it, as I can just getUnits().isFontRelative()?

Just another convenience to shorten up some code. Again, I don't have any issues with getting rid of the method in Size.

> 
>> public double calculateValue(Font font) - calculate the actual value using the size of the given font if the units are font-relative or percentage 
>> public double calculateValue(double multiplier) - calculate the actual value using the multiplier if the units are font-relative or percentage 
> 
> How does this work? Do these methods simply return a multiplier?

They take the value and apply the unit conversion. So, for example, if you have 2em, the EM SizeUnit implementation of calculateValue returns 2 * font.getSize(). 2rad returns 2*180/Math.PI. Rather than having Size figure out what calculation to use in some big switch statement, SizeUnits knows how to do the calculation. If we add more SizeUnits, all that needs to be done is the implementation of calculateValue. 

> 
> Richard



More information about the openjfx-dev mailing list