Skip to content

Commit 1039c31

Browse files
committed
реализация учитывания enter в диалогах
1 parent 135ffca commit 1039c31

File tree

12 files changed

+159
-28
lines changed

12 files changed

+159
-28
lines changed

libs/jfx-1.2.jar

-2.56 KB
Binary file not shown.

src/com/ss/editor/state/editor/impl/AbstractEditorState.java

Lines changed: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.ss.editor.Editor;
2121
import com.ss.editor.manager.ExecutorManager;
2222
import com.ss.editor.state.editor.EditorState;
23+
import com.ss.editor.ui.component.editor.FileEditor;
2324

2425
import rlib.logging.Logger;
2526
import rlib.logging.LoggerManager;
@@ -29,7 +30,7 @@
2930
*
3031
* @author Ronn
3132
*/
32-
public abstract class AbstractEditorState extends AbstractAppState implements EditorState {
33+
public abstract class AbstractEditorState<T extends FileEditor> extends AbstractAppState implements EditorState {
3334

3435
protected static final Logger LOGGER = LoggerManager.getLogger(EditorState.class);
3536

@@ -48,13 +49,19 @@ public abstract class AbstractEditorState extends AbstractAppState implements Ed
4849
protected static final String KEY_CTRL = "SSEditor.editorState.keyCtrl";
4950
protected static final String KEY_ALT = "SSEditor.editorState.keyAlt";
5051
protected static final String KEY_SHIFT = "SSEditor.editorState.keyShift";
52+
protected static final String KEY_S = "SSEditor.editorState.S";
5153

5254
/**
5355
* Слушатели сцены.
5456
*/
5557
private final ActionListener actionListener;
5658
private final AnalogListener analogListener;
5759

60+
/**
61+
* Редактор использующий этот стейт.
62+
*/
63+
private final T fileEditor;
64+
5865
/**
5966
* Опциональная камера для сцены.
6067
*/
@@ -85,7 +92,23 @@ public abstract class AbstractEditorState extends AbstractAppState implements Ed
8592
*/
8693
private boolean shiftDown;
8794

88-
public AbstractEditorState() {
95+
/**
96+
* Нажата ли сейчас левая кнопка мыши.
97+
*/
98+
private boolean buttonLeftDown;
99+
100+
/**
101+
* Нажата ли сейчас правая кнопка мыши.
102+
*/
103+
private boolean buttonRightDown;
104+
105+
/**
106+
* Нажат ли сейчас колесик.
107+
*/
108+
private boolean buttonMiddleDown;
109+
110+
public AbstractEditorState(final T fileEditor) {
111+
this.fileEditor = fileEditor;
89112
this.stateNode = new Node(getClass().getSimpleName());
90113
this.chaseCamera = needChaseCamera() ? createChaseCamera() : null;
91114
this.lightForChaseCamera = needLightForChaseCamera() ? createLightForChaseCamera() : null;
@@ -111,6 +134,13 @@ public void onAction(final String name, final boolean isPressed, final float tpf
111134
};
112135
}
113136

137+
/**
138+
* @return редактор использующий этот стейт.
139+
*/
140+
protected T getFileEditor() {
141+
return fileEditor;
142+
}
143+
114144
/**
115145
* Обработка перемещения мышки над 3D областью
116146
*/
@@ -128,6 +158,19 @@ protected void onActionImpl(final String name, final boolean isPressed, final fl
128158
setControlDown(isPressed);
129159
} else if (KEY_SHIFT.equals(name)) {
130160
setShiftDown(isPressed);
161+
} else if (MOUSE_LEFT_CLICK.equals(name)) {
162+
setButtonLeftDown(isPressed);
163+
} else if (MOUSE_MIDDLE_CLICK.equals(name)) {
164+
setButtonMiddleDown(isPressed);
165+
} else if (MOUSE_RIGHT_CLICK.equals(name)) {
166+
setButtonRightDown(isPressed);
167+
} else if(KEY_S.equals(name)) {
168+
169+
final FileEditor fileEditor = getFileEditor();
170+
171+
if(isControlDown() && fileEditor.isDirty()) {
172+
EXECUTOR_MANAGER.addFXTask(fileEditor::doSave);
173+
}
131174
}
132175
}
133176

@@ -141,7 +184,7 @@ protected boolean isAltDown() {
141184
/**
142185
* @param altDown нажат ли сейчас alt.
143186
*/
144-
protected void setAltDown(boolean altDown) {
187+
protected void setAltDown(final boolean altDown) {
145188
this.altDown = altDown;
146189
}
147190

@@ -155,7 +198,7 @@ protected boolean isControlDown() {
155198
/**
156199
* @param controlDown нажат ли сейчас control.
157200
*/
158-
protected void setControlDown(boolean controlDown) {
201+
protected void setControlDown(final boolean controlDown) {
159202
this.controlDown = controlDown;
160203
}
161204

@@ -169,10 +212,52 @@ protected boolean isShiftDown() {
169212
/**
170213
* @param shiftDown нажат ли сейчас Shift.
171214
*/
172-
protected void setShiftDown(boolean shiftDown) {
215+
protected void setShiftDown(final boolean shiftDown) {
173216
this.shiftDown = shiftDown;
174217
}
175218

219+
/**
220+
* @param buttonLeftDown нажата ли сейчас левая кнопка мыши.
221+
*/
222+
protected void setButtonLeftDown(final boolean buttonLeftDown) {
223+
this.buttonLeftDown = buttonLeftDown;
224+
}
225+
226+
/**
227+
* @param buttonMiddleDown нажат ли сейчас колесик.
228+
*/
229+
protected void setButtonMiddleDown(final boolean buttonMiddleDown) {
230+
this.buttonMiddleDown = buttonMiddleDown;
231+
}
232+
233+
/**
234+
* @param buttonRightDown нажата ли сейчас правая кнопка мыши.
235+
*/
236+
protected void setButtonRightDown(final boolean buttonRightDown) {
237+
this.buttonRightDown = buttonRightDown;
238+
}
239+
240+
/**
241+
* @return нажата ли сейчас левая кнопка мыши.
242+
*/
243+
protected boolean isButtonLeftDown() {
244+
return buttonLeftDown;
245+
}
246+
247+
/**
248+
* @return нажат ли сейчас колесик.
249+
*/
250+
protected boolean isButtonMiddleDown() {
251+
return buttonMiddleDown;
252+
}
253+
254+
/**
255+
* @return нажата ли сейчас правая кнопка мыши.
256+
*/
257+
protected boolean isButtonRightDown() {
258+
return buttonRightDown;
259+
}
260+
176261
/**
177262
* @return рутовый узел.
178263
*/
@@ -253,8 +338,12 @@ private void registerActionListener(final InputManager inputManager) {
253338
inputManager.addMapping(KEY_ALT, new KeyTrigger(KeyInput.KEY_RMENU), new KeyTrigger(KeyInput.KEY_LMENU));
254339
}
255340

341+
if (!inputManager.hasMapping(KEY_S)) {
342+
inputManager.addMapping(KEY_S, new KeyTrigger(KeyInput.KEY_S));
343+
}
344+
256345
inputManager.addListener(actionListener, MOUSE_LEFT_CLICK, MOUSE_LEFT_CLICK, MOUSE_MIDDLE_CLICK);
257-
inputManager.addListener(actionListener, KEY_CTRL, KEY_SHIFT, KEY_ALT);
346+
inputManager.addListener(actionListener, KEY_CTRL, KEY_SHIFT, KEY_ALT, KEY_S);
258347
}
259348

260349
@Override

src/com/ss/editor/state/editor/impl/material/MaterialEditorState.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.jme3.scene.shape.Sphere;
2121
import com.jme3.util.SkyFactory;
2222
import com.ss.editor.state.editor.impl.AbstractEditorState;
23+
import com.ss.editor.ui.component.editor.impl.material.MaterialFileEditor;
2324

2425
import rlib.geom.util.AngleUtils;
2526

@@ -28,7 +29,7 @@
2829
*
2930
* @author Ronn
3031
*/
31-
public class MaterialEditorState extends AbstractEditorState {
32+
public class MaterialEditorState extends AbstractEditorState<MaterialFileEditor> {
3233

3334
private static final Vector3f QUAD_OFFSET = new Vector3f(0, -2, 2);
3435
private static final Vector3f LIGHT_DIRECTION = new Vector3f(0.007654993F, 0.39636374F, 0.9180617F).negate();
@@ -84,7 +85,8 @@ public void done(final LightProbe result) {
8485
*/
8586
private int frame;
8687

87-
public MaterialEditorState() {
88+
public MaterialEditorState(final MaterialFileEditor fileEditor) {
89+
super(fileEditor);
8890
this.testBox = new Geometry("Box", new Box(2, 2, 2));
8991
this.testSphere = new Geometry("Sphere", new Sphere(30, 30, 2));
9092
this.testQuad = new Geometry("Quad", new Quad(4, 4));

src/com/ss/editor/state/editor/impl/model/ModelEditorState.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
*
4242
* @author Ronn
4343
*/
44-
public class ModelEditorState extends AbstractEditorState {
44+
public class ModelEditorState extends AbstractEditorState<ModelFileEditor> {
4545

4646
private static final float H_ROTATION = AngleUtils.degreeToRadians(45);
4747
private static final float V_ROTATION = AngleUtils.degreeToRadians(15);
@@ -69,11 +69,6 @@ public void done(final LightProbe result) {
6969
*/
7070
private final Array<Spatial> customSky;
7171

72-
/**
73-
* Редактор в который встроен этот стейт.
74-
*/
75-
private final ModelFileEditor editor;
76-
7772
/**
7873
* Узел для размещения модели.
7974
*/
@@ -144,8 +139,8 @@ public void done(final LightProbe result) {
144139
*/
145140
private int frame;
146141

147-
public ModelEditorState(final ModelFileEditor editor) {
148-
this.editor = editor;
142+
public ModelEditorState(final ModelFileEditor fileEditor) {
143+
super(fileEditor);
149144
this.modelNode = new Node("ModelNode");
150145
this.modelNode.setUserData(ModelEditorState.class.getName(), true);
151146
this.toolNode = new Node("ToolNode");
@@ -213,7 +208,7 @@ private void processClick(final boolean isPressed) {
213208
final Node modelNode = getModelNode();
214209
modelNode.collideWith(ray, results);
215210

216-
final ModelFileEditor editor = getEditor();
211+
final ModelFileEditor editor = getFileEditor();
217212

218213
if (results.size() < 1) {
219214
EXECUTOR_MANAGER.addFXTask(() -> editor.notifySelected(null));
@@ -230,13 +225,6 @@ private void processClick(final boolean isPressed) {
230225
EXECUTOR_MANAGER.addFXTask(() -> editor.notifySelected(collision.getGeometry()));
231226
}
232227

233-
/**
234-
* @return редактор в который встроен этот стейт.
235-
*/
236-
private ModelFileEditor getEditor() {
237-
return editor;
238-
}
239-
240228
/**
241229
* Создание вспомогательных элементов.
242230
*/

src/com/ss/editor/state/editor/impl/post/filter/PostFilterEditorState.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.jme3.util.SkyFactory;
1212
import com.ss.editor.manager.ExecutorManager;
1313
import com.ss.editor.state.editor.impl.AbstractEditorState;
14+
import com.ss.editor.ui.component.editor.impl.post.filter.PostFilterEditor;
1415

1516
import rlib.util.dictionary.ConcurrentObjectDictionary;
1617
import rlib.util.dictionary.DictionaryFactory;
@@ -20,7 +21,7 @@
2021
*
2122
* @author Ronn
2223
*/
23-
public class PostFilterEditorState extends AbstractEditorState {
24+
public class PostFilterEditorState extends AbstractEditorState<PostFilterEditor> {
2425

2526
private static final ExecutorManager EXECUTOR_MANAGER = ExecutorManager.getInstance();
2627

@@ -29,7 +30,8 @@ public class PostFilterEditorState extends AbstractEditorState {
2930
*/
3031
private final ConcurrentObjectDictionary<MaterialKey, GenericFilter> filters;
3132

32-
public PostFilterEditorState() {
33+
public PostFilterEditorState(final PostFilterEditor fileEditor) {
34+
super(fileEditor);
3335
this.filters = DictionaryFactory.newConcurrentAtomicObjectDictionary();
3436

3537
final AssetManager assetManager = EDITOR.getAssetManager();

src/com/ss/editor/ui/component/creator/impl/AbstractFileCreator.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javafx.scene.control.MultipleSelectionModel;
2626
import javafx.scene.control.TextField;
2727
import javafx.scene.control.TreeItem;
28+
import javafx.scene.input.KeyCode;
2829
import javafx.scene.layout.HBox;
2930
import javafx.scene.layout.VBox;
3031
import rlib.logging.Logger;
@@ -232,6 +233,12 @@ protected void createContent(final VBox root) {
232233
FXUtils.bindFixedWidth(settingsContainer, root.widthProperty().divide(2));
233234

234235
HBox.setMargin(resourceTree, RESOURCE_TREE_OFFSET);
236+
237+
root.setOnKeyReleased(event -> {
238+
if(event.getCode() == KeyCode.ENTER) {
239+
processCreate();
240+
}
241+
});
235242
}
236243

237244
/**

src/com/ss/editor/ui/component/editor/impl/AbstractFileEditor.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import javafx.beans.property.SimpleBooleanProperty;
1616
import javafx.scene.control.Button;
1717
import javafx.scene.image.ImageView;
18+
import javafx.scene.input.KeyCode;
19+
import javafx.scene.input.KeyEvent;
1820
import javafx.scene.layout.HBox;
1921
import javafx.scene.layout.Pane;
2022
import javafx.scene.layout.StackPane;
@@ -102,6 +104,8 @@ protected void createContent() {
102104
}
103105

104106
root = createRoot();
107+
root.setOnKeyPressed(this::processKeyPressed);
108+
root.setOnKeyReleased(this::processKeyReleased);
105109

106110
createContent(root);
107111

@@ -118,6 +122,25 @@ protected void createContent() {
118122
new StackPane(container);
119123
}
120124

125+
/**
126+
* Обработка ввода с клавиатуры.
127+
*/
128+
protected void processKeyReleased(final KeyEvent event) {
129+
130+
final KeyCode code = event.getCode();
131+
132+
if(code == KeyCode.S && event.isControlDown() && isDirty()) {
133+
doSave();
134+
}
135+
}
136+
137+
/**
138+
* Обработка ввода с клавиатуры.
139+
*/
140+
protected void processKeyPressed(final KeyEvent event) {
141+
142+
}
143+
121144
/**
122145
* Создание тулбара.
123146
*/

src/com/ss/editor/ui/component/editor/impl/material/MaterialFileEditor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public class MaterialFileEditor extends AbstractFileEditor<StackPane> {
150150
private boolean ignoreListeners;
151151

152152
public MaterialFileEditor() {
153-
this.editorState = new MaterialEditorState();
153+
this.editorState = new MaterialEditorState(this);
154154
this.fileChangedHandler = event -> processChangedFile((FileChangedEvent) event);
155155
addEditorState(editorState);
156156
}

src/com/ss/editor/ui/component/editor/impl/post/filter/PostFilterEditor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public class PostFilterEditor extends AbstractFileEditor<StackPane> {
114114
private boolean ignoreListeners;
115115

116116
public PostFilterEditor() {
117-
this.editorState = new PostFilterEditorState();
117+
this.editorState = new PostFilterEditorState(this);
118118
this.fileChangedHandler = event -> processChangedFile((FileChangedEvent) event);
119119
addEditorState(editorState);
120120
}

src/com/ss/editor/ui/dialog/GraphicsDialog.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ private void load() {
330330

331331
final CheckBox fxaaFilterCheckBox = getFXAAFilterCheckBox();
332332
fxaaFilterCheckBox.setSelected(editorConfig.isFXAA());
333+
334+
final CheckBox fullscreenCheckBox = getFullscreenCheckBox();
335+
fullscreenCheckBox.setSelected(editorConfig.isFullscreen());
333336
}
334337

335338
@Override

0 commit comments

Comments
 (0)