Thursday, September 22, 2016

Thursday Fun XXXIX


This week was JavaOne in San Francisco and it was a always :)
During the conference my friend Todd showed me some visualization framework that creates some kind of dashboards where one part of the dashboard was a world map.
When I saw that world map I thought it would be nice to have an interactive world map as a JavaFX control.
So I've created one and here it's what it looks like...

The map is based on SVGPath elements and to resize the map correctly I use the ScalableContentPane from Michael Hoffer's amazing VWorkFlows framework.
Each country could also hold a value which might be useful for some kind of data visualization.

If you are interested in the code you will find it as usual on github.

That's it for enjoy the upcoming the weekend and...keep coding :)

Friday, September 2, 2016

Friday Fun XXXVIII

Hello again,

Today it's just a short blogpost about another little fun component that I've found on the web. In principle it's just a button that could be fun using it as a submit button. Here is what it looks like...

I thought that might be fun to implement in JavaFX and here you go...
In the implementation is room for improvement because the progressbar does not really reflect the progress it takes to download something. So if you would do it right, the progressbar would be updated dependent on the current process. Here it is simply part of the animation.
After the Java BBQ last weekend I've decided to add some of the mentioned improvements and now the behavior is as follows. You can click the button and after that it will wait for updating the progress (0.0 - 1.0). If the progress reaches 1.0 the checkmark will appear and the button return to it's start look.
I've added a method called setFailed() which will show a cross and change the button color to red before it will return to it's start look.
Nevertheless the component is fun and here is a little video that shows my version in action...

And like always the source is available on github.

That's it for keep coding... :)

Friday, August 26, 2016

Friday Fun XXXVII


This time I have another fun component for you...well it's not really one component but more a container plus a component.
Last weekend I was skimming the web for some inspiration and stumbled upon an animated card navigation demo which you can find on dribbble.
I don't really know why I chose this card navigation thing because I have no use for it but I liked the challenge to create it in JavaFX :)

So here is a little video that shows my implementation...

As you can see my implementation has a little bit different behavior (esp. after one card was selected my cards move out to the right in parallel where in the original demo one card after another moved out to the right). In the beginning my version looked absolutely identical to the demo but somehow I did not like the animation and changed it to the current version.

In principle we have two components here

  • Card
  • CardBox

The Card class has a title and it has an AnchorPane where you can add your own content like follows:

Card card = new Card("My Card");
card.getContent().add(new Button("My Button"));

Instead of adding a Button you can add whatever JavaFX node you like and you can adjust it by using the static methods in AnchorPane:

  • AnchorPane.setTopAnchor(NODE, DISTANCE)
  • AnchorPane.setRightAnchor(NODE, DISTANCE)
  • AnchorPane.setBottomAnchor(NODE, DISTANCE)
  • AnchorPane.setLeftAnchor(NODE, DISTANCE)

The other class we have is the CardBox which extends StackPane. The CardBox also has an icon (which again is implemented using Ikonli) on the upper left corner which reacts on mouse clicks. If you click it the CardBox will show you all Cards it contains and you can select one Card by clicking on it.
As soon as you select a card all other cards will move out to the right and the selected Card will fill the whole area of the CardBox.

I guess that's it already for today, maybe you'll find this Card navigation menu useful and if you would like to have the code, feel free to fork it on github.

Oh just as a reminder...tomorrow the Java BBQ will happen so just in case you have time and would like to not hesitate to participate...

Otherwise enjoy the upcoming weekend and...keep coding :)

Friday, August 19, 2016

Friday Fun XXXVI


back from my vacation I've found a nice little menu control on the web and thought that might be a good candidate for my next Friday Fun component.
It's not really something special and it only took me last sunday morning to create it but it's fun :)
To give you an idea here are two screenshots that show the menu in open and in closed state...

So it's a simple button and when you press this button it's outer ring will grow to the menu which can contain up to 4 menu items.
The best usage for this control might be on a mobile application where you can put it on the bottom. The menu itself is translucent so that you can see the background shining through.
For the icons I make use of the really nice icon library called Ikonli of my colleague and friend Andres Almiray. The Ikonli library contains a lot of different icons but I only added the Material and MaterialDesign icons to the control. So if you would like to use for example the Fontawesome icons you need to add the appropriate dependency to your build.gradle e.g.

compile 'org.kordamp.ikonli:ikonli-fontawesome-pack:1.6.0'

Please find more information about the supported icon packs here.
The following code snippet will show you how to set the menu up...

FunMenu funMenu = new FunMenu();


funMenu.setOnItem1MousePressed(e -> System.out.println("Icon 1 pressed"));
funMenu.setOnItem2MousePressed(e -> System.out.println("Icon 2 pressed"));
funMenu.setOnItem3MousePressed(e -> System.out.println("Icon 3 pressed"));
funMenu.setOnItem4MousePressed(e -> System.out.println("Icon 4 pressed"));

As you can see it's really easy. When clicking an item the menu will automatically go back to the closed state.

You can style the menu by using CSS, here is the default CSS file so that you know what you have to override in your custom CSS file. (to be honest I was to lazy to create styleable properties for the parameters...sorry :) )...

.menu {
    -fx-background-radius: 1024;
    -fx-background-color : #ffcb4d65;

.menu-item {
    -fx-background-radius: 1024;
    -fx-background-color : transparent;

.menu-item-icon {
    -fx-icon-color: white;

.rotating-button {
    -fx-background-radius: 1024;
    -fx-background-insets: 0;
    -fx-background-color : #ffcb4d;

.cross {
    -fx-scale-shape     : true;
    -fx-shape           : "M 29 23 L 29 29 L 23 29 C 21.3431 29 20 30.3431 20 32 
                           C 20 33.6569 21.3431 35 23 35 L 29 35 L 29 41 
                           C 29 42.6569 30.3431 44 32 44 C 33.6569 44 35 42.6569 35 41 
                           L 35 35 L 41 35 C 42.6569 35 44 33.6569 44 32 
                           C 44 30.3431 42.6569 29 41 29 L 35 29 L 35 23 
                           C 35 21.3431 33.6569 20 32 20 
                           C 30.3431 20 29 21.3431 29 23 Z";
    -fx-background-color: white;

Here is a little video that shows the menu in action...

And if you are interested in the source code you can find it on github as always.

In principle that's all for keep coding... :)

Friday, July 29, 2016

Friday Fun XXXV

Hi there,

Well I could not withstand to create another Friday Fun control before my vacation which is another little gauge that might be useful for one or the other dashboard.
Last weekend I saw a similar gauge on a tweet and thought by myself that should be an easy here is the gauge from the tweet...

...and what should I was easy :)

Here is a little screenshot of my version...

This is not really something special but I think it might be useful. So on the outside you see what I call sections (green, yellow and red) and the bar that represents the current value of the gauge will always be drawn in the color of the current section.
If you switch off the visibility of the sections (setSectionsVisible(false)) the sections will disappear and the bar will be drawn in the barColor.
You could add the sections by calling the setSections(Section... sections) method or add single sections by calling the addSection(Section section) method.

And if you would like to see it in action, here is a little video..

As I said nothing special but if you are interested in the code you can find it on github as always.

That's it for today, so enjoy the summer and keep coding...

Friday, July 22, 2016

Friday Fun XXXIV


This is the last Friday Fun component before my vacation so I hope you like it :)
Tuesday I was skimming the web to get some inspiration and stumbled upon a nice little gauge at Dribbble. This is what it looks like...

The use case for such a control is really specific but I like how the designer did it and so I thought this might be an interesting control to create.
With most of the the controls I make again use of my Medusa library for the gauge model. The control itself is based on a JavaFX Region which is the easiest way to create custom controls. You just have to keep in mind that this approach is not very convenient when creating controls libraries because there is no separation of the model and the view.
For the colored areas I used the Medusa Sections and for the visualization of those sections I simply used JavaFX Path's.
The current quality indicator is just another path that will be translated, rotated and filled by the current section color.
To give you an idea how I create such controls let me show you the prototype that I created in an vector drawing prototype.

From this drawing I took all the parameters that I needed to create the control. And this is what the control looks like...

I'm not using the exact same colors as the original but I think it's close enough :)
For those of you who want to see it in action, here is a little video that shows the functionality...

This fits well where you have values that are good when they are small but not the way around which is the reason why I've added a property named reverseOrder which can be used to reverse the color scheme. Means if reverseOrder == true the colors will be from red (1) to green (10).

And that's all I have to say for today...and for at least the next 3 weeks because I will be on vacation...on Crete...yeah :)

If you would like to take a look at the code, feel free to fork it on github.

Enjoy the upcoming weekend and keep coding...

Friday, July 8, 2016

Friday Fun XXXIII


Today I just have a little control that I want to share with you, it's not really something special but sometimes could be useful, I named it ChargeControl. It could be used to visualize the charge of a battery, signal strength or goal reached etc.
The really nice thing about this control is that I wrote it in 30 minutes which simply shows how effective it can be to use JavaFX (if you know what you are doing ;) ).
So here is what it looks like...

As you can see it's not really amazing but it works which was the most important thing. Again I make use of Medusa for the model and one can set values from 0.0 - 1.0.
This control is really light-weight because it only contains Regions that are styled by CSS which makes the amount of code to realize it really small.

Well what should I say...I guess that's it already again and if you are interested in the code you will find it as always on github.

Enjoy the upcoming weekend and do never forget...keep coding ;)