Skip to content

Commit b845b26

Browse files
committed
refactoring, started to wok on remote control.
1 parent dfd2f0d commit b845b26

25 files changed

+321
-146
lines changed

build-native.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180

181181
<fx:platform>
182182
<fx:jvmarg value="-XX:+UseParallelGC"/>
183-
<!--<fx:jvmarg value="-agentlib:jdwp=transport=dt_socket,server=n,address=192.168.94.210:6005,suspend=y"/>-->
183+
<fx:jvmarg value="-agentlib:jdwp=transport=dt_socket,server=n,address=127.0.0.1:6005,suspend=y"/>
184184
</fx:platform>
185185

186186
<preferences shortcut="true" menu="true" install="false"/>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ dependencies {
6161
compile 'org.controlsfx:controlsfx:8.40.13'
6262

6363
compile 'com.github.JavaSaBr:RlibFX:4.1.3'
64-
compile 'com.github.JavaSaBr:RLib:6.7.0'
64+
compile 'com.github.JavaSaBr:RLib:6.7.1'
6565
compile 'com.github.JavaSaBr:JME3-JFX:1.7.1'
6666

6767
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public static void main(final String[] args) {
153153
InitializeManager.register(FileIconManager.class);
154154
InitializeManager.register(WorkspaceManager.class);
155155
InitializeManager.register(PluginManager.class);
156+
InitializeManager.register(RemoteControlManager.class);
156157
InitializeManager.initialize();
157158

158159
new EditorThread(new ThreadGroup("LWJGL"),

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ public static void args(final String[] args) {
4141
Config.DEV_DEBUG_JFX = Boolean.parseBoolean(value);
4242
} else if ("Graphics.enablePBR".equals(name)) {
4343
Config.ENABLE_PBR = Boolean.parseBoolean(value);
44+
} else if ("Server.api.port".equals(name)) {
45+
Config.REMOTE_CONTROL_PORT = Integer.parseInt(value);
4446
}
4547
}
4648

47-
System.out.println(System.getenv());
48-
4949
final Map<String, String> env = System.getenv();
50+
5051
if (env.containsKey("Server.api.version")) {
5152
final int version = Integer.parseInt(env.get("Server.api.version"));
5253
if (version == Config.SERVER_API_VERSION) {
@@ -55,5 +56,9 @@ public static void args(final String[] args) {
5556
System.exit(-1);
5657
}
5758
}
59+
60+
if (env.containsKey("Server.api.port")) {
61+
Config.REMOTE_CONTROL_PORT = Integer.parseInt(env.get("Server.api.port"));
62+
}
5863
}
5964
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ private void init() {
934934
for (Iterator<String> iterator = lastOpenedAssets.iterator(); iterator.hasNext(); ) {
935935

936936
final String assetUrl = iterator.next();
937-
final Path assetPath = get(assetUrl, uri -> Paths.get(new URI(uri)));
937+
final Path assetPath = get(assetUrl, uri -> Paths.get(uri));
938938

939939
if (!Files.exists(assetPath)) {
940940
iterator.remove();

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

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.nio.file.Files;
2424
import java.nio.file.Path;
2525
import java.nio.file.Paths;
26+
import java.util.EnumSet;
27+
import java.util.Set;
2628

2729
/**
2830
* The class to manage classpath.
@@ -31,6 +33,18 @@
3133
*/
3234
public class ClasspathManager {
3335

36+
public enum Scope {
37+
CORE,
38+
CUSTOM,
39+
PLUGINS,;
40+
41+
@NotNull
42+
public static final Set<Scope> ONLY_CORE = EnumSet.of(CORE);
43+
44+
@NotNull
45+
public static final Set<Scope> ALL = EnumSet.allOf(Scope.class);
46+
}
47+
3448
@NotNull
3549
private static final EditorConfig EDITOR_CONFIG = EditorConfig.getInstance();
3650

@@ -40,7 +54,7 @@ public class ClasspathManager {
4054
@NotNull
4155
public static final Array<String> CORE_LIBRARIES_NAMES = ArrayFactory.asArray(
4256
"jme3-core", "jme3-terrain", "jme3-effects",
43-
"jme3-testdata", "jme3-plugins", "tonegod"
57+
"jme3-testdata", "jme3-plugins", "tonegod", "jmonkeybuilder"
4458
);
4559

4660
@Nullable
@@ -88,7 +102,9 @@ private ClasspathManager() {
88102
coreScanner.setUseSystemClasspath(true);
89103
coreScanner.scan(path -> {
90104

91-
if (CORE_LIBRARIES_NAMES.search(path, (pattern, pth) -> pth.contains(pattern)) == null) {
105+
if (Files.isDirectory(Paths.get(path))) {
106+
return true;
107+
} else if (CORE_LIBRARIES_NAMES.search(path, (pattern, pth) -> pth.contains(pattern)) == null) {
92108
return false;
93109
} else if (path.contains("natives")) {
94110
return false;
@@ -260,7 +276,6 @@ private void setClassesLoader(@Nullable final URLClassLoader classesLoader) {
260276
public @Nullable URLClassLoader getClassesLoader() {
261277
return classesLoader;
262278
}
263-
264279
/**
265280
* Find all implementations of the interface class.
266281
*
@@ -269,17 +284,47 @@ private void setClassesLoader(@Nullable final URLClassLoader classesLoader) {
269284
* @return the list of all available implementations.
270285
*/
271286
public @NotNull <T> Array<Class<T>> findImplements(@NotNull final Class<T> interfaceClass) {
287+
return findImplements(interfaceClass, Scope.ONLY_CORE);
288+
}
289+
290+
/**
291+
* Get the custom scanner.
292+
*
293+
* @return the custom scanner.
294+
*/
295+
private @Nullable ClassPathScanner getCustomScanner() {
296+
return customScanner;
297+
}
298+
299+
/**
300+
* Find all implementations of the interface class.
301+
*
302+
* @param <T> the type of an interface.
303+
* @param interfaceClass the interface class.
304+
* @param scope the scope.
305+
* @return the list of all available implementations.
306+
*/
307+
public @NotNull <T> Array<Class<T>> findImplements(@NotNull final Class<T> interfaceClass,
308+
@NotNull final Set<Scope> scope) {
272309

273310
final Array<Class<T>> result = ArrayFactory.newArray(Class.class);
274311

275-
coreScanner.findImplements(result, interfaceClass);
276-
customScanner.findImplements(result, interfaceClass);
312+
if (scope.contains(Scope.CORE)) {
313+
coreScanner.findImplements(result, interfaceClass);
314+
}
277315

278-
final PluginManager pluginManager = PluginManager.getInstance();
279-
pluginManager.handlePlugins(plugin -> {
280-
final PluginContainer container = plugin.getContainer();
281-
container.getScanner().findImplements(result, interfaceClass);
282-
});
316+
final ClassPathScanner customScanner = getCustomScanner();
317+
if (customScanner != null && scope.contains(Scope.CUSTOM)) {
318+
customScanner.findImplements(result, interfaceClass);
319+
}
320+
321+
if (scope.contains(Scope.PLUGINS)) {
322+
final PluginManager pluginManager = PluginManager.getInstance();
323+
pluginManager.handlePlugins(plugin -> {
324+
final PluginContainer container = plugin.getContainer();
325+
container.getScanner().findImplements(result, interfaceClass);
326+
});
327+
}
283328

284329
return result;
285330
}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44
import com.ss.rlib.logging.Logger;
55
import com.ss.rlib.logging.LoggerManager;
66
import com.ss.rlib.network.NetworkFactory;
7+
import com.ss.rlib.network.packet.ReadablePacket;
8+
import com.ss.rlib.network.packet.ReadablePacketRegistry;
79
import com.ss.rlib.network.server.ServerNetwork;
810
import org.jetbrains.annotations.NotNull;
911
import org.jetbrains.annotations.Nullable;
1012

13+
import java.io.IOException;
14+
import java.net.InetSocketAddress;
15+
1116
/**
1217
* The manager to process remote control.
1318
*
@@ -21,7 +26,7 @@ public class RemoteControlManager {
2126
@Nullable
2227
private static RemoteControlManager instance;
2328

24-
private static @NotNull RemoteControlManager getInstance() {
29+
public static @NotNull RemoteControlManager getInstance() {
2530
if (instance == null) instance = new RemoteControlManager();
2631
return instance;
2732
}
@@ -34,6 +39,15 @@ private RemoteControlManager() {
3439
return;
3540
}
3641

37-
serverNetwork = NetworkFactory.newDefaultAsynchronousServerNetwork();
42+
final ClasspathManager classpathManager = ClasspathManager.getInstance();
43+
final Class<ReadablePacket>[] packets = classpathManager.findImplements(ReadablePacket.class, ClasspathManager.Scope.ONLY_CORE)
44+
.toArray(Class.class);
45+
46+
serverNetwork = NetworkFactory.newDefaultAsyncServerNetwork(ReadablePacketRegistry.of(packets));
47+
try {
48+
serverNetwork.bind(new InetSocketAddress(Config.REMOTE_CONTROL_PORT));
49+
} catch (final IOException e) {
50+
throw new RuntimeException(e);
51+
}
3852
}
3953
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.ss.editor.remote.control.client;
2+
3+
import com.ss.rlib.network.packet.impl.AbstractReadablePacket;
4+
5+
/**
6+
* The base implementation of a client packet.
7+
*
8+
* @author JavaSaBr
9+
*/
10+
public abstract class ClientPacket extends AbstractReadablePacket {
11+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.ss.editor.remote.control.client;
2+
3+
import com.ss.editor.config.EditorConfig;
4+
import com.ss.editor.manager.ExecutorManager;
5+
import com.ss.editor.ui.component.bar.action.OpenAssetAction;
6+
import com.ss.editor.ui.event.FXEventManager;
7+
import com.ss.editor.ui.event.impl.AssetComponentLoadedEvent;
8+
import com.ss.editor.ui.event.impl.RequestedOpenFileEvent;
9+
import com.ss.rlib.network.ConnectionOwner;
10+
import com.ss.rlib.network.annotation.PacketDescription;
11+
import javafx.event.Event;
12+
import javafx.event.EventHandler;
13+
import org.jetbrains.annotations.NotNull;
14+
15+
import java.nio.ByteBuffer;
16+
import java.nio.file.Path;
17+
import java.nio.file.Paths;
18+
19+
/**
20+
* The packet with request top open a file.
21+
*
22+
* @author JavaSaBr
23+
*/
24+
@PacketDescription(id = 1)
25+
public class OpenFileClientPacket extends ClientPacket {
26+
27+
@NotNull
28+
private static final FXEventManager FX_EVENT_MANAGER = FXEventManager.getInstance();
29+
30+
@NotNull
31+
private static final ExecutorManager EXECUTOR_MANAGER = ExecutorManager.getInstance();
32+
33+
@Override
34+
protected void readImpl(@NotNull final ConnectionOwner owner, @NotNull final ByteBuffer buffer) {
35+
36+
final Path assetPath = Paths.get(readString(buffer));
37+
final Path fileToOpen = Paths.get(readString(buffer));
38+
final Path assetFile = assetPath.relativize(fileToOpen);
39+
40+
final EditorConfig editorConfig = EditorConfig.getInstance();
41+
final Path currentAsset = editorConfig.getCurrentAsset();
42+
43+
if (currentAsset == null || !assetPath.equals(currentAsset)) {
44+
EXECUTOR_MANAGER.addFXTask(() -> {
45+
46+
final OpenAssetAction action = new OpenAssetAction();
47+
action.openAssetFolder(assetPath);
48+
49+
final EventHandler<Event> eventHandler = new EventHandler<Event>() {
50+
51+
@Override
52+
public void handle(final Event event) {
53+
FX_EVENT_MANAGER.removeEventHandler(AssetComponentLoadedEvent.EVENT_TYPE, this);
54+
FX_EVENT_MANAGER.notify(new RequestedOpenFileEvent(assetFile));
55+
}
56+
};
57+
58+
FX_EVENT_MANAGER.addEventHandler(AssetComponentLoadedEvent.EVENT_TYPE, eventHandler);
59+
});
60+
61+
} else {
62+
FX_EVENT_MANAGER.notify(new RequestedOpenFileEvent(assetFile));
63+
}
64+
}
65+
}

src/main/java/com/ss/editor/ui/component/asset/AssetComponent.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,16 @@ private void handleTreeLoading(@NotNull final Boolean finished) {
204204
}
205205

206206
if (finished) {
207+
208+
final EditorConfig editorConfig = EditorConfig.getInstance();
209+
final Path currentAsset = editorConfig.getCurrentAsset();
210+
207211
EXECUTOR_MANAGER.addFXTask(() -> setIgnoreExpanded(false));
212+
213+
if (currentAsset != null) {
214+
FX_EVENT_MANAGER.notify(new AssetComponentLoadedEvent(currentAsset));
215+
}
216+
208217
} else {
209218
setIgnoreExpanded(true);
210219
}

0 commit comments

Comments
 (0)