diff --git a/components/src/main/java/com/dlsc/jfxcentral2/components/overviewbox/UtilityOverviewBox.java b/components/src/main/java/com/dlsc/jfxcentral2/components/overviewbox/UtilityOverviewBox.java index b16f5904..ee856526 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/components/overviewbox/UtilityOverviewBox.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/components/overviewbox/UtilityOverviewBox.java @@ -6,7 +6,7 @@ import com.dlsc.jfxcentral2.utilities.cssplayground.CssPlaygroundView; import com.dlsc.jfxcentral2.utilities.paintpicker.GradientDesignerView; import com.dlsc.jfxcentral2.utilities.pathextractor.SVGPathExtractorView; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.ShadowDesignerView; +import com.dlsc.jfxcentral2.utilities.effectdesigner.EffectDesignerView; import com.dlsc.jfxcentral2.utils.ModelObjectTool; import javafx.scene.Node; import javafx.scene.control.Label; @@ -65,13 +65,13 @@ private Node createToolPane(Utility model) { setIcon(Material2OutlinedAL.COLOR_LENS); getStyleClass().add("gradient-designer-overview-box"); return new GradientDesignerView(sizeProperty()); - } else if (StringUtils.equalsIgnoreCase(model.getId(), "shadowdesigner")){ - setTitle("Shadow Designer"); + } else if (StringUtils.equalsIgnoreCase(model.getId(), "effectdesigner")){ + setTitle("Effect Designer"); setIcon(SimpleLineIcons.MAGIC_WAND); - getStyleClass().add("shadow-designer-overview-box"); - ShadowDesignerView shadowDesignerView = new ShadowDesignerView(); - shadowDesignerView.sizeProperty().bind(sizeProperty()); - return shadowDesignerView; + getStyleClass().add("effect-designer-overview-box"); + EffectDesignerView effectDesignerView = new EffectDesignerView(); + effectDesignerView.sizeProperty().bind(sizeProperty()); + return effectDesignerView; } return createComingSoonPane(); diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/CopyEffectCodeView.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/CopyEffectCodeView.java new file mode 100644 index 00000000..422de315 --- /dev/null +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/CopyEffectCodeView.java @@ -0,0 +1,71 @@ +package com.dlsc.jfxcentral2.utilities.effectdesigner; + +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.scene.control.Button; +import javafx.scene.layout.HBox; +import one.jpro.platform.routing.CopyUtil; +import org.apache.commons.lang3.StringUtils; +import org.kordamp.ikonli.boxicons.BoxiconsLogos; +import org.kordamp.ikonli.carbonicons.CarbonIcons; +import org.kordamp.ikonli.javafx.FontIcon; + +public class CopyEffectCodeView extends HBox { + + public CopyEffectCodeView(Runnable onCopyCompleted) { + getStyleClass().add("copy-effect-code-view"); + + FontIcon javaIcon = new FontIcon(CarbonIcons.CODE); + Button copyJavaCode = new Button("Java Code", javaIcon); + copyJavaCode.getStyleClass().addAll("fill-button","java-button"); + copyJavaCode.setOnAction(event -> onCopyCompleted.run()); + copyJavaCode.disableProperty().bind(javaCode.isEmpty()); + javaCodeProperty().addListener((observable, oldValue, newValue) -> { + if (!StringUtils.isEmpty(newValue)) { + CopyUtil.setCopyOnClick(copyJavaCode, newValue); + } + }); + + FontIcon cssIcon = new FontIcon(BoxiconsLogos.CSS3); + Button copyCssCode = new Button("CSS Code", cssIcon); + copyCssCode.getStyleClass().addAll("fill-button","css-button"); + copyCssCode.setOnAction(event -> onCopyCompleted.run()); + copyCssCode.disableProperty().bind(cssCode.isEmpty()); + cssCodeProperty().addListener((observable, oldValue, newValue) -> { + if (!StringUtils.isEmpty(newValue)) { + CopyUtil.setCopyOnClick(copyCssCode, newValue); + } + }); + + getChildren().setAll(copyJavaCode, copyCssCode); + } + + + private final StringProperty javaCode = new SimpleStringProperty(this, "javaCode"); + + public String getJavaCode() { + return javaCode.get(); + } + + public StringProperty javaCodeProperty() { + return javaCode; + } + + public void setJavaCode(String javaCode) { + this.javaCode.set(javaCode); + } + + private final StringProperty cssCode = new SimpleStringProperty(this, "cssCode"); + + public String getCssCode() { + return cssCode.get(); + } + + public StringProperty cssCodeProperty() { + return cssCode; + } + + public void setCssCode(String cssCode) { + this.cssCode.set(cssCode); + } +} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/EffectCodeGenerator.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/EffectCodeGenerator.java new file mode 100644 index 00000000..411dc9d7 --- /dev/null +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/EffectCodeGenerator.java @@ -0,0 +1,269 @@ +package com.dlsc.jfxcentral2.utilities.effectdesigner; + +import com.dlsc.jfxcentral2.utilities.paintpicker.impl.PaintConvertUtil; +import com.dlsc.jfxcentral2.utilities.effectdesigner.effect.BlendBottomInput; +import com.dlsc.jfxcentral2.utilities.effectdesigner.effect.BlendTopInput; +import com.dlsc.jfxcentral2.utilities.effectdesigner.effect.LightingBumpInput; +import com.dlsc.jfxcentral2.utilities.effectdesigner.effect.LightingContentInput; +import com.dlsc.jfxcentral2.utils.NumberUtil; +import com.dlsc.jfxcentral2.utils.StringUtil; +import javafx.scene.effect.Blend; +import javafx.scene.effect.Bloom; +import javafx.scene.effect.BlurType; +import javafx.scene.effect.BoxBlur; +import javafx.scene.effect.ColorAdjust; +import javafx.scene.effect.ColorInput; +import javafx.scene.effect.DisplacementMap; +import javafx.scene.effect.DropShadow; +import javafx.scene.effect.Effect; +import javafx.scene.effect.GaussianBlur; +import javafx.scene.effect.Glow; +import javafx.scene.effect.ImageInput; +import javafx.scene.effect.InnerShadow; +import javafx.scene.effect.Lighting; +import javafx.scene.effect.MotionBlur; +import javafx.scene.effect.PerspectiveTransform; +import javafx.scene.effect.Reflection; +import javafx.scene.effect.SepiaTone; +import javafx.scene.effect.Shadow; +import javafx.scene.image.Image; +import javafx.scene.paint.Color; +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.List; + +public class EffectCodeGenerator { + private static final Logger LOGGER = LogManager.getLogger(EffectCodeGenerator.class); + + private EffectCodeGenerator() { + } + + public static String effectsToJavaCode(List effects) { + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < effects.size(); i++) { + effectToJavaCode(sb, effects.get(i), i); + } + + return sb.toString(); + } + + private static void effectToJavaCode(StringBuilder sb, Effect effect, int index) { + String className = effect.getClass().getSimpleName(); + if (StringUtils.equalsAnyIgnoreCase(className, "BlendTopInput", "BlendBottomInput")) { + className = "Blend"; + } + if (StringUtils.equalsAnyIgnoreCase(className, "LightingBumpInput", "LightingContentInput")) { + className = "Lighting"; + } + + String instanceName = "effect" + index; + sb.append(className).append(" ").append(instanceName).append(" = new ").append(className).append("();").append(StringUtil.NEW_LINE); + + if (effect instanceof Blend temp) { + handleEffect(sb, instanceName, temp); + } else if (effect instanceof Bloom temp) { + handleEffect(sb, instanceName, temp); + } else if (effect instanceof BoxBlur temp) { + handleEffect(sb, instanceName, temp); + } else if (effect instanceof ColorAdjust temp) { + handleEffect(sb, instanceName, temp); + } else if (effect instanceof ColorInput temp) { + handleEffect(sb, instanceName, temp); + } else if (effect instanceof DisplacementMap temp) { + handleEffect(sb, instanceName, temp); + } else if (effect instanceof DropShadow temp) { + handleEffect(sb, instanceName, temp); + } else if (effect instanceof GaussianBlur temp) { + handleEffect(sb, instanceName, temp); + } else if (effect instanceof Glow temp) { + handleEffect(sb, instanceName, temp); + } else if (effect instanceof ImageInput temp) { + handleEffect(sb, instanceName, temp); + } else if (effect instanceof InnerShadow temp) { + handleEffect(sb, instanceName, temp); + } else if (effect instanceof Lighting temp) { + handleEffect(sb, instanceName, temp); + } else if (effect instanceof MotionBlur temp) { + handleEffect(sb, instanceName, temp); + } else if (effect instanceof PerspectiveTransform temp) { + handleEffect(sb, instanceName, temp); + } else if (effect instanceof Reflection temp) { + handleEffect(sb, instanceName, temp); + } else if (effect instanceof SepiaTone temp) { + handleEffect(sb, instanceName, temp); + } else if (effect instanceof Shadow temp) { + handleEffect(sb, instanceName, temp); + } else { + LOGGER.error("Unknown effect {}", effect); + } + + if (index > 0) { + String prevEffectName = "effect" + (index - 1); + if (effect instanceof BlendBottomInput) { + sb.append(instanceName).append(".setBottomInput(").append(prevEffectName).append(");").append(StringUtil.NEW_LINE); + } else if (effect instanceof BlendTopInput) { + sb.append(instanceName).append(".setTopInput(").append(prevEffectName).append(");").append(StringUtil.NEW_LINE); + } else if (effect instanceof LightingBumpInput) { + sb.append(instanceName).append(".setBumpInput(").append(prevEffectName).append(");").append(StringUtil.NEW_LINE); + } else if (effect instanceof LightingContentInput) { + sb.append(instanceName).append(".setContentInput(").append(prevEffectName).append(");").append(StringUtil.NEW_LINE); + } else { + sb.append(instanceName).append(".setInput(").append(prevEffectName).append(");").append(StringUtil.NEW_LINE); + } + } + + sb.append(StringUtil.NEW_LINE); + } + + private static void handleEffect(StringBuilder sb, String instanceName, Blend effect) { + sb.append(instanceName).append(".setMode(").append("BlendMode.").append(effect.getMode()).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setOpacity(").append(roundNumber(effect.getOpacity())).append(");").append(StringUtil.NEW_LINE); + } + + private static void handleEffect(StringBuilder sb, String instanceName, Glow effect) { + sb.append(instanceName).append(".setLevel(").append(roundNumber(effect.getLevel())).append(");").append(StringUtil.NEW_LINE); + } + + private static void handleEffect(StringBuilder sb, String instanceName, Bloom effect) { + sb.append(instanceName).append(".setThreshold(").append(roundNumber(effect.getThreshold())).append(");").append(StringUtil.NEW_LINE); + } + + private static void handleEffect(StringBuilder sb, String instanceName, BoxBlur effect) { + sb.append(instanceName).append(".setWidth(").append(roundNumber(effect.getWidth())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setHeight(").append(roundNumber(effect.getHeight())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setIterations(").append(roundNumber(effect.getIterations())).append(");").append(StringUtil.NEW_LINE); + } + + private static void handleEffect(StringBuilder sb, String instanceName, ColorAdjust effect) { + sb.append(instanceName).append(".setHue(").append(roundNumber(effect.getHue())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setSaturation(").append(roundNumber(effect.getSaturation())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setBrightness(").append(roundNumber(effect.getBrightness())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setContrast(").append(roundNumber(effect.getContrast())).append(");").append(StringUtil.NEW_LINE); + } + + private static void handleEffect(StringBuilder sb, String instanceName, ColorInput effect) { + sb.append(instanceName).append(".setX(").append(roundNumber(effect.getX())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setY(").append(roundNumber(effect.getY())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setWidth(").append(roundNumber(effect.getWidth())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setHeight(").append(roundNumber(effect.getHeight())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setPaint(").append(PaintConvertUtil.convertPaintToJavaCode(effect.getPaint(), false)).append(");").append(StringUtil.NEW_LINE); + } + + private static void handleEffect(StringBuilder sb, String instanceName, DisplacementMap effect) { + sb.append(instanceName).append(".setOffsetX(").append(roundNumber(effect.getOffsetX())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setOffsetY(").append(roundNumber(effect.getOffsetY())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setScaleX(").append(roundNumber(effect.getScaleX())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setScaleY(").append(roundNumber(effect.getScaleY())).append(");").append(StringUtil.NEW_LINE); + } + + private static void handleEffect(StringBuilder sb, String instanceName, DropShadow effect) { + buildShadowProperty(sb, instanceName, effect.getBlurType(), effect.getWidth(), effect.getHeight(), effect.getRadius(), effect.getColor()); + sb.append(instanceName).append(".setOffsetX(").append(roundNumber(effect.getOffsetX())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setOffsetY(").append(roundNumber(effect.getOffsetY())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setSpread(").append(roundNumber(effect.getSpread())).append(");").append(StringUtil.NEW_LINE); + } + + private static void handleEffect(StringBuilder sb, String instanceName, GaussianBlur effect) { + sb.append(instanceName).append(".setRadius(").append(roundNumber(effect.getRadius())).append(");").append(StringUtil.NEW_LINE); + } + + private static void handleEffect(StringBuilder sb, String instanceName, ImageInput effect) { + sb.append(instanceName).append(".setX(").append(roundNumber(effect.getX())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setY(").append(roundNumber(effect.getY())).append(");").append(StringUtil.NEW_LINE); + Image source = effect.getSource(); + if (source != null && source.getUrl() != null) { + sb.append(instanceName).append(".setSource(new Image(\"").append(source.getUrl()).append("\"));").append(StringUtil.NEW_LINE); + } + } + + private static void handleEffect(StringBuilder sb, String instanceName, InnerShadow effect) { + buildShadowProperty(sb, instanceName, effect.getBlurType(), effect.getWidth(), effect.getHeight(), effect.getRadius(), effect.getColor()); + sb.append(instanceName).append(".setOffsetX(").append(roundNumber(effect.getOffsetX())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setOffsetY(").append(roundNumber(effect.getOffsetY())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setChoke(").append(roundNumber(effect.getChoke())).append(");").append(StringUtil.NEW_LINE); + } + + private static void handleEffect(StringBuilder sb, String instanceName, Lighting effect) { + sb.append(instanceName).append(".setDiffuseConstant(").append(roundNumber(effect.getDiffuseConstant())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setSpecularConstant(").append(roundNumber(effect.getSpecularConstant())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setSpecularExponent(").append(roundNumber(effect.getSpecularExponent())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setSurfaceScale(").append(roundNumber(effect.getSurfaceScale())).append(");").append(StringUtil.NEW_LINE); + } + + private static void handleEffect(StringBuilder sb, String instanceName, MotionBlur effect) { + sb.append(instanceName).append(".setAngle(").append(roundNumber(effect.getAngle())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setRadius(").append(roundNumber(effect.getRadius())).append(");").append(StringUtil.NEW_LINE); + } + + private static void handleEffect(StringBuilder sb, String instanceName, PerspectiveTransform effect) { + sb.append(instanceName).append(".setLlx(").append(roundNumber(effect.getLlx())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setLly(").append(roundNumber(effect.getLly())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setLrx(").append(roundNumber(effect.getLrx())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setLry(").append(roundNumber(effect.getLry())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setUlx(").append(roundNumber(effect.getUlx())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setUly(").append(roundNumber(effect.getUly())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setUrx(").append(roundNumber(effect.getUrx())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setUry(").append(roundNumber(effect.getUry())).append(");").append(StringUtil.NEW_LINE); + } + + private static void handleEffect(StringBuilder sb, String instanceName, Reflection effect) { + sb.append(instanceName).append(".setFraction(").append(roundNumber(effect.getFraction())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setTopOffset(").append(roundNumber(effect.getTopOffset())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setBottomOpacity(").append(roundNumber(effect.getBottomOpacity())).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setTopOpacity(").append(roundNumber(effect.getTopOpacity())).append(");").append(StringUtil.NEW_LINE); + } + + private static void handleEffect(StringBuilder sb, String instanceName, SepiaTone effect) { + sb.append(instanceName).append(".setLevel(").append(roundNumber(effect.getLevel())).append(");").append(StringUtil.NEW_LINE); + } + + private static void handleEffect(StringBuilder sb, String instanceName, Shadow effect) { + buildShadowProperty(sb, instanceName, effect.getBlurType(), effect.getWidth(), effect.getHeight(), effect.getRadius(), effect.getColor()); + } + + private static void buildShadowProperty(StringBuilder sb, String instanceName, BlurType blurType, double width, double height, double radius, Color color) { + sb.append(instanceName).append(".setBlurType(").append("BlurType.").append(blurType).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setWidth(").append(roundNumber(width)).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setHeight(").append(roundNumber(height)).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setRadius(").append(roundNumber(radius)).append(");").append(StringUtil.NEW_LINE) + .append(instanceName).append(".setColor(").append(PaintConvertUtil.convertPaintToJavaCode(color, false)).append(");").append(StringUtil.NEW_LINE); + } + + private static String roundNumber(double value) { + return NumberUtil.trimTrailingZeros(value, 3); + } + + public static String convertToCss(InnerShadow innerShadow) { + return "-fx-effect: innershadow(" + + blurTypeToString(innerShadow.getBlurType()) + ", " + + PaintConvertUtil.convertPaintToCss(innerShadow.getColor()) + ", " + + innerShadow.getRadius() + ", " + + innerShadow.getChoke() + ", " + + innerShadow.getOffsetX() + ", " + + innerShadow.getOffsetY() + + ");"; + } + + public static String convertToCss(DropShadow dropShadow) { + return "-fx-effect: dropshadow(" + + blurTypeToString(dropShadow.getBlurType()) + ", " + + PaintConvertUtil.convertPaintToCss(dropShadow.getColor()) + ", " + + dropShadow.getRadius() + ", " + + dropShadow.getSpread() + ", " + + dropShadow.getOffsetX() + ", " + + dropShadow.getOffsetY() + + ");"; + } + + private static String blurTypeToString(BlurType blurType) { + return switch (blurType) { + case ONE_PASS_BOX -> "one-pass-box"; + case TWO_PASS_BOX -> "two-pass-box"; + case THREE_PASS_BOX -> "three-pass-box"; + case GAUSSIAN -> "gaussian"; + }; + } +} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/ShadowDesignerView.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/EffectDesignerView.java similarity index 70% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/ShadowDesignerView.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/EffectDesignerView.java index 6038520d..e98aef38 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/ShadowDesignerView.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/EffectDesignerView.java @@ -1,27 +1,30 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner; +package com.dlsc.jfxcentral2.utilities.effectdesigner; import com.dlsc.jfxcentral2.components.PaneBase; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.editor.BlendBottomInputEditor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.editor.BlendTopInputEditor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.editor.BloomEditor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.editor.BoxBlurEditor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.editor.ColorAdjustEditor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.editor.ColorInputEditor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.editor.DisplacementMapEditor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.editor.DropShadowEditor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.editor.GaussianBlurEditor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.editor.GlowEditor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.editor.ImageInputEditor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.editor.InnerShadowEditor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.editor.MotionBlurEditor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.editor.PerspectiveTransformEditor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.editor.ReflectionEditor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.editor.SepiaToneEditor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.editor.ShadowEditor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.effect.BlendBottomInput; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.effect.BlendTopInput; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.BlendBottomInputEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.BlendTopInputEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.BloomEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.BoxBlurEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.ColorAdjustEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.ColorInputEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.DisplacementMapEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.DropShadowEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.GaussianBlurEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.GlowEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.ImageInputEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.InnerShadowEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.LightingBumpInputEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.LightingContentInputEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.MotionBlurEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.PerspectiveTransformEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.ReflectionEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.SepiaToneEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.editor.ShadowEditor; +import com.dlsc.jfxcentral2.utilities.effectdesigner.effect.BlendBottomInput; +import com.dlsc.jfxcentral2.utilities.effectdesigner.effect.BlendTopInput; +import com.dlsc.jfxcentral2.utilities.effectdesigner.effect.LightingBumpInput; +import com.dlsc.jfxcentral2.utilities.effectdesigner.effect.LightingContentInput; import javafx.beans.InvalidationListener; -import javafx.beans.binding.Bindings; import javafx.geometry.Pos; import javafx.scene.Node; import javafx.scene.control.Label; @@ -45,10 +48,10 @@ import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; -public class ShadowDesignerView extends PaneBase { +public class EffectDesignerView extends PaneBase { - public ShadowDesignerView() { - getStyleClass().add("shadow-designer-view"); + public EffectDesignerView() { + getStyleClass().add("effect-designer-view"); setAlignment(Pos.TOP_LEFT); StackPane previewPane = new StackPane(); @@ -67,7 +70,10 @@ public ShadowDesignerView() { if (newEffect == null) { effectPaneWrapper.getChildren().clear(); } - Node node = createOptionPane(newEffect, () -> effectFlowPane.getEffects().remove(newEffect)); + Node node = createOptionPane(newEffect, () -> { + effectFlowPane.requestFocus(); + effectFlowPane.getEffects().remove(newEffect); + }); if (node == null) { effectPaneWrapper.getChildren().clear(); } else { @@ -80,8 +86,6 @@ public ShadowDesignerView() { VBox rightBox = new VBox(effectFlowPane, effectPaneWrapper); rightBox.getStyleClass().addAll("right-box", "with-non-effect"); - rightBox.alignmentProperty().bind(Bindings.createObjectBinding(() -> - effectPaneWrapper.isVisible() && !effectFlowPane.getEffects().isEmpty() ? Pos.TOP_LEFT : Pos.CENTER, effectPaneWrapper.visibleProperty())); effectFlowPane.getEffects().addListener((InvalidationListener) observable -> { if (effectFlowPane.getEffects().isEmpty()) { @@ -125,6 +129,10 @@ private Node createOptionPane(Effect newEffect, Runnable deleteAction) { node = new ImageInputEditor(effect, deleteAction); } else if (newEffect instanceof InnerShadow effect) { node = new InnerShadowEditor(effect, deleteAction); + } else if (newEffect instanceof LightingBumpInput effect){ + node = new LightingBumpInputEditor(effect, deleteAction); + } else if (newEffect instanceof LightingContentInput effect){ + node = new LightingContentInputEditor(effect, deleteAction); } else if (newEffect instanceof MotionBlur effect) { node = new MotionBlurEditor(effect, deleteAction); } else if (newEffect instanceof PerspectiveTransform effect) { diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/EffectEnum.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/EffectEnum.java similarity index 83% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/EffectEnum.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/EffectEnum.java index 96622df1..9058cbb0 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/EffectEnum.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/EffectEnum.java @@ -1,7 +1,9 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner; +package com.dlsc.jfxcentral2.utilities.effectdesigner; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.effect.BlendBottomInput; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.effect.BlendTopInput; +import com.dlsc.jfxcentral2.utilities.effectdesigner.effect.BlendBottomInput; +import com.dlsc.jfxcentral2.utilities.effectdesigner.effect.BlendTopInput; +import com.dlsc.jfxcentral2.utilities.effectdesigner.effect.LightingBumpInput; +import com.dlsc.jfxcentral2.utilities.effectdesigner.effect.LightingContentInput; import javafx.scene.effect.Bloom; import javafx.scene.effect.BoxBlur; import javafx.scene.effect.ColorAdjust; @@ -24,8 +26,8 @@ public enum EffectEnum { //BLEND("Blend", Blend.class), - BLEND_TOP_INPUT("Blend (TopInPut)", BlendTopInput.class), - BLEND_BOTTOM_INPUT("Blend (BottomInput)", BlendBottomInput.class), + BLEND_TOP_INPUT("Blend (Top)", BlendTopInput.class), + BLEND_BOTTOM_INPUT("Blend (Bottom)", BlendBottomInput.class), BLOOM("Bloom", Bloom.class), BOX_BLUR("BoxBlur", BoxBlur.class), COLOR_ADJUST("ColorAdjust", ColorAdjust.class), @@ -37,8 +39,8 @@ public enum EffectEnum { IMAGE_INPUT("ImageInput", ImageInput.class), INNER_SHADOW("InnerShadow", InnerShadow.class), //LIGHTING("Lighting", Lighting.class), - //LIGHTING_BUMP_INPUT("Lighting (BumpInput)", LightingBumpInput.class), - //LIGHTING_CONTENT_INPUT("Lighting (ContentInput)", LightingContentInput.class), + LIGHTING_BUMP_INPUT("Lighting (Bump)", LightingBumpInput.class), + LIGHTING_CONTENT_INPUT("Lighting (Content)", LightingContentInput.class), MOTION_BLUR("MotionBlur", MotionBlur.class), PERSPECTIVE_TRANSFORM("PerspectiveTransform", PerspectiveTransform.class), REFLECTION("Reflection", Reflection.class), diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/EffectFlowPane.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/EffectFlowPane.java similarity index 53% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/EffectFlowPane.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/EffectFlowPane.java index 24ae6fc4..8226e898 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/EffectFlowPane.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/EffectFlowPane.java @@ -1,19 +1,25 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner; +package com.dlsc.jfxcentral2.utilities.effectdesigner; import com.dlsc.jfxcentral2.components.CustomToggleButton; -import javafx.beans.InvalidationListener; +import com.dlsc.jfxcentral2.utils.IkonUtil; +import com.dlsc.jfxcentral2.utils.JFXCentralUtil; import javafx.beans.binding.Bindings; import javafx.beans.property.ReadOnlyObjectProperty; import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; +import javafx.scene.control.CustomMenuItem; import javafx.scene.control.MenuButton; import javafx.scene.control.MenuItem; import javafx.scene.control.Toggle; import javafx.scene.control.ToggleGroup; -import javafx.scene.effect.Blend; +import javafx.scene.effect.DropShadow; import javafx.scene.effect.Effect; +import javafx.scene.effect.InnerShadow; +import javafx.scene.input.MouseEvent; import javafx.scene.layout.FlowPane; +import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.kordamp.ikonli.javafx.FontIcon; @@ -21,6 +27,7 @@ import org.kordamp.ikonli.material2.Material2OutlinedMZ; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; @@ -31,12 +38,17 @@ public class EffectFlowPane extends FlowPane { public EffectFlowPane() { getStyleClass().add("effect-flow-pane"); - value.bind(Bindings.createObjectBinding(() -> effects.stream().reduce((effect1, effect2) -> { - if (effect2 instanceof Blend blend2) { - blend2.setTopInput(effect1); - return blend2; - } + effectValueBind(); + + effectsAddListener(); + + getChildren().addAll(createAddEffectButton(), createCopyCodeButton()); + toggleGroupAddListener(); + } + + private void effectValueBind() { + value.bind(Bindings.createObjectBinding(() -> effects.stream().reduce((effect1, effect2) -> { if (supportsInputMethod(effect2)) { try { effect2.getClass().getMethod("setInput", Effect.class).invoke(effect2, effect1); @@ -46,41 +58,52 @@ public EffectFlowPane() { } return effect2; }).orElse(null), effects)); + } - effects.addListener((InvalidationListener) it -> { - Toggle selectedToggle = TOGGLE_GROUP.getSelectedToggle(); - int index = TOGGLE_GROUP.getToggles().indexOf(selectedToggle); - Effect selectedEffect; - if (selectedToggle != null && index >= 0 && index < effects.size()) { - selectedEffect = effects.get(index); - } else { - selectedEffect = null; + private void toggleGroupAddListener() { + TOGGLE_GROUP.selectedToggleProperty().addListener((ob, ov, nv) -> { + if (effects.isEmpty()) { + setSelectedEffect(null); + return; } - TOGGLE_GROUP.getToggles().clear(); - int lastIndex = getChildren().size() - 1; - getChildren().remove(0, lastIndex); - effects.forEach(effect -> { - int i = getChildren().size() - 1; - CustomToggleButton effectButton = new CustomToggleButton((i + 1) + " " + effect.getClass().getSimpleName()); - effectButton.getStyleClass().add("effect-button"); - effectButton.setFocusTraversable(false); - if (i != effects.size() - 1) { - effectButton.setGraphic(new FontIcon(Material2OutlinedMZ.NAVIGATE_NEXT)); + setSelectedEffect(effects.get(TOGGLE_GROUP.getToggles().indexOf(nv))); + }); + } + + private MenuButton createCopyCodeButton() { + MenuButton copyCodeButton = new MenuButton("Copy Code"); + copyCodeButton.getStyleClass().addAll("fill-button", "copy-effect-code-button"); + copyCodeButton.setFocusTraversable(false); + copyCodeButton.setGraphic(new FontIcon(IkonUtil.copy)); + + CopyEffectCodeView copyEffectCodeView = new CopyEffectCodeView(() -> JFXCentralUtil.runInFXThread(copyCodeButton::hide, 220)); + CustomMenuItem customMenuItem = new CustomMenuItem(copyEffectCodeView, false); + copyCodeButton.setOnShowing(event -> { + String javaCode = EffectCodeGenerator.effectsToJavaCode(effects); + copyEffectCodeView.setJavaCode(javaCode); + + String cssCode = ""; + if (effects.size() == 1) { + Effect effect = effects.get(0); + if (effect instanceof DropShadow shadow) { + cssCode = EffectCodeGenerator.convertToCss(shadow); + } else if (effect instanceof InnerShadow shadow) { + cssCode = EffectCodeGenerator.convertToCss(shadow); } - getChildren().add(i, effectButton); - effectButton.setToggleGroup(TOGGLE_GROUP); - }); - //effects.forEach(effect -> { - // CustomToggleButton effectView = (CustomToggleButton) getChildren().get(effects.indexOf(effect)); - // effectView.setSelected(effect == selectedEffect); - //}); + } + copyEffectCodeView.setCssCode(cssCode); }); + copyCodeButton.getItems().addAll(customMenuItem); + copyCodeButton.managedProperty().bind(copyCodeButton.visibleProperty()); + copyCodeButton.visibleProperty().bind(Bindings.createBooleanBinding(() -> !effects.isEmpty(), effects)); + return copyCodeButton; + } + private MenuButton createAddEffectButton() { MenuButton addEffectButton = new MenuButton("Add Effect"); addEffectButton.setFocusTraversable(false); addEffectButton.setGraphic(new FontIcon(Material2AL.ADD_CIRCLE)); addEffectButton.getStyleClass().add("fill-button"); - getChildren().add(addEffectButton); List menuItems = Arrays.stream(EffectEnum.getAllNames()) .map(name -> { @@ -102,15 +125,58 @@ public EffectFlowPane() { }) .toList(); addEffectButton.getItems().addAll(menuItems); + return addEffectButton; + } - TOGGLE_GROUP.selectedToggleProperty().addListener((ob, ov, nv) -> { - if (nv == null) { - setSelectedEffect(null); - return; + private void effectsAddListener() { + effects.addListener((ListChangeListener.Change change) -> { + while (change.next()) { + if (change.wasRemoved()) { + for (Effect removedEffect : change.getRemoved()) { + for (Effect effect : effects) { + try { + Method setInputMethod = effect.getClass().getMethod("setInput", Effect.class); + Effect currentInput = (Effect) effect.getClass().getMethod("getInput").invoke(effect); + if (currentInput == removedEffect) { + setInputMethod.invoke(effect, (Effect) null); + } + } catch (Exception e) { + LOGGER.error("Error while removing input for effect", e); + } + } + } + } } - setSelectedEffect(effects.get(TOGGLE_GROUP.getToggles().indexOf(nv))); - }); + TOGGLE_GROUP.getToggles().clear(); + int lastIndex = getChildren().size() - 2; + getChildren().remove(0, lastIndex); + effects.forEach(effect -> { + int i = getChildren().size() - 2; + String className = effect.getClass().getSimpleName(); + if (StringUtils.equalsIgnoreCase(className, "BlendTopInput")) { + className = "Blend Top"; + } else if (StringUtils.equalsIgnoreCase(className, "BlendBottomInput")) { + className = "Blend Bottom"; + } else if (StringUtils.equalsIgnoreCase(className, "LightingBumpInput")) { + className = "Lighting Bump"; + } else if (StringUtils.equalsIgnoreCase(className, "LightingContentInput")) { + className = "Lighting Content"; + } + CustomToggleButton effectButton = new CustomToggleButton((i + 1) + " " + className); + effectButton.getStyleClass().add("effect-button"); + effectButton.setFocusTraversable(false); + if (i != effects.size() - 1) { + effectButton.setGraphic(new FontIcon(Material2OutlinedMZ.NAVIGATE_NEXT)); + } + getChildren().add(i, effectButton); + effectButton.setToggleGroup(TOGGLE_GROUP); + effectButton.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> this.requestFocus()); + }); + requestFocus(); + ObservableList toggles = TOGGLE_GROUP.getToggles(); + toggles.get(toggles.size() - 1).setSelected(true); + }); } private final ObservableList effects = FXCollections.observableArrayList(); diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/BlendBottomInputEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/BlendBottomInputEditor.java new file mode 100644 index 00000000..f8bd7cf2 --- /dev/null +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/BlendBottomInputEditor.java @@ -0,0 +1,11 @@ +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; + +import com.dlsc.jfxcentral2.utilities.effectdesigner.effect.BlendBottomInput; + +public class BlendBottomInputEditor extends BlendEditor { + + public BlendBottomInputEditor(BlendBottomInput effect, Runnable deleteAction) { + super(effect, deleteAction); + } + +} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/BlendTopInputEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/BlendEditor.java similarity index 54% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/BlendTopInputEditor.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/BlendEditor.java index a19caa88..6e3e2d9f 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/BlendTopInputEditor.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/BlendEditor.java @@ -1,18 +1,19 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.effect.BlendTopInput; import com.dlsc.jfxcentral2.utils.IkonUtil; +import javafx.scene.effect.Blend; import javafx.scene.effect.BlendMode; import java.util.List; -public class BlendTopInputEditor extends EffectEditor { - public BlendTopInputEditor(BlendTopInput effect, Runnable deleteAction) { +public class BlendEditor extends EffectEditor { + + public BlendEditor(Blend effect, Runnable deleteAction) { super(effect, deleteAction); } @Override - protected List createOptions(BlendTopInput effect) { + protected List createOptions(Blend effect) { return List.of( EffectPropertyFactory.create("Mode", IkonUtil.blendMode, BlendMode.class, null, effect.modeProperty()), EffectPropertyFactory.create("Opacity", IkonUtil.opacity, 0, 1, 1, effect.opacityProperty()) diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/BlendTopInputEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/BlendTopInputEditor.java new file mode 100644 index 00000000..cfd86faa --- /dev/null +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/BlendTopInputEditor.java @@ -0,0 +1,10 @@ +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; + +import com.dlsc.jfxcentral2.utilities.effectdesigner.effect.BlendTopInput; + +public class BlendTopInputEditor extends BlendEditor { + public BlendTopInputEditor(BlendTopInput effect, Runnable deleteAction) { + super(effect, deleteAction); + } + +} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/BloomEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/BloomEditor.java similarity index 88% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/BloomEditor.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/BloomEditor.java index 2f252c12..cc75d9e9 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/BloomEditor.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/BloomEditor.java @@ -1,4 +1,4 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; import com.dlsc.jfxcentral2.utils.IkonUtil; import javafx.scene.effect.Bloom; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/BoxBlurEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/BoxBlurEditor.java similarity index 92% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/BoxBlurEditor.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/BoxBlurEditor.java index 555cb655..f9b97f99 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/BoxBlurEditor.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/BoxBlurEditor.java @@ -1,4 +1,4 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; import com.dlsc.jfxcentral2.utils.IkonUtil; import javafx.scene.effect.BoxBlur; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/ColorAdjustEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/ColorAdjustEditor.java similarity index 93% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/ColorAdjustEditor.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/ColorAdjustEditor.java index bbbf7a46..ea24801b 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/ColorAdjustEditor.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/ColorAdjustEditor.java @@ -1,4 +1,4 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; import com.dlsc.jfxcentral2.utils.IkonUtil; import javafx.scene.effect.ColorAdjust; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/ColorInputEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/ColorInputEditor.java similarity index 93% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/ColorInputEditor.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/ColorInputEditor.java index 0514ba15..a00cee52 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/ColorInputEditor.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/ColorInputEditor.java @@ -1,4 +1,4 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; import com.dlsc.jfxcentral2.utils.IkonUtil; import javafx.scene.effect.ColorInput; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/DisplacementMapEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/DisplacementMapEditor.java similarity index 94% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/DisplacementMapEditor.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/DisplacementMapEditor.java index 0bc8dff6..733b24f4 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/DisplacementMapEditor.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/DisplacementMapEditor.java @@ -1,4 +1,4 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; import com.dlsc.jfxcentral2.utils.IkonUtil; import javafx.scene.effect.DisplacementMap; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/DropShadowEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/DropShadowEditor.java similarity index 95% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/DropShadowEditor.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/DropShadowEditor.java index 38c22d51..b673bd8f 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/DropShadowEditor.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/DropShadowEditor.java @@ -1,4 +1,4 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; import com.dlsc.jfxcentral2.utils.IkonUtil; import javafx.scene.effect.BlurType; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/EffectEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/EffectEditor.java similarity index 98% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/EffectEditor.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/EffectEditor.java index 4020b7a6..1cc4f6e5 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/EffectEditor.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/EffectEditor.java @@ -1,4 +1,4 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; import com.dlsc.gemsfx.Spacer; import com.dlsc.jfxcentral2.utils.IkonUtil; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/EffectPropertyFactory.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/EffectPropertyFactory.java new file mode 100644 index 00000000..2db6384e --- /dev/null +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/EffectPropertyFactory.java @@ -0,0 +1,328 @@ +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; + +import com.dlsc.jfxcentral2.components.FileHandlerView; +import com.dlsc.jfxcentral2.utilities.paintpicker.impl.PaintPicker; +import com.dlsc.jfxcentral2.utils.IkonUtil; +import com.dlsc.jfxcentral2.utils.NumberUtil; +import javafx.beans.binding.Bindings; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; +import javafx.scene.control.CheckBox; +import javafx.scene.control.ComboBox; +import javafx.scene.control.Label; +import javafx.scene.control.Slider; +import javafx.scene.control.Spinner; +import javafx.scene.control.TextField; +import javafx.scene.effect.Light; +import javafx.scene.effect.Lighting; +import javafx.scene.image.Image; +import javafx.scene.input.MouseEvent; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.HBox; +import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; +import javafx.scene.paint.Color; +import javafx.scene.paint.Paint; +import javafx.util.Pair; +import javafx.util.StringConverter; +import org.kordamp.ikonli.Ikon; +import org.kordamp.ikonli.jam.Jam; +import org.kordamp.ikonli.javafx.FontIcon; + +public class EffectPropertyFactory { + + public static > EffectPropperty create(String title, Ikon ikon, Class enumClass, StringConverter stringConverter, ObjectProperty valueProperty) { + ComboBox comboBox = new ComboBox<>(); + comboBox.getStyleClass().add("md-combo-box"); + comboBox.setFocusTraversable(false); + comboBox.setConverter(stringConverter); + comboBox.getItems().addAll(enumClass.getEnumConstants()); + comboBox.getSelectionModel().select(valueProperty.get()); + comboBox.valueProperty().addListener((ob, ov, nv) -> valueProperty.set(nv)); + + return new EffectPropperty(title, ikon, comboBox); + } + + public static EffectPropperty create(String title, Ikon ikon, double min, double max, double current, DoubleProperty valueProperty) { + Slider slider = createSlider(min, max, current); + slider.valueProperty().addListener((ob, ov, nv) -> valueProperty.set(nv.doubleValue())); + + Label valueLabel = createValueLabel(); + valueLabel.textProperty().bind(Bindings.createObjectBinding(() -> { + double value = valueProperty.get(); + slider.setValue(value); + return NumberUtil.trimTrailingZeros(value); + }, valueProperty)); + HBox sliderBox = new HBox(10, slider, valueLabel); + sliderBox.getStyleClass().add("slider-box"); + return new EffectPropperty(title, ikon, sliderBox); + } + + private static Label createValueLabel() { + Label valueLabel = new Label(); + valueLabel.getStyleClass().add("value-label"); + return valueLabel; + } + + private static Slider createSlider(double min, double max, double current) { + Slider slider = new Slider(min, max, current); + slider.setFocusTraversable(false); + slider.setMajorTickUnit(max); + slider.setMinorTickCount(0); + slider.setShowTickLabels(true); + return slider; + } + + public static EffectPropperty create(String title, Ikon ikon, int min, int max, int current, IntegerProperty valueProperty) { + Spinner spinner = new Spinner<>(min, max, current); + spinner.valueProperty().addListener((ob, ov, nv) -> valueProperty.set(nv)); + spinner.setFocusTraversable(false); + return new EffectPropperty(title, ikon, spinner); + } + + public static EffectPropperty create(String title, Ikon ikon, BooleanProperty valueProperty) { + CheckBox checkBox = new CheckBox(); + checkBox.setFocusTraversable(false); + checkBox.selectedProperty().bindBidirectional(valueProperty); + return new EffectPropperty(title, ikon, checkBox); + } + + public static EffectPropperty createWithColorPicker(String title, Ikon ikon, ObjectProperty valueProperty) { + PaintPicker colorPicker = createColorPicker(valueProperty); + colorPicker.paintProperty().addListener((ob, ov, nv) -> + valueProperty.set(nv instanceof Color color ? color : Color.TRANSPARENT)); + return new EffectPropperty(title, ikon, colorPicker); + } + + private static PaintPicker createColorPicker(ObjectProperty valueProperty) { + PaintPicker colorPicker = PaintPicker.createColorPicker(); + colorPicker.setFocusTraversable(false); + colorPicker.setPaintProperty(valueProperty.get()); + return colorPicker; + } + + public static EffectPropperty createWithPaintPicker(String title, Ikon ikon, ObjectProperty valueProperty) { + PaintPicker paintPicker = new PaintPicker(); + paintPicker.setFocusTraversable(false); + paintPicker.setPaintProperty(valueProperty.get()); + paintPicker.paintProperty().addListener((ob, ov, nv) -> valueProperty.set(nv)); + return new EffectPropperty(title, ikon, paintPicker); + } + + public static EffectPropperty create(String title, Ikon ikon, ObjectProperty valueProperty) { + TextField fileNameField = new TextField(); + fileNameField.getStyleClass().add("file-name-label"); + fileNameField.setEditable(false); + fileNameField.setFocusTraversable(false); + fileNameField.managedProperty().bind(fileNameField.visibleProperty()); + fileNameField.visibleProperty().bind(valueProperty.isNotNull()); + fileNameField.textProperty().bind(valueProperty.map(image -> { + if (image == null || image.getUrl() == null) { + return ""; + } + String url = image.getUrl(); + return url.substring(url.lastIndexOf("/") + 1); + })); + + FileHandlerView fileHandlerView = new FileHandlerView(false, false, true); + fileHandlerView.getSupportedExtensions().addAll(".png", ".jpg", ".jpeg", ".gif"); + fileHandlerView.setText("Click or drop Image file here"); + fileHandlerView.setOnUploadedFile(file -> { + valueProperty.set(new Image(file.toURI().toString())); + }); + + VBox fileBox = new VBox(fileNameField, fileHandlerView); + fileBox.getStyleClass().add("file-box"); + return new EffectPropperty(title, ikon, fileBox); + } + + public static EffectPropperty createLightEditor(Lighting effect) { + String[] lightBoxStyleClazz = {"distant", "point", "spot", "none"}; + + StackPane lightPaneWrapper = new StackPane(); + lightPaneWrapper.getStyleClass().add("light-pane-wrapper"); + + ComboBox comboBox = createLightModeBox(effect.lightProperty()); + lightModeHandler(effect, comboBox.getSelectionModel().getSelectedItem(), lightPaneWrapper, comboBox); + comboBox.addEventFilter(MouseEvent.ANY, event -> lightPaneWrapper.requestFocus()); + comboBox.getSelectionModel().selectedItemProperty().addListener((ob, ov, selectedItem) -> { + lightModeHandler(effect, selectedItem, lightPaneWrapper, comboBox); + }); + + VBox lightBox = new VBox(comboBox, lightPaneWrapper); + lightBox.getStyleClass().add("light-box"); + lightBox.getStyleClass().add(lightBoxStyleClazz[comboBox.getSelectionModel().getSelectedIndex()]); + comboBox.getSelectionModel().selectedIndexProperty().addListener((ob, ov, nv) -> { + lightBox.getStyleClass().removeAll(lightBoxStyleClazz); + lightBox.getStyleClass().add(lightBoxStyleClazz[nv.intValue()]); + }); + + return new EffectPropperty("Light", Jam.FLASHLIGHT_ON, lightBox); + } + + private static void lightModeHandler(Lighting effect, String selectedLightMode, StackPane lightPaneWrapper, ComboBox comboBox) { + switch (selectedLightMode) { + case "Distant Light" -> { + Pair> distantLightPane = createDistantLightPane(); + lightPaneWrapper.getChildren().setAll(distantLightPane.getKey()); + if (effect.lightProperty().isBound()) { + effect.lightProperty().unbind(); + } + effect.lightProperty().bind(distantLightPane.getValue()); + } + case "Point Light" -> { + Pair> pointLightPane = createPointLightPane(); + lightPaneWrapper.getChildren().setAll(pointLightPane.getKey()); + if (effect.lightProperty().isBound()) { + effect.lightProperty().unbind(); + } + effect.lightProperty().bind(pointLightPane.getValue()); + } + case "Spot Light" -> { + Pair> spotLightPane = createSpotLightPane(); + lightPaneWrapper.getChildren().setAll(spotLightPane.getKey()); + if (effect.lightProperty().isBound()) { + effect.lightProperty().unbind(); + } + effect.lightProperty().bind(spotLightPane.getValue()); + } + default -> { + lightPaneWrapper.getChildren().clear(); + if (effect.lightProperty().isBound()) { + effect.lightProperty().unbind(); + } + effect.lightProperty().set(null); + } + } + } + + private static ComboBox createLightModeBox(ObjectProperty valueProperty) { + ComboBox comboBox = new ComboBox<>(FXCollections.observableArrayList("Distant Light", "Point Light", "Spot Light", "None")); + comboBox.getStyleClass().add("md-combo-box"); + comboBox.setFocusTraversable(false); + + if (valueProperty.get() instanceof Light.Distant) { + comboBox.getSelectionModel().select("Distant Light"); + } else if (valueProperty.get() instanceof Light.Point) { + comboBox.getSelectionModel().select("Point Light"); + } else if (valueProperty.get() instanceof Light.Spot) { + comboBox.getSelectionModel().select("Spot Light"); + } else { + comboBox.getSelectionModel().select("None"); + } + return comboBox; + } + + private static void createSliderWithLabel(Slider slider, ObservableValue labelProperty, Ikon iconType, String iconText, GridPane lightPane, int row) { + Label label = new Label(iconText, new FontIcon(iconType)); + lightPane.add(label, 0, row); + + Label valueLabel = createValueLabel(); + valueLabel.textProperty().bind(labelProperty); + + HBox sliderBox = new HBox(10, slider, valueLabel); + sliderBox.getStyleClass().add("slider-box"); + lightPane.add(sliderBox, 1, row); + + } + + private static void createCommonColorPicker(ObjectProperty lightProperty, GridPane lightPane, int row) { + PaintPicker colorPicker = createColorPicker(lightProperty.get().colorProperty()); + colorPicker.paintProperty().addListener((ob, ov, nv) -> { + if (nv instanceof Color color) { + lightProperty.get().setColor(color); + } + }); + lightPane.add(colorPicker, 0, row, 2, 1); + } + + private static Pair> createPointLightPane() { + Light.Point point = new Light.Point(); + ObjectProperty valueProperty = new SimpleObjectProperty<>(point); + + GridPane lightPane = new GridPane(); + lightPane.getStyleClass().add("light-pane"); + + Slider xSlider = createSlider(-10, 10, 0); + xSlider.valueProperty().bindBidirectional(point.xProperty()); + createSliderWithLabel(xSlider, point.xProperty().map(value -> NumberUtil.trimTrailingZeros(value.doubleValue())), IkonUtil.x, "X", lightPane, 0); + + Slider ySlider = createSlider(-10, 10, 0); + createSliderWithLabel(ySlider, point.yProperty().map(value -> NumberUtil.trimTrailingZeros(value.doubleValue())), IkonUtil.y, "Y", lightPane, 1); + ySlider.valueProperty().bindBidirectional(point.yProperty()); + + Slider zSlider = createSlider(-10, 10, 0); + createSliderWithLabel(zSlider, point.zProperty().map(value -> NumberUtil.trimTrailingZeros(value.doubleValue())), IkonUtil.z, "Z", lightPane, 2); + zSlider.valueProperty().bindBidirectional(point.zProperty()); + + createCommonColorPicker(valueProperty, lightPane, 3); + + return new Pair<>(lightPane, valueProperty); + } + + private static Pair> createDistantLightPane() { + Light.Distant distant = new Light.Distant(); + ObjectProperty valueProperty = new SimpleObjectProperty<>(distant); + + GridPane lightPane = new GridPane(); + lightPane.getStyleClass().add("light-pane"); + + Slider azimuthSlider = createSlider(0, 360, 45); + createSliderWithLabel(azimuthSlider, distant.azimuthProperty().map(value -> NumberUtil.trimTrailingZeros(value.doubleValue())), IkonUtil.azimuth, "Azimuth", lightPane, 0); + azimuthSlider.valueProperty().bindBidirectional(distant.azimuthProperty()); + + Slider elevationSlider = createSlider(0, 360, 45); + createSliderWithLabel(elevationSlider, distant.elevationProperty().map(value -> NumberUtil.trimTrailingZeros(value.doubleValue())), IkonUtil.elevation, "Elevation", lightPane, 1); + elevationSlider.valueProperty().bindBidirectional(distant.elevationProperty()); + + createCommonColorPicker(valueProperty, lightPane, 2); + + return new Pair<>(lightPane, valueProperty); + } + + private static Pair> createSpotLightPane() { + Light.Spot spot = new Light.Spot(); + ObjectProperty valueProperty = new SimpleObjectProperty<>(spot); + + GridPane lightPane = new GridPane(); + lightPane.getStyleClass().add("light-pane"); + + Slider xSlider = createSlider(-10, 10, 0); + createSliderWithLabel(xSlider, spot.xProperty().map(value -> NumberUtil.trimTrailingZeros(value.doubleValue())), IkonUtil.x, "X", lightPane, 0); + xSlider.valueProperty().bindBidirectional(spot.xProperty()); + + Slider ySlider = createSlider(-10, 10, 0); + ySlider.valueProperty().bindBidirectional(spot.yProperty()); + createSliderWithLabel(ySlider, spot.yProperty().map(value -> NumberUtil.trimTrailingZeros(value.doubleValue())), IkonUtil.y, "Y", lightPane, 1); + + Slider zSlider = createSlider(-10, 10, 0); + zSlider.valueProperty().bindBidirectional(spot.zProperty()); + createSliderWithLabel(zSlider, spot.zProperty().map(value -> NumberUtil.trimTrailingZeros(value.doubleValue())), IkonUtil.z, "Z", lightPane, 2); + + Slider positionAtXSlider = createSlider(-10, 10, 0); + createSliderWithLabel(positionAtXSlider, spot.pointsAtXProperty().map(value -> NumberUtil.trimTrailingZeros(value.doubleValue())), IkonUtil.x, "Points\nAt X", lightPane, 3); + positionAtXSlider.valueProperty().bindBidirectional(spot.pointsAtXProperty()); + + Slider positionAtYSlider = createSlider(-10, 10, 0); + createSliderWithLabel(positionAtYSlider, spot.pointsAtYProperty().map(value -> NumberUtil.trimTrailingZeros(value.doubleValue())), IkonUtil.x, "Points\nAt Y", lightPane, 4); + positionAtYSlider.valueProperty().bindBidirectional(spot.pointsAtYProperty()); + + Slider positionAtZSlider = createSlider(-10, 10, 0); + createSliderWithLabel(positionAtZSlider, spot.pointsAtZProperty().map(value -> NumberUtil.trimTrailingZeros(value.doubleValue())), IkonUtil.x, "Points\nAt Z", lightPane, 5); + positionAtZSlider.valueProperty().bindBidirectional(spot.pointsAtZProperty()); + + Slider specularExponentSlider = createSlider(0, 4, 1); + createSliderWithLabel(specularExponentSlider, spot.specularExponentProperty().map(value -> NumberUtil.trimTrailingZeros(value.doubleValue())), IkonUtil.elevation, "Specular\nExponent", lightPane, 6); + specularExponentSlider.valueProperty().bindBidirectional(spot.specularExponentProperty()); + + createCommonColorPicker(valueProperty, lightPane, 7); + + return new Pair<>(lightPane, valueProperty); + } + +} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/EffectPropperty.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/EffectPropperty.java similarity index 92% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/EffectPropperty.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/EffectPropperty.java index 773f114d..6fa9a5ae 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/EffectPropperty.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/EffectPropperty.java @@ -1,4 +1,4 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; import javafx.scene.Node; import org.kordamp.ikonli.Ikon; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/GaussianBlurEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/GaussianBlurEditor.java similarity index 89% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/GaussianBlurEditor.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/GaussianBlurEditor.java index 7b27aff0..3a9a6707 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/GaussianBlurEditor.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/GaussianBlurEditor.java @@ -1,4 +1,4 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; import com.dlsc.jfxcentral2.utils.IkonUtil; import javafx.scene.effect.GaussianBlur; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/GlowEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/GlowEditor.java similarity index 88% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/GlowEditor.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/GlowEditor.java index 368ae8c4..63d83e1e 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/GlowEditor.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/GlowEditor.java @@ -1,4 +1,4 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; import com.dlsc.jfxcentral2.utils.IkonUtil; import javafx.scene.effect.Glow; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/ImageInputEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/ImageInputEditor.java similarity index 91% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/ImageInputEditor.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/ImageInputEditor.java index 3be3b2ef..57042f16 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/ImageInputEditor.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/ImageInputEditor.java @@ -1,4 +1,4 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; import com.dlsc.jfxcentral2.utils.IkonUtil; import javafx.scene.effect.ImageInput; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/InnerShadowEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/InnerShadowEditor.java similarity index 95% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/InnerShadowEditor.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/InnerShadowEditor.java index b2849202..4f9eca38 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/InnerShadowEditor.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/InnerShadowEditor.java @@ -1,4 +1,4 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; import com.dlsc.jfxcentral2.utils.IkonUtil; import javafx.scene.effect.BlurType; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/LightingBumpInputEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/LightingBumpInputEditor.java new file mode 100644 index 00000000..e0669dc0 --- /dev/null +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/LightingBumpInputEditor.java @@ -0,0 +1,11 @@ +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; + +import javafx.scene.effect.Lighting; + +public class LightingBumpInputEditor extends LightingEditor { + + public LightingBumpInputEditor(Lighting effect, Runnable deleteAction) { + super(effect, deleteAction); + } + +} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/LightingContentInputEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/LightingContentInputEditor.java new file mode 100644 index 00000000..944c29c3 --- /dev/null +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/LightingContentInputEditor.java @@ -0,0 +1,11 @@ +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; + +import javafx.scene.effect.Lighting; + +public class LightingContentInputEditor extends LightingEditor { + + public LightingContentInputEditor(Lighting effect, Runnable deleteAction) { + super(effect, deleteAction); + } + +} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/LightingEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/LightingEditor.java new file mode 100644 index 00000000..154ccbcd --- /dev/null +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/LightingEditor.java @@ -0,0 +1,27 @@ +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; + +import javafx.scene.effect.Lighting; +import org.kordamp.ikonli.material2.Material2SharpAL; +import org.kordamp.ikonli.materialdesign.MaterialDesign; +import org.kordamp.ikonli.octicons.Octicons; +import org.kordamp.ikonli.unicons.UniconsLine; + +import java.util.List; + +public class LightingEditor extends EffectEditor { + + public LightingEditor(Lighting effect, Runnable deleteAction) { + super(effect, deleteAction); + } + + @Override + protected List createOptions(Lighting effect) { + return List.of( + EffectPropertyFactory.create("Diffuse\nConstant", MaterialDesign.MDI_TEXTURE, 0, 2, 1, effect.diffuseConstantProperty()), + EffectPropertyFactory.create("Specular\nConstant", Octicons.MIRROR_24, 0, 2, 1, effect.specularConstantProperty()), + EffectPropertyFactory.create("Specular\nExponent", Material2SharpAL.CENTER_FOCUS_WEAK, 0, 40, 20, effect.specularExponentProperty()), + EffectPropertyFactory.create("Surface\nScale", UniconsLine.CIRCLE_LAYER, 0, 10, 1, effect.surfaceScaleProperty()), + EffectPropertyFactory.createLightEditor(effect) + ); + } +} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/MotionBlurEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/MotionBlurEditor.java similarity index 91% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/MotionBlurEditor.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/MotionBlurEditor.java index c543d4b1..44fa9718 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/MotionBlurEditor.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/MotionBlurEditor.java @@ -1,4 +1,4 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; import com.dlsc.jfxcentral2.utils.IkonUtil; import javafx.scene.effect.MotionBlur; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/PerspectiveTransformEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/PerspectiveTransformEditor.java similarity index 95% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/PerspectiveTransformEditor.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/PerspectiveTransformEditor.java index 6988ca98..4efcabce 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/PerspectiveTransformEditor.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/PerspectiveTransformEditor.java @@ -1,4 +1,4 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; import com.dlsc.jfxcentral2.utils.IkonUtil; import javafx.scene.effect.PerspectiveTransform; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/ReflectionEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/ReflectionEditor.java similarity index 93% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/ReflectionEditor.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/ReflectionEditor.java index 60f8ebe1..3a0473b6 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/ReflectionEditor.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/ReflectionEditor.java @@ -1,4 +1,4 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; import com.dlsc.jfxcentral2.utils.IkonUtil; import javafx.scene.effect.Reflection; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/SepiaToneEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/SepiaToneEditor.java similarity index 89% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/SepiaToneEditor.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/SepiaToneEditor.java index 7f521320..ed99c1e8 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/SepiaToneEditor.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/SepiaToneEditor.java @@ -1,4 +1,4 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; import com.dlsc.jfxcentral2.utils.IkonUtil; import javafx.scene.effect.SepiaTone; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/ShadowEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/ShadowEditor.java similarity index 94% rename from components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/ShadowEditor.java rename to components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/ShadowEditor.java index 21ee7528..581f790c 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/ShadowEditor.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/editor/ShadowEditor.java @@ -1,4 +1,4 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; +package com.dlsc.jfxcentral2.utilities.effectdesigner.editor; import com.dlsc.jfxcentral2.utils.IkonUtil; import javafx.scene.effect.BlurType; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/effect/BlendBottomInput.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/effect/BlendBottomInput.java new file mode 100644 index 00000000..8396bda8 --- /dev/null +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/effect/BlendBottomInput.java @@ -0,0 +1,19 @@ +package com.dlsc.jfxcentral2.utilities.effectdesigner.effect; + +import javafx.scene.effect.Blend; +import javafx.scene.effect.Effect; + +public class BlendBottomInput extends Blend { + public BlendBottomInput() { + + } + + public void setInput(Effect effect) { + setBottomInput(effect); + } + + public Effect getInput() { + return getBottomInput(); + } + +} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/effect/BlendTopInput.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/effect/BlendTopInput.java new file mode 100644 index 00000000..b2f283dd --- /dev/null +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/effect/BlendTopInput.java @@ -0,0 +1,18 @@ +package com.dlsc.jfxcentral2.utilities.effectdesigner.effect; + +import javafx.scene.effect.Blend; +import javafx.scene.effect.Effect; + +public class BlendTopInput extends Blend { + public BlendTopInput() { + } + + public void setInput(Effect effect) { + setTopInput(effect); + } + + public Effect getInput() { + return getTopInput(); + } + +} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/effect/LightingBumpInput.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/effect/LightingBumpInput.java new file mode 100644 index 00000000..4f622e93 --- /dev/null +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/effect/LightingBumpInput.java @@ -0,0 +1,19 @@ +package com.dlsc.jfxcentral2.utilities.effectdesigner.effect; + +import javafx.scene.effect.Effect; +import javafx.scene.effect.Lighting; + +public class LightingBumpInput extends Lighting { + + public LightingBumpInput() { + } + + public void setInput(Effect effect) { + setBumpInput(effect); + } + + public Effect getInput() { + return getBumpInput(); + } + +} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/effect/LightingContentInput.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/effect/LightingContentInput.java new file mode 100644 index 00000000..2b1351cc --- /dev/null +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/effectdesigner/effect/LightingContentInput.java @@ -0,0 +1,19 @@ +package com.dlsc.jfxcentral2.utilities.effectdesigner.effect; + +import javafx.scene.effect.Effect; +import javafx.scene.effect.Lighting; + +public class LightingContentInput extends Lighting { + + public LightingContentInput() { + + } + + public void setInput(Effect effect) { + setContentInput(effect); + } + + public Effect getInput() { + return getContentInput(); + } +} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/paintpicker/impl/PaintConvertUtil.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/paintpicker/impl/PaintConvertUtil.java index 49814f7a..2a98ca3a 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/paintpicker/impl/PaintConvertUtil.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utilities/paintpicker/impl/PaintConvertUtil.java @@ -72,28 +72,52 @@ public static String convertPaintToCss(Paint fxPaint) { } public static String convertPaintToJavaCode(Paint fxPaint) { + return convertPaintToJavaCode(fxPaint, true); + } + + public static String convertPaintToJavaCode(Paint fxPaint, boolean withDeclaration) { + StringBuilder sb = new StringBuilder(); + + if (withDeclaration) { + if (fxPaint instanceof LinearGradient) { + sb.append("LinearGradient paint = "); + } else if (fxPaint instanceof RadialGradient) { + sb.append("RadialGradient paint = "); + } else if (fxPaint instanceof Color) { + sb.append("Color paint = "); + } + } + if (fxPaint instanceof LinearGradient) { LinearGradient paint = (LinearGradient) fxPaint; - return "LinearGradient paint = new LinearGradient(" + System.lineSeparator() + - round(paint.getStartX()) + ", " + round(paint.getStartY()) + ", " + - round(paint.getEndX()) + ", " + round(paint.getEndY()) + ", " + - paint.isProportional() + ", " + - cycleMethodToStr(paint.getCycleMethod()) + "," + System.lineSeparator() + - stopsToString(paint.getStops()) + - ");"; + sb.append("new LinearGradient(").append(System.lineSeparator()) + .append(round(paint.getStartX())).append(", ").append(round(paint.getStartY())).append(", ") + .append(round(paint.getEndX())).append(", ").append(round(paint.getEndY())).append(", ") + .append(paint.isProportional()).append(", ") + .append(cycleMethodToStr(paint.getCycleMethod())).append(",").append(System.lineSeparator()) + .append(stopsToString(paint.getStops())) + .append(")"); } else if (fxPaint instanceof RadialGradient) { RadialGradient paint = (RadialGradient) fxPaint; - return "RadialGradient paint = new RadialGradient(" + System.lineSeparator() + - round(paint.getFocusAngle()) + ", " + round(paint.getFocusDistance()) + ", " + round(paint.getCenterX()) + ", " - + round(paint.getCenterY()) + ", " + round(paint.getRadius()) + ", " + paint.isProportional() + ", " - + cycleMethodToStr(paint.getCycleMethod())+ "," + System.lineSeparator() - + stopsToString(paint.getStops()) + ");"; + sb.append("new RadialGradient(").append(System.lineSeparator()) + .append(round(paint.getFocusAngle())).append(", ").append(round(paint.getFocusDistance())).append(", ") + .append(round(paint.getCenterX())).append(", ").append(round(paint.getCenterY())).append(", ") + .append(round(paint.getRadius())).append(", ").append(paint.isProportional()).append(", ") + .append(cycleMethodToStr(paint.getCycleMethod())).append(",").append(System.lineSeparator()) + .append(stopsToString(paint.getStops())) + .append(")"); } else if (fxPaint instanceof Color) { - return "Color paint = " + colorToJavaStr((Color) fxPaint) + ";"; + sb.append(colorToJavaStr((Color) fxPaint)); } - return ""; + + if (withDeclaration) { + sb.append(";"); + } + + return sb.toString(); } + private static void connectCycleMethodAndStops(StringBuilder strBuilder, CycleMethod cycleMethod, List stops) { switch (cycleMethod) { case REFLECT: diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/BlendBottomInputEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/BlendBottomInputEditor.java deleted file mode 100644 index edf36135..00000000 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/BlendBottomInputEditor.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; - -import com.dlsc.jfxcentral2.utilities.shadowdesigner.effect.BlendBottomInput; -import com.dlsc.jfxcentral2.utils.IkonUtil; -import javafx.scene.effect.BlendMode; - -import java.util.List; - -public class BlendBottomInputEditor extends EffectEditor { - - public BlendBottomInputEditor(BlendBottomInput effect, Runnable deleteAction) { - super(effect, deleteAction); - } - - @Override - protected List createOptions(BlendBottomInput effect) { - return List.of( - EffectPropertyFactory.create("Mode", IkonUtil.blendMode, BlendMode.class, null, effect.modeProperty()), - EffectPropertyFactory.create("Opacity", IkonUtil.opacity, 0, 1, 1, effect.opacityProperty()) - ); - } -} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/EffectPropertyFactory.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/EffectPropertyFactory.java deleted file mode 100644 index 1ef35bb4..00000000 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/EffectPropertyFactory.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; - -import com.dlsc.jfxcentral2.components.FileHandlerView; -import com.dlsc.jfxcentral2.utilities.paintpicker.impl.PaintPicker; -import com.dlsc.jfxcentral2.utils.NumberUtil; -import javafx.beans.binding.Bindings; -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.DoubleProperty; -import javafx.beans.property.IntegerProperty; -import javafx.beans.property.ObjectProperty; -import javafx.scene.control.CheckBox; -import javafx.scene.control.ComboBox; -import javafx.scene.control.Label; -import javafx.scene.control.Slider; -import javafx.scene.control.Spinner; -import javafx.scene.control.TextField; -import javafx.scene.image.Image; -import javafx.scene.layout.HBox; -import javafx.scene.layout.VBox; -import javafx.scene.paint.Color; -import javafx.scene.paint.Paint; -import javafx.util.StringConverter; -import org.kordamp.ikonli.Ikon; - -public class EffectPropertyFactory { - - public static > EffectPropperty create(String title, Ikon ikon, Class enumClass, StringConverter stringConverter, ObjectProperty valueProperty) { - ComboBox comboBox = new ComboBox<>(); - comboBox.getStyleClass().add("md-combo-box"); - comboBox.setFocusTraversable(false); - comboBox.setConverter(stringConverter); - comboBox.getItems().addAll(enumClass.getEnumConstants()); - comboBox.getSelectionModel().select(valueProperty.get()); - comboBox.valueProperty().addListener((ob, ov, nv) -> valueProperty.set(nv)); - - return new EffectPropperty(title, ikon, comboBox); - } - - public static EffectPropperty create(String title, Ikon ikon, double min, double max, double current, DoubleProperty valueProperty) { - Slider slider = new Slider(min, max, current); - slider.setFocusTraversable(false); - slider.setMajorTickUnit(max); - slider.setMinorTickCount(0); - slider.setShowTickLabels(true); - slider.valueProperty().addListener((ob, ov, nv) -> valueProperty.set(nv.doubleValue())); - Label valueLabel = new Label(); - valueLabel.getStyleClass().add("value-label"); - valueLabel.textProperty().bind(Bindings.createObjectBinding(() -> { - double value = valueProperty.get(); - slider.setValue(value); - return NumberUtil.trimTrailingZeros(value); - }, valueProperty)); - HBox sliderBox = new HBox(10, slider, valueLabel); - sliderBox.getStyleClass().add("slider-box"); - return new EffectPropperty(title, ikon, sliderBox); - } - - public static EffectPropperty create(String title, Ikon ikon, int min, int max, int current, IntegerProperty valueProperty) { - Spinner spinner = new Spinner<>(min, max, current); - spinner.valueProperty().addListener((ob, ov, nv) -> valueProperty.set(nv)); - spinner.setFocusTraversable(false); - return new EffectPropperty(title, ikon, spinner); - } - - public static EffectPropperty create(String title, Ikon ikon, BooleanProperty valueProperty) { - CheckBox checkBox = new CheckBox(); - checkBox.setFocusTraversable(false); - checkBox.selectedProperty().bindBidirectional(valueProperty); - return new EffectPropperty(title, ikon, checkBox); - } - - public static EffectPropperty createWithColorPicker(String title, Ikon ikon, ObjectProperty valueProperty) { - PaintPicker colorPicker = PaintPicker.createColorPicker(); - colorPicker.setFocusTraversable(false); - colorPicker.setPaintProperty(valueProperty.get()); - colorPicker.paintProperty().addListener((ob, ov, nv) -> - valueProperty.set(nv instanceof Color color ? color : Color.TRANSPARENT)); - return new EffectPropperty(title, ikon, colorPicker); - } - - public static EffectPropperty createWithPaintPicker(String title, Ikon ikon, ObjectProperty valueProperty) { - PaintPicker paintPicker = new PaintPicker(); - paintPicker.setFocusTraversable(false); - paintPicker.setPaintProperty(valueProperty.get()); - paintPicker.paintProperty().addListener((ob, ov, nv) -> valueProperty.set(nv)); - return new EffectPropperty(title, ikon, paintPicker); - } - - public static EffectPropperty create(String title, Ikon ikon, ObjectProperty valueProperty) { - TextField fileNameField = new TextField(); - fileNameField.getStyleClass().add("file-name-label"); - fileNameField.setEditable(false); - fileNameField.setFocusTraversable(false); - fileNameField.managedProperty().bind(fileNameField.visibleProperty()); - fileNameField.visibleProperty().bind(valueProperty.isNotNull()); - - FileHandlerView fileHandlerView = new FileHandlerView(false, false, true); - fileHandlerView.getSupportedExtensions().addAll(".png", ".jpg", ".jpeg", ".gif"); - fileHandlerView.setText("Click or drop Image file here"); - fileHandlerView.setOnUploadedFile(file -> { - valueProperty.set(new Image(file.toURI().toString())); - fileNameField.setText(file.getName()); - }); - - VBox fileBox = new VBox(fileNameField, fileHandlerView); - fileBox.getStyleClass().add("file-box"); - return new EffectPropperty(title, ikon, fileBox); - } - -} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/LightingBumpInputEditor.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/LightingBumpInputEditor.java deleted file mode 100644 index eb05b1c6..00000000 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/editor/LightingBumpInputEditor.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; - -import javafx.scene.effect.Lighting; - -import java.util.List; - -public class LightingBumpInputEditor extends EffectEditor { - - public LightingBumpInputEditor(Lighting effect, Runnable deleteAction) { - super(effect, deleteAction); - } - - @Override - protected List createOptions(Lighting effect) { - return List.of( - EffectPropertyFactory.create("Diffuse Constant", null, 0, 2, 1, effect.diffuseConstantProperty()), - EffectPropertyFactory.create("Specular Constant", null, 0, 2, 1, effect.specularConstantProperty()), - EffectPropertyFactory.create("Specular Exponent", null, 0, 40, 20, effect.specularExponentProperty()), - EffectPropertyFactory.create("Surface Scale", null, 0, 10, 1, effect.surfaceScaleProperty()) - - ); - } -} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/effect/BlendBottomInput.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/effect/BlendBottomInput.java deleted file mode 100644 index 3250faf8..00000000 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/effect/BlendBottomInput.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.effect; - -import javafx.scene.effect.Blend; - -public class BlendBottomInput extends Blend { - public BlendBottomInput() { - - } - - public void setInput(BlendBottomInput bottomInput) { - setBottomInput(bottomInput); - } -} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/effect/BlendTopInput.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/effect/BlendTopInput.java deleted file mode 100644 index e5c9d060..00000000 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/effect/BlendTopInput.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.effect; - -import javafx.scene.effect.Blend; - -public class BlendTopInput extends Blend { - public BlendTopInput() { - } - - public void setInput(BlendTopInput topInput) { - setTopInput(topInput); - } - -} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/effect/LightingBumpInput.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/effect/LightingBumpInput.java deleted file mode 100644 index b3cc3571..00000000 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/effect/LightingBumpInput.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.effect; - -import javafx.scene.effect.Lighting; - -public class LightingBumpInput extends Lighting { - - public LightingBumpInput() { - } - - public void setInput(LightingBumpInput bumpInput) { - setBumpInput(bumpInput); - } - -} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/effect/LightingContentInput.java b/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/effect/LightingContentInput.java deleted file mode 100644 index 9fac83d0..00000000 --- a/components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/effect/LightingContentInput.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.dlsc.jfxcentral2.utilities.shadowdesigner.effect; - -import javafx.scene.effect.Lighting; - -public class LightingContentInput extends Lighting { - - public LightingContentInput() { - - } - - public void setInput(LightingContentInput contentInput) { - setContentInput(contentInput); - } -} diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utils/IkonUtil.java b/components/src/main/java/com/dlsc/jfxcentral2/utils/IkonUtil.java index d91bbcbf..ec51752c 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utils/IkonUtil.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utils/IkonUtil.java @@ -33,11 +33,13 @@ import org.kordamp.ikonli.hawcons.HawconsStroke; import org.kordamp.ikonli.ionicons4.Ionicons4IOS; import org.kordamp.ikonli.lineawesome.LineAwesomeSolid; +import org.kordamp.ikonli.material.Material; import org.kordamp.ikonli.material2.Material2MZ; import org.kordamp.ikonli.materialdesign.MaterialDesign; import org.kordamp.ikonli.materialdesign2.MaterialDesignA; import org.kordamp.ikonli.materialdesign2.MaterialDesignN; import org.kordamp.ikonli.remixicon.RemixiconAL; +import org.kordamp.ikonli.runestroicons.Runestroicons; import org.kordamp.ikonli.subway.Subway; import org.kordamp.ikonli.themify.Themify; import org.kordamp.ikonli.unicons.UniconsLine; @@ -104,8 +106,12 @@ public interface IkonUtil { Ikon wrap = Themify.LOOP; Ikon iterations = Material2MZ.WAVES; Ikon level = CarbonIcons.BRIGHTNESS_CONTRAST; + Ikon disabled = Material.DO_NOT_DISTURB; Ikon x = CarbonIcons.X_AXIS; Ikon y = CarbonIcons.Y_AXIS; + Ikon z = MaterialDesignA.AXIS_X_ARROW; + Ikon azimuth = Runestroicons.COMPASS; + Ikon elevation = BootstrapIcons.SUNRISE; Ikon image = CarbonIcons.IMAGE; Ikon angle = MaterialDesignA.ANGLE_ACUTE; Ikon llx = Subway.RECTANGLE_3; diff --git a/components/src/main/java/com/dlsc/jfxcentral2/utils/JFXCentralUtil.java b/components/src/main/java/com/dlsc/jfxcentral2/utils/JFXCentralUtil.java index eb88b545..f6402fb8 100644 --- a/components/src/main/java/com/dlsc/jfxcentral2/utils/JFXCentralUtil.java +++ b/components/src/main/java/com/dlsc/jfxcentral2/utils/JFXCentralUtil.java @@ -1,7 +1,9 @@ package com.dlsc.jfxcentral2.utils; +import javafx.animation.PauseTransition; import javafx.application.Platform; import javafx.beans.property.ObjectProperty; +import javafx.util.Duration; public class JFXCentralUtil { private JFXCentralUtil() { @@ -39,4 +41,14 @@ public static void runInFXThread(ObjectProperty runnableProperty) { runInFXThread(runnableProperty.get()); } + public static void runInFXThread(Runnable runnable, long delayMillis) { + PauseTransition pauseTransition = new PauseTransition(Duration.millis(delayMillis)); + pauseTransition.setOnFinished(event -> { + if (runnable != null) { + runnable.run(); + } + }); + pauseTransition.play(); + } + } diff --git a/components/src/main/java/module-info.java b/components/src/main/java/module-info.java index 13386266..9d910a07 100644 --- a/components/src/main/java/module-info.java +++ b/components/src/main/java/module-info.java @@ -106,10 +106,10 @@ exports com.dlsc.jfxcentral2.components.hamburger; exports com.dlsc.jfxcentral2.components.topcontent; exports com.dlsc.jfxcentral2.utilities.pathextractor; - exports com.dlsc.jfxcentral2.utilities.shadowdesigner; - exports com.dlsc.jfxcentral2.utilities.shadowdesigner.editor; + exports com.dlsc.jfxcentral2.utilities.effectdesigner; + exports com.dlsc.jfxcentral2.utilities.effectdesigner.editor; exports com.dlsc.jfxcentral2.utilities.paintpicker.impl; - exports com.dlsc.jfxcentral2.utilities.shadowdesigner.effect; + exports com.dlsc.jfxcentral2.utilities.effectdesigner.effect; uses IkonProvider; } \ No newline at end of file diff --git a/components/src/main/resources/com/dlsc/jfxcentral2/theme.css b/components/src/main/resources/com/dlsc/jfxcentral2/theme.css index 4b202d0c..4313b39f 100644 --- a/components/src/main/resources/com/dlsc/jfxcentral2/theme.css +++ b/components/src/main/resources/com/dlsc/jfxcentral2/theme.css @@ -9417,14 +9417,14 @@ -fx-shape: "M50,40.1c0,6.1-4.9,11-11,11s-11-4.9-11-11s4.9-11,11-11S50,34,50,40.1zM79.6,84.5v4.2H48.9v-4.2H79.6zM63.5,119.6c-31,0-56.1-25.2-56.1-56.1c0-31,25.2-56.1,56.1-56.1c31,0,56.1,25.2,56.1,56.1 C119.6,94.5,94.5,119.6,63.5,119.6z M63.5,16.4c-26,0-47.1,21.1-47.1,47.1s21.1,47.1,47.1,47.1s47.1-21.1,47.1-47.1 S89.5,16.4,63.5,16.4zM50,86.9c0,6.1-4.9,11-11,11s-11-4.9-11-11c0-6.1,4.9-11,11-11S50,80.8,50,86.9zM100.3,40.1c0,6.1-4.9,11-11,11s-11-4.9-11-11s4.9-11,11-11S100.3,34,100.3,40.1zM100.3,85.9c0,6.1-4.9,11-11,11s-11-4.9-11-11c0-6.1,4.9-11,11-11S100.3,79.8,100.3,85.9zM80.1,38.5v4.2H49.3v-4.2H80.1zM87.2,47.8h4.2v30.8h-4.2V47.8zM36.9,48.1H41v30.8h-4.2V48.1z"; } -.gradient-designer-view .linear-gradient-view { +.gradient-designer-view .linear-gradient-view { -fx-font-family: "Roboto Condensed"; -fx-font-size: 20px; -fx-padding: 10px 0 0 0; -fx-spacing: 10px; } -.gradient-designer-view .linear-gradient-view .flow-pane { +.gradient-designer-view .linear-gradient-view .flow-pane { -fx-hgap: 12px; -fx-vgap: 10px; } @@ -9446,57 +9446,80 @@ } /** ---------------------------------------------------------------------------- - * ShadowDesignerView + * EffectDesignerView */ -.shadow-designer-view { +.effect-designer-view { -fx-min-height: 560px; } -.shadow-designer-view .left-box .effect-preview-pane { +.effect-designer-view .left-box .effect-preview-pane { -fx-pref-width: 200px; -fx-pref-height: 200px; -fx-background-color: -white; - -fx-border-color: -grey-10; + -fx-border-color: -grey-30; + -fx-border-width: 1px; } -.shadow-designer-view > .flow-pane { +.effect-designer-view > .flow-pane { -fx-hgap: 60px; -fx-vgap: 30px; } -.shadow-designer-view:md > .flow-pane { +.effect-designer-view:md > .flow-pane { -fx-hgap: 120px; } -.shadow-designer-view:sm-md > .flow-pane { +.effect-designer-view:sm-md > .flow-pane { -fx-alignment: center; } -.shadow-designer-view .left-box .effect-preview-pane .label { - -fx-font-size: 20px; +.effect-designer-view .left-box .effect-preview-pane .label { + -fx-font-size: 25px; + -fx-font-weight: bold; + -fx-text-fill: linear-gradient(from 0.0% 0.0% to 100.0% 0.0%, #fa00fc 0.0%, #03dbde 100.0%); } -.shadow-designer-view > .flow-pane { +.effect-designer-view > .flow-pane { /*-fx-border-color: #08e093;*/ } -.shadow-designer-view > .flow-pane > .left-box { +.effect-designer-view > .flow-pane > .left-box { -fx-padding: 50px; } -.shadow-designer-view > .flow-pane > .right-box { +.effect-designer-view > .flow-pane > .right-box { + -fx-alignment: top-left; +} + +.effect-designer-view > .flow-pane > .right-box.with-non-effect { + -fx-alignment: center; } -.shadow-designer-view > .flow-pane > .right-box.with-non-effect .menu-button { +.effect-designer-view > .flow-pane > .right-box.with-non-effect .menu-button { -fx-pref-width: 200px; -fx-background-radius: 200px; -fx-font-size: 20px; } -.shadow-designer-view > .flow-pane > .right-box.with-non-effect .menu-button .ikonli-font-icon { +.effect-designer-view > .flow-pane > .right-box.with-non-effect .menu-button .ikonli-font-icon { -fx-icon-size: 30px; } +.effect-designer-view .right-box .copy-effect-code-view { + -fx-spacing: 10px; +} + +.effect-designer-view .copy-effect-code-view .fill-button { + -fx-background-radius: 2px; + -fx-padding: 2px 5px; + -fx-font-size: 14px; +} + +.effect-designer-view .copy-effect-code-view .fill-button > .ikonli-font-icon { + -fx-scale-x: 0.8; + -fx-scale-y: 0.8; +} + /** ---------------------------------------------------------------------------- * EffectEditor @@ -9508,16 +9531,16 @@ -fx-spacing: 10px; } -.shadow-designer-view:lg .effect-editor { +.effect-designer-view:lg .effect-editor { -fx-pref-width: 420px; -fx-max-width: 420px; } -.shadow-designer-view:sm .effect-editor .property-name-label { +.effect-designer-view:sm .effect-editor .property-name-label { -fx-font-size: 12px; } -.shadow-designer-view:sm .effect-editor .property-name-label .ikonli-font-icon { +.effect-designer-view:sm .effect-editor .property-name-label .ikonli-font-icon { -fx-icon-size: 14px; } @@ -9533,7 +9556,7 @@ -fx-graphic-text-gap: 10px; } -.effect-editor .top-box .title-label .ikonli-font-icon{ +.effect-editor .top-box .title-label .ikonli-font-icon { -fx-icon-size: 18px; -fx-icon-color: -white; } @@ -9634,6 +9657,35 @@ -fx-icon-color: -grey-60; } +.effect-editor .light-pane-wrapper { + -fx-padding: 5px 0 0 0; +} + +.effect-editor .light-pane { + -fx-vgap: 5px; +} + +.effect-editor .light-pane .label { + -fx-text-alignment: center; + -fx-vgap: 5px; +} + +.effect-editor .light-box .combo-box-base { + -fx-pref-width: 320px; +} + +.effect-editor .light-box.distant .slider { + -fx-pref-width: 186px; +} + +.effect-editor .light-box.point .slider { + -fx-pref-width: 236px; +} + +.effect-editor .light-box.spot .slider { + -fx-pref-width: 185px; +} + /** ---------------------------------------------------------------------------- * EffectFlowPane */ @@ -9671,3 +9723,19 @@ .effect-flow-pane .menu-button .ikonli-font-icon { -fx-icon-size: 20px; } + +.effect-flow-pane .copy-effect-code-button .context-menu { + -fx-padding: 10px; + -fx-effect: dropshadow(three-pass-box, #2659d9d9, 10.0, 0.0, 0.0, 0.0); +} + +.effect-flow-pane .copy-effect-code-button .context-menu .menu-item { + -fx-border-width: 0; + -fx-padding: 0px; +} + +.effect-flow-pane .copy-effect-code-button .context-menu .menu-item:hover, +.effect-flow-pane .copy-effect-code-button .context-menu .menu-item:focused { + -fx-background-color: transparent; + -fx-border-width: 0; +} diff --git a/sampler/src/main/java/com/dlsc/jfxcentral2/demo/devtools/HelloShadowDesignerView.java b/sampler/src/main/java/com/dlsc/jfxcentral2/demo/devtools/HelloEffectDesignerView.java similarity index 56% rename from sampler/src/main/java/com/dlsc/jfxcentral2/demo/devtools/HelloShadowDesignerView.java rename to sampler/src/main/java/com/dlsc/jfxcentral2/demo/devtools/HelloEffectDesignerView.java index 821df43b..4e66fd9b 100644 --- a/sampler/src/main/java/com/dlsc/jfxcentral2/demo/devtools/HelloShadowDesignerView.java +++ b/sampler/src/main/java/com/dlsc/jfxcentral2/demo/devtools/HelloEffectDesignerView.java @@ -1,17 +1,17 @@ package com.dlsc.jfxcentral2.demo.devtools; import com.dlsc.jfxcentral2.demo.JFXCentralSampleBase; -import com.dlsc.jfxcentral2.utilities.shadowdesigner.ShadowDesignerView; +import com.dlsc.jfxcentral2.utilities.effectdesigner.EffectDesignerView; import javafx.scene.layout.Region; -public class HelloShadowDesignerView extends JFXCentralSampleBase { +public class HelloEffectDesignerView extends JFXCentralSampleBase { @Override protected Region createControl() { - return new ShadowDesignerView(); + return new EffectDesignerView(); } @Override public String getSampleName() { - return "Shadow Designer View"; + return "Effect Designer View"; } }