Awesome
cssfx
⚠ WARNING ⚠
In version
11.3.0
we have relocated & refactored the project.
- maven
groupId
has been changed tofr.brouillard.oss
- java module name has been changed from
cssfx
tofr.brouillard.oss.cssfx
- classes package has been changed from
org.fxmisc.cssfx
tofr.brouillard.oss.cssfx
⚠ WARNING ⚠
CSSFX enhances developer productivity by providing CSS reloading functionality in your running application.
While developing you can run your JavaFX application, modify some CSS sources in your preferred editor, hit save button (or CTLR+S or CMD-S) and your JavaFX application is modified in real time.
Project coordinates
Java >= 11
Versions compatible with JavaFX 11 start with 11.X
.
Find latest version on central or old ones before relocation.
Maven
<dependency>
<groupId>fr.brouillard.oss</groupId>
<artifactId>cssfx</artifactId>
<version>11.4.0</version>
</dependency>
Gradle
dependencies {
implementation "fr.brouillard.oss:cssfx:11.4.0"
}
Modular Java
CSSFX does not currently provide a module descriptor, but it defines its module name fr.brouillard.oss.cssfx
.
If you wish to use CSSFX from a modular javafx application you will need to require it for the moment as an automatic module.
// module-info.java
module your.module.name {
requires fr.brouillard.oss.cssfx;
}
Java 8
Versions compatible with JavaFX 8 are all 1.X
versions (see latest on central)
Maven
<dependency>
<groupId>org.fxmisc.cssfx</groupId>
<artifactId>cssfx</artifactId>
<version>1.1.1</version>
</dependency>
Gradle
dependencies {
implementation "org.fxmisc.cssfx:cssfx:1.1.1"
}
Usages
Embedded
Starting monitoring CSS changes in development is as simple as adding one line in your application code.
CSSFX.start()
Doing so CSSFX will start to track every CSS resource that will be declared on any Scene or Parent in your application. This monitoring will be active for all the Stage that your application will use.
You can also disable CSSFX by adding the following argument to the JVM: -Dcssfx.disable=true
.
Mapping URIs to files on disk
CSSFX uses a functional interface URIToPathConverter (a function<String, Path> in fact) in order to be able to map CSS uris to file on the disk.
By providing several default implementations CSSFX is expected to run for you out of the box, without changes.
CSSFX comes with converters for:
- Maven
- Gradle
- execution from jar file
By registering new converters, you can influence the way CSSFX resolves the files to monitor, see next paragraph for an example
If you think that CSSFX is missing some default converters, please post a new issue or create a pull request.
Converter example
Let's consider the following situation (sorry for the windows like path, you'll transform by yourself for other envs):
- my app is packaged in c:/jars/myapp.jar
- my sources are located in c:/projects/myapp/src/...
In order to support this setup, you could create your converter and use it in CSSFX
URIToPathConverter myConverter = new URIToPathConverter() {
@Override
public Path convert(String uri) {
Matcher m = Pattern.compile("jar:file:/.*\\.jar!/(.*\\.css)").matcher(uri);
if (m.matches()) {
final String sourceFile = m.replaceFirst("c:/projects/myapp/src/$1").replace('/', '\\');
return Paths.get(sourceFile);
}
return null;
}
};
CSSFX.addConverter(myConverter).start();
Embedded with homemade configuration
If you need more control on how CSSFX will monitor your application & CSS changes, then you can use some extended functionalities of the CSSFX
builder class.
There you will be able to:
- add/reset converters
- restrict monitoring on
- one Stage
- one Scene
- one Node
As an external application
TODO
As a java agent
TODO
Logging in CSSFX
CSSFX comes with a mini logging framework.
CSSFX supports different properties to change default logging behavior
System Property | Description |
---|---|
cssfx.log | activates CSSFX logging |
cssfx.log.level | set the logging level to use, possible values NONE ERROR WARN INFO DEBUG , default is INFO |
cssfx.log.type | set the type of "appender" to use, possible values none console jul , default is console |
You can also register your own LoggerFactory.
CSSFXLogger.setLoggerFactory((loggerName) -> (level, message, args) -> {
System.out.println("I log by myself, original message: " + String.format(message, args));
});
Build & release
Normal build
mvnw clean install
: UI tests are run headlessmvnw -P-ci clean install
: UI tests are run visible on screen
Release
mvnw -Prelease,ci clean install
: this will simulate a full build for oss delivery (javadoc, source attachement, GPG signature, ...)git tag -a -s -m "release X.Y.Z, additionnal reason" X.Y.Z
: tag the current HEAD with the given tag name. The tag is signed by the author of the release. Adapt with gpg key of maintainer.- Matthieu Brouillard command:
git tag -a -s -u 2AB5F258 -m "release X.Y.Z, additional reason" X.Y.Z
- Matthieu Brouillard public key
- Matthieu Brouillard command:
mvnw -Prelease,ci -DskipTests deploy
git push --follow-tags origin master
Credits
Many thanks to the JPro company which actively supports cssfx and promotes its usage.
Also, a big thank you to all contributors and people who reported issues or enhancement requests ; an OSS project is nothing without its users and community.
Special thanks to Tomas Mikula and his FXMisc project umbrella that have simplified the route of CSSFX to maven central prior to version 11.3.0
.