6 Replies Latest reply: Apr 3, 2013 8:10 PM by jsmith RSS

    JQuery like library for JavaFX ?

    se*328623*78
      Is somebody aware of a JQuery like library for querying/editing nodes in a JavaFX Scene Graph ?.
      If no library like that currently exists, does someone know if there are plans to provide something like that in the future ?
      A declarative way to query and modify Scene Graph nodes seems a very interesting library to me, and it should not be that difficult to implement in fact, in case it does not exist already.

      regards,

      Sergio
        • 1. Re: JQuery like library for JavaFX ?
          James_D
          I have hardly any experience in jQuery, but my impression is that it does two things:
          1. provides a simpler way to manage events, effects, and animations than using plain JavaScript
          2. provides a mechanism to perform element selection based on css class and id attributes

          The first is surely redundant in the context of JavaFX, as the Java language and FX framework already provide mechanisms for this. The second is readily managed using [url http://docs.oracle.com/javafx/2/api/javafx/scene/Node.html#lookup(java.lang.String)]Node.lookup and [url http://docs.oracle.com/javafx/2/api/javafx/scene/Node.html#lookupAll(java.lang.String)]Node.lookupAll.

          But there may be (almost certainly is) more to jQuery that I don't know, so I might be missing something here.
          • 2. Re: JQuery like library for JavaFX ?
            se*328623*78
            Hello, yes, I was looking something like Node.lookupAll. Although the API I had in mind was a bit more high level, in JQuery you can select a group of nodes and send them a message in one step, something like:

            $('selector').do_something(...)

            I would have to explicitly iterate on the answer returned by lookupAll, but it is almost what I need.

            thanks!

            Sergio
            • 3. Re: JQuery like library for JavaFX ?
              James_D
              se**** wrote:
              Hello, yes, I was looking something like Node.lookupAll. Although the API I had in mind was a bit more high level, in JQuery you can select a group of nodes and send them a message in one step, something like:

              $('selector').do_something(...)

              I would have to explicitly iterate on the answer returned by lookupAll, but it is almost what I need.
              With the new features in Java 8 (java.util.Stream.forEach(...), for example) this becomes a lot easier too....
              root.lookupAll(".my-class")
                 .stream()
                 .forEach(node -> node.setVisible(false));
              Edited by: James_D on Apr 3, 2013 3:08 PM
              • 4. Re: JQuery like library for JavaFX ?
                jsmith
                the API I had in mind was a bit more high level, in JQuery you can select a group of nodes and send them a message in one step, something like:
                $('selector').do_something(...)
                Use the streaming API for java 8 collections (not yet in jdk8 builds as of jdk8b83, but coming soon...)
                http://cr.openjdk.java.net/~briangoetz/lambda/sotc3.html
                $(".button").forEach(b -> b.setStyle("-fx-base: red;"));
                
                private Set<Node> $(String selector) {
                  return stage.getScene().getRoot().lookupAll(selector);
                }
                Ahh . . . I see James already posted this, still the ability to emulate the weird jQuery $ syntax is an interesting curiousity.
                • 5. Re: JQuery like library for JavaFX ?
                  KonradZuse
                  Sorry to cut in, but cool new feature, but what exactly is the uses? Is it in the API yet, also is there a list of New Features for JDK 8? I'm not even sure I know all the new goodies for 7 :P, I know I had a link for that at one point too.

                  Edited by: KonradZuse on Apr 3, 2013 5:49 PM


                  So I checked out that site, tons of cool info, so I will try and check out more on how it all, and Lambda works... Lambda is way more powerful than I originally thought.... People talking about "Bloaty" code can shove it :p.
                  • 6. Re: JQuery like library for JavaFX ?
                    jsmith
                    Features for jdk8:
                    http://openjdk.java.net/projects/jdk8/features

                    Features from jdk7:
                    http://openjdk.java.net/projects/jdk7/features/


                    Although both feature lists are pretty long, most changes are technical, specific and back end things which a lot of people never interact with directly.

                    The big changes in 8 are lambdas, defender methods and the updated collections interfaces and streaming api, which, taken together allow for use of constructs which originated in functional programming languages, such as map functions, foreach functions, etc. The key concept is that you can replace for loops with functions so that you say do an iteration rather than how to do the iteration. There are two reasons to do this. The first is that you can apply a concept like a spliterator to split apart an iteration and perform it in parallel. The second is that you are programming with higher level constructs like map, filter, fold, etc which results in more concise, less error prone code.