diff --git a/tools/demobench/build.gradle b/tools/demobench/build.gradle index c6dded517b..5b6f572094 100644 --- a/tools/demobench/build.gradle +++ b/tools/demobench/build.gradle @@ -3,6 +3,10 @@ version '0.7-SNAPSHOT' buildscript { ext.kotlin_version = '1.0.6' + ext.jna_version = '4.1.0' + ext.purejavacomm_version = '0.0.17' + ext.guava_version = '14.0.1' + ext.slf4j_version = '1.7.22' repositories { mavenCentral() @@ -18,13 +22,32 @@ apply plugin: 'kotlin' sourceCompatibility = 1.8 repositories { + flatDir { + dirs 'libs' + } + + mavenLocal() mavenCentral() + maven { + url 'http://www.sparetimelabs.com/maven2' + } } dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + + compile "net.java.dev.jna:jna:$jna_version" + compile "net.java.dev.jna:jna-platform:$jna_version" + compile "com.google.guava:guava:$guava_version" + compile "com.sparetimelabs:purejavacomm:$purejavacomm_version" + compile "org.slf4j:log4j-over-slf4j:$slf4j_version" + compile "org.slf4j:jul-to-slf4j:$slf4j_version" + compile "ch.qos.logback:logback-classic:1.1.3" + compile ":jediterm-terminal-2.5" + compile ':pty4j-0.7.2' + testCompile group: 'junit', name: 'junit', version: '4.11' // TornadoFX: A lightweight Kotlin framework for working with JavaFX UI's. - compile 'no.tornado:tornadofx:1.5.7' + compile 'no.tornado:tornadofx:1.6.0' } diff --git a/tools/demobench/libs/jediterm-terminal-2.5.jar b/tools/demobench/libs/jediterm-terminal-2.5.jar new file mode 100644 index 0000000000..018e852ae1 Binary files /dev/null and b/tools/demobench/libs/jediterm-terminal-2.5.jar differ diff --git a/tools/demobench/libs/linux/x86/libpty.so b/tools/demobench/libs/linux/x86/libpty.so new file mode 100755 index 0000000000..832504bc8d Binary files /dev/null and b/tools/demobench/libs/linux/x86/libpty.so differ diff --git a/tools/demobench/libs/linux/x86_64/libpty.so b/tools/demobench/libs/linux/x86_64/libpty.so new file mode 100755 index 0000000000..cd41f3b15b Binary files /dev/null and b/tools/demobench/libs/linux/x86_64/libpty.so differ diff --git a/tools/demobench/libs/macosx/x86/libpty.dylib b/tools/demobench/libs/macosx/x86/libpty.dylib new file mode 100755 index 0000000000..f05fb026cf Binary files /dev/null and b/tools/demobench/libs/macosx/x86/libpty.dylib differ diff --git a/tools/demobench/libs/macosx/x86_64/libpty.dylib b/tools/demobench/libs/macosx/x86_64/libpty.dylib new file mode 100755 index 0000000000..1093ba1c84 Binary files /dev/null and b/tools/demobench/libs/macosx/x86_64/libpty.dylib differ diff --git a/tools/demobench/libs/pty4j-0.7.2.jar b/tools/demobench/libs/pty4j-0.7.2.jar new file mode 100644 index 0000000000..e336572696 Binary files /dev/null and b/tools/demobench/libs/pty4j-0.7.2.jar differ diff --git a/tools/demobench/libs/win/x86/libwinpty.dll b/tools/demobench/libs/win/x86/libwinpty.dll new file mode 100644 index 0000000000..e1644b8ee8 Binary files /dev/null and b/tools/demobench/libs/win/x86/libwinpty.dll differ diff --git a/tools/demobench/libs/win/x86/winpty-agent.exe b/tools/demobench/libs/win/x86/winpty-agent.exe new file mode 100644 index 0000000000..3abad80b84 Binary files /dev/null and b/tools/demobench/libs/win/x86/winpty-agent.exe differ diff --git a/tools/demobench/libs/win/x86/winpty.dll b/tools/demobench/libs/win/x86/winpty.dll new file mode 100644 index 0000000000..f07b95a27b Binary files /dev/null and b/tools/demobench/libs/win/x86/winpty.dll differ diff --git a/tools/demobench/libs/win/x86_64/cyglaunch.exe b/tools/demobench/libs/win/x86_64/cyglaunch.exe new file mode 100644 index 0000000000..d84e6e964c Binary files /dev/null and b/tools/demobench/libs/win/x86_64/cyglaunch.exe differ diff --git a/tools/demobench/libs/win/x86_64/winpty-agent.exe b/tools/demobench/libs/win/x86_64/winpty-agent.exe new file mode 100644 index 0000000000..e1963c4e3c Binary files /dev/null and b/tools/demobench/libs/win/x86_64/winpty-agent.exe differ diff --git a/tools/demobench/libs/win/x86_64/winpty.dll b/tools/demobench/libs/win/x86_64/winpty.dll new file mode 100644 index 0000000000..f9bdec0394 Binary files /dev/null and b/tools/demobench/libs/win/x86_64/winpty.dll differ diff --git a/tools/demobench/libs/win/xp/winpty-agent.exe b/tools/demobench/libs/win/xp/winpty-agent.exe new file mode 100644 index 0000000000..cc18efda8c Binary files /dev/null and b/tools/demobench/libs/win/xp/winpty-agent.exe differ diff --git a/tools/demobench/libs/win/xp/winpty.dll b/tools/demobench/libs/win/xp/winpty.dll new file mode 100644 index 0000000000..bd40cd1e9d Binary files /dev/null and b/tools/demobench/libs/win/xp/winpty.dll differ diff --git a/tools/demobench/native/linux/x86/libpty.so b/tools/demobench/native/linux/x86/libpty.so new file mode 100755 index 0000000000..832504bc8d Binary files /dev/null and b/tools/demobench/native/linux/x86/libpty.so differ diff --git a/tools/demobench/native/linux/x86_64/libpty.so b/tools/demobench/native/linux/x86_64/libpty.so new file mode 100755 index 0000000000..cd41f3b15b Binary files /dev/null and b/tools/demobench/native/linux/x86_64/libpty.so differ diff --git a/tools/demobench/native/macosx/x86/libpty.dylib b/tools/demobench/native/macosx/x86/libpty.dylib new file mode 100755 index 0000000000..f05fb026cf Binary files /dev/null and b/tools/demobench/native/macosx/x86/libpty.dylib differ diff --git a/tools/demobench/native/macosx/x86_64/libpty.dylib b/tools/demobench/native/macosx/x86_64/libpty.dylib new file mode 100755 index 0000000000..1093ba1c84 Binary files /dev/null and b/tools/demobench/native/macosx/x86_64/libpty.dylib differ diff --git a/tools/demobench/native/win/x86/libwinpty.dll b/tools/demobench/native/win/x86/libwinpty.dll new file mode 100644 index 0000000000..e1644b8ee8 Binary files /dev/null and b/tools/demobench/native/win/x86/libwinpty.dll differ diff --git a/tools/demobench/native/win/x86/winpty-agent.exe b/tools/demobench/native/win/x86/winpty-agent.exe new file mode 100644 index 0000000000..3abad80b84 Binary files /dev/null and b/tools/demobench/native/win/x86/winpty-agent.exe differ diff --git a/tools/demobench/native/win/x86/winpty.dll b/tools/demobench/native/win/x86/winpty.dll new file mode 100644 index 0000000000..f07b95a27b Binary files /dev/null and b/tools/demobench/native/win/x86/winpty.dll differ diff --git a/tools/demobench/native/win/x86_64/cyglaunch.exe b/tools/demobench/native/win/x86_64/cyglaunch.exe new file mode 100644 index 0000000000..d84e6e964c Binary files /dev/null and b/tools/demobench/native/win/x86_64/cyglaunch.exe differ diff --git a/tools/demobench/native/win/x86_64/winpty-agent.exe b/tools/demobench/native/win/x86_64/winpty-agent.exe new file mode 100644 index 0000000000..e1963c4e3c Binary files /dev/null and b/tools/demobench/native/win/x86_64/winpty-agent.exe differ diff --git a/tools/demobench/native/win/x86_64/winpty.dll b/tools/demobench/native/win/x86_64/winpty.dll new file mode 100644 index 0000000000..f9bdec0394 Binary files /dev/null and b/tools/demobench/native/win/x86_64/winpty.dll differ diff --git a/tools/demobench/native/win/xp/winpty-agent.exe b/tools/demobench/native/win/xp/winpty-agent.exe new file mode 100644 index 0000000000..cc18efda8c Binary files /dev/null and b/tools/demobench/native/win/xp/winpty-agent.exe differ diff --git a/tools/demobench/native/win/xp/winpty.dll b/tools/demobench/native/win/xp/winpty.dll new file mode 100644 index 0000000000..bd40cd1e9d Binary files /dev/null and b/tools/demobench/native/win/xp/winpty.dll differ diff --git a/tools/demobench/src/main/java/net/corda/demobench/config/LoggingConfig.java b/tools/demobench/src/main/java/net/corda/demobench/config/LoggingConfig.java new file mode 100644 index 0000000000..912f72204c --- /dev/null +++ b/tools/demobench/src/main/java/net/corda/demobench/config/LoggingConfig.java @@ -0,0 +1,27 @@ +package net.corda.demobench.config; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.logging.LogManager; + +public class LoggingConfig { + + public LoggingConfig() throws IOException { + try (InputStream input = getLoggingProperties()) { + LogManager manager = LogManager.getLogManager(); + manager.readConfiguration(input); + } + } + + private static InputStream getLoggingProperties() throws IOException { + InputStream input = LoggingConfig.class.getResourceAsStream("logging.properties"); + if (input == null) { + File javaHome = new File(System.getProperty("java.home")); + input = new FileInputStream(new File(new File(javaHome, "lib"), "logging.properties")); + } + return input; + } + +} diff --git a/tools/demobench/src/main/java/net/corda/demobench/pty/PtyProcessTtyConnector.java b/tools/demobench/src/main/java/net/corda/demobench/pty/PtyProcessTtyConnector.java new file mode 100644 index 0000000000..9b6c8ee02d --- /dev/null +++ b/tools/demobench/src/main/java/net/corda/demobench/pty/PtyProcessTtyConnector.java @@ -0,0 +1,41 @@ +package net.corda.demobench.pty; + +import com.jediterm.terminal.ProcessTtyConnector; +import com.pty4j.PtyProcess; +import com.pty4j.WinSize; + +import java.nio.charset.Charset; + +/** + * Copied from JediTerm pty. + * @author traff + */ +public class PtyProcessTtyConnector extends ProcessTtyConnector { + private final PtyProcess myProcess; + private final String name; + + PtyProcessTtyConnector(String name, PtyProcess process, Charset charset) { + super(process, charset); + myProcess = process; + this.name = name; + } + + @Override + protected void resizeImmediately() { + if (getPendingTermSize() != null && getPendingPixelSize() != null) { + myProcess.setWinSize( + new WinSize(getPendingTermSize().width, getPendingTermSize().height, getPendingPixelSize().width, getPendingPixelSize().height)); + } + } + + @Override + public boolean isConnected() { + return myProcess.isRunning(); + } + + @Override + public String getName() { + return name; + } + +} diff --git a/tools/demobench/src/main/java/net/corda/demobench/pty/R3Pty.java b/tools/demobench/src/main/java/net/corda/demobench/pty/R3Pty.java new file mode 100644 index 0000000000..3f4cd27859 --- /dev/null +++ b/tools/demobench/src/main/java/net/corda/demobench/pty/R3Pty.java @@ -0,0 +1,118 @@ +package net.corda.demobench.pty; + +import com.jediterm.terminal.TerminalColor; +import com.jediterm.terminal.TextStyle; +import com.jediterm.terminal.TtyConnector; +import com.jediterm.terminal.ui.*; +import com.jediterm.terminal.ui.settings.DefaultSettingsProvider; +import com.jediterm.terminal.ui.settings.SettingsProvider; +import com.pty4j.PtyProcess; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.imageio.ImageIO; +import javax.swing.*; +import java.awt.*; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import static java.nio.charset.StandardCharsets.UTF_8; + +public class R3Pty implements AutoCloseable { + private static final Logger LOG = LoggerFactory.getLogger(R3Pty.class); + + private final JediTermWidget terminal; + private final String name; + + public R3Pty(String name, SettingsProvider settings, Dimension dimension) { + terminal = new JediTermWidget(dimension, settings); + this.name = name; + } + + @Override + public void close() { + LOG.info("Closing terminal '{}'", name); + terminal.close(); + } + + public String getName() { + return name; + } + + public JediTermWidget getTerminal() { + return terminal; + } + + private TtyConnector createTtyConnector(String[] command, Map environment, String workingDir) { + try { + PtyProcess process = PtyProcess.exec(command, environment, workingDir); + + try { + return new PtyProcessTtyConnector(name, process, UTF_8); + } catch (Exception e) { + process.destroyForcibly(); + process.waitFor(30, TimeUnit.SECONDS); + throw e; + } + } catch (Exception e) { + throw new IllegalStateException(e.getMessage(), e); + } + } + + public void run(String[] args, Map envs, String workingDir) { + if (terminal.isSessionRunning()) { + throw new IllegalStateException(terminal.getSessionName() + " is already running"); + } + + Map environment = new HashMap<>(envs); + environment.put("TERM", "xterm"); + + TerminalSession session = terminal.createTerminalSession(createTtyConnector(args, environment, workingDir)); + session.start(); + } + + public void run(String[] args, Map envs) { + run(args, envs, null); + } + + public void run(String... args) { + run(args, System.getenv()); + } + + public static void main(final String[] args) throws IOException { + JFrame frame = new JFrame("R3 Example"); + frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + frame.setIconImage(ImageIO.read(R3Pty.class.getResourceAsStream("/r3logo.png"))); + + SettingsProvider settings = new DefaultSettingsProvider() { + @Override + public TextStyle getDefaultStyle() { + return new TextStyle(TerminalColor.WHITE, TerminalColor.BLACK); + } + + @Override + public float getTerminalFontSize() { + return 20; + } + + @Override + public boolean emulateX11CopyPaste() { + return true; + } + }; + + R3Pty pty = new R3Pty("Bungo", settings, new Dimension(164, 40)); + + frame.getContentPane().add(pty.getTerminal(), BorderLayout.CENTER); + + frame.pack(); + frame.setLocationByPlatform(true); + frame.setResizable(true); + frame.setVisible(true); + + pty.run(args); + } + +} diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/DemoBench.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/DemoBench.kt index 84b84da37a..4abfa41e83 100644 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/DemoBench.kt +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/DemoBench.kt @@ -1,6 +1,9 @@ package net.corda.demobench +import javafx.scene.image.Image +import net.corda.demobench.views.DemoBenchView import tornadofx.App +import tornadofx.addStageIcon /** * README! @@ -33,5 +36,6 @@ import tornadofx.App class DemoBench : App(DemoBenchView::class) { init { + addStageIcon(Image("r3logo.png")) } -} \ No newline at end of file +} diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/DemoBenchView.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/DemoBenchView.kt deleted file mode 100644 index e81c5f706e..0000000000 --- a/tools/demobench/src/main/kotlin/net/corda/demobench/DemoBenchView.kt +++ /dev/null @@ -1,13 +0,0 @@ -package net.corda.demobench - -import javafx.scene.Parent -import tornadofx.View -import tornadofx.importStylesheet - -class DemoBenchView : View("Corda Demo Bench") { - override val root: Parent by fxml() - - init { - importStylesheet("/net/corda/demobench/style.css") - } -} diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/ui/CloseableTab.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/ui/CloseableTab.kt new file mode 100644 index 0000000000..f8590f0e99 --- /dev/null +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/ui/CloseableTab.kt @@ -0,0 +1,20 @@ +package net.corda.demobench.ui + +import com.sun.javafx.scene.control.behavior.TabPaneBehavior +import com.sun.javafx.scene.control.skin.TabPaneSkin +import javafx.scene.Node +import javafx.scene.control.Tab + +class CloseableTab(text: String, content: Node) : Tab(text, content) { + + fun requestClose() { + val b = behaviour + if (b.canCloseTab(this)) { + b.closeTab(this) + } + } + + private val behaviour: TabPaneBehavior + get() = (tabPane.skin as TabPaneSkin).behavior + +} diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/ui/PropertyLabel.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/ui/PropertyLabel.kt new file mode 100644 index 0000000000..25cfb953ac --- /dev/null +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/ui/PropertyLabel.kt @@ -0,0 +1,31 @@ +package net.corda.demobench.ui + +import javafx.scene.control.Label +import javafx.scene.layout.HBox + +class PropertyLabel() : HBox() { + + val nameLabel = Label() + val valueLabel = Label() + + var name : String + get() = nameLabel.text + set(value) { + nameLabel.text = value + } + + var value: String + get() = valueLabel.text + set(value) { + valueLabel.text = value + } + + init { + nameLabel.styleClass.add("property-name") + valueLabel.styleClass.add("property-value") + + children.addAll(nameLabel, valueLabel) + styleClass.add("property-label") + } + +} diff --git a/tools/demobench/src/main/kotlin/net/corda/demobench/views/DemoBenchView.kt b/tools/demobench/src/main/kotlin/net/corda/demobench/views/DemoBenchView.kt new file mode 100644 index 0000000000..36ab22e691 --- /dev/null +++ b/tools/demobench/src/main/kotlin/net/corda/demobench/views/DemoBenchView.kt @@ -0,0 +1,81 @@ +package net.corda.demobench.views + +import com.jediterm.terminal.TerminalColor +import com.jediterm.terminal.TextStyle +import com.jediterm.terminal.ui.settings.DefaultSettingsProvider +import javafx.application.Platform +import javafx.collections.FXCollections +import javafx.embed.swing.SwingNode +import javafx.scene.Parent +import javafx.scene.control.Button +import javafx.scene.control.TabPane +import javax.swing.SwingUtilities +import net.corda.demobench.pty.R3Pty +import net.corda.demobench.ui.CloseableTab +import tornadofx.* + +class DemoBenchView : View("Corda Demo Bench") { + + override val root by fxml() + + val addNodeButton by fxid - - diff --git a/tools/demobench/src/main/resources/net/corda/demobench/mock-term.png b/tools/demobench/src/main/resources/net/corda/demobench/mock-term.png deleted file mode 100644 index 4df6fc8808..0000000000 Binary files a/tools/demobench/src/main/resources/net/corda/demobench/mock-term.png and /dev/null differ diff --git a/tools/demobench/src/main/resources/net/corda/demobench/style.css b/tools/demobench/src/main/resources/net/corda/demobench/style.css index e25cf329c2..d5453f6a36 100644 --- a/tools/demobench/src/main/resources/net/corda/demobench/style.css +++ b/tools/demobench/src/main/resources/net/corda/demobench/style.css @@ -7,7 +7,7 @@ -fx-padding: 15px; } -.header Label { +.property-label .label { -fx-font-size: 14pt; -fx-text-fill: white; } @@ -20,4 +20,4 @@ -fx-base: #009759; -fx-background-radius: 5px; -fx-opacity: 80%; -} \ No newline at end of file +} diff --git a/tools/demobench/src/main/resources/net/corda/demobench/views/DemoBenchView.fxml b/tools/demobench/src/main/resources/net/corda/demobench/views/DemoBenchView.fxml new file mode 100644 index 0000000000..5740d99d5b --- /dev/null +++ b/tools/demobench/src/main/resources/net/corda/demobench/views/DemoBenchView.fxml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + diff --git a/tools/demobench/src/main/resources/net/corda/demobench/views/NodeTabView.fxml b/tools/demobench/src/main/resources/net/corda/demobench/views/NodeTabView.fxml new file mode 100644 index 0000000000..25fc9d23bf --- /dev/null +++ b/tools/demobench/src/main/resources/net/corda/demobench/views/NodeTabView.fxml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +