Skip to content
This repository was archived by the owner on Jan 15, 2021. It is now read-only.

Commit feab9a2

Browse files
committed
Starting javafx
1 parent 12ef0d4 commit feab9a2

File tree

107 files changed

+5107
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+5107
-1
lines changed

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ if(build_simulator_java)
1515

1616
include 'snobot_sim_utilities'
1717
include 'snobot_sim_gui'
18+
include 'snobot_sim_gui_javafx'
1819
include 'snobot_sim_joysticks'
1920
include 'snobot_sim_example_robot'
2021

snobot_sim_gui/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ dependencies {
2929

3030

3131
// 3rd Party
32-
native3rdPartyDeps 'net.java.jinput:jinput:2.0.9'
32+
compile 'net.java.jinput:jinput:2.0.9'
33+
wpilibNativeDeps 'net.java.jinput:jinput:2.0.9:natives-all'
3334
compile 'jfree:jcommon:1.0.16'
3435
compile 'jfree:jfreechart:1.0.13'
3536
compile 'org.apache.logging.log4j:log4j-api:2.12.0'

snobot_sim_gui_javafx/build.gradle

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
2+
evaluationDependsOn(':snobot_sim_utilities')
3+
evaluationDependsOn(':sim_adx_family')
4+
evaluationDependsOn(':sim_extension_navx')
5+
6+
ext
7+
{
8+
baseId = "snobot_sim_gui_javafx"
9+
}
10+
11+
apply from: "${rootDir}/common/base_java_script.gradle"
12+
13+
configurations {
14+
native3rdPartyDeps
15+
compile.extendsFrom(native3rdPartyDeps)
16+
}
17+
18+
configurations.maybeCreate("wpilibNativeDeps")
19+
dependencies {
20+
21+
compile "org.openjfx:javafx-base:11:win"
22+
compile "org.openjfx:javafx-graphics:11:win"
23+
compile "org.openjfx:javafx-controls:11:win"
24+
compile "org.openjfx:javafx-fxml:11:win"
25+
26+
// WPILib
27+
compile 'edu.wpi.first.wpilibj:wpilibj-java:' + allwpilibVersion()
28+
compile 'edu.wpi.first.wpiutil:wpiutil-java:' + getWpiUtilVersion()
29+
compile 'edu.wpi.first.cscore:cscore-java:' + getCsCoreVersion()
30+
runtime 'edu.wpi.first.cscore:cscore-jni:' + getCsCoreVersion() + ':all'
31+
compile 'edu.wpi.first.ntcore:ntcore-java:' + getNtCoreVersion()
32+
runtime 'edu.wpi.first.ntcore:ntcore-jni:' + getNtCoreVersion() + ':all'
33+
runtime 'edu.wpi.first.hal:hal-jni:' + allwpilibVersion() + ':all'
34+
compile 'org.opencv:opencv-java:' + getWpilibOpencvVersion()
35+
runtime 'org.opencv:opencv-jni:' + getWpilibOpencvVersion() + ':all'
36+
37+
// 3rd Party
38+
compile 'net.java.jinput:jinput:2.0.9'
39+
wpilibNativeDeps 'net.java.jinput:jinput:2.0.9:natives-all'
40+
compile 'jfree:jcommon:1.0.16'
41+
compile 'jfree:jfreechart:1.0.13'
42+
compile 'org.apache.logging.log4j:log4j-api:2.11.0'
43+
compile 'org.apache.logging.log4j:log4j-core:2.11.0'
44+
compile 'org.yaml:snakeyaml:1.18'
45+
compile 'com.miglayout:miglayout-swing:4.2'
46+
//compile 'org.python:jython:2.7.1b3'
47+
48+
// Internal
49+
compile project(":snobot_sim_utilities")
50+
compile project(":snobot_sim_joysticks")
51+
52+
if(build_simulator_cpp)
53+
{
54+
compile project(":snobot_sim_jni")
55+
wpilibNativeDeps project(':snobot_sim_jni').packageNativeFiles.outputs.files
56+
}
57+
58+
if(build_simulator_java)
59+
{
60+
compile project(":snobot_sim_java")
61+
wpilibNativeDeps project(':sim_extension_navx').packageNativeFiles.outputs.files
62+
wpilibNativeDeps project(':sim_adx_family').packageNativeFiles.outputs.files
63+
}
64+
65+
// Test
66+
testCompile 'org.junit.jupiter:junit-jupiter-api:5.2.0'
67+
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
68+
testRuntime 'org.junit.platform:junit-platform-launcher:1.2.0'
69+
runtime 'com.snobot.simulator:ctre_sim_override:' + getCtreSimVersion() + ':all'
70+
runtime 'com.snobot.simulator:rev_simulator:' + getRevRoboticsSimVersion() + ':all'
71+
}
72+
73+
apply from: "${rootDir}/common/extract_native_libraries.gradle"
74+
test.dependsOn extract_wpilib
75+
76+
77+
task unzipNativeLibraries(type: Copy) {
78+
79+
configurations.native3rdPartyDeps.each {
80+
from zipTree(it)
81+
into "build/native_libs"
82+
include "**/*.dll"
83+
include "**/*.lib"
84+
include "**/*.pdb"
85+
include "**/*.so*"
86+
include "**/*.a"
87+
include "**/*.dylib*"
88+
}
89+
90+
includeEmptyDirs = false
91+
92+
}
93+
94+
eclipse.classpath.file {
95+
whenMerged { classpath ->
96+
classpath.entries.each {
97+
if(it.path.contains("jinput") && !it.path.contains("natives")) {
98+
it.setNativeLibraryLocation("snobot_sim_gui_javafx/build/native_libs")
99+
}
100+
}
101+
}
102+
}
103+
104+
build.dependsOn unzipNativeLibraries
105+
106+
if(build_simulator_cpp)
107+
{
108+
compileJava.dependsOn(":snobot_sim_jni:build")
109+
}
110+
if(build_simulator_java)
111+
{
112+
compileJava.dependsOn(":snobot_sim_java:build")
113+
}
114+
115+
sourceSets.main.java.srcDir "${buildDir}/generated/java/"
116+
compileJava {
117+
apply from: "${rootDir}/common/create_version_file.gradle"
118+
createJavaVersion("com/snobot/simulator", "SnobotSimGuiVersion", "com.snobot.simulator", getVersionName())
119+
}
120+
121+
clean {
122+
delete "src/main/java/com/snobot/simulator/SnobotSimGuiVersion.java"
123+
}
124+
125+
126+
spotbugs {
127+
ignoreFailures = true
128+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.snobot.simulator;
2+
3+
import com.snobot.simulator.config.v1.SimulatorConfigReaderV1;
4+
import com.snobot.simulator.robot_container.IRobotClassContainer;
5+
6+
/**
7+
* Base class for a custom simulator.
8+
*
9+
* @author PJ
10+
*
11+
*/
12+
public class BaseSimulator implements ISimulatorUpdater
13+
{
14+
private final SimulatorConfigReaderV1 mConfigReader;
15+
private String mConfigFile;
16+
17+
protected BaseSimulator()
18+
{
19+
mConfigReader = new SimulatorConfigReaderV1();
20+
}
21+
22+
public boolean loadConfig(String aConfigFile)
23+
{
24+
mConfigFile = aConfigFile;
25+
return mConfigReader.loadConfig(mConfigFile);
26+
}
27+
28+
29+
@Override
30+
public void update()
31+
{
32+
// Nothing to do
33+
}
34+
35+
@Override
36+
public void setRobot(IRobotClassContainer aRobot)
37+
{
38+
// Nothing to do
39+
}
40+
41+
public String getConfigFile()
42+
{
43+
return mConfigFile;
44+
}
45+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.snobot.simulator;
2+
3+
import com.snobot.simulator.wrapper_accessors.DataAccessorFactory;
4+
import com.snobot.simulator.wrapper_accessors.java.JavaDataAccessor;
5+
6+
/**
7+
* Helper class that sets up the data accessor abstraction layer
8+
*
9+
* @author PJ
10+
*
11+
*/
12+
public final class DefaultDataAccessorFactory
13+
{
14+
private static final boolean sINITIALIZED = false;
15+
16+
private DefaultDataAccessorFactory()
17+
{
18+
19+
}
20+
21+
public static void initalize()
22+
{
23+
if (!sINITIALIZED)
24+
{
25+
DataAccessorFactory.setAccessor(new JavaDataAccessor());
26+
}
27+
}
28+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.snobot.simulator;
2+
3+
import com.snobot.simulator.robot_container.IRobotClassContainer;
4+
5+
public interface ISimulatorUpdater
6+
{
7+
8+
public abstract void update();
9+
10+
public abstract void setRobot(IRobotClassContainer aRobot);
11+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.snobot.simulator;
2+
3+
import com.sun.javafx.application.LauncherImpl;
4+
5+
public final class Main
6+
{
7+
private Main()
8+
{
9+
10+
}
11+
12+
public static void main(String[] aArgs)
13+
{
14+
DefaultDataAccessorFactory.initalize();
15+
16+
// JavaFX 11+ uses GTK3 by default, and has problems on some display
17+
// servers
18+
// This flag forces JavaFX to use GTK2
19+
// System.setProperty("jdk.gtk.version", "2");
20+
LauncherImpl.launchApplication(SimulatorApplication.class, SimulatorPreloader.class, aArgs);
21+
}
22+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.snobot.simulator;
2+
3+
import java.io.File;
4+
5+
import org.apache.logging.log4j.Level;
6+
import org.apache.logging.log4j.LogManager;
7+
8+
import com.snobot.simulator.robot_container.CppRobotContainer;
9+
import com.snobot.simulator.robot_container.IRobotClassContainer;
10+
import com.snobot.simulator.robot_container.JavaRobotContainer;
11+
12+
import edu.wpi.first.networktables.NetworkTableInstance;
13+
14+
public final class RobotContainerFactory
15+
{
16+
private RobotContainerFactory()
17+
{
18+
19+
}
20+
21+
public static IRobotClassContainer createRobotContainer(File aConfigDirectory, String aRobotType, String aRobotClassName)
22+
throws ReflectiveOperationException
23+
{
24+
LogManager.getLogger(RobotContainerFactory.class).log(Level.INFO, "Starting Robot Code");
25+
26+
IRobotClassContainer mRobot;
27+
28+
if (aRobotType == null || "java".equals(aRobotType))
29+
{
30+
mRobot = new JavaRobotContainer(aRobotClassName);
31+
}
32+
else if ("cpp".equals(aRobotType))
33+
{
34+
mRobot = new CppRobotContainer(aRobotClassName);
35+
}
36+
else
37+
{
38+
throw new RuntimeException("Unsupported robot type " + aRobotType);
39+
}
40+
41+
mRobot.constructRobot();
42+
43+
// Change the network table preferences path. Need to start
44+
// the robot, stop the server and restart it
45+
NetworkTableInstance inst = NetworkTableInstance.getDefault();
46+
inst.stopServer();
47+
inst.startServer(aConfigDirectory.toString() + "/networktables.ini");
48+
49+
return mRobot;
50+
}
51+
}

0 commit comments

Comments
 (0)