Friday, October 13, 2017

Friday Fun XLVII - Back to life...

Back to life...

after all that Serverside stuff in Singapore during the last months I'm finally back home and even more important back into JavaFX :)
So this week I have created a little JavaFX control which I saw on my iPhone and Mac. If you know iTunes you know that little progress/timer control which Apple uses to visualize the download of a song and also the playtime of that song.
It is not a really fancy control but maybe that is the reason why I like it, it is simple and does not need any explanation...very nice.
So here is a little screenshot of the control I'm talking about...

Yes it is very small so I did what I always do as a first step...I create a drawing which looks like follows...

So this control has more or less three states

These states have different visualizations as you can see in the image above. 
The STOPPED state is visualized with a ring and a play icon which indicates to click it to start a process.
In the waiting state the color is different and the outer ring has a gap and is rotating. In addition the icon changed from a play icon to a stop icon which indicates that you can stop the waiting by pressing the control.
In the running state the color changed back to the original one and the progress is visualized by an additional progress bar.
In my implementation the control will fire events in different situations, so you will find a TimerEvent class which has a Type. The types are as follows...
  • STARTED       (fired when the timer was started)
  • STOPPED       (fired when the timer was stopped)
  • CONTINUED   (fired when the timer was stopped and not finished yet)
  • FINISHED       (fired when the timer finished)
  • RESET           (fired when the reset() method was called)
  • WAITING       (fired when the timer was set to waiting)
You can attach a TimerEventListener to the control and your program can react on the different events that the control will fire.
The control has the following properties which you can use...
  • backgroundColor
  • color
  • waitingColor
  • playButtonVisible
  • duration
Most of the properties are self explaining so I will only shortly explain the playButtonVisible property.
Because this control might also come in handy when visualizing a download etc. it is not always needed to show the play button but only the stop button when it is running. For this reason the play button can be switched off.
The duration defines the time the control will running until it is finished.

Here is a little video of the control in action...

I have no really use case for this control and just created it because I like it and would like to see how much does it take to implement it in JavaFX

Well that's it for today, so as always you will find the code over at github...

Enjoy the upcoming weekend and...keep coding... 

Wednesday, June 14, 2017

TilesFX 1.4.4


Just on time before my next visit to Singapore I was able to release a new version of TilesFX. Last weekend I finally found some time to add some more features to TilesFX which I had on my list for some time.
First of all I've added a skin that simply shows a smoothed area chart called SmoothAreaChartTileSkin. As parameters you just have to add a list of ChartData objects.
The skin looks as follows...

This might sometime be useful for some dashboards if you would like to keep it simple :)

The next one that I've added is a RadarChartTileSkin which has two different Modes (Mode.POLYGON and Mode.SECTOR). Also the RadarChart takes a list of ChartData objects as parameter in Tile. The two different modes will look as follows...

As you can see both variants can be useful. In the example above I've used the RadarChart to visualize the temperature on every hour of the day which gives a nice temperature overview for measurements.
For the RadarChartTile I have implemented a limit of 128 ChartData elements which will be supported. The reason for this is that if you have more than 128 elements in a RadarChart you can't identify any value on the chart any more.

The third new skin I've added is a CountryTileSkin. In principle this tile simply shows the selected country as a SVGPath and a value with a unit.
This might come in handy if you would like to compare the data of a few countries on a dashboard with a little eye candy.
The CountryTileSkin looks like this...

Nothing really special but like I said...sometimes it could be handy :)
Because if I only show a single country I need SVG paths with a higher resolution which is the reason why I've added the file that contains the SVG paths for nearly all countries that you can also find in Java Locale.
The problem with this high resolution SVG paths is that they are big...the properties file alone is 1.3 MB which is the reason why the library is now 1.3 MB big.
For the WorldTileSkin I've only used lo resolution SVG paths where the file is only 125kb big but they don't look nice when used as a single country.

Well that's it for today, as always you can find the source code and binaries here:

Source Code: github

Binaries      : bintray

If you would like to know how to use the different skins in TilesFX you might want to check out the code from github and take a look at the Class that is part of the TilesFX library. If you run this Class you will get this...

In this demo I make use of nearly all skins that are available in TilesFX at the moment.

If you have any idea for tiles you need for you dashboard, please let me know and don't forget...keep coding... ;)

Friday, June 9, 2017

Java Geek Bike Ride + BBQ


Over the years it became some kind of tradition that the Java User Group M√ľnster organizes a little community event...the Java BBQ at my place in the summer. But this year I thought we need to improve that a bit. Instead of only having the BBQ, I thought we first should do some exercise before we start the BBQ :)
And for that reason we will do a little Java Geek Bike ride this year followed by the traditional Java BBQ.
So here is my plan for our's around 25km which should be ok because we are not on a hurry..

Because we'll do the bike ride everyone who would like to attend should bring a bike :)
And no won't be a race but a relaxed ride with enough time to have some "Fahrbier" ;)
If you have no chance to bring a bike with you, I could offer one more bike, otherwise feel free to only join the BBQ part. I could also offer a place to sleep for at least 2 person so just let me know if you need a place to stay, otherwise there are some B&B close by which might work for you.
As always feel free to present things you would like to talk about, e.g. last year one of our attendees presented some interesting stuff which ended in a session at the JavaLand conference... :)

The date for the Java Geek Bike Ride + BBQ will be the 

Saturday the 29th of July

I would suggest that we will start not too late which means maybe around 12pm.
As always I will take care about the drinks and you only have to bring some stuff for the BBQ.
Everyone should bring the kind of meat/sausages etc. she/he would like to eat and it would be awesome if some of you might be able to also bring some salad and bread for the BBQ.

If you are interested but don't know if you are "allowed" to come...just ping me...everybody is welcome as always.

You can find the place here:

Looking forward to spend a great day with you guys...

Keep coding...

Thursday, June 8, 2017

Another new TilesFX skin...


Last time when I was sitting in Singapore skimming the web for some interesting stuff I've stumbled upon a dashboard where a gauge was in front of a line graph. Unfortunately I did not save the image but it was stuck in my head and I thought it might sometime be useful to see not only the current value but also a little history of formerly measured values.
Here is a little screenshot of what I came up with...

As you can see the control shows a bar graph gauge which visualizes the current value. In the center of this gauge you will find a line graph that shows the history of the measured values. In this case I've made use of the strokeWithGradient() feature in combination with gradientStops() to color the line graph.
The time in the lower right corner shows the time of the last update and the text in the lower center shows the time from the first measurement in the line graph to the last measurement.
I think I should also add min- and maxValue to the gauge to get a better idea about the possible range but that's not done yet.
I can imagine that this kind of visualization might be interesting for some use cases but to be honest I'm not sure :)

The new skin can be found in the latest release of TilesFX (1.4.3) which you can find here

Source: github

Binary: bintray

The name of the skin is: SkinType.GAUGE_SPARK_LINE

The screenshot above was create using the following TileBuilder code:

tile = TileBuilder.create().skinType(SkinType.GAUGE_SPARK_LINE)
                  .prefSize(400, 400)
                  .barBackgroundColor(Color.rgb(255, 255, 255, 0.1))
                  .sections(new Section(0, 33, Tile.LIGHT_GREEN),
                            new Section(33, 67, Tile.YELLOW),
                            new Section(67, 100, Tile.LIGHT_RED))
                  .gradientStops(new Stop(0.0, Tile.LIGHT_GREEN),
                                 new Stop(0.33, Tile.LIGHT_GREEN),
                                 new Stop(0.33,Tile.YELLOW),
                                 new Stop(0.67, Tile.YELLOW),
                                 new Stop(0.67, Tile.LIGHT_RED),
                                 new Stop(1.0, Tile.LIGHT_RED))

And that's it for today, short but hopefully useful :)

Keep coding...

Monday, May 1, 2017

Formatting numbers in Medusa


Because of the the current project in Singapore I do not have a lot of time to code JavaFX but I try make use of every minute I can find :)
Last week someone found an interesting bug in Medusa that I was not aware of because it never showed up in my tests.
The following screenshot of the bugreport directly shows the problem...

The gauges on the screenshot use the Medusa DashboardSkin and the interesting part is the visualization of the value text.
In Medusa I have a method to adjust the font size so that the given text will fit into a given width. Means if the width of the given text will exceed the given width the font size will be decreased as along as the text will fit in the given width.
This behaviour leads to the different font size used for e.g. -54.90 and 0.0 in the screenshot above.
Well if you just use one gauge or all gauges are always in the same range this is no problem but if you have multiple gauges with values in different ranges (which is often the case) it simply doesn't look good.
So I've started to fix this problem and figured out that it was not that easy as I first thought.

The solution to this problem (at least the one that I've found...there might be better ones) is as follows.
First I figure out the longest text for the value. Therefor I measure the length of the minValue and the maxValue text. When doing this I have to take the number of decimals into account that was set by the user. Doing this gives me the maximum number of characters that can appear in the value text incl. the minus for negative values.
With having this numbers I can make use of the String.format() method to make sure the text will be formatted the right way.
But before I can do that I also have to take into account that instead of rounding the values I would like to simply cut of the decimals after the given number of decimals.
Therefor I have to take into account to use Math.floor() for positive and Math.ceil() for negative values when using String.format().
You might think why not simply use NumberFormat in combination with DecimalFormat because with this you can use patterns like "000.00" and a RoundingMode to format numbers but here you will run into problems with negative numbers and their minus character.
Well like I mentioned my solution might not be the perfect one but it works for Medusa and because of the limited time I have it is good enough for me :)

Here is a method that will format a given value in the range of the given min- and maxValue, the given number of decimals and the given locale...

public static String formatNumber(final Locale LOCALE, final double MIN_VALUE, 
                                  final double MAX_VALUE, final int DECIMALS, 
                                  final double VALUE) {
    StringBuilder sb        = new StringBuilder("%.").append(DECIMALS).append("f");
    String        f         = sb.toString();
    int           minLength = String.format(Locale.US, f, MIN_VALUE).length();
    int           maxLength = String.format(Locale.US, f, MAX_VALUE).length();
    int           length    = Math.max(minLength, maxLength);

    StringBuilder formatStringBuilder = new StringBuilder("%").append(length).append(".").append(DECIMALS).append("f");
    String        formatString        = formatStringBuilder.toString();

    double value = VALUE;
    if (value > 0) {
        value = Math.floor(VALUE * Math.pow(10, DECIMALS)) / Math.pow(10, DECIMALS);
    } else if (value < 0) {
        value = Math.ceil(VALUE * Math.pow(10, DECIMALS)) / Math.pow(10, DECIMALS);

    return String.format(LOCALE, formatString, value);

I don't know if this might be useful for someone else but even if not it fixed the bug in Medusa which is all I wanted :)

That's all for today, so...keep coding...

Friday, April 7, 2017

Friday Fun XLVI - Image Matrix


Last weekend when sitting in my hotel room in Singapore I had the idea to test the performance of my DotMatrix control again. So I thought what about pixelating an image and visualize it using the control.
Well to be honest it was just too easy to here is the result...

On the left side you see the original picture and on the right side the related pixelated matrix image.
So I thought why not adding some text and figured out that when I draw the text on the DotMatrix control I usually set all "transparent" pixels to the dotOffColor which doesn't look good in this example.
Therefor I've added another method to the DotMatrix control which only draws the pixels in a character that are "on". The method is called

  • setCharAtWithBackground()

So with this it was easy to add some text on top of the pixelated image without destroying the existing background pixels.
Now that this was done I decided it might be nice to be able to simply shift the DotMatrix in each direction. Long story short I've implemented for additional methods which are

  • shiftLeft()
  • shiftRight()
  • shiftUp()
  • shiftDown()

When calling one of this methods the whole DotMatrix will be shifted by one dot in the choosen direction and redraws itself.
Now I could really test the capability of the DotMatrix by calling for example the shiftLeft method in an AnimationTimer with an update rate of 10ms. So the result was nice as you can see in the following video...

You could also combine the calls like first calling shiftLeft() and after that shiftUp(). It's not perfect because both times the drawMatrix() method will be called but even with this little drawback the DotMatrix is fast enough to create a smooth scrolling effect.

Please keep in mind that you should not go crazy with the no of dots in the DotMatrix control. You will definitely see a decrease in performance if you go to a high number of columns and rows. In the video I use 100x85 dots for the DotMatrix which I think is good enough to use it also for images.

So I don't have any use case for the DotMatrix control at the moment but maybe one of you has and therefor you can find the source code as always over at github.

You will also find 2 other demos in the source code (Main2 and Main3). In Main2 I show you how to create one DotMatrix out of two images and in Main3 I show you how to use two images and draw them alternating on the have fun playing around with it :)

Well that's it for always I wish you a nice weekend and never forget...keep coding... ;)

Friday, March 31, 2017

Friday Fun XLV - StockTicker


On my way back from Singapore last time I've created a little Demo that shows the new StockTileSkin of my TilesFX library.
In principle the StockTileSkin is very similar to the SparkLineTileSkin with the difference that it always shows the increase/decrease of the reference value in percentage and as a number.

So in the demo I get the current stock quote of Oracle and IBM once a minute from the NYSE. Because I'm not really into the broker and banking business I have no idea if that makes sense, so forgive me if this idea is totally stupid :)

To understand how this Skin works it needs some more explanation...
First of all you have to define the so called averaging period, this number represents the number of values that you would like to show in the line graph.

In this example I've decided to poll the stock quote every minute and set the averaging period to 120 which means the graph will show the last 2 hours when filled up
If no value is present the min and max values will be taken from Tile.getMinValue() and Tile.getMaxValue(). You also have to make sure that these values are in a usable range because values in Tile will be clamped to the min- and maxValue (I might change this for this specific skin in the future).

For a real good demo I should preload the line chart with the data of the previous day but I did not had the time to extend the demo to this.
Means if you start the demo and the NYSE is closed at that time you won't see any change in the value at all. But if you start it during the trading hours of the NYSE you might see some changes over time (but keep in mind that I only poll once a 1 minute).
If you did not set the reference value, the first value of the data list will be taken to calculate the increase of decrease of the current value. 
If you would like to stick your manual set reference value you might want to set autoReferenceValue property to false.
The reference value will be visualized using a dashed line color with the tresholdColor.

In addition to the StockTileSkin I thought it might be nice to make use of my DotMatrix control and create and add a scrolling ticker too.
To give you an idea what I'm talking about, here is a screenshot of the demo...

The service that I use to get the stock quotes can be found at and is nice for testing some things. The problem is that first of all the data is not available for all companies so it took me some time to figure out two quotes that are updated regularly which made me end up with Oracle and IBM :)

If you would like to add another company stock symbol you can simply add it to the list of symbols in the Main.class. For example let's add Microsoft to the list

public class Main extends Application {
    private static final List<String> SYMBOLS;
    static {
        SYMBOLS = new ArrayList<>();
        SYMBOLS.add("MSFT"); // Simply add it to the list

Be aware that I did not spend much time in layouting mulitple stock items...means I've tried it with 2 and 3 stock might look bad with 4 but you will figure out how to make it better ;)

I hope that the StockTileSkin is somehow useful and if you have suggestions on how to improve it...please let me know :)

If you are interested in the source code of this demo you can find it as always on github.

And at last here is a little video that shows the StockTicker Demo in action after it ran for some time.

That's it for today...cheers from Singapore and...keep coding... :)