mihosoft.eu
Programming, Art, Linux, Free Software…
mihosoft.eu
Navigation
  • Home
  • VRL-Studio
  • SonoAir
  • Monochrome Wars
  • About
  • Impressum
  • Datenschutz
You are here: Home › Java › [Part 5] Custom Node Content

[Part 5] Custom Node Content

August 3, 2013 | Filed under: Java, JavaFX, VRL and tagged with: Java, JavaFX, JavaFX 8, JFXtras, visual programming, VRL, VRL-Studio, VWorkflows, window control, Window Node, Window System, workflow, workflows

UPDATE [23.05.2014]: This tutorial need features that are no longer part of the JFXtras library. If you have problems building it, you might want to try the JavaOne2013 project that also makes use of the Custom Node feature.

First of all, sorry for the delay. Many of you asked me how to add custom node content to VNodes. This tutorial will finally lift this secret 😉

If you haven’t done so already please read the previous parts of the tutorial: Part 1, Part 2, Part 3 and Part 4.

Short Demo on Custom Node Content:

Adding Content

The latest snaphot release (vworkflows-fx:0-1-r1-SNAPSHOT) contains a new skin factory that allows to register node skins for specific value types. Instead of FXValueSkinFactoryone has to use FXValueSkinFactoryinstead:

 // create skin factory for flow visualization
    FXValueSkinFactory fXSkinFactory = new FXValueSkinFactory(canvas.getContentPane());

Registering custom node skins is very easy:

 // register visualizations for Integer, String and Image
 fXSkinFactory.addSkinClassForValueType(Integer.class, IntegerFlowNodeSkin.class);
 fXSkinFactory.addSkinClassForValueType(String.class, StringFlowNodeSkin.class);
 fXSkinFactory.addSkinClassForValueType(Image.class, ImageFlowNodeSkin.class);

 // generate the ui for the flow
 flow.addSkinFactories(fXSkinFactory);

It is also possible to register multiple factories at the same time that use a different set of node skins!

Anatomy of a Custom Flow Node Skin

A custom node skin usually inherits from FXFlowNodeSkinBase and provides a custom version of the updateView()method:

public class CustomFlowNodeSkin extends FXFlowNodeSkinBase {
  @Override
  public void updateView() {
    // ...
  }
}

The version we provide in the tutorial project looks like this:

public abstract class CustomFlowNodeSkin extends FXFlowNodeSkinBase {

    public CustomFlowNodeSkin(FXSkinFactory skinFactory,
            VNode model, VFlow controller) {
        super(skinFactory, model, controller);
    }

    protected abstract Node createView();

    /**
     * Will be called once for each value change.
     */
    @Override
    public void updateView() {

        super.updateView();

        // we don't create custom view for flows
        if (getModel() instanceof VFlowModel) {
            return;
        }

        // we don't create a custom view if no value has been defined
        if (getModel().getValueObject().getValue() == null) {
            return;
        }

        // create the view
        Node view = createView();

        // add the view to scalable content pane
        if (view != null) {

            ScalableContentPane scalableContentPane = new ScalableContentPane();
            scalableContentPane.setPadding(new Insets(10));

            GridPane nodePane = new GridPane();
            nodePane.setAlignment(Pos.CENTER);
            scalableContentPane.setContentPane(nodePane);

            scalableContentPane.getContentPane().getChildren().add(view);
            getNode().setContentPane(scalableContentPane);
        }
    }
}

In the updateView() method we define a scalable container for the actual value view. If the node the skin visualizes does contain child nodes we don’t provide a custom view.

Example Skins:

The tutorial project provides the following skins:

Node Skin for String

Node Skin for String

Node Skin for Integer

Node Skin for Integer

Node Skin for Images

Node Skin for Images

