From 736a8c1b308f9e0c9e42b343206cb6797e528355 Mon Sep 17 00:00:00 2001 From: huangyuhui Date: Thu, 3 Aug 2017 23:54:15 +0800 Subject: [PATCH] FXML for decorator --- .../java/org/jackhuang/hmcl/ui/Controllers.kt | 6 +- .../java/org/jackhuang/hmcl/ui/Decorator.kt | 366 ++++++++---------- .../java/org/jackhuang/hmcl/ui/FXUtils.kt | 24 +- .../org/jackhuang/hmcl/ui/MainController.kt | 83 ---- .../hmcl/ui/animation/TransitionHandler.kt | 22 +- .../hmcl/ui/download/InstallTypePage.kt | 4 +- .../hmcl/ui/wizard/DefaultWizardDisplayer.kt | 1 + .../assets/css/jfoenix-components.css | 2 +- .../main/resources/assets/fxml/decorator.fxml | 56 +++ HMCL/src/main/resources/assets/fxml/main.fxml | 38 +- .../main/resources/assets/fxml/version.fxml | 49 +-- .../main/resources/assets/fxml/wizard.fxml | 2 +- .../java/org/jackhuang/hmcl/task/Scheduler.kt | 5 +- 13 files changed, 336 insertions(+), 322 deletions(-) create mode 100644 HMCL/src/main/resources/assets/fxml/decorator.fxml diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.kt b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.kt index 095fe61c9..5be1da9ec 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.kt +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.kt @@ -46,9 +46,7 @@ object Controllers { decorator.isCustomMaximize = false scene = Scene(decorator, 800.0, 480.0) - scene.stylesheets.addAll(Controllers::class.java.getResource("/css/jfoenix-design.css").toExternalForm(), - Controllers::class.java.getResource("/assets/css/jfoenix-components.css").toExternalForm(), - Controllers::class.java.getResource("/assets/css/jfoenix-main-demo.css").toExternalForm()) + scene.stylesheets.addAll(*stylesheets) stage.minWidth = 800.0 stage.maxWidth = 800.0 stage.maxHeight = 480.0 @@ -56,7 +54,7 @@ object Controllers { } fun navigate(node: Node?) { - mainController.setContentPage(node) + //mainController.setContentPage(node) } private fun loadPane(s: String): T = FXMLLoader(Controllers::class.java.getResource("/assets/fxml/$s.fxml")).load() diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Decorator.kt b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Decorator.kt index 186b49c47..0412adb06 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Decorator.kt +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Decorator.kt @@ -25,14 +25,12 @@ import javafx.beans.property.BooleanProperty import javafx.beans.property.ObjectProperty import javafx.beans.property.SimpleBooleanProperty import javafx.beans.property.SimpleObjectProperty +import javafx.fxml.FXML import javafx.geometry.BoundingBox import javafx.geometry.Bounds import javafx.geometry.Insets -import javafx.geometry.Pos import javafx.scene.Cursor import javafx.scene.Node -import javafx.scene.control.Button -import javafx.scene.control.Label import javafx.scene.control.Tooltip import javafx.scene.input.MouseEvent import javafx.scene.layout.* @@ -41,9 +39,8 @@ import javafx.scene.shape.Rectangle import javafx.stage.Screen import javafx.stage.Stage import javafx.stage.StageStyle -import java.util.ArrayList -class Decorator @JvmOverloads constructor(private val primaryStage: Stage, node: Node, max: Boolean = true, min: Boolean = true) : VBox() { +class Decorator @JvmOverloads constructor(private val primaryStage: Stage, node: Node, private val max: Boolean = true, min: Boolean = true) : VBox() { private var xOffset: Double = 0.0 private var yOffset: Double = 0.0 private var newX: Double = 0.0 @@ -53,126 +50,58 @@ class Decorator @JvmOverloads constructor(private val primaryStage: Stage, node: private var allowMove: Boolean = false private var isDragging: Boolean = false private var windowDecoratorAnimation: Timeline? = null - private val contentPlaceHolder: StackPane - private val titleContainer: BorderPane + @FXML lateinit var contentPlaceHolder: StackPane + @FXML lateinit var titleContainer: BorderPane + @FXML lateinit var buttonsContainer: HBox private val onCloseButtonAction: ObjectProperty private val customMaximize: BooleanProperty private var maximized: Boolean = false private var originalBox: BoundingBox? = null private var maximizedBox: BoundingBox? = null - private val btnMax: JFXButton + @FXML lateinit var btnMin: JFXButton + @FXML lateinit var btnMax: JFXButton + @FXML lateinit var btnClose: JFXButton + private val minus: SVGGlyph + private val resizeMax: SVGGlyph + private val resizeMin: SVGGlyph + private val close: SVGGlyph init { + loadFXML("/assets/fxml/decorator.fxml") + this.xOffset = 0.0 this.yOffset = 0.0 this.allowMove = false this.isDragging = false - this.contentPlaceHolder = StackPane() this.onCloseButtonAction = SimpleObjectProperty(Runnable { this.primaryStage.close() }) this.customMaximize = SimpleBooleanProperty(false) this.maximized = false this.primaryStage.initStyle(StageStyle.UNDECORATED) - this.isPickOnBounds = false - this.styleClass.add("jfx-decorator") - val minus = SVGGlyph(0, "MINUS", "M804.571 420.571v109.714q0 22.857-16 38.857t-38.857 16h-694.857q-22.857 0-38.857-16t-16-38.857v-109.714q0-22.857 16-38.857t38.857-16h694.857q22.857 0 38.857 16t16 38.857z", Color.WHITE) + minus = SVGGlyph(0, "MINUS", "M804.571 420.571v109.714q0 22.857-16 38.857t-38.857 16h-694.857q-22.857 0-38.857-16t-16-38.857v-109.714q0-22.857 16-38.857t38.857-16h694.857q22.857 0 38.857 16t16 38.857z", Color.WHITE) minus.setSize(12.0, 2.0) minus.translateY = 4.0 - val resizeMax = SVGGlyph(0, "RESIZE_MAX", "M726 810v-596h-428v596h428zM726 44q34 0 59 25t25 59v768q0 34-25 60t-59 26h-428q-34 0-59-26t-25-60v-768q0-34 25-60t59-26z", Color.WHITE) + resizeMax = SVGGlyph(0, "RESIZE_MAX", "M726 810v-596h-428v596h428zM726 44q34 0 59 25t25 59v768q0 34-25 60t-59 26h-428q-34 0-59-26t-25-60v-768q0-34 25-60t59-26z", Color.WHITE) resizeMax.setSize(12.0, 12.0) - val resizeMin = SVGGlyph(0, "RESIZE_MIN", "M80.842 943.158v-377.264h565.894v377.264h-565.894zM0 404.21v619.79h727.578v-619.79h-727.578zM377.264 161.684h565.894v377.264h-134.736v80.842h215.578v-619.79h-727.578v323.37h80.842v-161.686z", Color.WHITE) + resizeMin = SVGGlyph(0, "RESIZE_MIN", "M80.842 943.158v-377.264h565.894v377.264h-565.894zM0 404.21v619.79h727.578v-619.79h-727.578zM377.264 161.684h565.894v377.264h-134.736v80.842h215.578v-619.79h-727.578v323.37h80.842v-161.686z", Color.WHITE) resizeMin.setSize(12.0, 12.0) - val close = SVGGlyph(0, "CLOSE", "M810 274l-238 238 238 238-60 60-238-238-238 238-60-60 238-238-238-238 60-60 238 238 238-238z", Color.WHITE) + close = SVGGlyph(0, "CLOSE", "M810 274l-238 238 238 238-60 60-238-238-238 238-60-60 238-238-238-238 60-60 238 238 238-238z", Color.WHITE) close.setSize(12.0, 12.0) - val btnClose = JFXButton() - btnClose.styleClass.add("jfx-decorator-button") - btnClose.cursor = Cursor.HAND - btnClose.setOnAction { action -> (this.onCloseButtonAction.get() as Runnable).run() } btnClose.graphic = close - btnClose.ripplerFill = Color.WHITE - val btnMin = JFXButton() - btnMin.styleClass.add("jfx-decorator-button") - btnMin.cursor = Cursor.HAND - btnMin.setOnAction { action -> this.primaryStage.isIconified = true } btnMin.graphic = minus - btnMin.ripplerFill = Color.WHITE - this.btnMax = JFXButton() - this.btnMax.styleClass.add("jfx-decorator-button") - this.btnMax.cursor = Cursor.HAND - this.btnMax.ripplerFill = Color.WHITE - this.btnMax.setOnAction { action -> - if (!this.isCustomMaximize) { - this.primaryStage.isMaximized = !this.primaryStage.isMaximized - this.maximized = this.primaryStage.isMaximized - if (this.primaryStage.isMaximized) { - this.btnMax.graphic = resizeMin - this.btnMax.tooltip = Tooltip("Restore Down") - } else { - this.btnMax.graphic = resizeMax - this.btnMax.tooltip = Tooltip("Maximize") - } - } else { - if (!this.maximized) { - this.originalBox = BoundingBox(primaryStage.x, primaryStage.y, primaryStage.width, primaryStage.height) - val screen = Screen.getScreensForRectangle(primaryStage.x, primaryStage.y, primaryStage.width, primaryStage.height)[0] as Screen - val bounds = screen.visualBounds - this.maximizedBox = BoundingBox(bounds.minX, bounds.minY, bounds.width, bounds.height) - primaryStage.x = this.maximizedBox!!.minX - primaryStage.y = this.maximizedBox!!.minY - primaryStage.width = this.maximizedBox!!.width - primaryStage.height = this.maximizedBox!!.height - this.btnMax.graphic = resizeMin - this.btnMax.tooltip = Tooltip("Restore Down") - } else { - primaryStage.x = this.originalBox!!.minX - primaryStage.y = this.originalBox!!.minY - primaryStage.width = this.originalBox!!.width - primaryStage.height = this.originalBox!!.height - this.originalBox = null - this.btnMax.graphic = resizeMax - this.btnMax.tooltip = Tooltip("Maximize") - } - - this.maximized = !this.maximized - } - - } this.btnMax.graphic = resizeMax - titleContainer = BorderPane() - titleContainer.styleClass += "jfx-decorator-buttons-container" - titleContainer.isPickOnBounds = false - val titleWrapper = HBox() - titleWrapper.style += "-fx-padding: 15;" - titleWrapper.alignment = Pos.CENTER_LEFT - val title = Label("Hello Minecraft! Launcher") - title.alignment = Pos.CENTER_LEFT - title.style += "--fx-background-color: transparent; -fx-text-fill: white; -fx-font-size: 15px;" - title.isMouseTransparent = false - titleWrapper.children.setAll(title) - titleContainer.left = titleWrapper - val buttonsContainer = HBox() - buttonsContainer.styleClass.add("jfx-decorator-buttons-container") buttonsContainer.background = Background(*arrayOf(BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY))) - buttonsContainer.padding = Insets(4.0) - buttonsContainer.alignment = Pos.CENTER_RIGHT titleContainer.addEventHandler(MouseEvent.MOUSE_CLICKED) { mouseEvent -> if (mouseEvent.clickCount == 2) { this.btnMax.fire() } } - val btns = ArrayList