Skip to content

Commit 6933b79

Browse files
committed
fixed some problems with access to files.
1 parent 2f3524e commit 6933b79

7 files changed

Lines changed: 42 additions & 42 deletions

File tree

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
package com.ss.editor;
22

3-
import static java.nio.file.Files.newInputStream;
4-
53
import com.jme3.asset.AssetInfo;
64
import com.jme3.asset.AssetKey;
75
import com.jme3.asset.AssetLocator;
86
import com.jme3.asset.AssetManager;
9-
import com.jme3.asset.StreamAssetInfo;
10-
import com.jme3.asset.plugins.UrlAssetInfo;
117
import com.ss.editor.config.EditorConfig;
8+
import org.jetbrains.annotations.NotNull;
129

1310
import java.io.IOException;
14-
import java.net.URL;
11+
import java.io.InputStream;
1512
import java.nio.file.Files;
1613
import java.nio.file.Path;
17-
18-
import org.jetbrains.annotations.NotNull;
19-
import com.ss.rlib.util.FileUtils;
20-
import com.ss.rlib.util.array.Array;
21-
import com.ss.rlib.util.array.ArrayFactory;
14+
import java.nio.file.StandardOpenOption;
2215

2316
/**
2417
* The implementation of {@link AssetLocator} to load data from an asset folder.
@@ -27,15 +20,9 @@
2720
*/
2821
public class FolderAssetLocator implements AssetLocator {
2922

30-
@NotNull
31-
private static final Array<String> URL_EXTENSIONS = ArrayFactory.newArray(String.class);
32-
33-
static {
34-
URL_EXTENSIONS.add(FileExtensions.MODEL_SCENE);
35-
}
36-
3723
@Override
3824
public void setRootPath(@NotNull final String rootPath) {
25+
System.out.println(rootPath);
3926
}
4027

4128
@Override
@@ -49,21 +36,27 @@ public AssetInfo locate(final AssetManager manager, final AssetKey key) {
4936
final Path resolve = currentAsset.resolve(name);
5037
if (!Files.exists(resolve)) return null;
5138

52-
final String extension = FileUtils.getExtension(resolve);
39+
return new PathAssetInfo(manager, key, resolve);
40+
}
41+
42+
private class PathAssetInfo extends AssetInfo {
5343

54-
if (URL_EXTENSIONS.contains(extension)) {
44+
@NotNull
45+
private final Path path;
46+
47+
private PathAssetInfo(@NotNull final AssetManager manager, @NotNull final AssetKey key,
48+
@NotNull final Path path) {
49+
super(manager, key);
50+
this.path = path;
51+
}
52+
53+
@Override
54+
public @NotNull InputStream openStream() {
5555
try {
56-
final URL url = resolve.toUri().toURL();
57-
return UrlAssetInfo.create(manager, key, url);
56+
return Files.newInputStream(path, StandardOpenOption.READ);
5857
} catch (final IOException e) {
5958
throw new RuntimeException(e);
6059
}
6160
}
62-
63-
try {
64-
return new StreamAssetInfo(manager, key, newInputStream(resolve));
65-
} catch (final IOException e) {
66-
throw new RuntimeException(e);
67-
}
6861
}
6962
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ public class Messages {
183183
* The constant ASSET_EDITOR_DIALOG_TITLE.
184184
*/
185185
public static final String ASSET_EDITOR_DIALOG_TITLE;
186+
/**
187+
* The constant ASSET_EDITOR_DIALOG_WARNING_SELECT_FILE.
188+
*/
189+
public static final String ASSET_EDITOR_DIALOG_WARNING_SELECT_FILE;
190+
186191
/**
187192
* The constant SAVE_AS_EDITOR_DIALOG_TITLE.
188193
*/
@@ -2425,6 +2430,7 @@ public class Messages {
24252430
MATERIAL_FILE_EDITOR_ACTION_LIGHT = bundle.getString("MaterialFileEditorActionLight");
24262431

24272432
ASSET_EDITOR_DIALOG_TITLE = bundle.getString("AssetEditorDialogTitle");
2433+
ASSET_EDITOR_DIALOG_WARNING_SELECT_FILE = bundle.getString("AssetEditorDialogWarningSelectFile");
24282434
SAVE_AS_EDITOR_DIALOG_TITLE = bundle.getString("SaveAsEditorDialogTitle");
24292435
SAVE_AS_EDITOR_DIALOG_FIELD_FILENAME = bundle.getString("SaveAsEditorDialogFieldFilename");
24302436

src/main/java/com/ss/editor/ui/control/choose/ChooseTextureControl.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ public void setChangeHandler(@Nullable final Runnable changeHandler) {
115115
/**
116116
* tThe handler.
117117
*/
118-
@Nullable
119-
private Runnable getChangeHandler() {
118+
private @Nullable Runnable getChangeHandler() {
120119
return changeHandler;
121120
}
122121

@@ -168,8 +167,7 @@ protected void createComponents() {
168167
*
169168
* @return the label for the path to a texture.
170169
*/
171-
@NotNull
172-
protected Label getTextureLabel() {
170+
protected @NotNull Label getTextureLabel() {
173171
return notNull(textureLabel);
174172
}
175173

@@ -178,16 +176,14 @@ protected Label getTextureLabel() {
178176
*
179177
* @return the wrapper.
180178
*/
181-
@NotNull
182-
protected HBox getWrapper() {
179+
protected @NotNull HBox getWrapper() {
183180
return notNull(wrapper);
184181
}
185182

186183
/**
187184
* @return The image channels preview.
188185
*/
189-
@NotNull
190-
private ImageChannelPreview getTextureTooltip() {
186+
private @NotNull ImageChannelPreview getTextureTooltip() {
191187
return notNull(textureTooltip);
192188
}
193189

@@ -203,8 +199,7 @@ private void processAdd() {
203199
*
204200
* @return the selected file.
205201
*/
206-
@Nullable
207-
public Path getTextureFile() {
202+
public @Nullable Path getTextureFile() {
208203
return textureFile;
209204
}
210205

@@ -232,8 +227,7 @@ private void processRemove() {
232227
/**
233228
* @return the image preview.
234229
*/
235-
@NotNull
236-
private ImageView getTexturePreview() {
230+
private @NotNull ImageView getTexturePreview() {
237231
return notNull(texturePreview);
238232
}
239233

src/main/java/com/ss/editor/ui/dialog/asset/FileAssetEditorDialog.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package com.ss.editor.ui.dialog.asset;
22

3+
import com.ss.editor.Messages;
4+
import com.ss.editor.ui.component.asset.tree.resource.FolderResourceElement;
35
import com.ss.editor.ui.component.asset.tree.resource.ResourceElement;
4-
6+
import javafx.scene.control.Label;
57
import org.jetbrains.annotations.NotNull;
68
import org.jetbrains.annotations.Nullable;
79

810
import java.nio.file.Path;
911
import java.util.function.Consumer;
1012
import java.util.function.Function;
1113

12-
import javafx.scene.control.Label;
13-
1414
/**
1515
* The implementation of the {@link AssetEditorDialog} for choosing the {@link Path} from asset.
1616
*
@@ -56,6 +56,10 @@ protected void validate(@NotNull final Label warningLabel, @Nullable final Resou
5656
final Function<Path, String> validator = getValidator();
5757
String message = validator == null ? null : validator.apply(element.getFile());
5858

59+
if (message == null && element instanceof FolderResourceElement) {
60+
message = Messages.ASSET_EDITOR_DIALOG_WARNING_SELECT_FILE;
61+
}
62+
5963
if (message != null) {
6064
warningLabel.setText(message);
6165
}

src/main/resources/messages/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ TextFileEditorName=Text editor
4848
MaterialFileEditorName=Material Editor
4949

5050
AssetEditorDialogTitle=Choose resource
51+
AssetEditorDialogWarningSelectFile=Need to select a file instead of a folder.
5152

5253
SaveAsEditorDialogTitle=Save as file
5354
SaveAsEditorDialogFieldFilename=File name

src/main/resources/messages/messages_de.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ TextFileEditorName=Texteditor
4848
MaterialFileEditorName=Materialeditor
4949

5050
AssetEditorDialogTitle=Ressource wählen
51+
AssetEditorDialogWarningSelectFile=Need to select a file instead of a folder.
5152

5253
SaveAsEditorDialogTitle=Save as file
5354
SaveAsEditorDialogFieldFilename=File name

src/main/resources/messages/messages_ru.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ TextFileEditorName=Текстовый редактор
4949
MaterialFileEditorName=Редактор материалов
5050

5151
AssetEditorDialogTitle=Выбор ресурса
52+
AssetEditorDialogWarningSelectFile=Нужно выбрать файл а не папку.
5253

5354
SaveAsEditorDialogTitle=Сохранить как файл
5455
SaveAsEditorDialogFieldFilename=Имя файла

0 commit comments

Comments
 (0)