Browse Source

init

master
aligator 1 year ago
commit
ff6bcfe3bb

+ 44
- 0
build.gradle View File

@@ -0,0 +1,44 @@
1
+plugins {
2
+    id 'org.jetbrains.kotlin.jvm' version '1.2.51'
3
+    id 'application'
4
+}
5
+
6
+group 'de.jcode.colortest'
7
+version '1.0-SNAPSHOT'
8
+
9
+mainClassName = 'de.jcode.colortest.MainKt'
10
+
11
+repositories {
12
+    mavenCentral()
13
+}
14
+
15
+dependencies {
16
+    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
17
+    compile group: 'no.tornado', name: 'tornadofx', version: '1.7.16'
18
+}
19
+
20
+compileKotlin {
21
+    kotlinOptions.jvmTarget = "1.8"
22
+}
23
+compileTestKotlin {
24
+    kotlinOptions.jvmTarget = "1.8"
25
+}
26
+
27
+run {
28
+    standardInput = System.in
29
+}
30
+
31
+jar {
32
+    manifest {
33
+        attributes(
34
+                'Main-Class': mainClassName
35
+        )
36
+    }
37
+
38
+    // simple fat jar
39
+    from {
40
+        configurations.compile.collect {
41
+            it.isDirectory() ? it : zipTree(it)
42
+        }
43
+    }
44
+}

+ 2
- 0
settings.gradle View File

@@ -0,0 +1,2 @@
1
+rootProject.name = 'ColorTest'
2
+

+ 12
- 0
src/main/kotlin/Main.kt View File

@@ -0,0 +1,12 @@
1
+package de.jcode.colortest
2
+
3
+import de.jcode.colortest.style.Styles
4
+import de.jcode.colortest.views.MainView
5
+import javafx.application.Application
6
+import tornadofx.*
7
+
8
+class TornadoFXApp : App(MainView::class, Styles::class)
9
+
10
+fun main(args: Array<String>) {
11
+    Application.launch(TornadoFXApp::class.java, *args)
12
+}

+ 12
- 0
src/main/kotlin/controllers/MainAppController.kt View File

@@ -0,0 +1,12 @@
1
+package de.jcode.colortest.controllers
2
+
3
+import de.jcode.colortest.models.Theme
4
+import tornadofx.*
5
+
6
+class MainAppController : Controller() {
7
+    val theme = Theme(false)
8
+
9
+    fun toggleTheme() {
10
+        theme.darkTheme = theme.darkTheme.not()
11
+    }
12
+}

+ 27
- 0
src/main/kotlin/models/ThemeModel.kt View File

@@ -0,0 +1,27 @@
1
+package de.jcode.colortest.models
2
+
3
+import javafx.beans.property.SimpleBooleanProperty
4
+import tornadofx.*
5
+import java.util.*
6
+
7
+class Theme(darkIsDefault: Boolean) {
8
+    val id = UUID.randomUUID()
9
+
10
+    val darkThemeProperty = SimpleBooleanProperty(darkIsDefault)
11
+    var darkTheme: Boolean by darkThemeProperty
12
+
13
+    override fun equals(other: Any?): Boolean {
14
+        if (this === other) return true
15
+        if (other?.javaClass != javaClass) return false
16
+
17
+        other as Theme
18
+
19
+        if (id != other.id) return false
20
+
21
+        return true
22
+    }
23
+
24
+    override fun hashCode(): Int {
25
+        return id.hashCode()
26
+    }
27
+}

+ 23
- 0
src/main/kotlin/style/Styles.kt View File

@@ -0,0 +1,23 @@
1
+package de.jcode.colortest.style
2
+
3
+import javafx.scene.paint.Color
4
+import tornadofx.*
5
+
6
+class Styles : Stylesheet() {
7
+    companion object {
8
+        val lightTheme by cssclass()
9
+        val darkTheme by cssclass()
10
+    }
11
+
12
+    init {
13
+        lightTheme {
14
+            padding = box(20.px)
15
+            backgroundColor += Color.WHITE
16
+        }
17
+
18
+        darkTheme {
19
+            padding = box(20.px)
20
+            backgroundColor += Color.BLACK
21
+        }
22
+    }
23
+}

+ 21
- 0
src/main/kotlin/views/MainView.kt View File

@@ -0,0 +1,21 @@
1
+package de.jcode.colortest.views
2
+
3
+import com.sun.javafx.css.CssError
4
+import de.jcode.colortest.controllers.MainAppController
5
+import de.jcode.colortest.main
6
+import de.jcode.colortest.style.Styles
7
+import javafx.scene.Parent
8
+import tornadofx.*
9
+
10
+class MainView : View("Color Test") {
11
+    val mainApp: MainAppController by inject()
12
+
13
+    override val root = vbox {
14
+        toggleClass(Styles.darkTheme, mainApp.theme.darkThemeProperty)
15
+        toggleClass(Styles.lightTheme, mainApp.theme.darkThemeProperty.not())
16
+
17
+        button("Press me") {
18
+            action { mainApp.toggleTheme() }
19
+        }
20
+    }
21
+}

Loading…
Cancel
Save