Skip to content

Commit

Permalink
Improved appearance and updated localisation
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorFilimonov committed May 19, 2024
1 parent 09aa13d commit 330996c
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import automaton.constructor.controller.algorithms.ConversionToCFGController
import automaton.constructor.controller.algorithms.HellingsAlgoController
import automaton.constructor.model.automaton.Automaton
import automaton.constructor.model.automaton.PushdownAutomaton
import automaton.constructor.utils.I18N
import tornadofx.Controller

class AlgorithmsController(
Expand All @@ -13,7 +14,7 @@ class AlgorithmsController(
): Controller() {
fun convertToCFG() {
if (openedAutomaton !is PushdownAutomaton || openedAutomaton.stacks.size > 1) {
tornadofx.error("Conversion is done only for pushdown automatons with a single stack!")
tornadofx.error(I18N.messages.getString("CFGView.Error"))
return
}
ConversionToCFGController(openedAutomaton).convertToCFG()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package automaton.constructor.controller.algorithms
import automaton.constructor.model.automaton.PushdownAutomaton
import automaton.constructor.model.data.createAutomaton
import automaton.constructor.model.data.getData
import automaton.constructor.utils.I18N
import automaton.constructor.view.algorithms.CFGView
import tornadofx.Controller

Expand All @@ -12,6 +13,7 @@ class ConversionToCFGController(private val openedAutomaton: PushdownAutomaton):
val conversionToCFGWindow = find<CFGView>(mapOf(
CFGView::grammar to automatonCopy.convertToCFG()
))
conversionToCFGWindow.title = I18N.messages.getString("CFGView.Title")
conversionToCFGWindow.openWindow()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import automaton.constructor.controller.LayoutController
import automaton.constructor.model.automaton.Automaton
import automaton.constructor.model.automaton.FiniteAutomaton
import automaton.constructor.model.element.*
import automaton.constructor.utils.I18N
import automaton.constructor.view.algorithms.CFGView
import automaton.constructor.view.algorithms.HellingsAlgoExecutionView
import automaton.constructor.view.algorithms.HellingsAlgoGrammarView
Expand All @@ -27,16 +28,19 @@ class HellingsAlgoController(
var grammar: ContextFreeGrammar? = null

fun getGrammar() {
find<HellingsAlgoGrammarView>(mapOf(HellingsAlgoGrammarView::controller to this)).openWindow()
find<HellingsAlgoGrammarView>(mapOf(HellingsAlgoGrammarView::controller to this)).apply {
title = I18N.messages.getString("HellingsAlgorithm.Grammar.Title")
}.openWindow()
}

fun getInputGraph() {
val hellingsAlgoGraphWindow = find<HellingsAlgoGraphView>(mapOf(
find<HellingsAlgoGraphView>(mapOf(
HellingsAlgoGraphView::hellingsAlgoController to this,
HellingsAlgoGraphView::fileController to fileController,
HellingsAlgoGraphView::layoutController to layoutController
))
hellingsAlgoGraphWindow.openWindow()
)).apply {
title = I18N.messages.getString("HellingsAlgorithm.Graph.Title")
}.openWindow()
}

fun execute(graph: FiniteAutomaton) {
Expand All @@ -55,11 +59,13 @@ class HellingsAlgoController(
}
}

find<CFGView>(mapOf(CFGView::grammar to grammar)).openWindow()
find<CFGView>(mapOf(CFGView::grammar to grammar)).apply{
title = I18N.messages.getString("CFGView.Title")
}.openWindow()
val hellingsAlgoExecutionWindow = find<HellingsAlgoExecutionView>(mapOf(
HellingsAlgoExecutionView::m to m,
HellingsAlgoExecutionView::r to r
))
)).apply { title = I18N.messages.getString("HellingsAlgorithm.Execution.Title") }
hellingsAlgoExecutionWindow.openWindow()

hellingsAlgoExecutionWindow.nextIterationButton.action {
Expand Down Expand Up @@ -110,7 +116,8 @@ class HellingsAlgoController(
}
} while (rToAdd.isNotEmpty())
if (m.isEmpty()) {
hellingsAlgoExecutionWindow.nextIterationButton.text = "Close"
hellingsAlgoExecutionWindow.nextIterationButton.text = I18N.messages.getString(
"HellingsAlgorithm.Execution.Close")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import automaton.constructor.model.automaton.Automaton
import automaton.constructor.model.element.AutomatonVertex
import automaton.constructor.model.element.BuildingBlock
import automaton.constructor.model.element.Transition
import automaton.constructor.utils.I18N
import automaton.constructor.utils.hoverableTooltip
import javafx.beans.property.SimpleObjectProperty
import javafx.collections.ListChangeListener
Expand All @@ -19,7 +20,8 @@ class AdjacencyMatrixTransitionMap(

class AutomatonAdjacencyMatrixView(automaton: Automaton, automatonViewContext: AutomatonViewContext
): AutomatonTableView<AdjacencyMatrixTransitionView, AdjacencyMatrixTransitionMap>(automaton, automatonViewContext) {
private val transitionsColumns = TableColumn<AdjacencyMatrixTransitionMap, List<Transition>>("Targets")
private val transitionsColumns = TableColumn<AdjacencyMatrixTransitionMap, List<Transition>>(
I18N.messages.getString("AutomatonAdjacencyMatrixView.Targets"))
init {
transitionsByVertices.addListener(ListChangeListener {
while (it.next()) {
Expand All @@ -32,7 +34,7 @@ class AutomatonAdjacencyMatrixView(automaton: Automaton, automatonViewContext: A
transitionsByVertices.forEach { map ->
automaton.vertices.forEach { map.transitions[it] = SimpleObjectProperty(listOf()) }
}
sourceColumn.text = "Source"
sourceColumn.text = I18N.messages.getString("AutomatonAdjacencyMatrixView.State")
automaton.vertices.forEach { registerVertex(it) }
automaton.transitions.forEach { registerTransition(it) }
table.columns.add(transitionsColumns)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,20 @@ abstract class AutomatonTableView<T: TableTransitionView, M: TransitionMap>(
vbox {
add(table)
hbox {
button("Add state") {
button(I18N.messages.getString("AutomatonTableView.AddState")) {
action {
automaton.addState()
}
style = "-fx-font-size:30"
}
if (automaton.allowsBuildingBlocks) {
button("Add empty building block") {
button(I18N.messages.getString("AutomatonTableView.AddBuildingBlock")) {
action {
automaton.addBuildingBlock()
}
style = "-fx-font-size:30"
}
button("Copy building block from file") {
button(I18N.messages.getString("AutomatonTableView.CopyBuildingBlock")) {
action {
if (!automaton.allowsModificationsByUser) return@action
val file = automatonViewContext.fileController.chooseFile(
Expand All @@ -167,7 +167,7 @@ abstract class AutomatonTableView<T: TableTransitionView, M: TransitionMap>(
style = "-fx-font-size:30"
}
}
button("Add transition") {
button(I18N.messages.getString("AutomatonTableView.AddTransition")) {
action {
val test = Scope()
val newTransitionWindow = find<NewTransitionPopup>(test, mapOf(NewTransitionPopup::automaton to automaton))
Expand All @@ -176,7 +176,6 @@ abstract class AutomatonTableView<T: TableTransitionView, M: TransitionMap>(
style = "-fx-font-size:30"
}
}
alignment = Pos.TOP_LEFT
}

sourceColumn.cellValueFactory = PropertyValueFactory("source")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import automaton.constructor.model.automaton.Automaton
import automaton.constructor.model.element.AutomatonVertex
import automaton.constructor.model.element.BuildingBlock
import automaton.constructor.model.element.Transition
import automaton.constructor.utils.I18N
import automaton.constructor.utils.hoverableTooltip
import javafx.beans.property.SimpleObjectProperty
import javafx.scene.control.*
Expand All @@ -19,11 +20,13 @@ class TransitionTableTransitionMap(

class AutomatonTransitionTableView(automaton: Automaton, automatonViewContext: AutomatonViewContext
): AutomatonTableView<TransitionTableTransitionView, TransitionTableTransitionMap>(automaton, automatonViewContext) {
private val targetColumn = TableColumn<TransitionTableTransitionMap, AutomatonVertex>("To state")
private val transitionColumn = TableColumn<TransitionTableTransitionMap, List<Transition>>("Label")
private val targetColumn = TableColumn<TransitionTableTransitionMap, AutomatonVertex>(
I18N.messages.getString("AutomatonTransitionTableView.ToState"))
private val transitionColumn = TableColumn<TransitionTableTransitionMap, List<Transition>>(
I18N.messages.getString("AutomatonTransitionTableView.Label"))

init {
sourceColumn.text = "From state"
sourceColumn.text = I18N.messages.getString("AutomatonTransitionTableView.FromState")
targetColumn.cellValueFactory = PropertyValueFactory("target")
targetColumn.setCellFactory { VertexCell(this) }
transitionColumn.setCellValueFactory { p0 ->
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/automaton/constructor/view/AutomatonView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ class AutomatonView(val automaton: Automaton, automatonViewContext: AutomatonVie
val matrixTab = customizedZoomScrollPane { add(automatonAdjacencyMatrixView) }
tabpane {
tabClosingPolicy = TabPane.TabClosingPolicy.UNAVAILABLE
tab("Graph representation") {
tab(I18N.messages.getString("AutomatonView.Graph")) {
add(graphTab)
}
tab("State-transition table representation") {
tab(I18N.messages.getString("AutomatonView.Table")) {
add(tableTab)
}
tab("Adjacency matrix representation") {
tab(I18N.messages.getString("AutomatonView.Matrix")) {
add(matrixTab)
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/automaton/constructor/view/MainWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ class MainWindow(
testsController.createTests()
}
}
menu("Algorithms") {
menu("Pushdown automaton") {
item("Convert into context-free grammar").action {
menu(I18N.messages.getString("MainView.Algorithms")) {
menu(I18N.messages.getString("MainView.Algorithms.PushdownAutomaton")) {
item(I18N.messages.getString("MainView.Algorithms.PushdownAutomaton.CFG")).action {
algorithmsController.convertToCFG()
}
item("Hellings algorithm").action {
item(I18N.messages.getString("MainView.Algorithms.PushdownAutomaton.Hellings")).action {
algorithmsController.executeHellingsAlgo()
}
}
Expand Down
22 changes: 12 additions & 10 deletions src/main/kotlin/automaton/constructor/view/algorithms/CFGView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import automaton.constructor.model.element.CFGSymbol
import automaton.constructor.model.element.ContextFreeGrammar
import automaton.constructor.model.element.Nonterminal
import automaton.constructor.model.element.Production
import automaton.constructor.utils.I18N
import automaton.constructor.utils.getLabelsForNonterminal
import javafx.geometry.Insets
import javafx.scene.control.TableCell
import javafx.scene.control.TableColumn
import javafx.scene.control.cell.PropertyValueFactory
Expand Down Expand Up @@ -45,28 +47,28 @@ class RightSideCell: TableCell<Production, List<CFGSymbol>>() {
class CFGView: Fragment() {
val grammar: ContextFreeGrammar by param()
private val productionsTableView = tableview(grammar.productions.toObservable())
private val leftSideColumn = TableColumn<Production, Nonterminal>("Left side")
private val rightSideColumn = TableColumn<Production, List<CFGSymbol>>("Right side")
private val leftSideColumn = TableColumn<Production, Nonterminal>(I18N.messages.getString("CFGView.LeftSide"))
private val rightSideColumn = TableColumn<Production, List<CFGSymbol>>(I18N.messages.getString("CFGView.RightSide"))

init {
leftSideColumn.cellValueFactory = PropertyValueFactory("leftSide")
leftSideColumn.setCellFactory { LeftSideCell() }
rightSideColumn.cellValueFactory = PropertyValueFactory("rightSide")
rightSideColumn.setCellFactory { RightSideCell() }
leftSideColumn.minWidth = 100.0
rightSideColumn.minWidth = 100.0
leftSideColumn.minWidth = 150.0
rightSideColumn.minWidth = 150.0
productionsTableView.columns.addAll(leftSideColumn, rightSideColumn)
}

override val root = vbox {
hbox {
label("Initial nonterminal = ")
add(getLabelsForNonterminal(grammar.initialNonterminal!!))
label(I18N.messages.getString("CFGView.InitialNonterminal") + " = ") {
padding = Insets(5.0, 0.0, 5.0, 5.0)
}
add(getLabelsForNonterminal(grammar.initialNonterminal!!).apply {
padding = Insets(5.0, 5.0, 5.0, 0.0)
})
}
add(productionsTableView)

style {
fontSize = 15.0.px
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package automaton.constructor.view.algorithms

import automaton.constructor.controller.algorithms.HellingsTransition
import automaton.constructor.utils.I18N
import javafx.beans.property.SimpleBooleanProperty
import javafx.collections.ObservableList
import javafx.geometry.Insets
import javafx.scene.control.Button
import javafx.scene.control.ListCell
import javafx.scene.control.ListView
Expand Down Expand Up @@ -39,25 +41,29 @@ class HellingsAlgoExecutionView: Fragment() {
val r: ObservableList<HellingsTransition> by param()
private val mListView = ListView(m).apply { this.setCellFactory { HellingsTransitionCell() } }
private val rListView = ListView(r).apply { this.setCellFactory { HellingsTransitionCell() } }
val nextIterationButton = Button("Next iteration")
val nextIterationButton = Button(I18N.messages.getString("HellingsAlgorithm.Execution.NextIteration"))

override val root = vbox {
label ("Each triple (N, S, T) means that a word composed of symbols on the path between vertices S " +
"and T is output in the grammar if we take N as the initial nonterminal.")
label ("Once the algorithm finishes, the list r contains the solution.")
label (I18N.messages.getString("HellingsAlgorithm.Execution.Description")) {
padding = Insets(5.0, 5.0, 5.0, 5.0)
}
hbox {
vbox {
label("m:")
label("m:") {
padding = Insets(0.0, 0.0, 0.0, 5.0)
}
add(mListView)
}
vbox {
label("r:")
label("r:") {
padding = Insets(0.0, 0.0, 0.0, 5.0)
}
add(rListView)
}
}
add(nextIterationButton)
style {
fontSize = 15.0.px
hbox {
add(nextIterationButton)
padding = Insets(5.0, 5.0, 5.0, 5.0)
}
}
}
Loading

0 comments on commit 330996c

Please sign in to comment.