Skip to content

Commit 466d27a

Browse files
committed
improved editor property controls.
1 parent a292880 commit 466d27a

15 files changed

Lines changed: 75 additions & 55 deletions

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ dependencies {
5959

6060
compile 'com.github.JavaSaBr:RlibFX:4.1.2'
6161
compile 'com.github.JavaSaBr:RLib:6.3.2'
62-
compile 'com.github.JavaSaBr:JME3-JFX:1.5.5'
62+
compile 'com.github.JavaSaBr:JME3-JFX:1.6.0'
6363

6464
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
6565
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.6'

src/main/java/com/ss/editor/JFXApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.ss.editor;
22

33
import static com.jme3x.jfx.injfx.JmeToJFXIntegrator.bind;
4+
import static com.jme3x.jfx.injfx.processor.FrameTransferSceneProcessor.TransferMode.*;
45
import static com.ss.rlib.util.ObjectUtils.notNull;
56
import static java.nio.file.Files.newOutputStream;
67
import com.jme3.renderer.Renderer;
@@ -395,6 +396,7 @@ private void createSceneProcessor(@NotNull final EditorFXScene scene, @NotNull f
395396

396397
final FrameTransferSceneProcessor sceneProcessor = bind(editor, scene.getCanvas(), editor.getViewPort());
397398
sceneProcessor.setEnabled(false);
399+
sceneProcessor.setTransferMode(ON_CHANGES);
398400

399401
this.sceneProcessor = sceneProcessor;
400402

src/main/java/com/ss/editor/manager/JMEFilePreviewManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.ss.editor.manager;
22

33
import static com.jme3x.jfx.injfx.JmeToJFXIntegrator.bind;
4+
import static com.jme3x.jfx.injfx.processor.FrameTransferSceneProcessor.TransferMode.ON_CHANGES;
45
import static com.ss.editor.util.EditorUtil.getAssetFile;
56
import static com.ss.editor.util.EditorUtil.toAssetPath;
67
import static com.ss.rlib.util.FileUtils.getExtension;
@@ -357,6 +358,7 @@ private FrameTransferSceneProcessor prepareScene() {
357358
rootNode.attachChild(modelNode);
358359

359360
processor = bind(editor, imageView, imageView, editor.getPreviewViewPort(), false);
361+
processor.setTransferMode(ON_CHANGES);
360362
processor.setEnabled(false);
361363

362364
return processor;

src/main/java/com/ss/editor/plugin/api/file/creator/GenericFileCreator.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,9 @@ protected void createSettings(@NotNull final GridPane root) {
4848

4949
final Array<PropertyDefinition> definitions = getPropertyDefinitions();
5050
for (final PropertyDefinition definition : definitions) {
51-
5251
final PropertyEditorControl<?> control = build(vars, definition, this::validateFileName);
5352
control.prefWidthProperty().bind(widthProperty());
5453
root.add(control, 0, rowIndex++, 2, 1);
55-
56-
final Object defaultValue = definition.getDefaultValue();
57-
58-
if (defaultValue != null) {
59-
vars.set(definition.getId(), defaultValue);
60-
}
6154
}
6255
}
6356

src/main/java/com/ss/editor/plugin/api/property/control/AwtFontPropertyEditorControl.java

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
import static com.ss.rlib.util.ObjectUtils.notNull;
44
import com.ss.editor.plugin.api.property.PropertyDefinition;
55
import com.ss.editor.ui.css.CSSClasses;
6+
import com.ss.editor.ui.util.AutoCompleteComboBoxListener;
67
import com.ss.rlib.ui.util.FXUtils;
78
import com.ss.rlib.util.StringUtils;
89
import com.ss.rlib.util.VarTable;
910
import javafx.scene.control.ComboBox;
10-
import javafx.scene.control.ListCell;
1111
import javafx.scene.control.SingleSelectionModel;
12+
import javafx.util.StringConverter;
1213
import org.jetbrains.annotations.NotNull;
1314
import org.jetbrains.annotations.Nullable;
1415

1516
import java.awt.*;
17+
import java.util.Arrays;
1618

1719
/**
1820
* The control to choose string value from list.
@@ -22,20 +24,26 @@
2224
public class AwtFontPropertyEditorControl extends PropertyEditorControl<Font> {
2325

2426
@NotNull
25-
private class FontCell extends ListCell<Font> {
27+
private static final GraphicsEnvironment GRAPHICS_ENVIRONMENT = GraphicsEnvironment.getLocalGraphicsEnvironment();
2628

27-
@Override
28-
protected void updateItem(@Nullable final Font font, final boolean empty) {
29-
super.updateItem(font, empty);
29+
@NotNull
30+
private static final Font[] FONTS = GRAPHICS_ENVIRONMENT.getAllFonts();
3031

31-
if (font == null) {
32-
setText(StringUtils.EMPTY);
33-
return;
34-
}
32+
@NotNull
33+
private static final StringConverter<Font> STRING_CONVERTER = new StringConverter<Font>() {
3534

36-
setText(font.getFontName());
35+
@Override
36+
public String toString(@Nullable final Font font) {
37+
return font == null ? StringUtils.EMPTY : font.getFontName();
3738
}
38-
}
39+
40+
@Override
41+
public Font fromString(@NotNull final String fontName) {
42+
return Arrays.stream(FONTS)
43+
.filter(font -> font.getFontName().equals(fontName))
44+
.findAny().orElse(null);
45+
}
46+
};
3947

4048
/**
4149
* The list of available options of the string value.
@@ -52,15 +60,16 @@ protected AwtFontPropertyEditorControl(@NotNull final VarTable vars, @NotNull fi
5260
protected void createComponents() {
5361
super.createComponents();
5462

55-
final GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
56-
5763
comboBox = new ComboBox<>();
58-
comboBox.setCellFactory(param -> new FontCell());
59-
comboBox.setButtonCell(new FontCell());
6064
comboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> change());
6165
comboBox.prefWidthProperty().bind(widthProperty().multiply(DEFAULT_FIELD_W_PERCENT));
62-
comboBox.getItems().addAll(environment.getAllFonts());
66+
comboBox.getItems().addAll(FONTS);
67+
comboBox.setVisibleRowCount(20);
68+
comboBox.setConverter(STRING_CONVERTER);
69+
70+
AutoCompleteComboBoxListener.install(comboBox);
6371

72+
FXUtils.addClassesTo(comboBox.getEditor(), CSSClasses.TRANSPARENT_TEXT_FIELD, CSSClasses.TEXT_FIELD_IN_COMBO_BOX);
6473
FXUtils.addClassTo(comboBox, CSSClasses.ABSTRACT_PARAM_CONTROL_COMBO_BOX);
6574
FXUtils.addToPane(comboBox, this);
6675
}
@@ -82,10 +91,10 @@ protected void reload() {
8291
}
8392

8493
@Override
85-
protected void change() {
94+
protected void changeImpl() {
8695
final ComboBox<Font> comboBox = getComboBox();
8796
final SingleSelectionModel<Font> selectionModel = comboBox.getSelectionModel();
8897
setPropertyValue(selectionModel.getSelectedItem());
89-
super.change();
98+
super.changeImpl();
9099
}
91100
}

src/main/java/com/ss/editor/plugin/api/property/control/BooleanPropertyEditorControl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ protected void reload() {
5252
}
5353

5454
@Override
55-
protected void change() {
55+
protected void changeImpl() {
5656
setPropertyValue(getCheckBox().isSelected());
57-
super.change();
57+
super.changeImpl();
5858
}
5959
}

src/main/java/com/ss/editor/plugin/api/property/control/ColorPropertyEditorControl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ protected void reload() {
5757
}
5858

5959
@Override
60-
protected void change() {
60+
protected void changeImpl() {
6161
final ColorPicker colorPicker = getColorPicker();
6262
setPropertyValue(UIUtils.from(colorPicker.getValue()));
63-
super.change();
63+
super.changeImpl();
6464
}
6565
}

src/main/java/com/ss/editor/plugin/api/property/control/EnumPropertyEditorControl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import static com.ss.rlib.util.ClassUtils.unsafeCast;
44
import static com.ss.rlib.util.ObjectUtils.notNull;
5-
import com.ss.editor.ui.css.CSSClasses;
65
import com.ss.editor.plugin.api.property.PropertyDefinition;
6+
import com.ss.editor.ui.css.CSSClasses;
77
import com.ss.rlib.ui.util.FXUtils;
88
import com.ss.rlib.util.VarTable;
99
import javafx.scene.control.ComboBox;
@@ -42,6 +42,7 @@ protected void createComponents() {
4242
enumComboBox = new ComboBox<>();
4343
enumComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> change());
4444
enumComboBox.prefWidthProperty().bind(widthProperty().multiply(DEFAULT_FIELD_W_PERCENT));
45+
enumComboBox.setVisibleRowCount(20);
4546

4647
FXUtils.addClassTo(enumComboBox, CSSClasses.ABSTRACT_PARAM_CONTROL_COMBO_BOX);
4748
FXUtils.addToPane(enumComboBox, this);
@@ -64,10 +65,10 @@ protected void reload() {
6465
}
6566

6667
@Override
67-
protected void change() {
68+
protected void changeImpl() {
6869
final ComboBox<T> enumComboBox = getEnumComboBox();
6970
final SingleSelectionModel<T> selectionModel = enumComboBox.getSelectionModel();
7071
setPropertyValue(selectionModel.getSelectedItem());
71-
super.change();
72+
super.changeImpl();
7273
}
7374
}

src/main/java/com/ss/editor/plugin/api/property/control/FloatPropertyEditorControl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ protected void reload() {
6363
}
6464

6565
@Override
66-
protected void change() {
66+
protected void changeImpl() {
6767
setPropertyValue(getValueField().getValue());
68-
super.change();
68+
super.changeImpl();
6969
}
7070
}

src/main/java/com/ss/editor/plugin/api/property/control/IntegerPropertyEditorControl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ protected void reload() {
6363
}
6464

6565
@Override
66-
protected void change() {
66+
protected void changeImpl() {
6767
setPropertyValue(getValueField().getValue());
68-
super.change();
68+
super.changeImpl();
6969
}
7070
}

0 commit comments

Comments
 (0)