使用javafx框架tornadofx制作的成语字典小工具

2019-11-12 11:08:24 浏览数 (3)

使用borderpane布局,left部分包括一个用于输入查寻关键字的文本框、查询清空按键和26个英文字母按钮,center部分一个tableview,显示查寻结果;bottom采用label显示操作信息。

使用https://gitee.com/xwintop/xJavaFxTool 中的数据库

定义字典model:

代码语言:javascript复制
class Idiom {
    val wordProperty = stringProperty("")
    var word by wordProperty

    val pinyinProperty = stringProperty()
    var pinyin by pinyinProperty

    val explanationProperty = stringProperty()
    var explanation by explanationProperty

    val derivationProperty = stringProperty()
    var derivation by derivationProperty


    val exampleProperty = stringProperty()
    var example by exampleProperty
}

class IdiomViewModel : ItemViewModel<Idiom>() {
    val word = bind(defaultValue = "") { item?.wordProperty }
    val pinyin = bind { item?.pinyinProperty }
    val explanation = bind { item?.explanationProperty }
    val derivation = bind { item?.derivationProperty }
    val example = bind { item?.exampleProperty }
}

UI:

代码语言:javascript复制
class IdiomDataTool : View("成语字典") {
    val C: IdiomController by inject()
    val idiomVM: IdiomViewModel by inject()
    val index1 = stringProperty("")
    val index2 = stringProperty("")
    val index3 = stringProperty("")
    val index4 = stringProperty("")
    val selectWord = stringProperty("")
    val tfs = listOf(index1, index2, index3, index4, selectWord)

    override val root = borderpane {
        paddingAll = 10.0
        left = vbox(4) {
            prefWidth = 250.0
            vbox(4) {
                label("模糊查询")
                textfield(selectWord) { promptText = "输入查询的成语字段" }
                hbox(10) {
                    button("查询") {
                        action {
                            C.selectAction(selectWord.value)
                        }
                    }
                    button("清空") {
                        action {
                            C.clearAction(tfs)
                        }
                    }
                }
            }
            flowpane {
                hgap = 4.0
                vgap = 4.0
                "abcdefghijklmnopqrstuvwxyz".toCharArray().forEach {
                    button("$it") {
                        setPrefSize(40.0, 40.0)
                        style {
                            fontSize = 16.px
                        }
                        action {
                            selectWord.value = selectWord.value.plus(it)
                        }
                    }
                }
            }
        }
        center = tableview(C.idioms) {
            column("词目", Idiom::wordProperty).makeEditable()
            column("发音", Idiom::pinyinProperty).makeEditable()
            column("释义", Idiom::explanationProperty).makeEditable()
            column("出处", Idiom::derivationProperty).makeEditable()
            column("示例", Idiom::exampleProperty).makeEditable()
            bindSelected(idiomVM)
            onUserSelect(1) {
                C.msg.value = "查寻到${C.count.value}条记录。${idiomVM.word.value} :${idiomVM.explanation.value}"
//                tooltip(idiomVM.derivation.value)
            }
            smartResize()
        }
        bottom = hbox {
            paddingTop=5.0
            label(C.msg)
        }
    }
}

0 人点赞