<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"Iosevka Fixed SS16";
panose-1:2 0 5 9 3 0 0 0 0 4;}
@font-face
{font-family:"Times New Roman \(Body CS\)";
panose-1:2 11 6 4 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:10.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Iosevka Fixed SS16";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Iosevka Fixed SS16"">I think this proposal makes a lot of sense.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Iosevka Fixed SS16""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Iosevka Fixed SS16"">Having the trait interfaces inner classes of Trait clearly narrows down semantics. "Trait" might be too generic, maybe FxTrait or something like that? Just a thought.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Iosevka Fixed SS16""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Iosevka Fixed SS16"">What other traits/properties should we include?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Iosevka Fixed SS16""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Iosevka Fixed SS16"">Converting
</span><span style="font-size:11.0pt"><a href="https://github.com/openjdk/jfx/pull/1215">https://github.com/openjdk/jfx/pull/1215</a></span><span style="font-size:11.0pt;font-family:"Iosevka Fixed SS16""> to draft until this discussion comes to a resolution.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Iosevka Fixed SS16""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Iosevka Fixed SS16"">-andy<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Iosevka Fixed SS16""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Iosevka Fixed SS16""><o:p> </o:p></span></p>
<div id="mail-editor-reference-message-container">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">openjfx-dev <openjfx-dev-retn@openjdk.org> on behalf of Michael Strauß <michaelstrau2@gmail.com><br>
<b>Date: </b>Saturday, September 2, 2023 at 15:09<br>
<b>To: </b>openjfx-dev <openjfx-dev@openjdk.org><br>
<b>Subject: </b>JavaFX object traits<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">There's a proposal to add a common interface that identifies JavaFX<br>
objects that can hold an Observable<Object, Object> property map:<br>
<a href="https://github.com/openjdk/jfx/pull/1215">https://github.com/openjdk/jfx/pull/1215</a><br>
<br>
The reason for this is obvious: allow JavaFX objects that can hold<br>
properties to be consumed by code without depending on brittle<br>
`instanceof` checks. The problem is real, but I think we can do much<br>
better than that.<br>
<br>
Why have a common interface at all? Well, of course it allows<br>
consumers to treat different objects in a uniform way. But there's<br>
more to it: the interface specifies the _meaning_ of the method; it<br>
guarantees that `Foo::getProperties` and `Bar::getProperties` are, in<br>
fact, not only methods with the same name, but the same semantics.<br>
<br>
`getProperties` and `hasProperties` is one example of such commonality<br>
between dissimilar classes like `Node` and `MenuItem`. But I've come<br>
across other examples in my own projects. For example, I'd like to<br>
consume JavaFX objects that have the `visible` and `disable`<br>
properties. Other applications will have different use cases, but<br>
since we don't know all possible use cases, it's hard to come up with<br>
a set of useful combinations of properties and methods.<br>
<br>
However, I think we can use the Java type system to allow applications<br>
to compose types that fit their unique use case.<br>
<br>
We begin by identifying common properties, and create trait interfaces<br>
that describe those properties:<br>
<br>
public final class javafx.scene.Trait {<br>
public interface Visible {<br>
BooleanProperty visibleProperty()<br>
default boolean isVisible()...<br>
default void setVisible(boolean value)...<br>
}<br>
public interface Disable {<br>
BooleanProperty disableProperty()<br>
default boolean isDisable()...<br>
default void setDisable(boolean value)...<br>
}<br>
public interface Properties {<br>
ObservableMap<Object, Object> getProperties()<br>
default boolean hasProperties()...<br>
}<br>
...<br>
}<br>
<br>
These interfaces can now be implemented by all relevant JavaFX<br>
classes. This includes `Node`, `MenuItem`, and `Tab`, but applications<br>
are free to implement these trait interfaces themselves.<br>
<br>
Applications can now consume objects that implement any combination of<br>
traits, which gives applications the much-needed flexibility to use<br>
shared code for all kinds of JavaFX objects:<br>
<br>
<T extends Trait.Properties & Trait.Visible><br>
void doSomething(T node) {<br>
node.getProperties().put("foo", "bar");<br>
node.setVisible(true);<br>
}<br>
<br>
<T extends Trait.Text & Trait.Graphic><br>
void doAnotherThing(T node) {<br>
node.setText("hello");<br>
node.setGraphic(myGraphic);<br>
}<br>
<br>
What do you think?<o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</body>
</html>