Skip to content

Commit

Permalink
fix(dependency): add ScalaFX and JavaFX dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jahrim committed Feb 11, 2023
1 parent 3d3ab98 commit 2321757
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 0 deletions.
18 changes: 18 additions & 0 deletions buildSrc/src/main/kotlin/javafx/JavaFX.kt
@@ -0,0 +1,18 @@
package javafx

import utility.OS
import utility.OS.OSType

/**
* Extension for JavaFX.
*/
object JavaFX {
private val classifiers: Map<OSType, String> = mapOf(
OSType.Linux to "linux",
OSType.Mac to "mac",
OSType.Windows to "win",
)

/** @return the classifier for javafx artifacts. */
fun getClassifier(): String = classifiers.getValue(OS.getType())
}
24 changes: 24 additions & 0 deletions buildSrc/src/main/kotlin/utility/OS.kt
@@ -0,0 +1,24 @@
package utility

/**
* OS utility functions.
*/
object OS {
private val osName = System.getProperty("os.name")

/** Type of operative system. */
public enum class OSType { Linux, Mac, Windows }

/** @return the string identifier of this operative system. */
fun getString(): String = this.osName

/** @return the type of operative system. */
fun getType(): OSType = when {
this.osName.startsWith("Linux") -> OSType.Linux
this.osName.startsWith("Mac") -> OSType.Mac
this.osName.startsWith("Windows") -> OSType.Windows
else -> throw UnsupportedOSError("Could not infer the type of operative system.")
}

private data class UnsupportedOSError(override val message: String) : Error(message)
}
3 changes: 3 additions & 0 deletions chess/build.gradle.kts
@@ -1,4 +1,5 @@
import com.lordcodes.turtle.shellRun
import javafx.JavaFX
import wartremover.WartRemover
import java.util.regex.Pattern

Expand All @@ -17,6 +18,8 @@ dependencies {
implementation(libs.scala)
implementation(libs.bundles.scalafmt)
implementation(libs.vertx)
implementation(libs.scalafx)
libs.bundles.javafx.get().forEach { implementation("${it.module}:${it.version}:${JavaFX.getClassifier()}") }
testImplementation(libs.scalatest)
scalaCompilerPlugins(libs.wartremover)
}
Expand Down
2 changes: 2 additions & 0 deletions chess/src/main/scala/io/github/chess/Main.scala
Expand Up @@ -8,10 +8,12 @@ package io.github.chess

import io.github.chess.controllers.ChessController
import io.github.chess.services.ChessService
import io.github.chess.viewcontroller.ScalaFXHelloWorld
import io.vertx.core.Vertx

/** The main application. */
@main def main() =
val vertx = Vertx.vertx()
val service = ChessService(ChessController(vertx))
vertx.deployVerticle(service)
ScalaFXHelloWorld.main(Array.empty)
@@ -0,0 +1,46 @@
/*
* MIT License
* Copyright (c) 2023 Cesario Jahrim Gabriele & Derevyanchenko Maxim & Felice Mirko & Kentpayeva Madina
*
* Full license description available at: https://github.com/jahrim/PPS-22-chess/blob/master/LICENSE
*/
package io.github.chess.viewcontroller

import scalafx.application.JFXApp3
import scalafx.geometry.Insets
import scalafx.scene.Scene
import scalafx.scene.effect.DropShadow
import scalafx.scene.layout.HBox
import scalafx.scene.paint.Color._
import scalafx.scene.paint._
import scalafx.scene.text.Text

object ScalaFXHelloWorld extends JFXApp3:
override def start(): Unit =
stage = new JFXApp3.PrimaryStage:
// initStyle(StageStyle.Unified)
title = "ScalaFX Hello World"
scene = new Scene:
fill = Color.rgb(38, 38, 38)
content = new HBox:
padding = Insets(50, 80, 50, 80)
children = Seq(
new Text {
text = "Scala"
style = "-fx-font: normal bold 100pt sans-serif"
fill = new LinearGradient(endX = 0, stops = Stops(Red, DarkRed))
},
new Text {
text = "FX"
style = "-fx-font: italic bold 100pt sans-serif"
fill = new LinearGradient(
endX = 0,
stops = Stops(White, DarkGray)
)
effect = new DropShadow {
color = DarkGray
radius = 15
spread = 0.25
}
}
)
11 changes: 11 additions & 0 deletions gradle/libs.versions.toml
Expand Up @@ -6,6 +6,8 @@ scalafmt-version = "3.7.1"
wartremover-version = "3.0.9"
kotlin-qa-version = "0.2.1"
vertx-version = "4.3.7"
scalafx-version = "16.0.0-R24"
javafx-version = "16"
# insert the versions of the dependencies here...

[libraries]
Expand All @@ -15,10 +17,19 @@ scalafmt-cli = { module = "org.scalameta:scalafmt-cli_2.13", version.ref = "scal
scalafmt-config = { module = "org.scalameta:scalafmt-config_2.13", version.ref = "scalafmt-version" }
wartremover = { module = "org.wartremover:wartremover_3.2.2", version.ref = "wartremover-version" }
vertx = { module = "io.vertx:vertx-core", version.ref = "vertx-version" }
scalafx = { module = "org.scalafx:scalafx_3", version.ref = "scalafx-version" }
javafx-base = { module = "org.openjfx:javafx-base", version.ref = "javafx-version" }
javafx-controls = { module = "org.openjfx:javafx-controls", version.ref = "javafx-version" }
javafx-fxml = { module = "org.openjfx:javafx-fxml", version.ref = "javafx-version" }
javafx-graphics = { module = "org.openjfx:javafx-graphics", version.ref = "javafx-version" }
javafx-media = { module = "org.openjfx:javafx-media", version.ref = "javafx-version" }
javafx-swing = { module = "org.openjfx:javafx-swing", version.ref = "javafx-version" }
javafx-web = { module = "org.openjfx:javafx-web", version.ref = "javafx-version" }
# insert the dependencies here...

[bundles]
scalafmt = [ "scalafmt-cli", "scalafmt-config" ]
javafx = [ "javafx-base", "javafx-controls", "javafx-fxml", "javafx-graphics", "javafx-media", "javafx-swing", "javafx-web" ]
# insert groups of dependencies here...

[plugins]
Expand Down

0 comments on commit 2321757

Please sign in to comment.