Giter Site home page Giter Site logo

cssfx's Introduction

cssfx

Build Status Maven Central Open Hub project report for CSSFX

⚠ WARNING ⚠

In version 11.3.0 we have relocated & refactored the project.

  • maven groupId has been changed to fr.brouillard.oss
  • java module name has been changed from cssfx to fr.brouillard.oss.cssfx
  • classes package has been changed from org.fxmisc.cssfx to fr.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.

CSSFX YouTube demo

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 headless
  • mvnw -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
  • 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.

cssfx's People

Contributors

floriankirmaier avatar joshpetit avatar martinfrancois avatar mcfoggy avatar p-m-j avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cssfx's Issues

resolving dependency doesn't work

I tried adding the latest release to a project of mine.
It can't find it with Gradle.
Can it be, that the latest release wasn't published properly?

Listener get added exponentially.

Listeners are added Exponentially, because there is no check, whether a Window/Node/Scene is already monitored. Readding elements can lead to exponential growth/slowdown/crash.

CSSFX doesn't monitor changes in Application stylesheet

When I define global CSS file for all stages of javafx application (see below), then changes aren't reloaded.

        final URL globalCssFile = getClass().getResource("styles/Global.css");
        Application.setUserAgentStylesheet(globalCssFile.toExternalForm());

Removing stylesheets from scene not possible while using CSSFX

While working on dark mode support I noticed that I could not disable the dark mode anymore. I enable dark mode by adding additional stylesheets to my application. Then when I disable the dark mode I do so by removing those added stylesheets. This has no effect when using CSSFX.

full test suite fails

if we execute mvn test, then tests in BasicUITest fail.

executed standalone mvn test -Dtest=BasicUITest it works correctly.

fill README

Fill correctly the README to provide:

  • maven/gradle coordinates
  • 1 min basic usage
  • 5 min extended usage

Not working in Scala

I've tried running CSSFX in conjunction with Scala but I haven't had any luck so far. I thought sbt might be the issue but it doesn't work with Gradle either.
I don't know if you're interested in Scala but do you have any idea what the issue might be?

Replace cssfx's own logging functionality with slf4j

Please consider to replace cssfx's own logging functionality with slf4j. It's in order to support the major logging frameworks like log4j2, logback, etc. much easier.

slf4j removes the boilercode inside the user's JavaFX application to translate from cssfx's logger implementation to the major logging frameworks by implementing fr.brouillard.oss.cssfx.impl.log.CSSFXLogger.Logger and fr.brouillard.oss.cssfx.impl.log.CSSFXLogger.LoggerFactory.

provide module info

as stated in #30 cssfx is not modular.

we should remedy to that by:

  • either fixing the automatic module name
  • provide real module-info

Also the module name to expose must be defined:

  1. cssfx it is the current automatic module name:
    • good for compatibility reasons
    • bad for potential collisions in global namespace
  2. org.fxmisc.cssfx
    • avoid collisions by using the current groupId namespace
    • bad because out control, domain is owned by Thomas Mikula
  3. fr.brouillard.cssfx
    • avoid collisions by using an owned groupId namespace
    • its a controlled namespace (including for deployment in central)

IntelliJ + Windows: Changes not detected due to "___jb_tmp___"

Workaround:

Change the following setting in Intellij:
Settings/Preferences | Appearance & Behavior | System Settings | Use "safe write"

Details:

When activating the debug logging for cssfx, log statements like the following are generated:

2019-09-23T08:16:46.648961900Z [DEBUG] 'ENTRY_MODIFY' change detected in directory C:\Users\ogniesch\Documents\forum-facelift\forumviewer\UserInterfaceDesign\ApplicationTheme\src\main\resources\de\zeiss\<filename>\css
2019-09-23T08:16:46.648961900Z [DEBUG] file: <filename>.css___jb_tmp___ was modified
2019-09-23T08:16:46.649964300Z [DEBUG] file is not monitored

