Skip to content

Commit 16282eb

Browse files
committed
prepared infrastructure to edit controls
1 parent 1a2a896 commit 16282eb

25 files changed

+229
-552
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.ss.extension.scene.control;
2+
3+
import com.jme3.scene.control.Control;
4+
import com.ss.extension.property.EditableProperty;
5+
6+
import org.jetbrains.annotations.NotNull;
7+
8+
import rlib.util.array.Array;
9+
import rlib.util.array.ArrayFactory;
10+
11+
/**
12+
* The interface to implement an editable control.
13+
*
14+
* @author JavaSaBr
15+
*/
16+
public interface EditableControl extends Control {
17+
18+
Array<EditableProperty<?, ?>> EMPTY_PROPERTIES = ArrayFactory.newArray(EditableProperty.class);
19+
20+
/**
21+
* Get list of editable properties.
22+
*
23+
* @return the list of editable properties.
24+
*/
25+
@NotNull
26+
default Array<EditableProperty<?, ?>> getEditableProperties() {
27+
return EMPTY_PROPERTIES;
28+
}
29+
}
764 Bytes
Binary file not shown.
1.16 KB
Binary file not shown.

src/com/ss/editor/control/scene/ControlEditableGenericObjectFactory.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/com/ss/editor/control/scene/impl/AbstractControlEditableGenericObject.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/com/ss/editor/control/scene/impl/AnimControlEditableGenericObject.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/com/ss/editor/ui/control/app/state/property/builder/impl/AppStatePropertyBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import rlib.util.array.Array;
2929

3030
/**
31-
* The iproperty builder to build property controls of editable scene app states.
31+
* The property builder to build property controls of editable scene app states.
3232
*
3333
* @author JavaSaBr
3434
*/
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
package com.ss.editor.ui.control.model.property.builder.impl;
2+
3+
import com.jme3.math.ColorRGBA;
4+
import com.jme3.math.Vector2f;
5+
import com.jme3.math.Vector3f;
6+
import com.ss.editor.model.undo.editor.ModelChangeConsumer;
7+
import com.ss.editor.model.undo.editor.SceneChangeConsumer;
8+
import com.ss.editor.ui.control.model.property.control.BooleanModelPropertyControl;
9+
import com.ss.editor.ui.control.model.property.control.ColorModelPropertyControl;
10+
import com.ss.editor.ui.control.model.property.control.EnumControlPropertyControl;
11+
import com.ss.editor.ui.control.model.property.control.FloatModelPropertyControl;
12+
import com.ss.editor.ui.control.model.property.control.IntegerModelPropertyControl;
13+
import com.ss.editor.ui.control.model.property.control.Vector2fModelPropertyControl;
14+
import com.ss.editor.ui.control.model.property.control.Vector3fModelPropertyControl;
15+
import com.ss.editor.ui.control.property.AbstractPropertyControl;
16+
import com.ss.editor.ui.control.property.builder.impl.AbstractPropertyBuilder;
17+
import com.ss.extension.property.EditableProperty;
18+
import com.ss.extension.property.EditablePropertyType;
19+
import com.ss.extension.scene.control.EditableControl;
20+
21+
import org.jetbrains.annotations.NotNull;
22+
import org.jetbrains.annotations.Nullable;
23+
24+
import java.util.Objects;
25+
26+
import javafx.scene.layout.VBox;
27+
import rlib.ui.util.FXUtils;
28+
import rlib.util.ClassUtils;
29+
import rlib.util.array.Array;
30+
31+
/**
32+
* The property builder to build property controls of editable controls.
33+
*
34+
* @author JavaSaBr
35+
*/
36+
public class EditableControlPropertyBuilder extends AbstractPropertyBuilder<SceneChangeConsumer> {
37+
38+
private static final EditableControlPropertyBuilder INSTANCE = new EditableControlPropertyBuilder();
39+
40+
public static EditableControlPropertyBuilder getInstance() {
41+
return INSTANCE;
42+
}
43+
44+
protected EditableControlPropertyBuilder() {
45+
super(SceneChangeConsumer.class);
46+
}
47+
48+
@Override
49+
protected void buildForImpl(@NotNull final Object object, @Nullable final Object parent, @NotNull final VBox container,
50+
@NotNull final SceneChangeConsumer changeConsumer) {
51+
52+
if (!(object instanceof EditableControl)) return;
53+
54+
final EditableControl control = (EditableControl) object;
55+
56+
final Array<EditableProperty<?, ?>> editableProperties = control.getEditableProperties();
57+
if (editableProperties.isEmpty()) return;
58+
59+
for (final EditableProperty<?, ?> editableProperty : editableProperties) {
60+
61+
final EditablePropertyType type = editableProperty.getType();
62+
63+
switch (type) {
64+
case BOOLEAN: {
65+
66+
final EditableProperty<Boolean, ?> property = cast(editableProperty);
67+
final Boolean value = Objects.requireNonNull(property.getValue(), "Boolean value can't be null.");
68+
69+
final BooleanModelPropertyControl<EditableProperty<Boolean, ?>> propertyControl =
70+
new BooleanModelPropertyControl<>(value, property.getName(), changeConsumer);
71+
72+
addControl(container, property, propertyControl);
73+
break;
74+
}
75+
case FLOAT: {
76+
77+
final EditableProperty<Float, ?> property = cast(editableProperty);
78+
final Float value = Objects.requireNonNull(property.getValue(), "Float value can't be null.");
79+
80+
final FloatModelPropertyControl<EditableProperty<Float, ?>> propertyControl =
81+
new FloatModelPropertyControl<>(value, property.getName(), changeConsumer);
82+
83+
final float scrollPower = propertyControl.getScrollPower();
84+
final float mod = property.getScrollPower();
85+
86+
propertyControl.setScrollPower(scrollPower * mod);
87+
propertyControl.setMinMax(property.getMinValue(), property.getMaxValue());
88+
89+
addControl(container, property, propertyControl);
90+
break;
91+
}
92+
case COLOR: {
93+
94+
final EditableProperty<ColorRGBA, ?> property = cast(editableProperty);
95+
final ColorRGBA color = Objects.requireNonNull(property.getValue(), "Color value can't be null.");
96+
97+
final ColorModelPropertyControl<EditableProperty<ColorRGBA, ?>> propertyControl =
98+
new ColorModelPropertyControl<>(color, property.getName(), changeConsumer);
99+
100+
addControl(container, property, propertyControl);
101+
break;
102+
}
103+
case INTEGER: {
104+
105+
final EditableProperty<Integer, ?> property = cast(editableProperty);
106+
final Integer value = Objects.requireNonNull(property.getValue(), "Integer value can't be null.");
107+
108+
final IntegerModelPropertyControl<EditableProperty<Integer, ?>> propertyControl =
109+
new IntegerModelPropertyControl<>(value, property.getName(), changeConsumer);
110+
111+
addControl(container, property, propertyControl);
112+
break;
113+
}
114+
case VECTOR_2F: {
115+
116+
final EditableProperty<Vector2f, ?> property = cast(editableProperty);
117+
final Vector2f value = Objects.requireNonNull(property.getValue(), "Vector2f value can't be null.");
118+
119+
final Vector2fModelPropertyControl<EditableProperty<Vector2f, ?>> propertyControl =
120+
new Vector2fModelPropertyControl<>(value, property.getName(), changeConsumer);
121+
122+
addControl(container, property, propertyControl);
123+
break;
124+
}
125+
case VECTOR_3F: {
126+
127+
final EditableProperty<Vector3f, ?> property = cast(editableProperty);
128+
final Vector3f value = Objects.requireNonNull(property.getValue(), "Vector3f value can't be null.");
129+
130+
final Vector3fModelPropertyControl<EditableProperty<Vector3f, ?>> propertyControl =
131+
new Vector3fModelPropertyControl<>(value, property.getName(), changeConsumer);
132+
133+
addControl(container, property, propertyControl);
134+
break;
135+
}
136+
case ENUM: {
137+
138+
final EditableProperty<Enum<?>, ?> property = cast(editableProperty);
139+
final Enum<?> value = Objects.requireNonNull(property.getValue(), "Enum value can't be null.");
140+
141+
final EnumControlPropertyControl<Enum<?>, EditableProperty<Enum<?>, ?>> propertyControl =
142+
new EnumControlPropertyControl<>(value, property.getName(), changeConsumer);
143+
144+
addControl(container, property, propertyControl);
145+
break;
146+
}
147+
default: {
148+
break;
149+
}
150+
}
151+
}
152+
}
153+
154+
protected <T> void addControl(final @NotNull VBox container, @NotNull final EditableProperty<T, ?> property,
155+
@NotNull final AbstractPropertyControl<ModelChangeConsumer, EditableProperty<T, ?>, T> propertyControl) {
156+
157+
propertyControl.setApplyHandler(EditableProperty::setValue);
158+
propertyControl.setSyncHandler(EditableProperty::getValue);
159+
propertyControl.setEditObject(property);
160+
161+
FXUtils.addToPane(propertyControl, container);
162+
}
163+
164+
private <T> EditableProperty<T, ?> cast(@NotNull final EditableProperty<?, ?> property) {
165+
return ClassUtils.unsafeCast(property);
166+
}
167+
}

0 commit comments

Comments
 (0)