Showing posts with label javafx. Show all posts
Showing posts with label javafx. Show all posts

Saturday, April 4, 2015

Javaland 2015 - Day 2

Better late then never here it is, my summary of our second day at Javaland 2015 :-)!

After a first day with a lot of interesting talks and fantastic rides with the Black Mamba we started day 2 at Javaland. This day came up with a lot of JavaFX talks. Perfect, because the last Project at work made heavy use of JavaFX. So i decided to take a look how other programmers work with JavaFX.

Hendrik Ebbers from Canoo and Alexander Casall (Saxonia AG) started after the Keynote with "Enterprise Applications with JavaFX". They gave an overview how to build JavaFX Applications that communicate with JEE Backend Systems and gave some best practice tips how to bind data models to their corresponding view (Model-View-View-Model Pattern), and how to synchronize views between two instances of one JavaFX Application. Theyalso mentioned some interessting JavaFX Libraries that addresses the named Topics:


Well, as you can see, Java Developers are not very creativ when inventing a Name for a library ;-)

IoT

Another big Topic at day two was IoT - Internet of things. Maybe you did not know this term you probably get in touch with it. Since not even Computers and Smartphones but also TVs, Refrigerators, Watches and lot more devices can connect to the Internet we talk about the IoT. To get an easy introduction into that Topic i decided to watch "IoT Magic Show" with Stephen Chin (yeah, the men with the Motorcycle :-) ). Stephen and a colleague explained IoT with the help of three Magic tricks. The most impressing one was the first one. Three People from the audience had to choose one gamingcard and Stephens colleague had to guess what gaming they had choosen. As you might guess he guessed right every Card!
The trick mainly based on an really tiny RFID-Chip inside every Card. With a Little RFID detector hidden in his Hand, he hovered over the Card with the face down. The RFID-Chip transmitted the type of the Card to the detector. Over a Network the result was transmitted to a RasberryPI and finally send to Google Glasses.
That showed how Network capable devices can communicate with each other.

2048

Need a break after a lot of reading? How about playing 2048 to relax? If you don't know 2048 the game you may want to checkout http://gabrielecirulli.github.io/2048/. It is fun and easy to learn!

Bruno Borges and a colleague showed their implementation of 2048 with JavaFX in the next talk. They covered how they did the databinding, the design and the animations with JavaFX to achieve the typical 2048 Feeling. Finally they introduced the port to Android Devices, done with JavaFXPort (http://www.javafxports.org/page/home). You can find the app in the Play-Store https://play.google.com/store/apps/details?id=org.jpereda.game2048

Groovy Traits

A less visited talk but not less interessting was "Traits and their usage inside groovy" by Jochen Theodorou. Jochen talked about the reason why they invented and implemented traits and why it is better to use traits then mixins.
With a lot of examples he showed use cases and best practices.

Projector Pattern

Finally we visited "Efficency and Flexibility of the projector pattern" by Dierk König. Maybe you don't know the pattern it is very likely that you already used this pattern when you programmed some GUI Application. In short words the projector pattern is when you work with an API that describes what the GUI should Display, but not how things are displayed. For this reason you use a Projector and only the projector knows how to Display GUI Elements.

Wednesday, December 10, 2014

Stackoverflow in JavaFX ChangeListeners

JavaFXs ChangeListeners are an easy way to monitor changes on JavaFX Properties and do some work if a change happened. But as easy as that is you easily can run into a stackoverflow because you'd changed the monitored property inside the ChangeListener.
Imagine you like to sort a Collection every time it is modified. Do sorting inside the ChangeListener raises a Stackoverflow because the sort itself raises a change event. So, how can we prevent that? The answer is simple: remove the ChangeListener before the code that modifies the property and then add it again!

public void onChanged(javafx.collections.ListChangeListener.Change<? extends Pair<String, L>> change){
        change.getList().removeListener(this);
        Collections.sort(change.getList(), comparator());
        change.getList().addListener(this);
    }


In this example we monitor a list and sort it when its content changes.

Saturday, November 15, 2014

JavaFX TabPane and Tab change

At the moment i am working with JavaFX building a little Application that has a lot of configurable parameters. For the reason of not getting lost on a dialog with thousand of different checkboxes, textfields and so on, the parameter controls should be grouped with the JavaFX control TabPane. A TabPane was quickly done but soon i realized that it is not so easy to prevent the user from changing the current tab if the parameters grouped in this tab have invalid values. Instead of switching to the selected tab i rather like to show a validation error message. So i did some reading on the JavaFX API but there is no way out of the box to achieve this behavior. You can do some work if the tab has changed but not before it is changed. If you have a similar issue with the TabPane maybe my solution will work for you :-)

class StateAwareChangeListener implements ChangeListener<Tab>
  {

    /**
     * go to previous tab if validation fails and this flag is true.
     */
    private boolean roleback;

    /**
     * If validation is ok change the tab.
     *
     * {@inheritDoc}
     *
     */
    @Override
    public void changed(ObservableValue<? extends Tab> arg0, Tab arg1, Tab arg2)
    {
      if (roleback) {
        roleback = false;
        return;
      }

      boolean validateConfig = validateIfChangeIsPossible();
      if (validateConfig == false) {
        roleback = true;
        tabPane.getSelectionModel().select(arg1);
      }
    }
  }

This listener calls the method validateIfChangeIsPossible that you have to implement by yourself. If changing the tab is possible return true. If false the old tab is selected again. You can also parse the new tab as a parameter into validateIfChangeIsPossible, if you need the information.

Finally add this class as a ChangeListener to the selectedItemProperty of the TabPane:

tabPane.getSelectionModel().selectedItemProperty().addListener(new StateAwareChangeListener()); 

Tuesday, October 28, 2014

JavaFX SceneBuilder or how to add more Cols and Rows to a GridPane

Yeah, i know it sounds simple: add some additional columns and / or rows to a GridPane with the SceneBuilder. Minute over minute i looked at the Properties-View of the GridPane but no way to add columns or rows.
Solution: right click on the GridPane in the hierachy view and simply select what you want to do ;-)