• Home
  • Events
  • About
  • Friday Fun XLIV – The Matrix

    March 23rd, 2017


    Last weekend I was thinking about a dot matrix display and remembered that this was always something I would like to do in JavaFX. Well after spending nearly 2 weeks in Singapore working on infrastructure documentation etc. I really needed some coding and because of the jetlag I had enough time during the early mornings to create a little control.

    To give you an idea what I’m talking about here is a little screenshot of the control…

    So as you can see this is not a really fancy control but more something simple and there is a reason for that. I remember that I’ve once started to create some kind of matrix control for JavaFX but that was in the early JavaFX 2 days and we had no Canvas node which was the reason why I’ve used nodes for each dot in the old version. But with this amount of dots the whole thing became really slow and because of that I simply never tried again.

    But when I thought about it over the weekend the Canvas node came to my mind again and so I’ve started a new approach with the dot matrix control.

    So this version runs completely in one Canvas node and is based on an integer array to make it fast. The main idea behind the dot matrix display was to create some kind of animated stock ticker.

    This idea lead to 3 requirements

    1. the matrix size has to be configurable
    2. it must be fast enough for animation
    3. it must be possible to set colors for each dot
    4. it should be possible to show text

    So let’s take a short look at each requirement.

    1. To make the matrix size configurable it is in principle only needed to define the number of dots per column and row you would like to see in the dot matrix. But there is one drawback here, if the control should be resizable you will also need to define the preferred size of the control to be able to resize it with the right aspect ratio.

    Therefor you will find a constructor that not only takes the number of columns and rows but also the preferredWidth and preferredHeight. In addition you could also add a color for the dot on and dot off state.

    So to create a DotMatrix with a size of 128×16 dots and a dot on color of red and a dot off color of dark gray you have to write the following code…

    or if you prefer using the DotMatrixBuilder it will look like follows…

    2. To make the dot matrix fast enough for animation I’ve tried to avoid as much overhead as possible. With overhead I mean things like

    • many nodes on the scene graph
    • crazy graphics (e.g. each dot has light reflection etc.)
    • complex drawing method

    To avoid as many nodes on the scene graph as possible the best solution is to make use of the Canvas node. This represents only one node on the scenegraph, can contain complex graphics and the redraw is more or less under your control (immediate mode rendering).

    And in addition the Canvas node is really fast πŸ™‚

    A picture explains more than 1000 words…so here is a screenshot of a former matrix that I did in Enzo…

    I think you now understand what I mean with crazy graphics…I mean it looks nice but for a bigger display this is simply overkill. For this control I used nodes for each dot…or better each LED.

    Because when animating the control I have to call the drawing method a lot and therefor this drawing method has to be as short and simple as possible. So let’s take a look at the drawing method in the DotMatrix control…

    That’s all, I clear the canvas, then simply iterate over the rows and columns, set the fill for the current dot and draw a circle at the current position defined by x and y.

    Keeping things simple makes the drawing fast enough to do some animation.

    3. To make it possible to set the color for each dot you need a 2d data structure which defines the position and stores the color. You can think of all possible combinations of Lists, Maps and custom Objects to realize that but if you would like to keep it simple you could simply stick with a simple 2-dimensional integer array. This will contain the x and y coordinates of each dot and you could use a 1 to enable the dot or a 0 to disable the dot.

    This works and is simple and fast BUT how to enable custom colors for each dot???

    For this it would be great to represent a color as an integer value but if you take a look at the javafx.scene.paint.Color class you will find all sorts of methods but unfortunately no method that returns the color as an integer value. Lucky me I remembered that the java.awt.Color class had such a method and so it was easy to take a look at the source code of OpenJDK (it’s so nice to be able to have the source code of Java available).

    To convert a color into an integer you simply can make use of some bit-shifting and the code to convert a color into an integer looks as follows…

    Now with this in place it was easy to store the color value as integer in the 2-dimensional array of the matrix. Oh and of course it would also be nice to have a method to convert an integer back to a Color, so here it is…

    In JavaFX the opacity is defined by a double compared to an int in the AWT color which is the reason for the ALPHA_FACTOR multiplication here.

    So now we can define for each dot in the matrix the location and the color by simply using a 2-dimensional integer array which is good for the performance.

    Means most of the work in the drawing method is done by converting an integer back to a Color. But because all of the operations used for the conversion are mainly bit-shifting and object creation this is not a problem.

    4. To be able to show text on the DotMatrix I needed to create some mapping of characters to dots. So my idea was to keep the DotMatrix close to a real hardware DotMatrix where you can define the xy position of the dot and a color. Means in the DotMatrix control switching on a dot is done by calling the method

    As you can see I don’t call the drawMatrix() method automatically which means I leave that up to you. So first one can set all the pixels needed and then you can call the drawMatrix() method. With this approach you can avoid a redraw after set a pixel.

    This is a big advantage when doing some kind of dot matrix ticker where text is moving from right to left. In this case you can first set a vertical line of pixels before you really draw them.

    But if you would like to automatically redraw after a pixel was set you will also find a method called setPixelWithRedraw() which does exactly this.

    Now back to the character mapping, here I’ve decided to create an 8×8 font for the ASCII characters between 32 – 126. And if you only need numbers I’ve also created an 8×8 font that only contains the numbers from 0 – 9.

    Again the goal was to keep it as simple as possible which was the reason to define each character by an integer array. So for example the digit 0 looks like this…

    As you can see I used the binary literals which is nice to represent a matrix of dots.

    Now the only thing I had to do was to read out each bit of each row and do some math related to the dot position.

    These calculations can be found in the setCharAt() and setDigitAt() methods in the DotMatrix control.

    A demo of how to use the DotMatrix control for a running text display can be found in the Demo class in the source code.

    I will definitely add this control also to TilesFX because it could be handy as a stock ticker on a dashboard.

    So that’s it for today, I hope this control will be useful for someone except me πŸ™‚


    I’ve removed the plain digits and added another MatrixFont which is 8×11 pixels. So now you can choose between

    • MatrixFont8x8
    • MatrixFont8x11

    In addition I’ve also added the possibility to set the dot shape to either DotShape.ROUND which is default or to DotShape.SQUARE.

    Here is a little video which shows the control in action…

    Please find the source code as usual at github.

    More examples can be found here

    Enjoy the upcoming weekend and keep coding…

    Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • email
    • Print
    • Twitter
    • LinkedIn
    • XING
    • Facebook
    • Google Bookmarks

    Customize your dashboard

    January 18th, 2017


    This is just a short post about the TilesFX library (github, bintray, maven) in combination with other libraries like

    The TilesFX standard tiles are nice and might be good for most of the typical dashboard content but what if you need more than that?

    Let’s say you would like to see a listview or one of your custom controls on such tile…

    Well for that reason I’ve added the CustomTileSkin which has the title and the text property of the standard tiles and which comes with an area where you can put your own JavaFX nodes.

    So this is what it looks like…

    As you can see the area for custom JavaFX nodes fills most of the tile so that you should have enough space for your components. If you setTextVisible(false) the area will even grow a bit more in y-direction.

    To give you an idea on how to use other controls within TilesFX I’ve created a little demo project which you can find on github at


    If you would like to start the demo from the command line you simple can call gradle Demo on the shell as follows:

    This will start the Main class of the project and will show you the following screen…

    In this demo you will see nearly all of the standard tiles in TilesFX (except the WeatherTileSkin) and in addition there is also one tile that simply uses an icon from the Ikonli library, nine tiles that shows some gauges from my Medusa library and three regulators from my Regulators library.

    The Tile class in TilesFX defines some colors that fit nicely to the standard tiles, so you can choose between GRAY, RED, GREEN, BLUE, ORANGE, YELLOW_ORANGE, YELLOW and MAGENTA. In addition also the standard FOREGROUND and BACKGROUND color are available in the Tile class. As you can see in the image above I made use of the Tile.BLUE color for all the Medusa gauges.

    I hope this demo will help you to make use of TilesFX for your own dashboards.

    That’s it for today…so keep coding… πŸ™‚


    Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • email
    • Print
    • Twitter
    • LinkedIn
    • XING
    • Facebook
    • Google Bookmarks

    Friday Fun XLIII

    January 12th, 2017


    Today it’s just a short post but I thought it might be of interest for one or the other. Two days ago the idea came to my mind that it might be fun to combine my world map control with my heat map control. To be honest I had no idea where I could use it for but I thought it might be useful for some cases.

    So I was skimming the web for use cases and found a couple of them which let me create this little fun control for you.

    In principle it is the world map from this post that now also contains a heat map from this post. The world map has all features as the original version, the only difference is that the hover effect and selection effect is disabled by default. But you can enable it if you like.

    I was surprised how easy it was to combine both maps into one and so the whole creation took me around 30min. The harder part was to find some data that I can use to test the capabilities of the combined map.

    The problem was that I needed data that came with latitude and longitude coordinates and in the end I found a simple list that contains around 7000 cities with their latitude/longitude coordinates.

    The idea of the heat map is to visualize some kind of hot spots on a map. The hot spots become bigger the more “events” are in the same area. Long story short, here are some screenshots of the same data using different heat map settings…

    As you can see the visualization depends on the used color mapping (color gradient from center of an event to the outside) and the event radius (size of each event).

    The code to generate the upper heatmap looks as follows…

    Where the code for the lower heatmap looks like this…

    If you would like to see only the hot spots without the base background color you simply have to set fadeColors(true) and you will get something like this…

    In principle that’s all I have to share with you today and I hope it might be useful for some of you.

    As always you can find the code over at github, so feel free to fork it and use it πŸ™‚

    Oh and do not forget…keep coding πŸ˜‰


    Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • email
    • Print
    • Twitter
    • LinkedIn
    • XING
    • Facebook
    • Google Bookmarks


    December 21st, 2016

    Aloha everyone,

    This will be my last post for 2016 and I have something for you which you might like. Always when I needed a dashboard I had to create it by myself completely from scratch.

    So I’ve decided to create a little library that contains at least some tiles that might be useful for dashboards.

    And because I love to tinker around with some hardware I’ve also added some tiles for interaction (like sliders and switches).

    To make it short…here is a screenshot of the current state…

    On the screenshot above you can see all tiles that are currently available and some of them are also available in Medusa (but there you will find only gauge related tiles).

    The default size of the tiles at the moment is 250x250px and I did not spend much time in resizing etc.

    Here is a short list of tiles that are part of the library at the moment:

    • ClockTile (a simple digital clock)
    • GaugeTile (a gauge like in Medusa)
    • HighLowTile (a tile that might be useful to show current value compared to reference value)
    • LineChartTile (a simple JavaFX line chart on a tile)
    • PercentageTile (a tile that shows the current value in percentage)
    • PlusMinusTile (a tile that has 2 buttons to increase/decrease a value)
    • SliderTile (a tile with a slider to set a value)
    • SparkLineTile (a tile containing a spark line graph like in Medusa)
    • SwitchTile (a tile that has a switch to toggle a value)
    • TextTile (a tile that contains a custom text)
    • TimerControlTile (a tile with a clock and time sections to control a value)
    • WorldMapTile (a tile with a world map like the one from worldfx)
    • WeatherTile (a tile that shows weather info using DarkSky)
    • NumberTile (a tile that simply shows a number, unit and some text)
    • TimeTile (a tile that shows a LocalTime which can be used for Durations etc.)
    • BarChartTile (a simple tile showing up to 4 bars in a sorted order)

    To make use of the WeatherTile you will need a DarkSky API key which you can get at

    DarkSky.net. The nice thing about using DarkSky is that they allow you to call the weather update 1000x a day for free. This should be more than enough for your private project.

    For those of you that would like to see it in action here is a little video…

    As always you can find the binary on bintray and the code on github under the following links

    The library will also be made available on maven central and you should be able to find it when you search for tilesfx. At the moment there is not much documentation except the Demo file which is part of the source code, please take a look at it to understand the usage. Another thing that would be nice to have would be a better TileLayout for dashboards, in my Demo I use a FlowLayout which allows me to use tiles of a different size.


    Please keep in mind that all of my code is open source which does not automatically mean it’s ready for production!

    If you have the need for a specific tile…please let me know and I might add it to the library.

    Well and that’s it for 2016, I wish all of you a merry christmas and a happy new year…and do not forget…keep coding… πŸ˜‰


    Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • email
    • Print
    • Twitter
    • LinkedIn
    • XING
    • Facebook
    • Google Bookmarks

    Friday Fun XLII

    December 15th, 2016


    Last week I’ve found a nice little progress indicator on the web that I really like and so I made the decision to create it in JavaFX.

    To be honest I did not really create a progress indicator but only the animation that you can use for whatever you like.

    There is really nothing special about this control so here is a little video that shows it in action…

    And if you are interested in the source you will find it as always on github

    A really short post this week πŸ™‚

    Keep coding and enjoy x-mas πŸ™‚


    Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • email
    • Print
    • Twitter
    • LinkedIn
    • XING
    • Facebook
    • Google Bookmarks