1. Introduction
Font Awesome gives you scalable vector icons that can instantly be customized. This plugin enables toolkit specific icon support.
Currently supported FontAwesome version is 4.4.0
.
FontAwesome by Dave Gandy (@davegandy)
Font License: SIL OFL 1.1 (http://scripts.sil.org/OFL)
Applies to all font files
Code License: MIT (http://opensource.org/licenses/mit-license.html)
Applies to all CSS files
Griffon version: 2.3.0
2. Usage
2.1. Swing
The griffon-fontawesome-swing:1.4.0
JAR provides a new Icon class: griffon.swing.support.fontawesome.FontAwesomeIcon
.
You may use this class with any Swing component that supports an Icon property.
2.2. JavaFX
The griffon-fontawesome-javafx:1.4.0
JAR provides a new Node class: griffon.javafx.support.fontawesome.FontAwesomeIcon
.
You may use this class with any JavaFX control that accepts a graphic property. You may also use the icon directly as
it is a subclass of javafx.scene.control.Label
. The icon class can be used inside an FXML file too.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.GridPane?>
<?import griffon.javafx.support.fontawesome.FontAwesomeIcon?>
<GridPane prefHeight="60.0" prefWidth="200.0"
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.example.AppController">
<children>
<Button fx:id="preferencesActionTarget"
GridPane.columnIndex="0" GridPane.rowIndex="0"
mnemonicParsing="false"
prefWidth="200.0">
<graphic>
<FontAwesomeIcon fontAwesome="FA_GEAR"/>
</graphic>
</Button>
</children>
</GridPane>
The JavaFX icon requires the usage of the FontAwesome
enum value.
2.3. Action Resources
Action icons can be set using resources files if the following format is used:
iconClassName|name:size:color
size
and color
are optional.
Here’s an example using the Swing icon
org.example.AppController.action.Preferences.small_icon=griffon.swing.support.fontawesome.FontAwesomeIcon|fa-gear
The JavaFX version for the same icon value is
org.example.AppController.action.Preferences.icon=griffon.javafx.support.fontawesome.FontAwesomeIcon|fa-gear
3. Configuration
The plugin delivers artifacts for both Swing and JavaFX. It also contains Groovy enhancements that can be used in combination with the respective UI toolkit DSL (SwingBuilder and GroovyFX).
3.1. Gradle
You have two options for configuring this plugin: automatic and manual.
3.1.1. Automatic
As long as the project has the org.codehaus.griffon.griffon
plugin applied to it you
may include the following snippet in build.gradle
dependencies {
griffon 'org.codehaus.griffon.plugins:griffon-fontawesome-plugin:1.4.0'
}
The griffon
plugin will take care of the rest given its configuration.
3.1.2. Manual
You will need to configure any of the following blocks depending on your setup
dependencies {
compile 'org.codehaus.griffon.plugins:griffon-fontawesome-swing:1.4.0'
}
dependencies {
compile 'org.codehaus.griffon.plugins:griffon-fontawesome-javafx:1.4.0'
}
dependencies {
compile 'org.codehaus.griffon.plugins:griffon-fontawesome-swing-groovy:1.4.0'
}
dependencies {
compile 'org.codehaus.griffon.plugins:griffon-fontawesome-javafx-groovy:1.4.0'
}
3.2. Maven
First configure the griffon-fontawesome-plugin
BOM in your POM file, by placing the following
snippet before the <build>
element
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.codehaus.griffon.plugins</groupId>
<artifactId>griffon-fontawesome-plugin</artifactId>
<version>1.4.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Next configure dependencies as required by your particular setup
<dependency>
<groupId>org.codehaus.griffon.plugins</groupId>
<artifactId>griffon-fontawesome-swing</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.griffon.plugins</groupId>
<artifactId>griffon-fontawesome-javafx</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.griffon.plugins</groupId>
<artifactId>griffon-fontawesome-swing-groovy</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.griffon.plugins</groupId>
<artifactId>griffon-fontawesome-javafx-groovy</artifactId>
</dependency>
4. Modules
The following sections display all bindings per module. Use this information to successfully override a binding on your own modules or to troubleshoot a module binding if the wrong type has been applied by the Griffon runtime.
4.1. JavaFX
Module name: fontawesome-javafx-groovy
Depends on: javafx-groovy
bind(BuilderCustomizer.class)
.to(FontAwesomeJavaFXBuilderCustomizer.class)
.asSingleton();
The following nodes will become available on a Groovy View
Node | Type |
---|---|
fontAwesomeIcon |