Refactor shutdown code, although AWT is still misbehaving.

This commit is contained in:
Chris Rankin 2017-01-24 13:58:27 +00:00
parent 55b5a5a393
commit f2dd59ebd3
4 changed files with 18 additions and 48 deletions

View File

@ -6,6 +6,11 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.logging.LogManager;
/**
* Configuration class for JUL / TornadoFX.
* Requires <code>-Djava.util.logging.config.class=net.corda.demobench.config.LoggingConfig</code>
* to be added to the JVM's command line.
*/
public class LoggingConfig {
public LoggingConfig() throws IOException {
@ -16,7 +21,8 @@ public class LoggingConfig {
}
private static InputStream getLoggingProperties() throws IOException {
InputStream input = LoggingConfig.class.getResourceAsStream("logging.properties");
ClassLoader classLoader = LoggingConfig.class.getClassLoader();
InputStream input = classLoader.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"));

View File

@ -1,19 +1,13 @@
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;
@ -81,38 +75,4 @@ public class R3Pty implements AutoCloseable {
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);
}
}

View File

@ -3,11 +3,12 @@ package net.corda.demobench.views
import com.jediterm.terminal.TerminalColor
import com.jediterm.terminal.TextStyle
import com.jediterm.terminal.ui.settings.DefaultSettingsProvider
import java.util.*
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.Tab
import javafx.scene.control.TabPane
import javax.swing.SwingUtilities
import net.corda.demobench.pty.R3Pty
@ -27,11 +28,9 @@ class DemoBenchView : View("Corda Demo Bench") {
importStylesheet("/net/corda/demobench/style.css")
primaryStage.setOnCloseRequest {
// Close all open tabs
FXCollections.observableArrayList(nodeTabPane.tabs).forEach {
(it as CloseableTab).requestClose()
}
log.info("Exiting")
closeAllTabs()
Platform.exit()
}
@ -42,13 +41,19 @@ class DemoBenchView : View("Corda Demo Bench") {
addNodeButton.fire()
}
private fun closeAllTabs() {
ArrayList<Tab>(nodeTabPane.tabs).forEach {
(it as CloseableTab).requestClose()
}
}
fun createNode(): CloseableTab {
val pty = R3Pty("Banksy", settingsProvider, java.awt.Dimension(160, 80))
val nodeTabView = NodeTabView(pty.name)
val nodeTab = CloseableTab(pty.name, nodeTabView.root)
// Ensure that we close the terminal along with the tab.
nodeTab.setOnClosed {
nodeTab.setOnCloseRequest {
pty.close()
}

View File

@ -13,5 +13,4 @@
<root level="info">
<appender-ref ref="FILE" />
</root>
</configuration>