Skip to content

Commit

Permalink
Add ShadowDesignerView
Browse files Browse the repository at this point in the history
  • Loading branch information
leewyatt committed Oct 13, 2023
1 parent 8a7d1c5 commit 63fdb63
Show file tree
Hide file tree
Showing 38 changed files with 1,556 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +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.utils.ModelObjectTool;
import javafx.scene.Node;
import javafx.scene.control.Label;
Expand All @@ -16,6 +17,7 @@
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.material2.Material2OutlinedAL;
import org.kordamp.ikonli.materialdesign2.MaterialDesignS;
import org.kordamp.ikonli.simplelineicons.SimpleLineIcons;

public class UtilityOverviewBox extends OverviewBox<Utility> {

Expand Down Expand Up @@ -63,6 +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");
setIcon(SimpleLineIcons.MAGIC_WAND);
getStyleClass().add("shadow-designer-overview-box");
ShadowDesignerView shadowDesignerView = new ShadowDesignerView();
shadowDesignerView.sizeProperty().bind(sizeProperty());
return shadowDesignerView;
}

return createComingSoonPane();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.dlsc.jfxcentral2.utilities.paintpicker.impl.datamodel.ColorFormat;
import com.dlsc.jfxcentral2.utils.IkonUtil;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
Expand Down Expand Up @@ -60,6 +61,7 @@ public FXColorInfoPane() {
fieldHsl.setText("0,0,0,1.0");
fieldRgb.setText("0,0,0,1.0");
fieldHex.setText("#000000FF");
managedProperty().bind(visibleProperty());

buildUI();
}
Expand Down Expand Up @@ -126,10 +128,10 @@ private void copyFXCodeOnClick() {
Paint fxPaint = paintPickerController.paintProperty().get();
if (type == CodeType.JAVAFX_CODE) {
String javaCode = PaintConvertUtil.convertPaintToJavaCode(fxPaint);
CopyUtil.setCopyOnClick(copyCodeBtn, javaCode);
Platform.runLater(() -> CopyUtil.setCopyOnClick(copyCodeBtn, javaCode));
} else if (type == CodeType.JAVAFX_CSS) {
String cssCode = PaintConvertUtil.convertPaintToCss(fxPaint);
CopyUtil.setCopyOnClick(copyCodeBtn, cssCode);
Platform.runLater(() -> CopyUtil.setCopyOnClick(copyCodeBtn, cssCode));
}
}
}
Expand All @@ -144,8 +146,8 @@ private BorderPane createColorPane(String text, TextField field) {
Button copyBtn = new Button("", new FontIcon(IkonUtil.copy));
copyBtn.getStyleClass().addAll("fill-button", "copy-button");
pane.setRight(copyBtn);
CopyUtil.setCopyOnClick(copyBtn, text);
field.textProperty().addListener((ob, ov, nv) -> CopyUtil.setCopyOnClick(copyBtn, field.getText()));
Platform.runLater(() -> CopyUtil.setCopyOnClick(copyBtn, field.getText()));
field.textProperty().addListener((ob, ov, nv) -> Platform.runLater(() -> CopyUtil.setCopyOnClick(copyBtn, field.getText())));
return pane;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ public PaintPicker(Delegate delegate) {

modeSwitch.getToggles().addAll(colorToggleButton, linearToggleButton, radialToggleButton);

HBox hBox = new HBox( colorToggleButton, linearToggleButton, radialToggleButton);
hBox.setAlignment(Pos.CENTER_LEFT);
HBox modeButtonsBox = new HBox( colorToggleButton, linearToggleButton, radialToggleButton);
modeButtonsBox.setAlignment(Pos.CENTER_LEFT);
modeButtonsBox.getStyleClass().add("mode-buttons-box");
modeButtonsBox.managedProperty().bind(modeButtonsBox.visibleProperty());

root_vbox = new VBox(hBox);
root_vbox = new VBox(modeButtonsBox);
root_vbox.setAlignment(Pos.CENTER);
root_vbox.setMinHeight(-1.0);
root_vbox.setPrefHeight(-1.0);
Expand All @@ -111,7 +113,14 @@ public PaintPicker(Delegate delegate, PaintMode paintMode) {
controller.setSingleMode(paintMode);
}


/**
* Creates a color picker.
*/
public static PaintPicker createColorPicker() {
PaintPicker paintPicker = new PaintPicker((warningKey, arguments) -> {});
paintPicker.getStyleClass().add("only-color-mode");
return paintPicker;
}

public final ObjectProperty<Paint> paintProperty() {
return controller.paintProperty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public ColorPicker(PaintPickerController pe) {
chip_region = new Region();
hexaTextfield = new TextField();
hue_slider = new Slider();
hue_slider.setFocusTraversable(false);
gridPane = new GridPane();
stackPane0 = new StackPane();
region2 = new Region();
Expand Down Expand Up @@ -303,6 +304,7 @@ public ColorPicker(PaintPickerController pe) {
alpha_region.setStyle("");

alpha_slider.setBlockIncrement(0.01);
alpha_slider.setFocusTraversable(false);
alpha_slider.setMax(1.0);
alpha_slider.getStyleClass().add("opacity-slider");
GridPane.setMargin(stackPane0, new Insets(0.0, 0.0, 2.0, 0.0));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.dlsc.jfxcentral2.utilities.shadowdesigner;

import com.dlsc.jfxcentral2.utilities.shadowdesigner.effect.BlendBottomInput;
import com.dlsc.jfxcentral2.utilities.shadowdesigner.effect.BlendTopInput;
import javafx.scene.effect.Bloom;
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.MotionBlur;
import javafx.scene.effect.PerspectiveTransform;
import javafx.scene.effect.Reflection;
import javafx.scene.effect.SepiaTone;
import javafx.scene.effect.Shadow;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public enum EffectEnum {
//BLEND("Blend", Blend.class),
BLEND_TOP_INPUT("Blend (TopInPut)", BlendTopInput.class),
BLEND_BOTTOM_INPUT("Blend (BottomInput)", BlendBottomInput.class),
BLOOM("Bloom", Bloom.class),
BOX_BLUR("BoxBlur", BoxBlur.class),
COLOR_ADJUST("ColorAdjust", ColorAdjust.class),
COLOR_INPUT("ColorInput", ColorInput.class),
DISPLACEMENT_MAP("DisplacementMap", DisplacementMap.class),
DROP_SHADOW("DropShadow", DropShadow.class),
GAUSSIAN_BLUR("GaussianBlur", GaussianBlur.class),
GLOW("Glow", Glow.class),
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),
MOTION_BLUR("MotionBlur", MotionBlur.class),
PERSPECTIVE_TRANSFORM("PerspectiveTransform", PerspectiveTransform.class),
REFLECTION("Reflection", Reflection.class),
SEPIA_TONE("SepiaTone", SepiaTone.class),
SHADOW("Shadow", Shadow.class);

private static final Logger LOGGER = LogManager.getLogger(EffectEnum.class);
private final String name;
private final Class<? extends Effect> effectClass;

EffectEnum(String name, Class<? extends Effect> effectClass) {
this.name = name;
this.effectClass = effectClass;
}

public String getName() {
return name;
}

public Class<? extends Effect> getEffectClass() {
return effectClass;
}

public static Class<? extends Effect>[] getAllEffectClass() {
EffectEnum[] values = EffectEnum.values();
Class<? extends Effect>[] classes = new Class[values.length];
for (int i = 0; i < values.length; i++) {
classes[i] = values[i].getEffectClass();
}
return classes;
}

public static String[] getAllNames() {
EffectEnum[] values = EffectEnum.values();
String[] names = new String[values.length];
for (int i = 0; i < values.length; i++) {
names[i] = values[i].getName();
}
return names;
}

public static EffectEnum findByName(String name) {
EffectEnum[] values = EffectEnum.values();
for (EffectEnum value : values) {
if (StringUtils.equalsIgnoreCase(value.getName(), name)) {
return value;
}
}
return null;
}

@Override
public String toString() {
return name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package com.dlsc.jfxcentral2.utilities.shadowdesigner;

import com.dlsc.jfxcentral2.components.CustomToggleButton;
import javafx.beans.InvalidationListener;
import javafx.beans.binding.Bindings;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
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.Effect;
import javafx.scene.layout.FlowPane;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.material2.Material2AL;
import org.kordamp.ikonli.material2.Material2OutlinedMZ;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;

public class EffectFlowPane extends FlowPane {
private static final Logger LOGGER = LogManager.getLogger(EffectFlowPane.class);
private static final ToggleGroup TOGGLE_GROUP = new ToggleGroup();

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;
}

if (supportsInputMethod(effect2)) {
try {
effect2.getClass().getMethod("setInput", Effect.class).invoke(effect2, effect1);
} catch (Exception e) {
LOGGER.error("Error while setting input for effect", e);
}
}
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;
}
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));
}
getChildren().add(i, effectButton);
effectButton.setToggleGroup(TOGGLE_GROUP);
});
//effects.forEach(effect -> {
// CustomToggleButton effectView = (CustomToggleButton) getChildren().get(effects.indexOf(effect));
// effectView.setSelected(effect == selectedEffect);
//});
});

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<MenuItem> menuItems = Arrays.stream(EffectEnum.getAllNames())
.map(name -> {
MenuItem menuItem = new MenuItem(name);
menuItem.setOnAction(event -> {
try {
EffectEnum effectEnum = EffectEnum.findByName(name);
if (effectEnum == null) {
return;
}
Effect effect = effectEnum.getEffectClass().getDeclaredConstructor().newInstance();
effects.add(effect);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
NoSuchMethodException e) {
LOGGER.error("Error while creating effect", e);
}
});
return menuItem;
})
.toList();
addEffectButton.getItems().addAll(menuItems);

