Skip to content

Commit b4e35eb

Browse files
committed
working on import button.
1 parent 12b5b67 commit b4e35eb

29 files changed

+446
-35
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ dependencies {
125125
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.3'
126126

127127
// extensions
128-
compile ('com.github.JavaSaBr:jmonkeybuilder-extension:1.9.2') {
128+
compile ('com.github.JavaSaBr:jmonkeybuilder-extension:1.9.3') {
129129
exclude group: 'org.jmonkeyengine'
130130
}
131131
compile ('com.github.JavaSaBr:tonegodemitter:2.4.0') {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import com.ss.editor.analytics.google.GAnalytics;
3434
import com.ss.editor.annotation.FromAnyThread;
3535
import com.ss.editor.annotation.JMEThread;
36+
import com.ss.editor.asset.locator.FileSystemAssetLocator;
37+
import com.ss.editor.asset.locator.FolderAssetLocator;
3638
import com.ss.editor.config.Config;
3739
import com.ss.editor.config.EditorConfig;
3840
import com.ss.editor.executor.impl.JMEThreadExecutor;
@@ -276,6 +278,7 @@ public void simpleInitApp() {
276278

277279
final AssetManager assetManager = getAssetManager();
278280
assetManager.registerLocator("", FolderAssetLocator.class);
281+
assetManager.registerLocator("", FileSystemAssetLocator.class);
279282
assetManager.addAssetEventListener(EditorConfig.getInstance());
280283

281284
final AudioRenderer audioRenderer = getAudioRenderer();

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

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.ss.rlib.util.array.ConcurrentArray;
4343
import javafx.application.Application;
4444
import javafx.application.Platform;
45+
import javafx.beans.value.ChangeListener;
4546
import javafx.collections.ObservableList;
4647
import javafx.scene.image.Image;
4748
import javafx.stage.Stage;
@@ -55,6 +56,7 @@
5556
import java.io.IOException;
5657
import java.io.PrintStream;
5758
import java.nio.file.Paths;
59+
import java.util.Collection;
5860

5961
/**
6062
* The starter of the JavaFX application.
@@ -179,6 +181,36 @@ private static void startJMEApplication(@NotNull final JmeToJFXApplication appli
179181
}
180182
}
181183

184+
/**
185+
* Create a new focus listener.
186+
*
187+
* @return the new focus listener.
188+
*/
189+
@FXThread
190+
private static @NotNull ChangeListener<Boolean> makeFocusedListener() {
191+
return (observable, oldValue, newValue) -> {
192+
193+
final Editor editor = Editor.getInstance();
194+
final Stage stage = notNull(JFXApplication.getStage());
195+
196+
if (newValue || stage.isFocused()) {
197+
editor.setPaused(false);
198+
return;
199+
}
200+
201+
final EditorConfig editorConfig = EditorConfig.getInstance();
202+
if (!editorConfig.isStopRenderOnLostFocus()) {
203+
editor.setPaused(false);
204+
return;
205+
}
206+
207+
final JFXApplication application = JFXApplication.getInstance();
208+
final Window window = ArrayUtils.getInReadLock(application.openedWindows, windows -> windows.search(Window::isFocused));
209+
210+
editor.setPaused(window == null);
211+
};
212+
}
213+
182214
/**
183215
* Start.
184216
*/
@@ -236,7 +268,8 @@ public JFXApplication() {
236268
*/
237269
@FXThread
238270
public void addWindow(@NotNull final Window window) {
239-
ArrayUtils.runInWriteLock(openedWindows, window, Array::add);
271+
window.focusedProperty().addListener(makeFocusedListener());
272+
ArrayUtils.runInWriteLock(openedWindows, window, Collection::add);
240273
}
241274

242275
/**
@@ -418,10 +451,7 @@ private void createSceneProcessor(@NotNull final EditorFXScene scene, @NotNull f
418451
this.sceneProcessor = sceneProcessor;
419452

420453
final Stage stage = notNull(getStage());
421-
stage.focusedProperty().addListener((observable, oldValue, newValue) -> {
422-
final EditorConfig editorConfig = EditorConfig.getInstance();
423-
editor.setPaused(editorConfig.isStopRenderOnLostFocus() && !newValue);
424-
});
454+
stage.focusedProperty().addListener(makeFocusedListener());
425455

426456
Platform.runLater(scene::notifyFinishBuild);
427457
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.ss.editor.asset.locator;
2+
3+
import com.jme3.asset.AssetInfo;
4+
import com.jme3.asset.AssetKey;
5+
import com.jme3.asset.AssetLocator;
6+
import com.jme3.asset.AssetManager;
7+
import org.jetbrains.annotations.NotNull;
8+
9+
import java.nio.file.Files;
10+
import java.nio.file.Path;
11+
import java.nio.file.Paths;
12+
13+
/**
14+
* The implementation of asset locator to use file system as asset folder.
15+
*
16+
* @author JavaSaBr
17+
*/
18+
public class FileSystemAssetLocator implements AssetLocator {
19+
20+
@Override
21+
public void setRootPath(@NotNull final String rootPath) {
22+
23+
}
24+
25+
@Override
26+
public AssetInfo locate(@NotNull final AssetManager manager, @NotNull final AssetKey key) {
27+
28+
final Path absoluteFile = Paths.get(key.getName());
29+
if (!Files.exists(absoluteFile)) return null;
30+
31+
return new FolderAssetLocator.PathAssetInfo(manager, key, absoluteFile);
32+
}
33+
}

src/main/java/com/ss/editor/FolderAssetLocator.java renamed to src/main/java/com/ss/editor/asset/locator/FolderAssetLocator.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ss.editor;
1+
package com.ss.editor.asset.locator;
22

33
import com.jme3.asset.AssetInfo;
44
import com.jme3.asset.AssetKey;
@@ -12,6 +12,7 @@
1212
import java.io.InputStream;
1313
import java.nio.file.Files;
1414
import java.nio.file.Path;
15+
import java.nio.file.Paths;
1516
import java.nio.file.StandardOpenOption;
1617

1718
/**
@@ -28,7 +29,10 @@ public void setRootPath(@NotNull final String rootPath) {
2829

2930
@Override
3031
@JMEThread
31-
public AssetInfo locate(final AssetManager manager, final AssetKey key) {
32+
public AssetInfo locate(@NotNull final AssetManager manager, @NotNull final AssetKey key) {
33+
34+
final Path absoluteFile = Paths.get(key.getName());
35+
if (Files.exists(absoluteFile)) return null;
3236

3337
final EditorConfig editorConfig = EditorConfig.getInstance();
3438
final Path currentAsset = editorConfig.getCurrentAsset();
@@ -41,13 +45,13 @@ public AssetInfo locate(final AssetManager manager, final AssetKey key) {
4145
return new PathAssetInfo(manager, key, resolve);
4246
}
4347

44-
private class PathAssetInfo extends AssetInfo {
48+
public static class PathAssetInfo extends AssetInfo {
4549

4650
@NotNull
4751
private final Path path;
4852

49-
private PathAssetInfo(@NotNull final AssetManager manager, @NotNull final AssetKey key,
50-
@NotNull final Path path) {
53+
public PathAssetInfo(@NotNull final AssetManager manager, @NotNull final AssetKey key,
54+
@NotNull final Path path) {
5155
super(manager, key);
5256
this.path = path;
5357
}

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

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public class JMEFilePreviewManager extends AbstractControl {
7171
@NotNull
7272
private static final Array<String> JME_FORMATS = ArrayFactory.newArray(String.class);
7373

74+
@NotNull
75+
private static final Array<String> MODELS_FORMATS = ArrayFactory.newArray(String.class);
76+
7477
@NotNull
7578
private static final Array<String> AUDIO_FORMATS = ArrayFactory.newArray(String.class);
7679

@@ -80,6 +83,9 @@ public class JMEFilePreviewManager extends AbstractControl {
8083
AUDIO_FORMATS.add(FileExtensions.AUDIO_OGG);
8184
AUDIO_FORMATS.add(FileExtensions.AUDIO_MP3);
8285
AUDIO_FORMATS.add(FileExtensions.AUDIO_WAV);
86+
MODELS_FORMATS.add(FileExtensions.JME_OBJECT);
87+
MODELS_FORMATS.add(FileExtensions.MODEL_BLENDER);
88+
MODELS_FORMATS.add(FileExtensions.MODEL_GLTF);
8389
}
8490

8591
@NotNull
@@ -105,6 +111,32 @@ public class JMEFilePreviewManager extends AbstractControl {
105111
return notNull(instance);
106112
}
107113

114+
/**
115+
* Check the file.
116+
*
117+
* @param file the file
118+
* @return true is the file is a file of a model.
119+
*/
120+
@FromAnyThread
121+
public static boolean isModelFile(@Nullable final Path file) {
122+
if (file == null) return false;
123+
final String extension = getExtension(file);
124+
return MODELS_FORMATS.contains(extension);
125+
}
126+
127+
/**
128+
* Check the file by the asset path.
129+
*
130+
* @param assetPath the asset path.
131+
* @return true is the file is a file of a model.
132+
*/
133+
@FromAnyThread
134+
public static boolean isModelFile(@Nullable final String assetPath) {
135+
if (StringUtils.isEmpty(assetPath)) return false;
136+
final String extension = getExtension(assetPath);
137+
return MODELS_FORMATS.contains(extension);
138+
}
139+
108140
/**
109141
* Check the file.
110142
*
@@ -241,7 +273,7 @@ protected void controlRender(@NotNull final RenderManager renderManager, @NotNul
241273
}
242274

243275
/**
244-
* Show a file.
276+
* Show the file.
245277
*
246278
* @param file the file.
247279
* @param fitWidth the target width of preview.
@@ -258,6 +290,20 @@ public void show(@NotNull final Path file, final int fitWidth, final int fitHeig
258290
showPreview(path, getExtension(assetFile));
259291
}
260292

293+
/**
294+
* Show the external file.
295+
*
296+
* @param file the file.
297+
* @param fitWidth the target width of preview.
298+
* @param fitHeight the target height of preview.
299+
*/
300+
@FromAnyThread
301+
public void showExternal(@NotNull final Path file, final int fitWidth, final int fitHeight) {
302+
imageView.setFitHeight(fitHeight);
303+
imageView.setFitWidth(fitWidth);
304+
showPreview(file.toString(), getExtension(file));
305+
}
306+
261307
/**
262308
* Show a preview of the file by the asset path.
263309
*
@@ -268,7 +314,7 @@ public void show(@NotNull final Path file, final int fitWidth, final int fitHeig
268314
private void showPreview(@NotNull final String path, @NotNull final String extension) {
269315
if (FileExtensions.JME_MATERIAL.equals(extension)) {
270316
EDITOR_THREAD_EXECUTOR.addToExecute(() -> showMaterial(path));
271-
} else if (FileExtensions.JME_OBJECT.equals(extension)) {
317+
} else if (isModelFile(path)) {
272318
EDITOR_THREAD_EXECUTOR.addToExecute(() -> showObject(path));
273319
} else {
274320
EDITOR_THREAD_EXECUTOR.addToExecute(this::clear);
@@ -384,9 +430,8 @@ private void clearImpl() {
384430
*
385431
* @return the image view with a preview.
386432
*/
387-
@NotNull
388433
@FXThread
389-
public ImageView getImageView() {
434+
public @NotNull ImageView getImageView() {
390435
return imageView;
391436
}
392437

@@ -395,8 +440,8 @@ public ImageView getImageView() {
395440
*
396441
* @return the transfer processor.
397442
*/
398-
@NotNull
399-
private FrameTransferSceneProcessor prepareScene() {
443+
@JMEThread
444+
private @NotNull FrameTransferSceneProcessor prepareScene() {
400445

401446
final Editor editor = Editor.getInstance();
402447
final AssetManager assetManager = editor.getAssetManager();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected void createSettings(@NotNull final GridPane root) {
5757

5858
@Override
5959
@FXThread
60-
public void show(final @NotNull Window owner) {
60+
public void show(@NotNull final Window owner) {
6161
super.show(owner);
6262
validateFileName();
6363
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.ss.editor.plugin.api.property.control;
2+
3+
import com.ss.editor.Messages;
4+
import com.ss.editor.annotation.FXThread;
5+
import com.ss.editor.plugin.api.property.PropertyDefinition;
6+
import com.ss.editor.ui.dialog.file.chooser.ExternalFileEditorDialog;
7+
import com.ss.rlib.util.VarTable;
8+
import javafx.scene.control.Label;
9+
import org.jetbrains.annotations.NotNull;
10+
import org.jetbrains.annotations.Nullable;
11+
12+
import java.nio.file.Path;
13+
import java.nio.file.Paths;
14+
15+
/**
16+
* The control to edit files from file system.
17+
*
18+
* @author JavaSaBr
19+
*/
20+
public class ExternalFileResourcePropertyControl extends ResourcePropertyEditorControl<Path> {
21+
22+
/**
23+
* The target extension.
24+
*/
25+
@Nullable
26+
private final String extension;
27+
28+
public ExternalFileResourcePropertyControl(@NotNull final VarTable vars,
29+
@NotNull final PropertyDefinition definition,
30+
@NotNull final Runnable validationCallback) {
31+
super(vars, definition, validationCallback);
32+
this.extension = definition.getExtension();
33+
}
34+
35+
@Override
36+
@FXThread
37+
protected void processSelect() {
38+
super.processSelect();
39+
40+
final ExternalFileEditorDialog dialog = new ExternalFileEditorDialog(this::openExternalFile);
41+
dialog.setTitleText(Messages.ASSET_EDITOR_DIALOG_TITLE);
42+
dialog.setInitDirectory(Paths.get(System.getProperty("user.home")));
43+
dialog.show();
44+
}
45+
46+
/**
47+
* Handle selected file.
48+
*
49+
* @param path the selected file.
50+
*/
51+
@FXThread
52+
private void openExternalFile(@NotNull final Path path) {
53+
setPropertyValue(path);
54+
change();
55+
reload();
56+
}
57+
58+
59+
@Override
60+
@FXThread
61+
protected void reload() {
62+
63+
final Path resource = getPropertyValue();
64+
final Label resourceLabel = getResourceLabel();
65+
resourceLabel.setText(resource == null ? NOT_SELECTED : resource.toString());
66+
67+
super.reload();
68+
}
69+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public class PropertyEditorControlFactory {
5656
return new AwtFontPropertyEditorControl(vars, definition, validation);
5757
case RESOURCE_FROM_CLASSPATH:
5858
return new ClasspathResourcePropertyControl(vars, definition, validation);
59+
case EXTERNAL_FILE:
60+
return new ExternalFileResourcePropertyControl(vars, definition, validation);
5961
default:
6062
throw new IllegalArgumentException("Unknown the type " + definition.getPropertyType());
6163
}

0 commit comments

Comments
 (0)