Skip to content
Snippets Groups Projects
Commit ad822eb2 authored by Kaj Koivunen's avatar Kaj Koivunen :coffee:
Browse files

ohjelmalogiikka pois ui-luokista ja pääluokkaan

parent e397038d
No related branches found
No related tags found
No related merge requests found
......@@ -54,6 +54,7 @@ class ReaderTab : View("Reader") {
*/
@Suppress("unused") // IDEA doesn't detect uses of these functions since they are called from JS in the WebView
class WebViewCallback {
/***/
fun test(message: String) {
println(message)
}
......@@ -69,7 +70,7 @@ class DictionaryTab : View("Kanji Dictionary") {
/** TornadoFX root */
override val root = vbox {
(app as Ronove).cellSelection!!.addListener(fun(_, _, newSelection) {
(app as Ronove).cellSelection.addListener(fun(_, _, newSelection) {
if (newSelection != null) {
getCharacters(newSelection.original)
}
......
package guru.kake.ronove
import javafx.beans.property.ReadOnlyObjectProperty
import javafx.beans.property.SimpleIntegerProperty
import tornadofx.*
/**
......@@ -9,12 +10,26 @@ import tornadofx.*
class Ronove: App(MainView::class, RonoveStylesheet::class) {
/** Current project data */
var project = Project()
/** Property for listening to changes on selected table view cell */
var cellSelection: ReadOnlyObjectProperty<Line>? = null
var cellSelection: ReadOnlyObjectProperty<Line> = Line().toProperty()
/** Currently selected page */
var currentPage = SimpleIntegerProperty(0)
/** Amount of pages in project */
var pageCount = project.pages.size.toProperty()
/**
* Change current page
* @param page page to change to
*/
fun changePage(page: Int) {
currentPage.value = page
}
}
/** Program main */
fun main(args: Array<String>) {
launch<Ronove>(args)
}
}
\ No newline at end of file
......@@ -98,7 +98,6 @@ class MainView : View("Ronove") {
init {
primaryStage.icons.add(Image("/ronove128.png"))
//openInternalWindow<SplashScreen>(params = mapOf(SplashScreen::project to (app as Ronove).project))
SplashScreen((app as Ronove).project).openModal(stageStyle = StageStyle.UTILITY, block = true,
modality = Modality.APPLICATION_MODAL, owner = primaryStage)
}
......
package guru.kake.ronove
import javafx.application.Platform
import javafx.beans.property.SimpleIntegerProperty
import javafx.event.EventHandler
import javafx.scene.control.*
import javafx.scene.input.KeyEvent
......@@ -11,22 +10,16 @@ import tornadofx.*
* The central view of the main window used to shew the table of the translation data
*/
class TranslationPageView : View() {
private val project = (app as Ronove).project
init {
PageJumpMenu.pageView = this
}
private lateinit var tableView: TableView<Line>
private lateinit var pageJumps: PageJumpMenu
/** Property for current page for listening to page changes */
private var currentPage = SimpleIntegerProperty(0)
/** Property for count of page for listening to changes */
var pageCount = project.pages.size.toProperty()
/** TornadoFX root */
override val root = borderpane {
tableView = tableview(project.pages[0].lines.asObservable()) {
tableView = tableview {
isEditable = true
column("Original", Line::original).makeEditable()
......@@ -60,24 +53,16 @@ class TranslationPageView : View() {
init {(app as Ronove).cellSelection = tableView.selectionModel.selectedItemProperty()}
/**
* Change the page to edit and load the page to the view
* @param page Page to change to
*/
fun changePage(page: Int) {
currentPage.value = page
}
/**
* Loads the currently selected page to the table view
*/
private fun refresh() {
tableView.items = project.pages[currentPage.value].lines.asObservable()
tableView.items = (app as Ronove).project.pages[(app as Ronove).currentPage.value].lines.asObservable()
}
init {
currentPage.addListener { _ -> refresh(); pageJumps.refresh()}
pageCount.addListener { _ -> pageJumps.refresh()}
(app as Ronove).currentPage.addListener { _ -> refresh(); pageJumps.refresh()}
(app as Ronove).pageCount.addListener { _ -> pageJumps.refresh()}
}
}
......@@ -94,19 +79,18 @@ class PageJumpMenu : Fragment() {
*/
fun refresh() { replaceWith<PageJumpMenu>() }
private fun changePage(page: Int) = pageView.changePage(page)
/** TornadoFX root */
override val root = hbox {
addClass(RonoveStylesheet.vcenter)
button("<<") {action {changePage(1)}}
button("<<") {action {(app as Ronove).changePage(1)}}
button("<")
for (i in 1..5) {
button("$i") {action {changePage(i)}}
button("$i") {action {(app as Ronove).changePage(i)}}
}
menubutton("...") {
for (i in 1..pageView.pageCount.get()) {
item("$i") {action {changePage(i)}}
for (i in 1..(app as Ronove).pageCount.get()) {
item("$i") {action {(app as Ronove).changePage(i)}}
}
}
button(">")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment