[API Review] RT-21094 - Styleable interface
David Grieve
david.grieve at oracle.com
Wed Jan 23 17:59:05 PST 2013
Thanks for the feedback. I think I have it straight now:
List<CssMetaData<? extends Styleable, ?>> getCssMetaData();
e.g.,
CssMetaData<Node, Number> OPACITY;
@Override
public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() {
List<CssMetaData<? extends Styleable, ?>> list;
list = new ArrayList<CssMetaData<? extends Styleable, ?>>();
list.add(OPACITY);
return list;
}
On Jan 22, 2013, at 6:00 PM, Tom Schindl <tom.schindl at bestsolution.at> wrote:
> Hi,
>
> I didn't understand what <S extends Styleable> ... would be good for
> because this will lead to a warning in the subclasses:
>
>> public class Node implements Styleable {
>>
>> @Override
>> public List<CssMetaData<Node, Object>> getMetaData() {
>> // TODO Auto-generated method stub
>> return null;
>> }
>>
>> }
>
>>> Type safety: The return type List<CssMetaData<Node,Object>> for getMetaData() from the type Node needs unchecked conversion to conform to List<CssMetaData<? extends Styleable,Object>> from the type Styleable
>
> And I think the value should not be ? but Object. What we'd really need
> here are self-references but Java does not have them.
>
> One of the problems with generic lists is that they are not covariant
>
> List<Styleable,Object> v = ...;
> List<Node,Object> l = ...;
> v = l; // illegal
>
> and so one can not overload them in subclasses and return a more
> specific one, same goes for adding/removing elements:
>
> List<CssMetaData<Styleable,Object>> l = ...;
> CssMetaData<Button,Boolean> v = ...
> l.add(v); // illegal
>
> So something is going wrong here!
>
> Tom
>
> Am 22.01.13 23:15, schrieb David Grieve:
>> The JIRA is public now, thanks for pointing that out.
>>
>> The getCssMetaData() API should be
>>
>> <S extends Styleable> List<CssMetaData<S, ?>> getCssMetaData();
>>
>>
>> On Jan 22, 2013, at 4:42 PM, Tom Schindl <tom.schindl at bestsolution.at
>> <mailto:tom.schindl at bestsolution.at>> wrote:
>>
>>> Hi,
>>>
>>> The problem I see with this is that CssMetaData accepts 2 generic
>>> parameters but your API returns a RAW-Type, this looks bogus to me!
>>>
>>> BTW the JIRA is not public.
>>>
>>> Tom
>>>
>>> Am 22.01.13 22:09, schrieb David Grieve:
>>>> http://javafx-jira.kenai.com/browse/RT-21094
>>>>
>>>> There is a class in private implementation called Styleable which
>>>> allows SceneBuilder to look at a Tooltip (for example) and get the
>>>> info it needs for styling. What I'd like to do is make Styleable part
>>>> of the public API _and_ have Node and PopupControl (there may be a
>>>> couple of other controls) implement Styleable. From the CSS
>>>> standpoint, Styleable contains the API that CSS needs to match
>>>> selectors and set calculated values on properties.
>>>>
>>>> By making Styleable public API, I can change CssMetaData from
>>>> CssMetaData<N extends Node, V> to CssMetaData<N extends Styleable,
>>>> V>. This is important to do now before the CSS API is fully baked so
>>>> that we can, in the future, have Scene be Styleable.
>>>>
>>>> public interface Styleable {
>>>>
>>>> /**
>>>> * The type of this {@code Styleable} that is to be used in
>>>> selector matching.
>>>> * This is analogous to an "element" in HTML.
>>>> * (<a href="
>>>> http://www.w3.org/TR/CSS2/selector.html#type-selectors">CSS Type
>>>> Selector</a>).
>>>> */
>>>> String getType();
>>>>
>>>> /**
>>>> * The id of this {@code Styleable}. This simple string identifier
>>>> is useful for
>>>> * finding a specific Node within the scene graph. While the id of
>>>> a Node
>>>> * should be unique within the scene graph, this uniqueness is not
>>>> enforced.
>>>> * This is analogous to the "id" attribute on an HTML element
>>>> * (<a
>>>> href="http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier">CSS
>>>> ID Specification</a>).
>>>> * <p>
>>>> * For example, if a Node is given the id of "myId", then the
>>>> lookup method can
>>>> * be used to find this node as follows:
>>>> <code>scene.lookup("#myId");</code>.
>>>> * </p>
>>>> */
>>>> String getId();
>>>>
>>>> /**
>>>> * A list of String identifiers which can be used to logically group
>>>> * Nodes, specifically for an external style engine. This variable is
>>>> * analogous to the "class" attribute on an HTML element and, as
>>>> such,
>>>> * each element of the list is a style class to which this Node
>>>> belongs.
>>>> *
>>>> * @see <a
>>>> href="http://www.w3.org/TR/css3-selectors/#class-html">CSS3 class
>>>> selectors</a>
>>>> */
>>>> List<String> getStyleClass();
>>>>
>>>> /**
>>>> * The inline style. This is analogous to the "style" attribute of an
>>>> * HTML element.
>>>> */
>>>> String getStyle();
>>>>
>>>> /**
>>>> * Return the parent of this Styleable, or null if there is no
>>>> parent.
>>>> */
>>>> Styleable getStyleableParent();
>>>>
>>>> /**
>>>> * The CssMetaData of this Styleable
>>>> */
>>>> List<CssMetaData> getCssMetaData();
>>>>
>>>> }
>>>>
>>>
>>>
>>> --
>>> B e s t S o l u t i o n . a t EDV Systemhaus GmbH
>>> ------------------------------------------------------------------------
>>> tom schindl geschäftsführer/CEO
>>> ------------------------------------------------------------------------
>>> eduard-bodem-gasse 5-7/1 A-6020 innsbruck fax ++43 512 935833
>>> http://www.BestSolution.at phone ++43 512 935834
>>
>
>
> --
> B e s t S o l u t i o n . a t EDV Systemhaus GmbH
> ------------------------------------------------------------------------
> tom schindl geschäftsführer/CEO
> ------------------------------------------------------------------------
> eduard-bodem-gasse 5-7/1 A-6020 innsbruck fax ++43 512 935833
> http://www.BestSolution.at phone ++43 512 935834
More information about the openjfx-dev
mailing list