TOGGLE_GROUP.selectedToggleProperty().addListener((ob, ov, nv) -> {
if (nv == null) {
setSelectedEffect(null);
return;
}
setSelectedEffect(effects.get(TOGGLE_GROUP.getToggles().indexOf(nv)));
});

}

private final ObservableList<Effect> effects = FXCollections.observableArrayList();

public ObservableList<Effect> getEffects() {
return effects;
}

private final ReadOnlyObjectWrapper<Effect> value = new ReadOnlyObjectWrapper<>(this, "value", null);

public Effect getValue() {
return value.get();
}

public ReadOnlyObjectProperty<Effect> valueProperty() {
return value.getReadOnlyProperty();
}

private void setValue(Effect value) {
this.value.set(value);
}

private boolean supportsInputMethod(Effect effect) {
try {
effect.getClass().getMethod("setInput", Effect.class);
return true;
} catch (NoSuchMethodException e) {
return false;
}
}

private final ReadOnlyObjectWrapper<Effect> selectedEffect = new ReadOnlyObjectWrapper<>(this, "selectedEffect");

public Effect getSelectedEffect() {
return selectedEffect.get();
}

public ReadOnlyObjectProperty<Effect> selectedEffectProperty() {
return selectedEffect.getReadOnlyProperty();
}

private void setSelectedEffect(Effect selectedEffect) {
this.selectedEffect.set(selectedEffect);
}
}
Loading

0 comments on commit 63fdb63

Please sign in to comment.