Color.toWeb & Color.toHexString

Richard Bair richard.bair at oracle.com
Tue Jul 10 09:27:33 PDT 2012


Hi Pavel,

On Jul 10, 2012, at 7:50 AM, Pavel Safrata wrote:

> Hello,
> based on Jira issue
> http://javafx-jira.kenai.com/browse/RT-22400
> I propose the following new methods to Color class (targeting Lombard):
> 
> 
> public String toWeb()
> 
> This method will return the simplest string representation of the color using one of the following notations:
> 
> #rrggbb
> rgb(r, g, b)
> rgba(r, g, b, a)
> 
> The resulting string, when passed to Color.toWeb(), will produce an eqivalent color.

I like the idea that color.equals(Color.web(color.toWeb())).

How do we determine which format is going to be returned by toWeb? I think it should be consistent (ie: pick one to use all the time). Otherwise it becomes arbitrary and folks cannot easily parse the results or do what they need with it.

> public String toHexString()
> 
> This method will return a string rrggbb without the leading hash. It will ignore opacity and will round the values to the nearest color that can be represented with such string. An example of use is displaying a web-based color value in a color picker.

Why remove the #? What is the use case for toHexString()?

Richard


More information about the openjfx-dev mailing list