New blog software

javascriptreactgatsby

I've started this blog in 2009 with a Wordpress installation. Then in 2014 I re-implemented the blog based on the static site generator Jekyll. This was a great experience back then and I'm still a big fan of static site generators and the way you are creating content with them. However, recently I wasn't that satisfied with Jekyll anymore, and so I started to work on a re-write of the blog system again.

Since roughly start of 2019, this blog is now using Gatsby.js under the hood. Gatsby is also a static site generator that lets me write articles with Markdown files like before. Like jekyll it then creates a bunch of HTML, JavaScript and CSS files that I can upload to my webserver. In the past few months I was also rewriting the website for the Java User Group Görlitz which was also using Jekyll in the past and now uses Gatsby.js too.

In this blog post I will write down some thoughts of why I switched the blogging tool, what I've learned on the way, what is still missing compared to Jekyll and what I'm planning for the future.

more...

Implement your own Redux in Java. Part 5: Async Middleware

javareduxfunctional programming

In this series of blog posts I'm implementing my own Redux in Java to use with JavaFX.

However, the purpose is not to create a production-ready library (because there is already ReduxFX available) but instead to learn by re-implementing it.

In the previous part I've upgraded the middleware API to match the original one from Redux.js. This was a prerequisite to implement asynchronous middlewares. And this will be the topic for this part.

Topics in this blog series (maybe I will adjust this in the process of writing):

more...

Implement your own Redux in Java. Part 4: Middleware

javaredux

In this series of blog posts I'm implementing my own Redux in Java to use with JavaFX.

However, the purpose is not to create a production-ready library (because there is already ReduxFX available) but instead to learn by re-implementing it.

In the previous part I've introduced the basic concept of "middlewares", one of the extension mechanisms of Redux. However, in the first approach I was using a simplified API for middlewares to get a better understanding of the concept. The actual API of Middlewares is a little more complex. In this part I will show the limitations of the previous API and what kinds of middlewares you can't build with it. Then I will transform the API and the implementation to the "real" API. This will be a prerequisite to implement middlewares for asynchronous behavior, which will be the topic of the next part.

Topics in this blog series (maybe I will adjust this in the process of writing):

more...

Implement your own Redux in Java. Part 3: First approach on Middlewares

javaredux

In this series of blog posts I'm implementing my own Redux in Java to use with JavaFX.

However, the purpose is not to create a production-ready library (because there is already ReduxFX available) but instead to learn by re-implementing it.

In the previous part I've showed how to connect the basic redux store to a JavaFX view. In this part I will take a first look into the first extension mechanism that Redux provides: Middlewares.

Topics in this blog series (maybe I will adjust this in the process of writing):

more...

Highlight Days in JavaFX DatePicker

javafx

Today I had the requirement to implement a highlighting of some days in the JavaFX DatePicker. As I haven't found an existing blog post or tutorial that describes this topic I will provide a short example here.

Similar to other JavaFX controls like ListView or TreeTable the DatePicker can be configured with a CellFactory. In this cellFactory you can configure the styling of individual cells.

The basic code looks like this:

DatePicker datePicker = new DatePicker();

datePicker.setDayCellFactory(new Callback<DatePicker, DateCell>() {
  @Override
  public DateCell call(DatePicker param) {
    return new DateCell() {
      @Override
      public void updateItem(LocalDate item, boolean empty) {
        super.updateItem(item, empty);
      }
    }
  }
})

JavaFX will reuse existing DateCell instances when the visible viewport is changed when the user switches between pages in the DatePicker. This way JavaFX saves resources and minimizes new instances as much as possible.

To reuse existing cells we need to override the updateItem method which will get the new LocalDate object as parameter. Inside this method we can now check if this day should get a special styling.

In my example I will highlight the holidays (in Saxony, Germany) with a special color.

more...

Implement your own Redux in Java. Part 2: Simple FXML Views

javaredux

In this series of blog posts I'm implementing my own Redux in Java to use with JavaFX.

However, the purpose is not to create a production-ready library (because there is already ReduxFX available) but instead to learn by re-implementing it.

In the previous part I've showed how the basic Redux functionality can be implemented. In this part I will show how to use it with JavaFX and how to combine a simple FXML based JavaFX View with our Redux store.

Topics in this blog series (maybe I will adjust this in the process of writing):

more...

Implement your own Redux in Java. Part 1: Basic Redux functionality

javaredux

To learn and understand new tech things I'm often implementing them on my own. I mean, How hard can it be? This time I'd like to show how to implement Redux with Java targeted towards JavaFX. The purpose here is not to actually use this implementation because there is already a really good one available. The purpose is only to see that Redux actually isn't that complex when it comes to a basic implementation of the library. As this topic includes a lot of sub-topics I will start a little series of blog posts that will cover the implementation of a Redux library in Java, the extension mechanisms of Redux and how to use them with JavaFX.

Topics in this blog series (maybe I will adjust this in the process of writing):

more...

GraphQL Example App 'Bloggie'

reactjavascriptgraphql

In the past I've given several talks on GraphQL (JavaLand 2017, JUG Saxony, JUG Berlin, BEDCon 2017, OOP 2018), a query language for web API's. In those talks I've used the example of a blog application with the name "Bloggie". Today I have made the github repository of this example public so that everyone interested in this example app can see the source code.

You can find it here: https://github.com/manuel_mauky/bloggie

bloggie screenshot

The app shows articles and authors both in a overview page and a details page and a comment section will be added in the future. The idea of this repository is to not only contain a single example but instead to implement the same use-case with different technologies and implementation styles.

At the moment I have a backend implemented with node.js and a frontend written with React.js and Apollo Client but in the future I'm planning to add other variants too. For example, a student I'm mentoring has compared several ways to implement GraphQL servers. This includes node.js, pure Java and Java with Java-Persistence API. So it's likely that I will add a Java implementation too.

In the frontend I'm planning to add another implementation with Angular and maybe another react-variant using a different graphql client library.

What is important to notice here is: This app is not intended for real-world usage! It's neither optimized for a good usability as a blogging platform nor can I guarantee the absence of bugs or security issues. The only purpose of the repository is to show and learn technologies and patterns around GraphQL.

One of the reasons to "open-source" the example app is that I'm planing to write more blog posts on GraphQL, React, Redux and other web technologies in the future. Because even though I'm programming with JavaScript for 10 years now and I've also used react.js, redux and GraphQL for several applications I haven't been blogging about these topics in the past.

more...

Javaland 2018: Talk about Immutables

java

I will be speaking at the Javaland conference 2018. This conference is organized by the iJUG e.V. which is the association of german speaking Java User Groups of which we as JUG Görlitz are a part of. The conference is also special because of the location: It will take place in the Phantasialand Brühl, a theme park in the area of cologne. It will last from 13th to 15th of march.

javaland banner

My talk will be about immutable data with Java. As I'm a fan of functional programming, I'm using immutable data structures a lot. For example when developing applications with Redux both in JavaScript and in Java, immutability is an important thing to keep in mind. For me personally, thinking in immutable objects is not a big deal anymore. It's natural and by this time I'm used to it. But when I talk to other developers or doing code reviews I sometimes see people having problems with this kind of development style. Therefore I hope to give a good introduction to the topic with the talk and also show how people can implement their own immutable data structures in Java - either by hand or by using third-party libraries. And I will also take a short look at other JVM languages like Kotlin or Frege.

more...

JavaFX Dialogs: How to set min-size and prevent closing?

javafx

In this post I will write about two problems with JavaFX dialogs and how to solve them: How can you set a minimal size for a dialog and how can you prevent the dialog from closing?

How to set a min-size for JavaFX Dialogs?

If you create a JavaFX Application Window without further configuration, you can resize the window without limitations. This means you can change the size so that no content is visible anymore.

todo app with JavaFX

To prevent this you have to set a minHeight and minWidth on the Stage of the window:

public class TestApp extends Application {
	@Override
	public void start(Stage primaryStage) {
		VBox root = new Vbox();

		primaryStage.setMinHeight(200);
		primaryStage.setMinWidth(200);

		primaryStage.setScene(new Scene(root, 400, 400);
		primaryStage.show();
	}
}

With Dialog you have a similar situation. By default JavaFX Dialogs are not resizeable but it is possible to change this default behavior. However, if the Dialog is set to be resizeable you are then able to minimize the size to 0 pixel like with the application window. In contrast to the main application window you can't set the min-size on the Dialog though. At least not directly.

To fix this you have to set the min-size on the stage of the dialog. This can be done like this:

Dialog dialog = new Dialog<>();
dialog.setResizable(true);

final Window window = dialog.getDialogPane().getScene().getWindow();
Stage stage = (Stage) window;

stage.setMinHeight(200);
stage.setMinWidth(200);

How to prevent the closing of a Dialog.

Another situation that we were facing in a real-world app lately was to prevent closing of a JavaFX Dialog when some validation logic has failed.

In the JavaDoc for the Dialog class you can find two paragraphs that look promising at a first glance: "Dialog Validation / Intercepting Button Actions" and "Dialog Closing Rules".

The first one tells you how you can add validation rules for dialog buttons and how to prevent the dialog from closing if the condition is not met when attempting to close the dialog.

With the lookup method of the DialogPane you can get the buttons of the Dialog and add EventFilters on them. If your validation fails you can consume the event to prevent the Dialog from closing:

Dialog dialog = new Dialog();

dialog.getDialogPane().getButtonTypes.addAll(ButtonType.OK, ButtonType.CANCEL);

TextField textField = new TextField();

dialog.getDialogPane().setContent(textField);

// Create an event filter that consumes the action if the text is empty
EventHandler<ActionEvent> filter = event -> {
	if(textField.getText().isEmpty()) {
		event.consume();
	}
};

// lookup the buttons
Button okButton = (Button) dialog.getDialogPane().lookup(ButtonType.OK);
Button cancelButton = (Button) dialog.getDialogPane().lookup(ButtonType.CANCEL);

// add the event-filter
okButton.addEventFilter(ActionEvent.ACTION, filter);
cancelButton.addEventFilter(ActionEvent.ACTION, filter);

The code above creates a Dialog with a TextField and two Buttons (OK and CANCEL). You can't close the dialog with these buttons as long as the TextField is empty. In many situations this may not be your desired behavior: Typically you like to prevent closing with the OK Button but allow the user to cancel the action and close the dialog with the CANCEL button. However, in other situations you may want to achive exactly this: Prevent the closing even when the cancel button is pressed. So everything is ok with this code? Not quite. You can still click the "x" in the window of the dialog and the Dialog will close no matter what your validation says.

This is when the second part of the JavaDoc page comes into play. It describes the rules when it's possible to close a Dialog "abnormally" (which includes clicking the "x" but also pressing some OS specific shortcut like Alt+F4 on Windows). These rules are not bad. You can only close a dialog this way if the dialog has a CANCEL Button. From a usability perspective this makes sense: If the user can't finish the process in the dialog she may want cancel it either by pressing the cancel button of the dialog or the "x" in the window title.

But what if (for some reasons) you have other requirements? What if you have to prevent the closing even though it might not result in good usability? For this usage there is no easy API available.

But it is still possible with some workarounds: In JavaFX you can prevent the closing of a Stage by adding an event-filter with the setOnCloseRequest method. With this knowledge you can use the same approach from the beginning of this article to access the Stage of the dialog to add this event-filter:

Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();

stage.setOnCloseRequest(event -> {
	if(tf.getText().isEmpty()) {
		event.consume();
	}
});
more...