Skip to content

Commit 4d04bf4

Browse files
committed
fixed some problems with UI on windows.
1 parent 43d4636 commit 4d04bf4

File tree

15 files changed

+213
-41
lines changed

15 files changed

+213
-41
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,9 @@ public void update() {
413413
//System.out.println(cam.getRotation());
414414
//System.out.println(cam.getLocation());
415415

416-
super.update();
416+
if (Config.ENABLE_3D) {
417+
super.update();
418+
}
417419

418420
} catch (final AssetNotFoundException | RendererException | AssertionError | ArrayIndexOutOfBoundsException |
419421
NullPointerException | StackOverflowError | IllegalStateException | UnsupportedOperationException e) {

src/main/java/com/ss/editor/config/Config.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ public final class Config {
114114
*/
115115
public static boolean ENABLE_PBR;
116116

117+
/**
118+
* The flag to enable 3D part of this editor.
119+
*/
120+
public static boolean ENABLE_3D;
121+
117122
static {
118123

119124
final GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
@@ -128,6 +133,7 @@ public final class Config {
128133
DEV_DEBUG_JFX_KEY_INPUT = vars.getBoolean("Dev.jfxKeyInput", false);
129134
DEV_DEBUG_JFX = vars.getBoolean("Dev.debugJFX", false);
130135
ENABLE_PBR = vars.getBoolean("Graphics.enablePBR", true);
136+
ENABLE_3D = vars.getBoolean("Graphics.enable3D", true);
131137

132138
GRAPHICS_DEVICE = device;
133139
OPERATING_SYSTEM = new OperatingSystem();

src/main/java/com/ss/editor/ui/component/asset/tree/ResourceTree.java

Lines changed: 84 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,15 @@
1313
import com.ss.editor.ui.component.asset.tree.context.menu.action.*;
1414
import com.ss.editor.ui.component.asset.tree.context.menu.filler.AssetTreeMultiContextMenuFiller;
1515
import com.ss.editor.ui.component.asset.tree.context.menu.filler.AssetTreeSingleContextMenuFiller;
16-
import com.ss.editor.ui.component.asset.tree.resource.FileResourceElement;
17-
import com.ss.editor.ui.component.asset.tree.resource.FolderResourceElement;
18-
import com.ss.editor.ui.component.asset.tree.resource.LoadingResourceElement;
19-
import com.ss.editor.ui.component.asset.tree.resource.ResourceElement;
16+
import com.ss.editor.ui.component.asset.tree.resource.*;
2017
import com.ss.editor.ui.util.UiUtils;
2118
import com.ss.rlib.function.IntObjectConsumer;
2219
import com.ss.rlib.util.StringUtils;
2320
import com.ss.rlib.util.array.Array;
2421
import com.ss.rlib.util.array.ArrayComparator;
2522
import com.ss.rlib.util.array.ArrayFactory;
2623
import com.ss.rlib.util.array.ConcurrentArray;
24+
import javafx.application.Platform;
2725
import javafx.collections.FXCollections;
2826
import javafx.collections.ObservableList;
2927
import javafx.event.ActionEvent;
@@ -67,13 +65,17 @@ public class ResourceTree extends TreeView<ResourceElement> {
6765
final int firstLevel = getLevel(first);
6866
final int secondLevel = getLevel(second);
6967

70-
if (firstLevel != secondLevel) return firstLevel - secondLevel;
68+
if (firstLevel != secondLevel) {
69+
return firstLevel - secondLevel;
70+
}
7171

7272
final Path firstFile = notNull(first).getFile();
73-
final String firstName = firstFile.getFileName().toString();
73+
final Path firstFileFileName = firstFile.getFileName();
74+
final String firstName = firstFileFileName == null ? firstFile.toString() : firstFileFileName.toString();
7475

7576
final Path secondFile = notNull(second).getFile();
76-
final String secondName = secondFile.getFileName().toString();
77+
final Path secondFileName = secondFile.getFileName();
78+
final String secondName = secondFileName == null ? secondFile.toString() : secondFileName.toString();
7779

7880
return StringUtils.compareIgnoreCase(firstName, secondName);
7981
};
@@ -239,7 +241,10 @@ private void processChangedExpands(@NotNull final Number newValue) {
239241
}
240242

241243
final IntObjectConsumer<ResourceTree> expandHandler = getExpandHandler();
242-
if (expandHandler == null) return;
244+
if (expandHandler == null) {
245+
return;
246+
}
247+
243248
expandHandler.accept(newValue.intValue(), this);
244249
}
245250

@@ -269,7 +274,7 @@ private void lazyLoadChildren() {
269274
*/
270275
@BackgroundThread
271276
private void lazyLoadChildren(@NotNull final TreeItem<ResourceElement> treeItem,
272-
@Nullable final Consumer<@NotNull TreeItem<ResourceElement>> callback) {
277+
@Nullable final Consumer<TreeItem<ResourceElement>> callback) {
273278

274279
final ResourceElement element = treeItem.getValue();
275280
final Array<ResourceElement> children = element.getChildren(extensionFilter, isOnlyFolders());
@@ -288,10 +293,11 @@ private void lazyLoadChildren(@NotNull final TreeItem<ResourceElement> treeItem,
288293
@FxThread
289294
private void lazyLoadChildren(@NotNull final TreeItem<ResourceElement> treeItem,
290295
@NotNull final Array<ResourceElement> children,
291-
@Nullable final Consumer<@NotNull TreeItem<ResourceElement>> callback) {
296+
@Nullable final Consumer<TreeItem<ResourceElement>> callback) {
292297

293298
final ObservableList<TreeItem<ResourceElement>> items = treeItem.getChildren();
294299
if (items.size() != 1 || items.get(0).getValue() != LoadingResourceElement.getInstance()) {
300+
if (callback != null) callback.accept(treeItem);
295301
return;
296302
}
297303

@@ -438,22 +444,49 @@ private boolean isReadOnly() {
438444
}
439445

440446
/**
441-
* Fill the tree using the asset folder.
447+
* Fill the tree using the root folder.
442448
*
443-
* @param assetFolder the asset folder.
449+
* @param rootFolder the root folder.
444450
*/
445451
@FxThread
446-
public void fill(@NotNull final Path assetFolder) {
452+
public void fill(@NotNull final Path rootFolder) {
447453

448454
final Consumer<Boolean> onLoadHandler = getOnLoadHandler();
449-
if (onLoadHandler != null) onLoadHandler.accept(Boolean.FALSE);
455+
if (onLoadHandler != null) {
456+
onLoadHandler.accept(Boolean.FALSE);
457+
}
458+
459+
final TreeItem<ResourceElement> currentRoot = getRoot();
460+
if (currentRoot != null) {
461+
setRoot(null);
462+
}
463+
464+
showLoading();
465+
466+
EXECUTOR_MANAGER.addBackgroundTask(() -> startBackgroundFill(rootFolder));
467+
}
468+
469+
/**
470+
* Fill the tree using the list of root folders.
471+
*
472+
* @param rootFolders the list of root folder.
473+
*/
474+
@FxThread
475+
public void fill(@NotNull final Array<Path> rootFolders) {
476+
477+
final Consumer<Boolean> onLoadHandler = getOnLoadHandler();
478+
if (onLoadHandler != null) {
479+
onLoadHandler.accept(Boolean.FALSE);
480+
}
450481

451482
final TreeItem<ResourceElement> currentRoot = getRoot();
452-
if (currentRoot != null) setRoot(null);
483+
if (currentRoot != null) {
484+
setRoot(null);
485+
}
453486

454487
showLoading();
455488

456-
EXECUTOR_MANAGER.addBackgroundTask(() -> startBackgroundFill(assetFolder));
489+
EXECUTOR_MANAGER.addBackgroundTask(() -> startBackgroundFill(rootFolders));
457490
}
458491

459492
/**
@@ -554,9 +587,9 @@ private void showLoading() {
554587
* Start the background process of filling.
555588
*/
556589
@BackgroundThread
557-
private void startBackgroundFill(@NotNull final Path assetFolder) {
590+
private void startBackgroundFill(@NotNull final Path path) {
558591

559-
final ResourceElement rootElement = createFor(assetFolder);
592+
final ResourceElement rootElement = createFor(path);
560593
final TreeItem<ResourceElement> newRoot = new TreeItem<>(rootElement);
561594
newRoot.setExpanded(true);
562595

@@ -570,7 +603,34 @@ private void startBackgroundFill(@NotNull final Path assetFolder) {
570603
setRoot(newRoot);
571604

572605
final Consumer<Boolean> onLoadHandler = getOnLoadHandler();
573-
if (onLoadHandler != null) onLoadHandler.accept(Boolean.TRUE);
606+
if (onLoadHandler != null) {
607+
onLoadHandler.accept(Boolean.TRUE);
608+
}
609+
});
610+
}
611+
612+
/**
613+
* Start the background process of filling.
614+
*/
615+
@BackgroundThread
616+
private void startBackgroundFill(@NotNull final Array<Path> paths) {
617+
618+
final ResourceElement rootElement = new FoldersResourceElement(paths);
619+
final TreeItem<ResourceElement> newRoot = new TreeItem<>(rootElement);
620+
newRoot.setExpanded(true);
621+
622+
fill(newRoot);
623+
624+
if (!isLazyMode() && isNeedCleanup()) {
625+
cleanup(newRoot);
626+
}
627+
628+
EXECUTOR_MANAGER.addFxTask(() -> {
629+
setRoot(newRoot);
630+
final Consumer<Boolean> onLoadHandler = getOnLoadHandler();
631+
if (onLoadHandler != null) {
632+
Platform.runLater(() -> onLoadHandler.accept(Boolean.TRUE));
633+
}
574634
});
575635
}
576636

@@ -649,7 +709,9 @@ private void fill(@NotNull final TreeItem<ResourceElement> treeItem) {
649709

650710
final ResourceElement element = treeItem.getValue();
651711
final Array<String> extensionFilter = getExtensionFilter();
652-
if (!element.hasChildren(extensionFilter, isOnlyFolders())) return;
712+
if (!element.hasChildren(extensionFilter, isOnlyFolders())) {
713+
return;
714+
}
653715

654716
final ObservableList<TreeItem<ResourceElement>> items = treeItem.getChildren();
655717

@@ -957,7 +1019,6 @@ public void expandTo(@NotNull final Path file, final boolean needSelect) {
9571019
if (isLazyMode()) {
9581020

9591021
final TreeItem<ResourceElement> targetItem = findItemForValue(getRoot(), file);
960-
9611022
if (targetItem == null) {
9621023

9631024
TreeItem<ResourceElement> parentItem = null;
@@ -968,11 +1029,12 @@ public void expandTo(@NotNull final Path file, final boolean needSelect) {
9681029
if (parentItem != null) {
9691030
break;
9701031
}
1032+
9711033
parent = parent.getParent();
9721034
}
9731035

9741036
if (parentItem == null) {
975-
return;
1037+
parentItem = getRoot();
9761038
}
9771039

9781040
final TreeItem<ResourceElement> toLoad = parentItem;

src/main/java/com/ss/editor/ui/component/asset/tree/ResourceTreeCell.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ protected void updateItem(@Nullable final ResourceElement item, boolean empty) {
141141

142142
icon.setImage(ICON_MANAGER.getIcon(file, folder, true, DEFAULT_FILE_ICON_SIZE));
143143

144-
setText(fileName.toString());
144+
setText(fileName == null ? file.toString() : fileName.toString());
145145
setGraphic(icon);
146146
createToolTip();
147147
}

src/main/java/com/ss/editor/ui/component/asset/tree/resource/FolderResourceElement.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,11 @@ public boolean hasChildren(@NotNull final Array<String> extensionFilter, final b
9393

9494
return false;
9595
}
96+
97+
@Override
98+
public String toString() {
99+
return "FolderResourceElement{" +
100+
"file=" + file +
101+
'}';
102+
}
96103
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.ss.editor.ui.component.asset.tree.resource;
2+
3+
import com.ss.editor.annotation.FromAnyThread;
4+
import com.ss.rlib.util.FileUtils;
5+
import com.ss.rlib.util.array.Array;
6+
import com.ss.rlib.util.array.ArrayCollectors;
7+
import com.ss.rlib.util.array.ArrayFactory;
8+
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.annotations.Nullable;
10+
11+
import java.io.IOException;
12+
import java.nio.file.AccessDeniedException;
13+
import java.nio.file.DirectoryStream;
14+
import java.nio.file.Files;
15+
import java.nio.file.Path;
16+
import java.util.Objects;
17+
import java.util.stream.Collectors;
18+
19+
import static com.ss.editor.ui.component.asset.tree.resource.ResourceElementFactory.createFor;
20+
import static com.ss.rlib.util.array.ArrayCollectors.toArray;
21+
22+
/**
23+
* The presentation of list of folders.
24+
*
25+
* @author JavaSaBr
26+
*/
27+
public class FoldersResourceElement extends ResourceElement {
28+
29+
/**
30+
* The list of folders.
31+
*/
32+
@NotNull
33+
private final Array<Path> folders;
34+
35+
public FoldersResourceElement(@NotNull final Array<Path> folders) {
36+
super(folders.first());
37+
this.folders = folders;
38+
}
39+
40+
@Override
41+
@FromAnyThread
42+
public @Nullable Array<ResourceElement> getChildren(@NotNull final Array<String> extensionFilter, final boolean onlyFolders) {
43+
return folders.stream().map(ResourceElementFactory::createFor)
44+
.collect(toArray(ResourceElement.class));
45+
}
46+
47+
@Override
48+
@FromAnyThread
49+
public boolean hasChildren(@NotNull final Array<String> extensionFilter, final boolean onlyFolders) {
50+
return !folders.isEmpty();
51+
}
52+
53+
@Override
54+
public boolean equals(Object o) {
55+
if (this == o) return true;
56+
if (o == null || getClass() != o.getClass()) return false;
57+
if (!super.equals(o)) return false;
58+
FoldersResourceElement that = (FoldersResourceElement) o;
59+
return Objects.equals(folders, that.folders);
60+
}
61+
62+
@Override
63+
public int hashCode() {
64+
return Objects.hash(super.hashCode(), folders);
65+
}
66+
67+
@Override
68+
public String toString() {
69+
return "FoldersResourceElement";
70+
}
71+
}

src/main/java/com/ss/editor/ui/component/asset/tree/resource/LoadingResourceElement.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ public static LoadingResourceElement getInstance() {
2626
private LoadingResourceElement() {
2727
super(Paths.get("./"));
2828
}
29+
30+
@Override
31+
public String toString() {
32+
return "LoadingResourceElement";
33+
}
2934
}

src/main/java/com/ss/editor/ui/component/asset/tree/resource/ResourceElement.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,8 @@ public boolean hasChildren(@NotNull final Array<String> extensionFilter, final b
8181
@Override
8282
public int compareTo(@Nullable final ResourceElement other) {
8383
if (other == null) return -1;
84-
8584
final Path file = getFile();
8685
final Path otherFile = other.getFile();
87-
8886
return file.getNameCount() - otherFile.getNameCount();
8987
}
9088

src/main/java/com/ss/editor/ui/dialog/SettingsDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
public class SettingsDialog extends EditorDialog {
5353

5454
@NotNull
55-
private static final Point DIALOG_SIZE = new Point(800, 480);
55+
private static final Point DIALOG_SIZE = new Point(-1, -1);
5656

5757
@NotNull
5858
private static final ExecutorManager EXECUTOR_MANAGER = ExecutorManager.getInstance();

0 commit comments

Comments
 (0)