Pārlūkot izejas kodu

:arrow_up: Upgrade components and core modules

:memo: Addressed/removed some TODOs

Components Module
:recycle: MFXFabBehavior: moved extended variant management in the component class, behaviors should not change the component state
:recycle: WithVariants: added method to remove variants from a component

Core Module
:recycle: When: added non-static method for disposal

Signed-off-by: Alessadro Parisi <alessandro.parisi406@gmail.com>
Alessadro Parisi 2 gadi atpakaļ
vecāks
revīzija
80024aa4b1

+ 3 - 0
modules/components/CHANGELOG.md

@@ -52,6 +52,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 - Reworked and renamed applyInitSizes(...) to onInitSizesChanged(). Init sizes now are taken into account by the new
   LayoutStrategy API
 - MFXFabSkin: do not take into account the init width as it is used by the LayoutStrategy now
+- MFXFabBehavior: moved extended variant management in the component class, behaviors should not change the component
+  state
+- WithVariants: added method to remove variants from a component
 
 ## Removed
 

+ 0 - 8
modules/components/src/main/java/io/github/palexdev/mfxcomponents/behaviors/MFXFabBehavior.java

@@ -71,17 +71,9 @@ public class MFXFabBehavior extends MFXButtonBehavior {
 	 * <p></p>
 	 * This is automatically called by the {@link MFXFabBase#extendedProperty()} when it changes.
 	 */
-	// TODO refactor this. Behavior classes should NOT change the component's state
 	public void extend(boolean animate) {
 		MFXFabBase fab = getFab();
 		boolean extended = fab.isExtended();
-		if (extended) {
-			fab.getStyleClass().remove("fab");
-			fab.getStyleClass().add("fab-extended");
-		} else {
-			fab.getStyleClass().remove("fab-extended");
-			fab.getStyleClass().add("fab");
-		}
 		double targetSize = computeWidth();
 		double targetTextOpacity = extended ? 1.0 : 0.0;
 

+ 0 - 2
modules/components/src/main/java/io/github/palexdev/mfxcomponents/controls/base/MFXSkinBase.java

@@ -85,8 +85,6 @@ public abstract class MFXSkinBase<C extends Control & WithBehavior<B>, B extends
 	// Delegate Methods
 	//================================================================================
 
-	// TODO behaviors should also integrate with the new When constructs if possible
-
 	/**
 	 * Delegate for {@link BehaviorBase#register(ObservableValue, ChangeListener)}.
 	 * <p>

+ 9 - 2
modules/components/src/main/java/io/github/palexdev/mfxcomponents/controls/fab/MFXFab.java

@@ -20,9 +20,9 @@ package io.github.palexdev.mfxcomponents.controls.fab;
 
 import io.github.palexdev.mfxcomponents.theming.base.WithVariants;
 import io.github.palexdev.mfxcomponents.theming.enums.FABVariants;
+import io.github.palexdev.mfxcomponents.theming.enums.MFXThemeManager;
 import io.github.palexdev.mfxcore.observables.When;
 import io.github.palexdev.mfxcore.utils.fx.SceneBuilderIntegration;
-import io.github.palexdev.mfxresources.MFXResources;
 import io.github.palexdev.mfxresources.fonts.MFXFontIcon;
 
 import java.util.List;
@@ -128,10 +128,17 @@ public class MFXFab extends MFXFabBase implements WithVariants<MFXFab, FABVarian
 		return this;
 	}
 
+	@Override
+	public MFXFab removeVariants(FABVariants... variants) {
+		WithVariants.removeVariants(this, variants);
+		onInitSizesChanged();
+		return this;
+	}
+
 	@Override
 	protected void sceneBuilderIntegration() {
 		SceneBuilderIntegration.ifInSceneBuilder(() -> {
-			String theme = MFXResources.load("sass/md3/mfx-light.css");
+			String theme = MFXThemeManager.LIGHT.load();
 			When.onChanged(sceneProperty())
 					.condition((o, n) -> n != null && !n.getStylesheets().contains(theme))
 					.then((o, n) -> n.getStylesheets().add(theme))

+ 10 - 1
modules/components/src/main/java/io/github/palexdev/mfxcomponents/controls/fab/MFXFabBase.java

@@ -24,6 +24,8 @@ import io.github.palexdev.mfxcomponents.controls.base.MFXSkinBase;
 import io.github.palexdev.mfxcomponents.controls.buttons.MFXButton;
 import io.github.palexdev.mfxcomponents.controls.buttons.MFXElevatedButton;
 import io.github.palexdev.mfxcomponents.skins.MFXFabSkin;
+import io.github.palexdev.mfxcomponents.theming.base.WithVariants;
+import io.github.palexdev.mfxcomponents.theming.enums.FABVariants;
 import io.github.palexdev.mfxcore.base.properties.styleable.StyleableBooleanProperty;
 import io.github.palexdev.mfxcore.observables.When;
 import io.github.palexdev.mfxcore.utils.fx.StyleUtils;
@@ -109,7 +111,14 @@ public class MFXFabBase extends MFXElevatedButton {
 	 * <p>
 	 * Also note that this uses {@link #getFabBehavior()} to get the behavior, since it's 'null' safe and exception safe.
 	 */
-	protected final void extend() {
+	protected void extend() {
+		boolean extended = isExtended();
+		if (extended) {
+			WithVariants.addVariants(this, FABVariants.EXTENDED);
+		} else {
+			WithVariants.removeVariants(this, FABVariants.EXTENDED);
+		}
+
 		Skin<?> skin = getSkin();
 		if (skin == null) {
 			// Let's ensure that no other listeners have been added before...

+ 4 - 0
modules/components/src/main/java/io/github/palexdev/mfxcomponents/theming/base/Variant.java

@@ -30,5 +30,9 @@ import io.github.palexdev.mfxcomponents.theming.enums.FABVariants;
  * (such as {@link WithVariants}) to apply the variant style class to the component.
  */
 public interface Variant {
+
+	/**
+	 * @return the style class that identifies this variant
+	 */
 	String variantStyleClass();
 }

+ 27 - 0
modules/components/src/main/java/io/github/palexdev/mfxcomponents/theming/base/WithVariants.java

@@ -21,6 +21,7 @@ package io.github.palexdev.mfxcomponents.theming.base;
 import io.github.palexdev.mfxcomponents.controls.base.MFXControl;
 import io.github.palexdev.mfxcomponents.controls.base.MFXLabeled;
 import io.github.palexdev.mfxcomponents.controls.base.MFXStyleable;
+import javafx.collections.ObservableList;
 import javafx.scene.Node;
 
 import java.util.LinkedHashSet;
@@ -74,6 +75,8 @@ public interface WithVariants<N extends Node, V extends Variant> {
 
 	N setVariants(V... variants);
 
+	N removeVariants(V... variants);
+
 	/**
 	 * Adds all the given variants to the given control.
 	 * <p>
@@ -104,6 +107,18 @@ public interface WithVariants<N extends Node, V extends Variant> {
 		return control;
 	}
 
+	/**
+	 * Removes all the given variants from the given control.
+	 */
+	@SafeVarargs
+	static <C extends MFXControl<?>, V extends Variant> C removeVariants(C control, V... variants) {
+		ObservableList<String> styleClass = control.getStyleClass();
+		for (V variant : variants) {
+			styleClass.remove(variant.variantStyleClass());
+		}
+		return control;
+	}
+
 	/**
 	 * Adds all the given variants to the given labeled.
 	 * <p>
@@ -133,4 +148,16 @@ public interface WithVariants<N extends Node, V extends Variant> {
 		labeled.getStyleClass().setAll(classes);
 		return labeled;
 	}
+
+	/**
+	 * Removes all the given variants from the given labeled.
+	 */
+	@SafeVarargs
+	static <L extends MFXLabeled<?>, V extends Variant> L removeVariants(L labeled, V... variants) {
+		ObservableList<String> styleClass = labeled.getStyleClass();
+		for (V variant : variants) {
+			styleClass.remove(variant.variantStyleClass());
+		}
+		return labeled;
+	}
 }

+ 0 - 3
modules/components/src/main/java/io/github/palexdev/mfxcomponents/theming/enums/FABVariants.java

@@ -34,9 +34,6 @@ public enum FABVariants implements Variant {
 	SURFACE("surface"),
 	SECONDARY("secondary"),
 	TERTIARY("tertiary"),
-	// TODO this is a good way of managing it without relying on PseudoClasses
-	// TODO the only improvement I'd make is to have a bunch of methods here responsible for applying the variant
-	// TODO 'fab-extended' should be applied only after 'fab' is removed
 	EXTENDED("fab-extended"),
 	;
 

+ 1 - 0
modules/core/CHANGELOG.md

@@ -32,6 +32,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 - Added method to retrieve the component's behavior object, thus creating a bridge between the Control the View(skin)
   and the Behavior
 - Moved executeNow(...) methods to the base class for a better fluent API
+- When: added non-static method for disposal
 
 ## Fixed
 

+ 3 - 4
modules/core/src/main/java/io/github/palexdev/mfxcore/base/bindings/ExternalSource.java

@@ -69,7 +69,6 @@ public class ExternalSource<S> extends AbstractSource<S, S> {
 	//================================================================================
 	// Methods
 	//================================================================================
-	// TODO check this documentation
 
 	/**
 	 * Activates this invalidating source by adding a listener to it that will trigger the specified {@link #getAction()}.
@@ -84,7 +83,7 @@ public class ExternalSource<S> extends AbstractSource<S, S> {
 	/**
 	 * Unsupported.
 	 *
-	 * @throws UnsupportedOperationException {@code InvalidatingSources} do not operate on a target
+	 * @throws UnsupportedOperationException {@code ExternalSources} do not operate on a target
 	 */
 	@Override
 	protected void listen(Target<S> target) {
@@ -94,7 +93,7 @@ public class ExternalSource<S> extends AbstractSource<S, S> {
 	/**
 	 * Unsupported.
 	 *
-	 * @throws UnsupportedOperationException {@code InvalidatingSources} are not directly responsible for updating
+	 * @throws UnsupportedOperationException {@code ExternalSources} are not directly responsible for updating
 	 *                                       a target
 	 */
 	@Override
@@ -105,7 +104,7 @@ public class ExternalSource<S> extends AbstractSource<S, S> {
 	/**
 	 * Unsupported.
 	 *
-	 * @throws UnsupportedOperationException {@code InvalidatingSources} are not directly responsible for
+	 * @throws UnsupportedOperationException {@code ExternalSources} are not directly responsible for
 	 *                                       updating sources
 	 */
 	@Override

+ 0 - 2
modules/core/src/main/java/io/github/palexdev/mfxcore/base/bindings/base/IBinding.java

@@ -80,8 +80,6 @@ public interface IBinding<T> {
 		return state() == BindingState.DISPOSED;
 	}
 
-	// TODO note that this checks only the state not MFXBindings
-
 	/**
 	 * Checks if the bindings state is {@link BindingState#BOUND}.
 	 * <p>

+ 10 - 0
modules/core/src/main/java/io/github/palexdev/mfxcore/observables/When.java

@@ -148,6 +148,16 @@ public abstract class When<T> {
 			invalidationListener = null;
 	}
 
+	/**
+	 * Attempts to dispose this construct by invoking {@link #disposeFor(ObservableValue)} on the current given
+	 * observable.
+	 * <p></p>
+	 * If the construct has not been registered yet, or the observable is null, nothing will happen.
+	 */
+	public void requestDisposal() {
+		disposeFor(observableValue);
+	}
+
 	//================================================================================
 	// Static Methods
 	//================================================================================

+ 0 - 1
modules/release/build.gradle

@@ -19,7 +19,6 @@ java {
     tasks.withType(Jar).each { it.archiveBaseName.set("materialfx-all") }
 }
 
-// TODO rename materialfx package to mfxcomponents
 shadowJar {
     mergeServiceFiles()
     dependencies {