From 2af617d576bf609eba0519c0334b4f4713ba60a9 Mon Sep 17 00:00:00 2001 From: Andreas Billmann Date: Mon, 10 Oct 2016 23:09:31 +0200 Subject: [PATCH] JavaFX client for converting SmartCSV.fx config files --- build.gradle | 5 +- .../smartcsv/fx/converter/ConverterFX.kt | 120 ++++++++++++++++++ 2 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/ninja/javafx/smartcsv/fx/converter/ConverterFX.kt diff --git a/build.gradle b/build.gradle index 71cb42e..fcbea61 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'ninja.javafx' -version '1.0-SNAPSHOT' +version '1.1-SNAPSHOT' buildscript { ext.kotlin_version = '1.0.4' @@ -15,7 +15,7 @@ buildscript { apply plugin: 'kotlin' apply plugin: 'application' -mainClassName = 'ninja.javafx.smartcsv.fx.converter.ConverterKt' +mainClassName = 'ninja.javafx.smartcsv.fx.converter.ConverterFX' repositories { mavenCentral() @@ -25,4 +25,5 @@ repositories { dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile 'com.beust:klaxon:0.24' + compile 'no.tornado:tornadofx:1.5.6' } diff --git a/src/main/kotlin/ninja/javafx/smartcsv/fx/converter/ConverterFX.kt b/src/main/kotlin/ninja/javafx/smartcsv/fx/converter/ConverterFX.kt new file mode 100644 index 0000000..f2ba0d3 --- /dev/null +++ b/src/main/kotlin/ninja/javafx/smartcsv/fx/converter/ConverterFX.kt @@ -0,0 +1,120 @@ +/* + The MIT License (MIT) + ----------------------------------------------------------------------------- + Copyright (c) 2016 javafx.ninja + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ +package ninja.javafx.smartcsv.fx.converter + +import javafx.geometry.Insets +import javafx.scene.control.Label +import javafx.scene.layout.GridPane +import javafx.scene.layout.Priority +import javafx.stage.FileChooser +import tornadofx.* + +class ConverterFX : App() { + override val primaryView = FileInputView::class + + +} + +class FileInput { + var name by property() + fun nameProperty() = getProperty(FileInput::name) +} + +class FileInputView : View("SmartCSV.fx Converter") { + override val root = GridPane() + private val fileinput = FileInput() + private val fileChooser = FileChooser() + private val state = Label() + + val controller: FileInputController by inject() + + + init { + primaryStage.width = 600.0 + primaryStage.height = 120.0 + + fileChooser.title = "Open old config file" + fileChooser.extensionFilters.addAll(FileChooser.ExtensionFilter("JSON Files", "*.json")) + + with(root) { + + padding = Insets(8.0, 8.0, 8.0, 8.0) + + root.vgap = 8.0 + root.hgap = 8.0 + + textfield() { + isEditable = false + isDisable = false + isMouseTransparent = true + isFocusTraversable = false + useMaxWidth = true + bind(fileinput.nameProperty()) + gridpaneConstraints { + columnRowIndex(0, 0) + hGrow = Priority.ALWAYS + } + } + + button("Select File") { + gridpaneConstraints { + columnRowIndex(1, 0) + } + setOnAction { + state.text = null + val selectedFile = fileChooser.showOpenDialog(primaryStage) + if (selectedFile != null) { + fileinput.name = selectedFile.absolutePath + } + } + + } + + this += state + state.gridpaneConstraints { + columnRowIndex(0, 1) + } + + + button("Convert") { + gridpaneConstraints { + columnRowIndex(1, 1) + } + setOnAction { + controller.convert(fileinput.name) + state.text = "converted ${fileinput.name}" + fileinput.name = null + } + disableProperty().bind(fileinput.nameProperty().isNull) + } + + + } + } +} + +class FileInputController : Controller() { + + fun convert(inputValue: String) { + Converter(inputValue).convert() + println("Converted $inputValue!") + } +} \ No newline at end of file