dialog working, download files working
This commit is contained in:
parent
7db4d246d9
commit
5b321f0d40
5 changed files with 80 additions and 48 deletions
|
@ -12,7 +12,7 @@ import javafx.stage.Stage;
|
||||||
class App : Application() {
|
class App : Application() {
|
||||||
|
|
||||||
override fun start(stage: Stage) {
|
override fun start(stage: Stage) {
|
||||||
var scene = Scene(loadFXML("primary"), 1500.0, 900.0)
|
var scene = Scene(loadFXML("primary"), 963.0, 713.0)
|
||||||
stage.title = "Server For Dummies"
|
stage.title = "Server For Dummies"
|
||||||
stage.scene = scene
|
stage.scene = scene
|
||||||
stage.show()
|
stage.show()
|
||||||
|
|
|
@ -9,11 +9,11 @@ class Download: Runnable {
|
||||||
public var size: Int
|
public var size: Int
|
||||||
public var downloaded: Int
|
public var downloaded: Int
|
||||||
public var contentLength: Int
|
public var contentLength: Int
|
||||||
|
public var status: Status
|
||||||
|
|
||||||
private final val MAX_BUFFER_SIZE: Number = 1024
|
private final val MAX_BUFFER_SIZE: Number = 1024
|
||||||
|
|
||||||
private var url: URL
|
private var url: URL
|
||||||
private var status: Status
|
|
||||||
|
|
||||||
constructor (url: URL) {
|
constructor (url: URL) {
|
||||||
this.url = url
|
this.url = url
|
||||||
|
@ -23,10 +23,6 @@ class Download: Runnable {
|
||||||
contentLength = 1
|
contentLength = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun status(): Status {
|
|
||||||
return status
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun start() {
|
public fun start() {
|
||||||
val thread = Thread(this)
|
val thread = Thread(this)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
|
@ -35,6 +35,8 @@ import javafx.scene.text.TextAlignment
|
||||||
import javafx.scene.text.Text
|
import javafx.scene.text.Text
|
||||||
import javafx.scene.Scene
|
import javafx.scene.Scene
|
||||||
import javafx.scene.input.MouseEvent
|
import javafx.scene.input.MouseEvent
|
||||||
|
import javafx.scene.image.Image
|
||||||
|
import javafx.scene.image.ImageView
|
||||||
import javafx.stage.FileChooser
|
import javafx.stage.FileChooser
|
||||||
import javafx.stage.FileChooser.ExtensionFilter
|
import javafx.stage.FileChooser.ExtensionFilter
|
||||||
import javafx.stage.DirectoryChooser
|
import javafx.stage.DirectoryChooser
|
||||||
|
@ -63,6 +65,8 @@ class PrimaryController {
|
||||||
@FXML
|
@FXML
|
||||||
lateinit private var parentPane: Pane
|
lateinit private var parentPane: Pane
|
||||||
@FXML
|
@FXML
|
||||||
|
lateinit private var directoryPane: Pane
|
||||||
|
@FXML
|
||||||
lateinit private var buttonBar: ButtonBar
|
lateinit private var buttonBar: ButtonBar
|
||||||
@FXML
|
@FXML
|
||||||
lateinit private var flightCheckbox: CheckBox
|
lateinit private var flightCheckbox: CheckBox
|
||||||
|
@ -96,6 +100,12 @@ class PrimaryController {
|
||||||
lateinit private var statusBar: Label
|
lateinit private var statusBar: Label
|
||||||
@FXML
|
@FXML
|
||||||
lateinit private var progressBar: ProgressBar
|
lateinit private var progressBar: ProgressBar
|
||||||
|
@FXML
|
||||||
|
lateinit private var startButton: Button
|
||||||
|
@FXML
|
||||||
|
lateinit private var buildButton: Button
|
||||||
|
|
||||||
|
private var building = false
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private fun onDirectoryButtonClick() {
|
private fun onDirectoryButtonClick() {
|
||||||
|
@ -139,22 +149,49 @@ class PrimaryController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private fun onBuild() {
|
private fun onBuild() {
|
||||||
|
if (building) {
|
||||||
|
building = false
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
building = true
|
||||||
|
worldSettingsPane.isDisable = true
|
||||||
|
directoryPane.isDisable = true
|
||||||
|
parentPane.isDisable = true
|
||||||
|
startButton.isDisable = true
|
||||||
|
buildButton.text = "Cancel Build"
|
||||||
|
|
||||||
|
@Suppress("OPT_IN_USAGE")
|
||||||
GlobalScope.launch(Dispatchers.Default) {
|
GlobalScope.launch(Dispatchers.Default) {
|
||||||
withContext(Dispatchers.JavaFx){statusBar.text = "Downloading a file..."}
|
|
||||||
progressBar.isVisible = true
|
progressBar.isVisible = true
|
||||||
val download = Download(URL("https://brysonsteck.xyz/pub/a-really-big-file"))
|
var downloads = mapOf(
|
||||||
download.start()
|
"Java 20" to "https://download.java.net/java/GA/jdk20.0.1/b4887098932d415489976708ad6d1a4b/9/GPL/openjdk-20.0.1_linux-x64_bin.tar.gz",
|
||||||
while (download.status() == Download.Status.DOWNLOADING) {
|
"BuildTools" to "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar",
|
||||||
var prog = (download.downloaded.toDouble() / download.contentLength.toDouble())
|
)
|
||||||
// for whatever reason I need to print something to the screen in order for it to work
|
downloads.forEach {
|
||||||
print("")
|
withContext(Dispatchers.JavaFx){statusBar.text = "Downloading ${it.key}..."}
|
||||||
if (prog >= 0.01) {
|
val download = Download(URL(it.value))
|
||||||
withContext(Dispatchers.JavaFx) {progressBar.progress = prog}
|
download.start()
|
||||||
|
while (download.status == Download.Status.DOWNLOADING) {
|
||||||
|
var prog = (download.downloaded.toDouble() / download.contentLength.toDouble())
|
||||||
|
// for whatever reason I need to print something to the screen in order for it to update the progress bar
|
||||||
|
print("")
|
||||||
|
if (prog >= 0.01) {
|
||||||
|
withContext(Dispatchers.JavaFx) {progressBar.progress = prog}
|
||||||
|
}
|
||||||
|
if (!building) download.status = Download.Status.CANCELLED
|
||||||
|
Thread.sleep(300)
|
||||||
}
|
}
|
||||||
Thread.sleep(300)
|
|
||||||
}
|
}
|
||||||
progressBar.isVisible = false
|
progressBar.isVisible = false
|
||||||
withContext(Dispatchers.JavaFx){statusBar.text = "Ready."}
|
withContext(Dispatchers.JavaFx){
|
||||||
|
worldSettingsPane.isDisable = false
|
||||||
|
directoryPane.isDisable = false
|
||||||
|
parentPane.isDisable = false
|
||||||
|
startButton.isDisable = false
|
||||||
|
buildButton.text = "Build Server"
|
||||||
|
statusBar.text = if (building) {"Ready."} else {"Server build cancelled."}
|
||||||
|
building = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,16 +200,39 @@ class PrimaryController {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createDialog() {
|
private fun createDialog(type: String, msg: String, yes: String, no: String) {
|
||||||
|
val resources = this.javaClass.getResource("icons/$type.png")
|
||||||
val dialog = Stage();
|
val dialog = Stage();
|
||||||
dialog.initModality(Modality.APPLICATION_MODAL);
|
dialog.initModality(Modality.APPLICATION_MODAL);
|
||||||
val dialogScene = Scene(App().loadFXML("dialog"), 300.0, 200.0);
|
val scenePane = Pane()
|
||||||
|
val dialogScene = Scene(scenePane, 400.0, 150.0);
|
||||||
|
val imagePane = Pane()
|
||||||
|
val icon = Image("$resources")
|
||||||
|
imagePane.layoutX = 14.0
|
||||||
|
imagePane.layoutY = 14.0
|
||||||
|
imagePane.scaleX = 0.7
|
||||||
|
imagePane.scaleY = 0.7
|
||||||
|
imagePane.children.add(ImageView(icon))
|
||||||
|
val label = Label(msg)
|
||||||
|
label.layoutX = 115.0
|
||||||
|
label.layoutY = 40.0
|
||||||
|
val buttonBar = ButtonBar()
|
||||||
|
buttonBar.padding = Insets(10.0, 10.0, 10.0, 10.0)
|
||||||
|
buttonBar.layoutX = 0.0
|
||||||
|
buttonBar.layoutY = 107.0
|
||||||
|
buttonBar.prefWidth = 400.0
|
||||||
|
val noButton = Button(no)
|
||||||
|
val yesButton = Button(yes)
|
||||||
|
yesButton.isDefaultButton = true
|
||||||
|
buttonBar.buttons.add(noButton)
|
||||||
|
buttonBar.buttons.add(yesButton)
|
||||||
|
scenePane.children.addAll(imagePane, label, buttonBar)
|
||||||
dialog.setScene(dialogScene);
|
dialog.setScene(dialogScene);
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadServerDir(dir: String): Boolean {
|
private fun loadServerDir(dir: String): Boolean {
|
||||||
createDialog()
|
createDialog("info", "There is no server in this directory.\nCreate one?", "Yes", "No")
|
||||||
var directory = dir
|
var directory = dir
|
||||||
var hasServer = false
|
var hasServer = false
|
||||||
if (!File(directory).isDirectory) {
|
if (!File(directory).isDirectory) {
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<?import javafx.geometry.Insets?>
|
|
||||||
<?import javafx.scene.control.Button?>
|
|
||||||
<?import javafx.scene.control.ButtonBar?>
|
|
||||||
<?import javafx.scene.control.Label?>
|
|
||||||
<?import javafx.scene.layout.Pane?>
|
|
||||||
|
|
||||||
|
|
||||||
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1">
|
|
||||||
<children>
|
|
||||||
<Pane fx:id="iconPane" layoutX="14.0" layoutY="14.0" prefHeight="82.0" prefWidth="82.0" />
|
|
||||||
<Label fx:id="dialogLabel" layoutX="115.0" layoutY="40.0" text="Dialog Box" />
|
|
||||||
<ButtonBar layoutY="157.0" prefHeight="43.0" prefWidth="400.0">
|
|
||||||
<buttons>
|
|
||||||
<Button fx:id="otherButton" mnemonicParsing="false" text="Decline" />
|
|
||||||
<Button fx:id="defaultButton" defaultButton="true" mnemonicParsing="false" text="Accept" />
|
|
||||||
</buttons>
|
|
||||||
<padding>
|
|
||||||
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
|
||||||
</padding>
|
|
||||||
</ButtonBar>
|
|
||||||
</children>
|
|
||||||
</Pane>
|
|
|
@ -19,9 +19,9 @@
|
||||||
<?import javafx.scene.layout.Pane?>
|
<?import javafx.scene.layout.Pane?>
|
||||||
<?import javafx.scene.text.Font?>
|
<?import javafx.scene.text.Font?>
|
||||||
|
|
||||||
<Pane fx:id="primary" maxHeight="900.0" maxWidth="1500.0" minHeight="620.0" minWidth="963.0" prefHeight="708.0" prefWidth="963.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="xyz.brysonsteck.serverfordummies.PrimaryController">
|
<Pane fx:id="primary" maxHeight="713.0" maxWidth="963.0" minHeight="713.0" minWidth="963.0" prefHeight="713.0" prefWidth="963.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="xyz.brysonsteck.serverfordummies.PrimaryController">
|
||||||
<children>
|
<children>
|
||||||
<HBox prefHeight="39.0" prefWidth="963.0">
|
<HBox fx:id="directoryPane" prefHeight="39.0" prefWidth="963.0">
|
||||||
<children>
|
<children>
|
||||||
<Button id="openFile" fx:id="chooseDirectoryButton" lineSpacing="10.0" mnemonicParsing="false" onMouseClicked="#onDirectoryButtonClick" text="Choose Directory...">
|
<Button id="openFile" fx:id="chooseDirectoryButton" lineSpacing="10.0" mnemonicParsing="false" onMouseClicked="#onDirectoryButtonClick" text="Choose Directory...">
|
||||||
<opaqueInsets>
|
<opaqueInsets>
|
||||||
|
@ -220,8 +220,8 @@
|
||||||
</Pane>
|
</Pane>
|
||||||
<ButtonBar fx:id="buttonBar" disable="true" layoutY="635.0" prefHeight="40.0" prefWidth="963.0">
|
<ButtonBar fx:id="buttonBar" disable="true" layoutY="635.0" prefHeight="40.0" prefWidth="963.0">
|
||||||
<buttons>
|
<buttons>
|
||||||
<Button mnemonicParsing="false" onMouseClicked="#onBuild" text="Build Server" />
|
<Button fx:id="buildButton" mnemonicParsing="false" onMouseClicked="#onBuild" text="Build Server" />
|
||||||
<Button defaultButton="true" mnemonicParsing="false" text="Start Server" />
|
<Button fx:id="startButton" defaultButton="true" mnemonicParsing="false" prefWidth="120.0" text="Start Server" />
|
||||||
</buttons>
|
</buttons>
|
||||||
<padding>
|
<padding>
|
||||||
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0" />
|
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0" />
|
||||||
|
|
Loading…
Add table
Reference in a new issue