[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-openjfx-dev
Subject:    Re: Event when CSS is applied
From:       Tom Eugelink <tbee () tbee ! org>
Date:       2015-02-19 7:20:31
Message-ID: 54E58EBF.7090303 () tbee ! org
[Download RAW message or body]

(after a night's sleep)

Well... I was trying to do things by composition and it did not work. My implemention \
worked, but it had to depend on a layoutChildren, only at the top level (Skin), which \
was not fine grained enough.

Interesting is that for JFXtras Agenda I used the inherit pattern, but because Agenda \
has a lot of nested layout (week -> day -> appointment -> time, title, ...). \
Inheritance was used there out of a need for encapsulation; the composition code got \
very complex. But it probably saved me from a lot of CSS and layout woos.

Now, back to the gauge, I just tried to see if I could hammer a composition pattern \
onto NeedlePane. The separation between construction and layout is a good thing, so I \
                ended up doing this:
- Removing the whole NeedlePane class and replace it with a "Pane needlePane = new \
                Pane();" since we're doing absolute layout.
- Convert the constructor to a method "private void constructNeedlePane()"
- Convert the layoutChildren to a method "private void layoutNeedlePane()"
- Then I tried to wire it up by listening to "needlePane.needsLayoutProperty()"

That did not work... It worked partially, which was weird.
What of course did work was hooking into layoutChildren():

         final private Pane needlePane = new Pane() {
             @Override
             protected void layoutChildren() {
                 super.layoutChildren();
                 layoutNeedlePane();
             }
         };

So, now I have composed the layout with a smallish hack. But, getting back to my \
remark on Agenda... Encapsulation was a good thing there, and actually I like using \
"extends" (I always complain when things are final, and I cannot override). So I'm \
not too displeased with what we ended up with. ;-)

Tom



On 18-2-2015 22:50, Tomas Mikula wrote:
> Hmm, my view is rather reverse to yours:
> The fact that the implementation of layout is best solved with
> inheritance is a sign that JavaFX does _not_ aim enough at doing
> things via composition.
> 
> Tomas
> 
> On Wed, Feb 18, 2015 at 4:37 PM, Tom Eugelink <tbee@tbee.org> wrote:
> > 
> > On 18-2-2015 21:49, Tomas Mikula wrote:
> > > So back to your original question:
> > > 
> > > > Basically I would like to be informed when the styling of a node has been
> > > > applied or changed. Is there some place that can provide this information?
> > > Turns out you don't actually need this information ;)
> > > 
> > 
> > Indeed. Pattern learned.
> > 
> > What does surprise me is that JavaFX aims at doing things via composition,
> > that is why almost everything is final, and where the structure in my
> > original code comes from. This turns out is best solved with inheritance.
> > 
> > Tom
> > 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic