Aug 28

FontAwesomeFX 8.0.9 with 40 new icons

I have updated FontAwesomeFX and released version 8.0.9.
A few days ago the FontAwesome 4.2.0 was released with 40 additional icons (FontAwesome now contains 479 icons).

Also I added a simple browser to preview all contained icons.
You can start it via: de.jensd.fx.fontawesome.test.IconOverview

iconsbrowser_8.0.9

Download Binaries
Sources @ Bitbucket

Maven Artifact:

<dependency>
  <groupId>de.jensd</groupId>
  <artifactId>fontawesomefx</artifactId>
  <version>8.0.9</version>
</dependency>
Aug 27

MQTT.fx 0.0.7 released

A new version of MQTT.fx is available featuring:

  • Scripting support
  • Setup/Re-configuration tool
  • Reviewed Connection Profile Editor
  • Reviewed UI and style

007_start
Download binaries HERE.

Scripting support

I have added support for scripts executed by the Nashorn Engine.
Thought it might be helpful for testing a MQTT message flow of a certain setup, e.g. simulate sensors sending temperature value messages. All controlled via the UI.

007_executescript

Adding new scripts

New scripts can be easily made available for execution via the UI. The app is scanning a folder named “scripts” located at the MQTT.fx working directory:
OS X: [USER_HOME]/Library/Application Support/MQTT-FX/scripts
Windows: [USER_HOME]\AppData\Local\MQTT-FX\scripts
Linux: [USER_HOME]/MQTT-FX/scripts
If this folder does not exists it is created by MQTT.fx containing a demo script.

007_workingdir

Naming convention:

[INDEX]__[NAME].js
01__Switch_Fountain_Test.js

[INDEX] - controls the order of the entry in the drop down menu
__ - delimiter between index and name
[NAME] - the name of the menu entry (words are delimit by '_')

Hint:
If you name a script “separator”, e.g. 02__separator.js a separator is added to the menu at the “index” position.

007_scripting

Example script:

var Thread = Java.type("java.lang.Thread");
var System = Java.type('java.lang.System');

function execute(action) {
    out("Test Script: " + action.getName());
    for (var i = 0; i < 10; i++) {
        switchON();
        Thread.sleep(500);
        switchOFF();
        Thread.sleep(500);
    }
    action.setExitCode(0);
    action.setResultText("done.");
    out("Test Script: Done");
    return action;
}

function switchON() {
    out("fountain ON");
    mqttManager.publish("home/garden/fountain", "ON");
}

function switchOFF() {
    out("fountain OFF");
    mqttManager.publish("home/garden/fountain", "OFF");
}

function out(message){
    System.out.println(message);
}

The entry point of execution is the function execute(action).
During script execution System.out is hooked by MQTT.fx to print output to the console. Thus with System.out.println() messaged can be printed to the UI-console.

The interface to the broker-connection is the bound mqttManager. Messages can be published via the established broker connection.

Setup/Re-configuration Tool

If no configuration can be found, the app assumes its first start. The user is promoted with a setup dialog to create e new configuration.

Also if a configuration has been found but it seems to be corrupt or the format doesn't fit a newer version also a new configuration can be created or the exiting config can be opened in an external editor (assumed an editor has been assigned to open *.xml-files.

007_setup

Reviewed Connection Profile Editor
Now the Connection Profile Editor is recognising wether the chosen profile has been changed (buttons are enabled/disabled accordingly). Changes can be reverted as not already applied.

007_newprofile

Reviewed UI and Style

Greetings from Yosemity! ;-)

Aug 20

Poor mans input constraints

For me the best way to prevent the user from annoying errors and error messages is simply in the first line to try not to allow the user e.g. to enter invalid data or to execute actions while data in incomplete (disabled buttons/menu entries).
If only numbers allowed in an input field I think its a better approach to restict user input to numbers only instead of validating and popping up with error messages after applying or “OK”.

Swing has a JFormattedTextField which allows setting a format pattern to verify the input data. Sadly the current JavaFX API doesn’t contain such kind of control but thers is a way by adding an EventHandler for KEY_TYPED-Events and to consume the event at certain conditions. Consuming the event will end up the event bubbling phase. (see Handling JavaFX Events for more informations).
Clearly this can be implemented in a new control or by creating a subclass of TextField. But there is also a simple approach by attaching the wanted constraints to existing instances of standard controls. As you my know the editor controls of Cells and ComboBoxes are also TextFields. Thus such a handler can also be attached e.g. to a ComboBox.

Limitation/Disclaimer:
Don’t sue me for this very simple approach ;-)!
As this is just a limitaion of the INPUT while TYPING it can be bypassed e.g. by copy-paste.
Clearly in the long run a JFormattedTextField like control supporting pattern matching, validation and user feedback is needed!

Runnable demo and code can be found here.

InputConstraintsDemo

        InputConstraints.noBlanks(noBlanksField);
        InputConstraints.noLeadingBlanks(noLeadingBlanksField);
        InputConstraints.numbersOnly(numbersOnlyField);
        InputConstraints.lettersOnly(lettersOnlyField);

        InputConstraints.noLeadingBlanks(valueComboBox.getEditor());
        InputConstraints.noLeadingBlanks(noLeadingBlanksComboBox.getEditor());
        InputConstraints.noBlanks(noBlanksComboBox.getEditor());
        InputConstraints.numbersOnly(numbersOnlyComboBox.getEditor());
        InputConstraints.lettersOnly(lettersOnlyComboBox.getEditor());
public class InputContraints{

    private InputContraints() {
        // not needed here
    }

    public static void noLeadingAndTrailingBlanks(final TextField textField) {
        textField.addEventFilter(KeyEvent.KEY_TYPED, createNoLeadingBlanksInputHandler());
        textField.focusedProperty().addListener((Observable observable) -> {
            textField.setText(textField.getText().trim());
        });
    }

    public static void noLeadingBlanks(final TextField textField) {
        textField.addEventFilter(KeyEvent.KEY_TYPED, createNoLeadingBlanksInputHandler());
    }

    public static void noBlanks(final TextField textField) {
        textField.addEventFilter(KeyEvent.KEY_TYPED, createNoBlanksInputHandler());
        textField.focusedProperty().addListener((Observable observable) -> {
            textField.setText(textField.getText().trim());
        });
    }

    public static void numbersOnly(final TextField textField) {
        numbersOnly(textField, Integer.MAX_VALUE);
    }

    public static void numbersOnly(final TextField textField, final Integer maxLenth) {
        textField.addEventFilter(KeyEvent.KEY_TYPED, createNumbersOnlyInputHandler(maxLenth));
        textField.focusedProperty().addListener((Observable observable) -> {
            textField.setText(textField.getText().trim());
        });
    }

    public static void lettersOnly(final TextField textField) {
        lettersOnly(textField, Integer.MAX_VALUE);
    }

    public static void lettersOnly(final TextField textField, final Integer maxLenth) {
        textField.addEventFilter(KeyEvent.KEY_TYPED, createLettersOnlyInputHandler(maxLenth));
        textField.focusedProperty().addListener((Observable observable) -> {
            textField.setText(textField.getText().trim());
        });
    }

    public static EventHandler<KeyEvent> createNoLeadingBlanksInputHandler() {
        return (KeyEvent event) -> {
            if (event.getSource() instanceof TextField) {
                TextField textField = (TextField) event.getSource();
                if (" ".equals(event.getCharacter()) && textField.getCaretPosition() == 0) {
                    event.consume();
                }
            }
        };
    }

    public static EventHandler<KeyEvent> createNumbersOnlyInputHandler(final Integer maxLength) {
        return createPatternInputHandler(maxLength, "[0-9.]");
    }

    public static EventHandler<KeyEvent> createLettersOnlyInputHandler(final Integer maxLength) {
        return createPatternInputHandler(maxLength, "[A-Za-z]");
    }

    public static EventHandler<KeyEvent> createNoBlanksInputHandler() {
        return (KeyEvent event) -> {
            if (event.getSource() instanceof TextField) {
                if (" ".equals(event.getCharacter())) {
                    event.consume();
                }
            }
        };
    }

    public static EventHandler<KeyEvent> createPatternInputHandler(final Integer maxLength, String pattern) {
        return (KeyEvent event) -> {
            if (event.getSource() instanceof TextField) {
                TextField textField = (TextField) event.getSource();
                if (textField.getText().length() >= maxLength || !event.getCharacter().matches(pattern)) {
                    event.consume();
                }
            }
        };
    }
}
Aug 12

MQTT.fx 0.0.6 released

I have just released a new version of MQTT.fx (0.0.6).

Introducing Connection Profiles
Instead of choosing a certain broker address and a broker port using the same connection options, I now have implemented Connection Profiles.

A named Connection Profile contains all information for a certain broker connection (address, port, Auth/SSL/TLS settings, Last Will/Testament, etc.). It’s much easier now to connect to different brokers with changed setups and connection options:

mqtt-connprofiles

Now a connection can be established by just choosing the name of a previous defined profile:

mqtt-connprofiles2

Support for SSL/TLS

Also I have started to implement support for SSL/TLS secured connections.
Unsecure:
MQTT.fx - v0.0.6 - connected unsecure
Secured:
MQTT.fx - v0.0.6 - connected secure

Support for Certificate Files
mqtt-certificates

Support for Keystores
Edit Connection Profiles keytores

Hint:
Again the configuration-format has changed, v0.0.6 will conflict with former versions and MQTT.fx won’t start.
In this case just delete (or rename) the mqttfx-config.xml.
Windows: [USER_HOME]\AppData\Local\MQTT-FX\mqttfx-config.xml
OS X: [USER_HOME]/Library/Application Support/MQTT-FX/mqttfx-config.xml

The new configration is automatically created on next app start.

Download binaries HERE.

Jul 28

“PiMac unibody” or a new home for my touch screen

In preparation for the JavaOne 2014 Session my 7″ touch screen from Chalk-Elec finally found a new home.
I bought a 1 mm sheet of aluminium and treated it with my jig saw and a rasp and folded a triangle stand for the screen. Basically there would be room enough for e.g. a Rapsberry Pi and it also stand touching the display:

DSC_9673

DSC_9675

DSC_9672

DSC_9668

Some anti slip pads on the button side

IMG_3589

IMG_3587

The Sketch

PiMac Scetch

Jul 27

MQTT.fx 0.0.5 released

Just released a new version of MQTT.fx.

New:

  • “Publish”, “Subscribe” and “Broker Status” can now be detached to be opened in a separate window: Just drag a tab title and drop it where the window should be placed. Closing of the window restores the content at the former position.
  • also I have done some UI polish

Download binaries HERE.

MQTT.fx0.0.5

Jul 15

TabPaneDetacher: Make your tabs detachable

I though it would be cool to detach e.g. the pane to publish messages in MQTT.fx if needed by just dragging the tab and dropping it at the wanted position to open its content as a dedicated new window.

drag tab

The TabPaneDetacher provides an easy to use way to enable the detach capability of with any JavaFX TabPane instance just by calling:

public class TabPaneDetacherDemoController {

    @FXML
    private TabPane demoTabPane;
    
    @FXML
    public void initialize() {
        TabPaneDetacher.create().makeTabsDetachable(demoTabPane);
    }    
    
}

The tab is removed from the tab pane and a new window is created containing the content of the tab, the window title is set to the tab name value. On closing that window the tab is restored at the original position:

Code can be found here in my Bitbucket repo.

Jul 10

UI logic with using JavaFX Bindings

For MQTT.fx I needed a ComboBox to enter new Topics or to choose recent topics from list.
But I want the user to enter or choose only (more or less) reasonable values otherwise the “Publish”/”Subscribe” buttons should be disabled:

ComboBox Bindings Demo 1

ComboBox Bindings Demo 2

Using the JavaFX Bindings API prevents some boilerplate code (implementing Listeners) and it is even more flexible as the result can be bound to several controls and at the end of the day its much more readable.

Contraint 1: The selection must not be empty.

  1. First create a JavaFX BooleanBinding.
  2. Then bind it to the disabledProperty of the button.

Contraint 2: Entered values must not contain only blanks (leading/trailing blanks can be trimmed later).

My approach is to

  1. add an EventFilter and to consume the event in case of only entered character is “SPACE”
  2. and if there are just blanks left when editing the value the content is cleared.
public class ComboBoxBindingsDemoController {

    @FXML
    private Label valueLabel;

    @FXML
    private Button goButton;

    @FXML
    private ComboBox<String> valueComboBox;

    private ObservableList<String> demoItemsList;
    private static final Pattern LEADING_BLANKS_PATTERN = Pattern.compile("^\\s*+");

    @FXML
    public void initialize() {
        valueComboBox.setItems(getDemoItemsList());

        BooleanBinding goButtonState = valueComboBox.editorProperty().get().textProperty().isEmpty()
                .or(valueComboBox.valueProperty().asString().isEmpty());

        goButton.disableProperty().bind(goButtonState);

        valueComboBox.getEditor().addEventFilter(KeyEvent.KEY_TYPED, (KeyEvent event) -> {
            Matcher matcher = LEADING_BLANKS_PATTERN.matcher(valueComboBox.getEditor().getText());
            if (" ".equals(event.getCharacter()) && valueComboBox.getEditor().getText().length() == 0) {
                event.consume();
            }
            else if(matcher.matches()){
                valueComboBox.getEditor().clear();
            }
        });

    }

    public ObservableList<String> getDemoItemsList() {
        if (demoItemsList == null) {
            demoItemsList = FXCollections.observableArrayList();
            demoItemsList.add("Erlangen");
            demoItemsList.add("Nürnberg");
            demoItemsList.add("Büchenbach");
        }
        return demoItemsList;
    }

    @FXML
    public void goAction() {
        System.out.println("Value '" + valueComboBox.getValue().trim() + "'");
    }

}

Complete runnable demo can be found at Bitbucket.

Jul 03

MQTT.fx 0.0.4 released

Just released new version of MQTT.fx.
Download binaries HERE.

MQTT.fx - v0.0.4

New:
- revisited UI (return of “real” buttons)
- extended support for $SYS-topics: subscription for mosquitto or Hive MQ can be choosen (in respect to @dobermai).
- publish and subcrive/receive are now different tabs
- experimental support for http-proxy (in respect to @dimaki123).
- last choosen broker & port is restored at next app start
- updated 3rd party libs (e.g. now using features of ControlsFX 8.0.6)
MQTT.fx - v0.0.4 - broker status
MQTT.fx - v0.0.4 - subscribe
MQTT.fx - v0.0.4 - connection options
MQTT.fx - v0.0.4 - validation

Fixed:
- publish to topics even if not subscribed before (in respect to @_efwe_)

Hint:
Configuration-format has changed, v0.0.4 might conflict with former versions.
In this case just delete (or rename) the mqttfx-config.xml.
Windows: [USER_HOME]\MQTT-FX\mqttfx-config.xml
OS X: [USER_HOME]/Library/Application Support/MQTT-FX/mqttfx-config.xml
The new configration is automatically created on next app start.