-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,556 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/EffectEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
158 changes: 158 additions & 0 deletions
158
components/src/main/java/com/dlsc/jfxcentral2/utilities/shadowdesigner/EffectFlowPane.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.