Skip to content

Instantly share code, notes, and snippets.

@ribasco
Last active December 16, 2020 05:36
Show Gist options
  • Save ribasco/1e4f9f5bd96ccb562eae84a39113b8c8 to your computer and use it in GitHub Desktop.
Save ribasco/1e4f9f5bd96ccb562eae84a39113b8c8 to your computer and use it in GitHub Desktop.
Intellij IDE JavaFX Live Templates

JavaFX Live Templates for IntelliJ IDE

Shortcut templates for generating lazy properties in JavaFX (Read-Only properties included)

Installation (Tested in IDE version 2020.3)

Store the text below in JavaFX.xml and save it to settings.zip with the following structure

 settings.zip
     |___  templates
            |__ JavaFX.xml

to import, go to File -> Manage IDE Settings -> Import Settings

Template shortcuts

  • fxlbool - Boolean Property (Lazy)
  • fxldouble - Double Property (Lazy)
  • fxlfloat - Float Property (Lazy)
  • fxlint - Integer Property (Lazy)
  • fxlstring - String Property (Lazy)
  • fxlobj - Object Property (Lazy)
  • fxllist - List Property (Lazy)
  • fxlset - Set Property (Lazy)

For read-only versions, prefix it with fxlr* instead

Example:

Typing fxlobj in editor and inputting color as the property name will produce:

    private ObjectProperty<Color> color;

    public Color getColor() {
        return colorProperty().get();
    }

    public void setColor(Color value) {
        colorProperty().set(value);
    }

    public ObjectProperty<Color> colorProperty() {
        if (this.color == null) {
            this.color = new SimpleObjectProperty<>(this, "color");
        }
        return this.color;
    }

Read-Only Version:

    private ReadOnlyObjectWrapper<Color> color;

    public Color getColor() {
        return colorWrapper().get();
    }

    private void setColor(Color value) {
        colorWrapper().set(value);
    }

    public ReadOnlyObjectProperty<Color> colorProperty() {
        return colorWrapper().getReadOnlyProperty();
    }

    private ReadOnlyObjectWrapper<Color> colorWrapper() {
        if (this.color == null) {
            this.color = new ReadOnlyObjectWrapper<>(this, "color");
        }
        return this.color;
    }
<templateSet group="JavaFX">
<template name="fxlbool" value="private BooleanProperty $VARIABLE$;&#10;&#10;public boolean is$VARIABLE_UPPER$() {&#10; return $VARIABLE$Property().get();&#10;}&#10;&#10;public void set$VARIABLE_UPPER$(boolean value) {&#10; $VARIABLE$Property().set(value);&#10;}&#10;&#10;public BooleanProperty $VARIABLE$Property() {&#10; if (this.$VARIABLE$ == null) {&#10; this.$VARIABLE$ = new SimpleBooleanProperty(this, &quot;$VARIABLE$&quot;);&#10; }&#10; return this.$VARIABLE$;&#10;}" description="Boolean Property (Lazy)" toReformat="true" toShortenFQNames="true">
<variable name="VARIABLE" expression="camelCase(String)" defaultValue="" alwaysStopAt="true" />
<variable name="VARIABLE_UPPER" expression="capitalize(VARIABLE)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
</context>
</template>
<template name="fxlobj" value="private ObjectProperty&lt;$TYPE$&gt; $VARIABLE$;&#10;&#10;public $TYPE$ get$METHOD$() {&#10; return $VARIABLE$Property().get();&#10;}&#10;&#10;public void set$METHOD$($TYPE$ value) {&#10; $VARIABLE$Property().set(value);&#10;}&#10;&#10;public ObjectProperty&lt;$TYPE$&gt; $VARIABLE$Property() {&#10; if (this.$VARIABLE$ == null) {&#10; this.$VARIABLE$ = new SimpleObjectProperty&lt;&gt;(this, &quot;$VARIABLE$&quot;);&#10; }&#10; return this.$VARIABLE$;&#10;}" description="Object Property (Lazy)" toReformat="true" toShortenFQNames="true">
<variable name="TYPE" expression="variableOfType(Type)" defaultValue="" alwaysStopAt="true" />
<variable name="VARIABLE" expression="variableOfType(TYPE)" defaultValue="" alwaysStopAt="true" />
<variable name="METHOD" expression="capitalize(VARIABLE)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_CONSUMER" value="false" />
</context>
</template>
<template name="fxldouble" value="private DoubleProperty $VARIABLE$;&#10;&#10;public double get$VARIABLE_UPPER$() {&#10; return $VARIABLE$Property().get();&#10;}&#10;&#10;public void set$VARIABLE_UPPER$(double value) {&#10; $VARIABLE$Property().set(value);&#10;}&#10;&#10;public DoubleProperty $VARIABLE$Property() {&#10; if (this.$VARIABLE$ == null) {&#10; this.$VARIABLE$ = new SimpleDoubleProperty(this, &quot;$VARIABLE$&quot;);&#10; }&#10; return this.$VARIABLE$;&#10;}" description="Double Property (Lazy)" toReformat="true" toShortenFQNames="true" useStaticImport="true">
<variable name="VARIABLE" expression="camelCase(String)" defaultValue="" alwaysStopAt="true" />
<variable name="VARIABLE_UPPER" expression="capitalize(VARIABLE)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
</context>
</template>
<template name="fxlint" value="private IntegerProperty $VARIABLE$;&#10;&#10;public double get$VARIABLE_UPPER$() {&#10; return $VARIABLE$Property().get();&#10;}&#10;&#10;public void set$VARIABLE_UPPER$(int value) {&#10; $VARIABLE$Property().set(value);&#10;}&#10;&#10;public IntegerProperty $VARIABLE$Property() {&#10; if (this.$VARIABLE$ == null) {&#10; this.$VARIABLE$ = new SimpleIntegerProperty(this, &quot;$VARIABLE$&quot;);&#10; }&#10; return this.$VARIABLE$;&#10;}" description="Integer Property (Lazy)" toReformat="true" toShortenFQNames="true" useStaticImport="true">
<variable name="VARIABLE" expression="camelCase(String)" defaultValue="" alwaysStopAt="true" />
<variable name="VARIABLE_UPPER" expression="capitalize(VARIABLE)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
</context>
</template>
<template name="fxlfloat" value="private FloatProperty $VARIABLE$;&#10;&#10;public float get$VARIABLE_UPPER$() {&#10; return $VARIABLE$Property().get();&#10;}&#10;&#10;public void set$VARIABLE_UPPER$(float value) {&#10; $VARIABLE$Property().set(value);&#10;}&#10;&#10;public FloatProperty $VARIABLE$Property() {&#10; if (this.$VARIABLE$ == null) {&#10; this.$VARIABLE$ = new SimpleFloatProperty(this, &quot;$VARIABLE$&quot;);&#10; }&#10; return this.$VARIABLE$;&#10;}" description="Float Property (Lazy)" toReformat="true" toShortenFQNames="true" useStaticImport="true">
<variable name="VARIABLE" expression="camelCase(String)" defaultValue="" alwaysStopAt="true" />
<variable name="VARIABLE_UPPER" expression="capitalize(VARIABLE)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
</context>
</template>
<template name="fxlstring" value="private StringProperty $VARIABLE$;&#10;&#10;public String get$VARIABLE_UPPER$() {&#10; return $VARIABLE$Property().get();&#10;}&#10;&#10;public void set$VARIABLE_UPPER$(String value) {&#10; $VARIABLE$Property().set(value);&#10;}&#10;&#10;public StringProperty $VARIABLE$Property() {&#10; if (this.$VARIABLE$ == null) {&#10; this.$VARIABLE$ = new SimpleStringProperty(this, &quot;$VARIABLE$&quot;);&#10; }&#10; return this.$VARIABLE$;&#10;}" description="String Property (Lazy)" toReformat="true" toShortenFQNames="true" useStaticImport="true">
<variable name="VARIABLE" expression="camelCase(String)" defaultValue="" alwaysStopAt="true" />
<variable name="VARIABLE_UPPER" expression="capitalize(VARIABLE)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
</context>
</template>
<template name="fxllist" value="private ListProperty&lt;$TYPE$&gt; $VARIABLE$;&#10;&#10;public ObservableList&lt;$TYPE$&gt; get$METHOD$() {&#10; return $VARIABLE$Property().get();&#10;}&#10;&#10;public void set$METHOD$(ObservableList&lt;$TYPE$&gt; value) {&#10; $VARIABLE$Property().set(value);&#10;}&#10;&#10;public ListProperty&lt;$TYPE$&gt; $VARIABLE$Property() {&#10; if (this.$VARIABLE$ == null) {&#10; this.$VARIABLE$ = new SimpleListProperty&lt;&gt;(this, &quot;$VARIABLE$&quot;, FXCollections.observableArrayList());&#10; }&#10; return this.$VARIABLE$;&#10;}" description="List Property (Lazy)" toReformat="true" toShortenFQNames="true">
<variable name="TYPE" expression="variableOfType(Type)" defaultValue="" alwaysStopAt="true" />
<variable name="VARIABLE" expression="variableOfType(TYPE)" defaultValue="" alwaysStopAt="true" />
<variable name="METHOD" expression="capitalize(VARIABLE)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_CONSUMER" value="false" />
</context>
</template>
<template name="fxlrbool" value="private ReadOnlyBooleanWrapper $VARIABLE$;&#10;&#10;public boolean is$VARIABLE_UPPER$() {&#10; return $VARIABLE$Wrapper().get();&#10;}&#10;&#10;private void set$VARIABLE_UPPER$(boolean value) {&#10; $VARIABLE$Wrapper().set(value);&#10;}&#10;&#10;public ReadOnlyBooleanProperty $VARIABLE$Property() {&#10; return $VARIABLE$Wrapper().getReadOnlyProperty();&#10;}&#10;&#10;private ReadOnlyBooleanWrapper $VARIABLE$Wrapper() {&#10; if (this.$VARIABLE$ == null) {&#10; this.$VARIABLE$ = new ReadOnlyBooleanWrapper(this, &quot;$VARIABLE$&quot;);&#10; }&#10; return this.$VARIABLE$;&#10;}" description="Read-Only Boolean Property (Lazy)" toReformat="true" toShortenFQNames="true">
<variable name="VARIABLE" expression="camelCase(String)" defaultValue="" alwaysStopAt="true" />
<variable name="VARIABLE_UPPER" expression="capitalize(VARIABLE)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
</context>
</template>
<template name="fxlrint" value="private ReadOnlyIntegerWrapper $VARIABLE$;&#10;&#10;public int get$VARIABLE_UPPER$() {&#10; return $VARIABLE$Wrapper().get();&#10;}&#10;&#10;public ReadOnlyIntegerProperty $VARIABLE$Property() {&#10; return $VARIABLE$Wrapper().getReadOnlyProperty();&#10;}&#10;&#10;private void set$VARIABLE_UPPER$(int value) {&#10; $VARIABLE$Wrapper().set(value);&#10;}&#10;&#10;private ReadOnlyIntegerWrapper $VARIABLE$Wrapper() {&#10; if (this.$VARIABLE$ == null) {&#10; this.$VARIABLE$ = new ReadOnlyIntegerWrapper(this, &quot;$VARIABLE$&quot;);&#10; }&#10; return this.$VARIABLE$;&#10;}" description="Read-Only Integer Property (Lazy)" toReformat="true" toShortenFQNames="true">
<variable name="VARIABLE" expression="camelCase(String)" defaultValue="" alwaysStopAt="true" />
<variable name="VARIABLE_UPPER" expression="capitalize(VARIABLE)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
</context>
</template>
<template name="fxlrobj" value="private ReadOnlyObjectWrapper&lt;$TYPE$&gt; $VARIABLE$;&#10;&#10;public $TYPE$ get$METHOD$() {&#10; return $VARIABLE$Wrapper().get();&#10;}&#10;&#10;private void set$METHOD$($TYPE$ value) {&#10; $VARIABLE$Wrapper().set(value);&#10;}&#10;&#10;public ReadOnlyObjectProperty&lt;$TYPE$&gt; $VARIABLE$Property() {&#10; return $VARIABLE$Wrapper().getReadOnlyProperty();&#10;}&#10;&#10;private ReadOnlyObjectWrapper&lt;$TYPE$&gt; $VARIABLE$Wrapper() {&#10; if (this.$VARIABLE$ == null) {&#10; this.$VARIABLE$ = new ReadOnlyObjectWrapper&lt;&gt;(this, &quot;$VARIABLE$&quot;);&#10; }&#10; return this.$VARIABLE$;&#10;}" description="Read-Only Object Property (Lazy)" toReformat="true" toShortenFQNames="true">
<variable name="TYPE" expression="variableOfType(Type)" defaultValue="" alwaysStopAt="true" />
<variable name="VARIABLE" expression="variableOfType(TYPE)" defaultValue="" alwaysStopAt="true" />
<variable name="METHOD" expression="capitalize(VARIABLE)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_CONSUMER" value="false" />
</context>
</template>
<template name="fxlrdouble" value="private ReadOnlyDoubleWrapper $VARIABLE$;&#10;&#10;public double get$VARIABLE_UPPER$() {&#10; return $VARIABLE$Wrapper().get();&#10;}&#10;&#10;public ReadOnlyDoubleProperty $VARIABLE$Property() {&#10; return $VARIABLE$Wrapper().getReadOnlyProperty();&#10;}&#10;&#10;private void set$VARIABLE_UPPER$(double value) {&#10; $VARIABLE$Wrapper().set(value);&#10;}&#10;&#10;private ReadOnlyDoubleWrapper $VARIABLE$Wrapper() {&#10; if (this.$VARIABLE$ == null) {&#10; this.$VARIABLE$ = new ReadOnlyDoubleWrapper(this, &quot;$VARIABLE$&quot;);&#10; }&#10; return this.$VARIABLE$;&#10;}" description="Read-Only Double Property (Lazy)" toReformat="true" toShortenFQNames="true">
<variable name="VARIABLE" expression="camelCase(String)" defaultValue="" alwaysStopAt="true" />
<variable name="VARIABLE_UPPER" expression="capitalize(VARIABLE)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
</context>
</template>
<template name="fxlrfloat" value="private ReadOnlyFloatWrapper $VARIABLE$;&#10;&#10;public float get$VARIABLE_UPPER$() {&#10; return $VARIABLE$Wrapper().get();&#10;}&#10;&#10;public ReadOnlyFloatProperty $VARIABLE$Property() {&#10; return $VARIABLE$Wrapper().getReadOnlyProperty();&#10;}&#10;&#10;private void set$VARIABLE_UPPER$(float value) {&#10; $VARIABLE$Wrapper().set(value);&#10;}&#10;&#10;private ReadOnlyFloatWrapper $VARIABLE$Wrapper() {&#10; if (this.$VARIABLE$ == null) {&#10; this.$VARIABLE$ = new ReadOnlyFloatWrapper(this, &quot;$VARIABLE$&quot;);&#10; }&#10; return this.$VARIABLE$;&#10;}" description="Read-Only Float Property (Lazy)" toReformat="true" toShortenFQNames="true">
<variable name="VARIABLE" expression="camelCase(String)" defaultValue="" alwaysStopAt="true" />
<variable name="VARIABLE_UPPER" expression="capitalize(VARIABLE)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
</context>
</template>
<template name="fxlrlist" value="private ReadOnlyListWrapper&lt;$TYPE$&gt; $VARIABLE$;&#10;&#10;public ObservableList&lt;$TYPE$&gt; get$METHOD$() {&#10; return $VARIABLE$Wrapper().get();&#10;}&#10;&#10;private void set$METHOD$(ObservableList&lt;$TYPE$&gt; value) {&#10; $VARIABLE$Wrapper().set(value);&#10;}&#10;&#10;public ReadOnlyListProperty&lt;$TYPE$&gt; $VARIABLE$Property() {&#10; return $VARIABLE$Wrapper().getReadOnlyProperty();&#10;}&#10;&#10;private ReadOnlyListWrapper&lt;$TYPE$&gt; $VARIABLE$Wrapper() {&#10; if (this.$VARIABLE$ == null) {&#10; this.$VARIABLE$ = new ReadOnlyListWrapper&lt;&gt;(this, &quot;$VARIABLE$&quot;, FXCollections.observableArrayList());&#10; }&#10; return this.$VARIABLE$;&#10;}" description="Read-Only List Property (Lazy)" toReformat="true" toShortenFQNames="true">
<variable name="TYPE" expression="variableOfType(Type)" defaultValue="" alwaysStopAt="true" />
<variable name="VARIABLE" expression="variableOfType(TYPE)" defaultValue="" alwaysStopAt="true" />
<variable name="METHOD" expression="capitalize(VARIABLE)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_CONSUMER" value="false" />
</context>
</template>
<template name="fxlrset" value="private ReadOnlySetWrapper&lt;$TYPE$&gt; $VARIABLE$;&#10;&#10;public ObservableSet&lt;$TYPE$&gt; get$METHOD$() {&#10; return $VARIABLE$Wrapper().get();&#10;}&#10;&#10;private void set$METHOD$(ObservableSet&lt;$TYPE$&gt; value) {&#10; $VARIABLE$Wrapper().set(value);&#10;}&#10;&#10;public ReadOnlySetProperty&lt;$TYPE$&gt; $VARIABLE$Property() {&#10; return $VARIABLE$Wrapper().getReadOnlyProperty();&#10;}&#10;&#10;private ReadOnlySetWrapper&lt;$TYPE$&gt; $VARIABLE$Wrapper() {&#10; if (this.$VARIABLE$ == null) {&#10; this.$VARIABLE$ = new ReadOnlySetWrapper&lt;&gt;(this, &quot;$VARIABLE$&quot;, FXCollections.observableSet(new HashSet&lt;&gt;()));&#10; }&#10; return this.$VARIABLE$;&#10;}" description="Read-Only List Property (Lazy)" toReformat="true" toShortenFQNames="true">
<variable name="TYPE" expression="variableOfType(Type)" defaultValue="" alwaysStopAt="true" />
<variable name="VARIABLE" expression="variableOfType(TYPE)" defaultValue="" alwaysStopAt="true" />
<variable name="METHOD" expression="capitalize(VARIABLE)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_CONSUMER" value="false" />
</context>
</template>
<template name="fxlset" value="private SetProperty&lt;$TYPE$&gt; $VARIABLE$;&#10;&#10;public ObservableSet&lt;$TYPE$&gt; get$METHOD$() {&#10; return $VARIABLE$Property().get();&#10;}&#10;&#10;public void set$METHOD$(ObservableSet&lt;$TYPE$&gt; value) {&#10; $VARIABLE$Property().set(value);&#10;}&#10;&#10;public SetProperty&lt;$TYPE$&gt; $VARIABLE$Property() {&#10; if (this.$VARIABLE$ == null) {&#10; this.$VARIABLE$ = new SimpleSetProperty&lt;&gt;(this, &quot;$VARIABLE$&quot;, FXCollections.observableSet(new HashSet&lt;&gt;()));&#10; }&#10; return this.$VARIABLE$;&#10;}" description="Set Property (Lazy)" toReformat="true" toShortenFQNames="true">
<variable name="TYPE" expression="variableOfType(Type)" defaultValue="" alwaysStopAt="true" />
<variable name="VARIABLE" expression="variableOfType(TYPE)" defaultValue="" alwaysStopAt="true" />
<variable name="METHOD" expression="capitalize(VARIABLE)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
<option name="JAVA_COMMENT" value="false" />
<option name="JAVA_CONSUMER" value="false" />
</context>
</template>
<template name="fxlrstring" value="private ReadOnlyStringWrapper $VARIABLE$;&#10;&#10;public String get$VARIABLE_UPPER$() {&#10; return $VARIABLE$Wrapper().get();&#10;}&#10;&#10;public ReadOnlyStringProperty $VARIABLE$Property() {&#10; return $VARIABLE$Wrapper().getReadOnlyProperty();&#10;}&#10;&#10;private void set$VARIABLE_UPPER$(String value) {&#10; $VARIABLE$Wrapper().set(value);&#10;}&#10;&#10;private ReadOnlyStringWrapper $VARIABLE$Wrapper() {&#10; if (this.$VARIABLE$ == null) {&#10; this.$VARIABLE$ = new ReadOnlyStringWrapper(this, &quot;$VARIABLE$&quot;);&#10; }&#10; return this.$VARIABLE$;&#10;}" description="Read-Only String Property (Lazy)" toReformat="true" toShortenFQNames="true">
<variable name="VARIABLE" expression="camelCase(String)" defaultValue="" alwaysStopAt="true" />
<variable name="VARIABLE_UPPER" expression="capitalize(VARIABLE)" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_CODE" value="true" />
</context>
</template>
</templateSet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment