浏览代码

MFXButton fix
Fixed NullPointerException when MFXButton is FLAT.
The DropShadowEffect now is set LEVEL0 instead of null

PAlex404 5 年之前
父节点
当前提交
e6dbcd834c

+ 1 - 2
README.md

@@ -6,5 +6,4 @@ This projects aims to be a successor to [JFoenix](https://github.com/jfoenixadmi
 As of now I have redone only the material button class, here's a preview:  
 [![Alt text](https://img.youtube.com/vi/lD3IEDe_A8w/0.jpg)](https://www.youtube.com/watch?v=lD3IEDe_A8w)  
   
-I will start pushing commits as soon as possible, I just want to make sure the components I make are enough good and usable so keep an eye for updates.
-
+To start the demo type 'gradlew run'.

+ 7 - 22
demo/src/main/java/it/paprojects/materialfx/demo/Demo.java

@@ -1,39 +1,24 @@
 package it.paprojects.materialfx.demo;
 
 import fr.brouillard.oss.cssfx.CSSFX;
-import it.paprojects.materialfx.MFXResources;
-import it.paprojects.materialfx.controls.MFXButton;
-import it.paprojects.materialfx.utils.ButtonType;
 import javafx.application.Application;
-import javafx.geometry.Pos;
+import javafx.fxml.FXMLLoader;
 import javafx.scene.Scene;
-import javafx.scene.layout.StackPane;
-import javafx.scene.paint.Color;
+import javafx.scene.layout.AnchorPane;
 import javafx.stage.Stage;
-import javafx.util.Duration;
+
+import java.io.IOException;
 
 public class Demo extends Application {
 
     @Override
-    public void start(Stage primaryStage) {
+    public void start(Stage primaryStage) throws IOException {
         CSSFX.start();
 
-        StackPane pane = new StackPane();
-        pane.getStylesheets().add(MFXResources.load("css/mfx-button.css").toString());
-
-        MFXButton button = new MFXButton("MFXButton");
-        button.setPrefWidth(500);
-        button.setPrefHeight(200);
-        button.setButtonType(ButtonType.RAISED);
-        pane.getChildren().add(button);
-        StackPane.setAlignment(button, Pos.CENTER);
-
-        button.setRippleColor(Color.rgb(10, 120, 200));
-        button.setRippleRadius(255);
-        button.setRippleInDuration(Duration.millis(600));
+        AnchorPane anchorPane = FXMLLoader.load(MFXResources.load("buttons_demo.fxml"));
 
         primaryStage.setTitle("HELLO THERE");
-        primaryStage.setScene(new Scene(pane, 800, 600));
+        primaryStage.setScene(new Scene(anchorPane));
         primaryStage.show();
     }
 

+ 16 - 0
demo/src/main/java/it/paprojects/materialfx/demo/MFXResources.java

@@ -0,0 +1,16 @@
+package it.paprojects.materialfx.demo;
+
+import java.net.URL;
+
+/**
+ * Utility class which manages the access to this project's assets.
+ * Helps keeping the assets files structure organized.
+ */
+public class MFXResources {
+
+    private MFXResources() {}
+
+    public static URL load(String path) {
+        return MFXResources.class.getResource(path);
+    }
+}

+ 1 - 0
demo/src/main/java/module-info.java

@@ -4,5 +4,6 @@ module MaterialFX.demo.main {
     requires fr.brouillard.oss.cssfx;
     requires javafx.graphics;
     requires javafx.controls;
+    requires javafx.fxml;
     exports it.paprojects.materialfx.demo;
 }

+ 1 - 1
materialfx/src/main/java/it/paprojects/materialfx/effects/DepthLevel.java

@@ -6,7 +6,7 @@ import javafx.scene.paint.Color;
  * Enumerator which defines 5 levels of {@code DropShadow} effects from {@code LEVEL1} to {@code LEVEL5}.
  */
 public enum DepthLevel {
-    //LEVEL0(Color.rgb(0, 0, 0, 0), 0, 0, 0, 0),
+    LEVEL0(Color.rgb(0, 0, 0, 0), 0, 0, 0, 0),
     LEVEL1(Color.rgb(0, 0, 0, 0.20), 10, 0.12, -1, 2),
     LEVEL2(Color.rgb(0, 0, 0, 0.20), 15, 0.16, 0, 4),
     LEVEL3(Color.rgb(0, 0, 0, 0.20), 20, 0.19, 0, 6),

+ 1 - 1
materialfx/src/main/java/it/paprojects/materialfx/effects/RippleGenerator.java

@@ -20,7 +20,7 @@ import java.util.List;
 import static it.paprojects.materialfx.effects.MFXDepthManager.shadowOf;
 
 public class RippleGenerator extends Group {
-    private final String STYLE_CLASS = "rippleGenerator";
+    private final String STYLE_CLASS = "ripple-generator";
     private static final StyleablePropertyFactory<RippleGenerator> FACTORY = new StyleablePropertyFactory<>(Group.getClassCssMetaData());
 
     private final Control control;

+ 1 - 1
materialfx/src/main/java/it/paprojects/materialfx/skins/MFXButtonSkin.java

@@ -33,7 +33,7 @@ public class MFXButtonSkin extends ButtonSkin {
                 break;
             }
             case FLAT: {
-                getSkinnable().setEffect(null);
+                getSkinnable().setEffect(MFXDepthManager.shadowOf(DepthLevel.LEVEL0));
                 getSkinnable().setPickOnBounds(true);
                 break;
             }