Files ending with jb_tmp are generated by IntelliJ. I think they are moved to the original path, and for some reason, this is not detected by the API used for file monitoring.

PathsWatcher does not close WatchService leading to Thread buildup

Pretty simple issue actually. Here is a visualVM screenshot:

image

PathsWatcher.stop should call watchService.close() but doesn't.

    private WatchService watchService;

    public void stop() {
        watcherThread.interrupt();
       // add:
       watchService.stop(); // might need try-catch
    }

Linear or Exponential Growth due to unregister logic

CSSFXMonitor
When the following methods are called: registerNode unregisterNode registerNode then the listener of the first registerNode are not cleanedUp. If this process is repeated, more and more listeners get collected ultimately slowing down the application. The same happens for the other register and unregister methods.

Ironically this escalates when I'm opening ScenicView in the same JVM (Without the cssfx inside of ScenicView). Then it slowly slows down until it crashes.

My recommendation is to remove the unregister events entirely like it was done in my original PR.
It's really hard to get the unregister logic correct.

I've tested that removing the whole unregister logic fixes the problem.

Redundant maven dependencies

I noticed that CssFX on maven central is strangely dependent on org.openjdk:javafx-javafx-controls:11, I think this should be a bug, can it be fixed?

Stylesheets in FXML files used via AfterburnerFX are not monitored

Our application uses AfterburnerFX and tons of FXML files. The CSS files are discovered either by "Convention" (css file has same name as fxml file) or via "Configuration" (declared explicitly in fxml file). I tried both and changing the CSS file does not trigger a reload.

Example:

<VBox styleClass="overview" xmlns="http://javafx.com/javafx/8.0.121"
      xmlns:fx="http://javafx.com/fxml/1" minWidth="400" maxWidth="400"
      stylesheets="@ElectricityRatePlanOverview.css, @../RatePlanOverview.css"
      fx:controller="uk.co.senapt.desktop.ui.module.product.rateplan.electricity.ElectricityRatePlanOverviewController">
</VBox>

NPE when adding stylesheets

For my new ShowcaseFX view / app I constantly need to add and remove stylesheets. When doing to I keep getting this NPE:

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
	at java.base/java.util.regex.Matcher.getTextLength(Matcher.java:1770)
	at java.base/java.util.regex.Matcher.reset(Matcher.java:416)
	at java.base/java.util.regex.Matcher.<init>(Matcher.java:253)
	at java.base/java.util.regex.Pattern.matcher(Pattern.java:1133)
	at fr.brouillard.oss.cssfx@11.5.0/fr.brouillard.oss.cssfx.impl.CSSFXMonitor$URIRegistrar.classpathToURI(CSSFXMonitor.java:319)
	at fr.brouillard.oss.cssfx@11.5.0/fr.brouillard.oss.cssfx.impl.CSSFXMonitor$URIRegistrar.register(CSSFXMonitor.java:342)
	at fr.brouillard.oss.cssfx@11.5.0/fr.brouillard.oss.cssfx.impl.CSSFXMonitor$StyleSheetChangeListener.onChanged(CSSFXMonitor.java:399)
	at javafx.base/com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
	at javafx.base/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
	at javafx.base/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:239)
	at javafx.base/javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
	at javafx.base/javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
	at javafx.base/javafx.collections.ObservableListBase.endChange(ObservableListBase.java:211)
	at javafx.base/javafx.collections.ModifiableObservableListBase.addAll(ModifiableObservableListBase.java:109)
	at com.dlsc.showcasefx@0.0.6/com.dlsc.showcase.impl.CssShowcaseViewSkin.updateStylesheets(CssShowcaseViewSkin.java:103)
	at com.dlsc.showcasefx@0.0.6/com.dlsc.showcase.impl.CssShowcaseViewSkin.lambda$new$0(CssShowcaseViewSkin.java:90)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.