Skip to content

Commit 3dcde66

Browse files
committed
refactored editor area.
1 parent f6dd261 commit 3dcde66

2 files changed

Lines changed: 52 additions & 21 deletions

File tree

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
package com.ss.editor.ui.component;
22

3+
import com.ss.editor.annotation.FXThread;
4+
import com.ss.editor.annotation.FromAnyThread;
5+
import org.jetbrains.annotations.Nullable;
6+
37
/**
4-
* Интерфейс для реализации компонента сцены экрана.
8+
* The interface to implement a scene component.
59
*
6-
* @author Ronn
10+
* @author JavaSaBr
711
*/
812
public interface ScreenComponent {
913

1014
/**
11-
* Gets component id.
15+
* Gets the component id.
1216
*
13-
* @return индентификатор компонента.
17+
* @return the component id.
1418
*/
15-
public default String getComponentId() {
19+
@Nullable
20+
@FromAnyThread
21+
default String getComponentId() {
1622
return null;
1723
}
1824

1925
/**
20-
* Уведомление о завершении построения сцены.
26+
* Notify about finishing building the result scene.
2127
*/
22-
public default void notifyFinishBuild() {
28+
@FXThread
29+
default void notifyFinishBuild() {
2330
}
2431
}

src/main/java/com/ss/editor/ui/component/editor/area/EditorAreaComponent.java

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import com.jme3x.jfx.injfx.processor.FrameTransferSceneProcessor;
77
import com.ss.editor.Editor;
88
import com.ss.editor.JFXApplication;
9+
import com.ss.editor.annotation.BackgroundThread;
910
import com.ss.editor.annotation.FXThread;
11+
import com.ss.editor.annotation.FromAnyThread;
12+
import com.ss.editor.annotation.JMEThread;
1013
import com.ss.editor.file.converter.FileConverter;
1114
import com.ss.editor.file.converter.FileConverterDescription;
1215
import com.ss.editor.file.converter.FileConverterRegistry;
@@ -103,7 +106,7 @@ public class EditorAreaComponent extends TabPane implements ScreenComponent {
103106
private static final Editor EDITOR = Editor.getInstance();
104107

105108
/**
106-
* The tale of opened editors.
109+
* The table of opened editors.
107110
*/
108111
@NotNull
109112
private final ConcurrentObjectDictionary<Path, Tab> openedEditors;
@@ -178,6 +181,7 @@ private void switchEditor(@NotNull final ObservableValue<? extends Tab> observab
178181
/**
179182
* Handle changing the current asset folder.
180183
*/
184+
@FXThread
181185
private void processEvent(@NotNull final ChangedCurrentAssetFolderEvent event) {
182186
setIgnoreOpenedFiles(true);
183187
try {
@@ -195,46 +199,51 @@ private void processEvent(@NotNull final ChangedCurrentAssetFolderEvent event) {
195199
/**
196200
* @param ignoreOpenedFiles the flag for ignoring changing the list of opened editors.
197201
*/
202+
@FromAnyThread
198203
private void setIgnoreOpenedFiles(final boolean ignoreOpenedFiles) {
199204
this.ignoreOpenedFiles = ignoreOpenedFiles;
200205
}
201206

202207
/**
203208
* @return the flag for ignoring changing the list of opened editors.
204209
*/
210+
@FromAnyThread
205211
private boolean isIgnoreOpenedFiles() {
206212
return ignoreOpenedFiles;
207213
}
208214

209215
/**
210-
* Handle renaming of a file.
216+
* Handle a renamed file.
211217
*/
218+
@FXThread
212219
private void processEvent(@NotNull final RenamedFileEvent event) {
213220

214221
final Path prevFile = event.getPrevFile();
215222
final Path newFile = event.getNewFile();
216223

217-
handleMovingFiles(prevFile, newFile);
224+
handleMovedFiles(prevFile, newFile);
218225
}
219226

220227
/**
221-
* Handle moving of a file.
228+
* Handle a moved file.
222229
*/
230+
@FXThread
223231
private void processEvent(@NotNull final MovedFileEvent event) {
224232

225233
final Path prevFile = event.getPrevFile();
226234
final Path newFile = event.getNewFile();
227235

228-
handleMovingFiles(prevFile, newFile);
236+
handleMovedFiles(prevFile, newFile);
229237
}
230238

231239
/**
232-
* Handle moving/renaming of a file.
240+
* Handle a moved/renamed file.
233241
*
234242
* @param prevFile the prev version of the file.
235243
* @param newFile the new version of the file.
236244
*/
237-
private void handleMovingFiles(@NotNull final Path prevFile, @NotNull final Path newFile) {
245+
@FXThread
246+
private void handleMovedFiles(@NotNull final Path prevFile, @NotNull final Path newFile) {
238247

239248
final ConcurrentObjectDictionary<Path, Tab> openedEditors = getOpenedEditors();
240249
final long stamp = openedEditors.writeLock();
@@ -277,8 +286,9 @@ private void handleMovingFiles(@NotNull final Path prevFile, @NotNull final Path
277286
}
278287

279288
/**
280-
* Handle the request for converting a file.
289+
* Handle the request to convert a file.
281290
*/
291+
@FXThread
282292
private void processConvertFile(@NotNull final RequestedConvertFileEvent event) {
283293

284294
final Path file = event.getFile();
@@ -294,13 +304,15 @@ private void processConvertFile(@NotNull final RequestedConvertFileEvent event)
294304
* @return the tale of opened editors.
295305
*/
296306
@NotNull
307+
@FromAnyThread
297308
private ConcurrentObjectDictionary<Path, Tab> getOpenedEditors() {
298309
return openedEditors;
299310
}
300311

301312
/**
302-
* Handle the request for creating a file.
313+
* Handle the request to create a file.
303314
*/
315+
@FXThread
304316
private void processCreateFile(@NotNull final RequestedCreateFileEvent event) {
305317

306318
final Path file = event.getFile();
@@ -313,8 +325,9 @@ private void processCreateFile(@NotNull final RequestedCreateFileEvent event) {
313325
}
314326

315327
/**
316-
* Handle the request for closing an Editor.
328+
* Handle the request to close a file editor.
317329
*/
330+
@FXThread
318331
private void processChangeTabs(@NotNull final ListChangeListener.Change<? extends Tab> change) {
319332
if (!change.next()) return;
320333

@@ -344,6 +357,7 @@ private void processChangeTabs(@NotNull final ListChangeListener.Change<? extend
344357
* @return the current editor.
345358
*/
346359
@Nullable
360+
@FXThread
347361
public FileEditor getCurrentEditor() {
348362
final Tab selectedTab = getSelectionModel().getSelectedItem();
349363
if (selectedTab == null) return null;
@@ -352,11 +366,12 @@ public FileEditor getCurrentEditor() {
352366
}
353367

354368
/**
355-
* Handle changing an active editor.
369+
* Handle a changed active file editor.
356370
*
357371
* @param prevTab the previous editor.
358372
* @param newTab the new editor.
359373
*/
374+
@JMEThread
360375
private void processShowEditor(@Nullable final Tab prevTab, @Nullable final Tab newTab) {
361376

362377
final AppStateManager stateManager = EDITOR.getStateManager();
@@ -396,8 +411,9 @@ private void processShowEditor(@Nullable final Tab prevTab, @Nullable final Tab
396411
}
397412

398413
/**
399-
* Handle the request for opening a file.
414+
* Handle the request to open a file.
400415
*/
416+
@FXThread
401417
private void processOpenFile(@NotNull final RequestedOpenFileEvent event) {
402418

403419
final Path file = event.getFile();
@@ -417,6 +433,7 @@ private void processOpenFile(@NotNull final RequestedOpenFileEvent event) {
417433
EXECUTOR_MANAGER.addBackgroundTask(() -> processOpenFileImpl(event, file));
418434
}
419435

436+
@BackgroundThread
420437
private void processOpenFileImpl(@NotNull final RequestedOpenFileEvent event, @NotNull final Path file) {
421438

422439
final EditorFXScene scene = JFX_APPLICATION.getScene();
@@ -460,12 +477,13 @@ private void processOpenFileImpl(@NotNull final RequestedOpenFileEvent event, @N
460477
}
461478

462479
/**
463-
* Add and open new editor.
480+
* Add and open the new file editor.
464481
*
465482
* @param editor the editor
466483
* @param needShow the need show
467484
*/
468-
public void addEditor(@NotNull final FileEditor editor, final boolean needShow) {
485+
@FXThread
486+
private void addEditor(@NotNull final FileEditor editor, final boolean needShow) {
469487

470488
final Path editFile = editor.getEditFile();
471489

@@ -505,11 +523,13 @@ public void addEditor(@NotNull final FileEditor editor, final boolean needShow)
505523
}
506524

507525
@Override
526+
@FromAnyThread
508527
public String getComponentId() {
509528
return COMPONENT_ID;
510529
}
511530

512531
@Override
532+
@FXThread
513533
public void notifyFinishBuild() {
514534
setIgnoreOpenedFiles(true);
515535
try {
@@ -519,6 +539,10 @@ public void notifyFinishBuild() {
519539
}
520540
}
521541

542+
/**
543+
* Load all opened files.
544+
*/
545+
@FXThread
522546
private void loadOpenedFiles() {
523547

524548
final Workspace workspace = WORKSPACE_MANAGER.getCurrentWorkspace();

0 commit comments

Comments
 (0)