The LCD gauge and the segment display are part of the JFXtras library (http://jfxtras.org). See Gerrit Grunwalds Enzo library for other very nice and lightweight gauges (depends on JDK 8).

Feedback

If you’d like to contribute or if you want to ask questions about VRL, VWorkflows and other related projects join the Developer & User groups:

  • Developer Group: https://groups.google.com/forum/#!forum/vrl-developers
  • User Group: https://groups.google.com/forum/#!forum/vrl-studio-users

Demo Application

Download the tutorial code from GitHub.

Requirements:

  • Java 7 or a recent Java 8 preview build (>=b98)
  • Optional: Netbeans >=7.3 with Gradle Plugin

Building & Running:

To run the application from the command line just type ./gradlew run.

Stay tuned and follow me on Twitter

To be continued…

Did you like this article? Share it with your friends!

Tweet

Written by admin

Visit my Website Follow me on Twitter

9 Responses to "[Part 5] Custom Node Content"

  1. JavaFX links of the week, August 5 // JavaFX News, Demos and Insight // FX Experience says:
    August 5, 2013 at 01:37

    […] has posted part five about custom node content in his VWorkflows library. He has also posted to note that VWorkflows is also available via Maven now […]

    Reply
  2. Java desktop links of the week, August 5 « Jonathan Giles says:
    August 11, 2013 at 22:40

    […] has posted part five about custom node content in his VWorkflows library. He has also posted to note that VWorkflows is also available via Maven now […]

    Reply
  3. ufukhalisufuk says:
    November 29, 2013 at 20:08

    Hi, how can i add the components(like Button) in Node? i ran your first tutorial. VNode n1 = flow.newNode(); these code blocks in it.

    n1.add(buton); Has VNode1 got any methods like this?

    Reply
    1. miho says:
      December 2, 2013 at 17:32

      Hi,

      VNode is part of the model API. It is not JavaFX specific. If you want to add a button to the JavaFX UI you have to implement your own skin. See code of this tutorial for an example:

      Use the Integer skin as template. Just remove the content of the createView() method and change it to something like this:

      @Override
      public Node createView() {
          return new Button("JavaFX Button")
      }
      

      If you need further help you can also ask questions on the VRL Developer Forum

      Regards, Michael

      Reply
  4. Lawrence says:
    February 9, 2015 at 17:14

    Hi,

    First of all i want to congratulate you on the job that u have done. I am trying to do an open source project and i would like to use workflow in it, but i can’t seem to make the loading part work. (there is a “TODO: TODO: visualizationRequest isnot persistent!” in WorkflowIO class ). I am struggling for some time now to make it work but can’t seem to get to the bottom of it. Do you have by any chance an update on this ? I would really appreciate it.

    Regards, Lawrence.

    Reply
    1. miho says:
      February 9, 2015 at 17:56

      Hi Lawrence,

      thanks for using VWorkflows 🙂 Could you please add an issue on Github (https://github.com/miho/VWorkflows/issues)? If you can then also add some sample code to demonstrate the problem. I’ll fix this as soon as possible.

      Regards, Michael

      Reply
      1. Lawrence says:
        February 9, 2015 at 21:47

        Hello Michael,

        Thank you for the fast response, that’s so cool! I will add a simple example from your first tutorial in order do make the issue better understood. Thank you again so much.

        Regards, Lawrence

        Reply
  5. destin says:
    March 29, 2015 at 09:42

    Hi Michael, Thank you for that pretty library, but i have a question: How can i change a zoom by dragging to zoom by mouse in ScalableContentPane?

    P.s sorry for my bad English=)

    Reply
  6. Lando Calrissian says:
    May 26, 2015 at 03:13

    Is there a specific version I should have of vWorkflow? The addSkinClassForValueType method isn’t available for the FXSkinFactory class.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pages

  • About
  • Datenschutz
  • Impressum
  • Seminar 2019

Categories

  • 3D Printing
  • Any-Key
  • Art
  • C/C++
  • Devoxx
  • Digital Painting
  • Featured
  • IoT
  • Java
  • JavaFX
  • Javakurs 2015
  • JavaOne
  • Linux
  • Linux on Apple Hardware
  • Linux: Daily Usage Tips
  • Mobile Apps
  • Mobile Devices
  • Programming Languages
  • Repair Things
  • Science
  • Sonos
  • Teaching
  • Uncategorized
  • Virtual Reality
  • VRL

Tags

3D 3D Printing 3d visualization AirSonos Apple Music Devoxx Devoxx 2013 gradle graph iOS Java Java 8 JavaFX JavaFX 8 JavaOne JavaOne 2013 jdk9 JFXtras JInternalFrame Linux MacBook MDI mobile apps OpenDive OpenJDK OpenJFX Open Source Performance scientific visualization SonoAir Sonos Ultimaker Virtual Reality Virtual World visual programming VPlot VRL VRL-Studio VWorkflows window control Window Node Window System workflow workflows X11

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

JavaOne Rockstar

JavaOne Rockstar
Follow @mihosoft

Recent Posts

  • Native JDK9 Application Bundles
  • Running C code from Java via VTCC
  • SonoAir finally supports macOS High Sierra!
  • JavaOne 2017 Community Keynote Artwork
  • The JGrounds App: better teaching apps for Java 9 [BOF5047]

Recent Comments

  • ¿Ventanas completamente personalizadas de JavaFX? - Fallosweb.com on VFXWindows
  • JavaFX entirely customized windows? – w3toppers.com on VFXWindows
  • Volel Mondesir on Adding Custom Icons to JFXtras Window Control (VFXWindows)
  • Volel Mondesir on Adding Custom Icons to JFXtras Window Control (VFXWindows)
  • Switching between different JDK versions in Windows - ErrorsFixing on JSelect: switch between different JDK versions

Archives

  • February 2018
  • October 2017
  • September 2017
  • February 2017
  • June 2016
  • May 2016
  • November 2015
  • September 2015
  • July 2015
  • March 2015
  • September 2014
  • March 2014
  • February 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • November 2010
  • February 2010
  • November 2009
  • October 2009
  • February 2009
  • August 2008
  • May 2008
  • April 2008
  • March 2008
Privacy & Cookies: this site uses cookies. By continuing to use this website, you agree to their use.
To find out more, see here: Impressum & Datenschutz

© 2025 mihosoft.eu