Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions src/main/java/fr/brouillard/oss/cssfx/CSSFX.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import java.util.Set;
import java.util.concurrent.Callable;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Node;
Expand All @@ -40,7 +43,29 @@

public class CSSFX {
// prevent multiple global starts of CSSFX
private static boolean isCssFXStarted = false;
private static boolean isGlobalCssFXStarted = false;

private static boolean isAnyCssFXStarted = false;


private static BooleanProperty cssFXStarted = new SimpleBooleanProperty(false);
Comment on lines +46 to +51

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the purpose of keeping several states? isn't only one enough?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isGlobalCssFXStarted prevents starting CSSFX.start() twice - which would end in twice as many listeners.

isAnyCssFXStarted just tells us, whether CSSFX was started in any way.

It's worth noting, that It's not really possible to start CSSFX.



/**
* A property which indicates if CSSFX is started or not.
* @return the property
*/
public static ReadOnlyBooleanProperty cssFXStartedProperty() {
return cssFXStarted;
}

/**
* @return Indicates if CSSFX is started or not.
*/
public static boolean isCSSFXStarted() {
return cssFXStarted.get();
}


/**
* Directly start monitoring the CSS of the application using defaults:
Expand All @@ -51,8 +76,8 @@ public class CSSFX {
* @return a Runnable object to stop CSSFX monitoring
*/
synchronized public static Runnable start() {
if(!isCssFXStarted) {
isCssFXStarted = true;
if(!isGlobalCssFXStarted) {
isGlobalCssFXStarted = true;
return new CSSFXConfig().start();
} else {
return () -> {};
Expand Down Expand Up @@ -199,11 +224,14 @@ public CSSFXConfig addConverter(URIToPathConverter converter) {
* @return a Runnable object to stop CSSFX monitoring
*/
public Runnable start() {

if(Boolean.getBoolean("cssfx.disable")) {
System.out.println("CSSFX was not started, because it's disabled via the system property 'cssfx.disable'");
return () -> {};
}

cssFXStarted.set(true);

Comment on lines +233 to +234

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we lack a cleanup of this state change during stop action

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stop mechanism doesn't really work.
The listener still stays active.
And it's not really used in any application I know of.
So I would rather suggest removing the stop method.

if (!CSSFXLogger.isInitialized()) {
if (Boolean.getBoolean("cssfx.log")) {
LogLevel toActivate = LogLevel.INFO;
Expand Down