Skip to content

Commit

Permalink
+ about dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
gciatto committed Oct 22, 2020
1 parent 7fa2054 commit bbc9aa4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,21 @@ import javafx.scene.Parent
import javafx.scene.Scene
import javafx.scene.control.Alert
import javafx.scene.control.ButtonType
import javafx.scene.image.Image
import javafx.stage.Stage
import javafx.stage.WindowEvent
import java.net.URL
import kotlin.system.exitProcess

class PrologIDEApplication : Application() {
override fun start(stage: Stage) {
try {
val loader = FXMLLoader(javaClass.getResource("PrologIDEView.fxml"))
val root = loader.load<Parent>()
stage.title = "tuProlog IDE v$VERSION"
stage.title = "tuProlog IDE"
stage.scene = Scene(root)
stage.icons.add(Image(TUPROLOG_LOGO.openStream()))
stage.icons.add(TUPROLOG_LOGO)
stage.onCloseRequest = EventHandler(this::onCloseRequest)
stage.scene.stylesheets += JAVA_KEYWORDS_LIGHT.toExternalForm()
stage.scene.stylesheets += LIGHT_CODE_AREA.toExternalForm()
stage.scene.stylesheets += JAVA_KEYWORDS_LIGHT
stage.scene.stylesheets += LIGHT_CODE_AREA
stage.show()
} catch (e: Throwable) {
e.printStackTrace()
Expand All @@ -49,17 +47,6 @@ class PrologIDEApplication : Application() {
}

companion object {

val JAVA_KEYWORDS_LIGHT: URL = PrologIDEApplication::class.java.getResource("java-keywords-light.css")

val JAVA_KEYWORDS_DARK: URL = PrologIDEApplication::class.java.getResource("java-keywords-dark.css")

val LIGHT_CODE_AREA: URL = PrologIDEApplication::class.java.getResource("light-code-area.css")

val DARK_CODE_AREA: URL = PrologIDEApplication::class.java.getResource("dark-code-area.css")

val TUPROLOG_LOGO: URL = PrologIDEApplication::class.java.getResource("2p-logo.png")

@JvmStatic
fun main(args: Array<String>) {
launch(PrologIDEApplication::class.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.unibo.tuprolog.ui.gui

import it.unibo.tuprolog.Info
import it.unibo.tuprolog.core.Struct
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.core.TermFormatter
Expand Down Expand Up @@ -32,6 +33,7 @@ import javafx.scene.control.TextField
import javafx.scene.control.TreeItem
import javafx.scene.control.TreeView
import javafx.scene.control.cell.PropertyValueFactory
import javafx.scene.image.ImageView
import javafx.scene.input.KeyEvent
import javafx.scene.input.MouseEvent
import javafx.scene.layout.Region
Expand Down Expand Up @@ -419,17 +421,17 @@ class PrologIDEController : Initializable {
}

private fun onCaretMovedIn(area: CodeArea) {
// val (l, c) = area.text.caretLocation(area.caretPosition)
lblCaret.text = "Line: ${area.caretPosition + 1} | Column: ${area.caretColumn + 1}"
val (l, c) = area.text.caretLocation(area.caretPosition)
lblCaret.text = "Line: ${l} | Column: ${c}"
}

// private fun String.caretLocation(position: Int): Pair<Int, Int> {
// val portion = this.subSequence(0, position)
// val lines = portion.count { it == '\n' } + 1
// val lastLine = portion.lastIndexOf('\n')
// val columns = position - lastLine
// return lines to columns
// }
private fun String.caretLocation(position: Int): Pair<Int, Int> {
val portion = this.subSequence(0, position)
val lines = portion.count { it == '\n' } + 1
val lastLine = portion.lastIndexOf('\n')
val columns = position - lastLine
return lines to columns
}

@FXML
fun onMouseClickedOnCurrentFile(e: MouseEvent) {
Expand Down Expand Up @@ -462,4 +464,22 @@ class PrologIDEController : Initializable {
fun onNewFilePressed(e: ActionEvent) {
model.newFile()
}

@FXML
fun onAbout(e: ActionEvent) {
val dialog = Alert(Alert.AlertType.INFORMATION)
dialog.title = "About"
dialog.headerText = "tuProlog IDE v${Info.VERSION}"
dialog.dialogPane.graphic = ImageView(TUPROLOG_LOGO).also {
it.fitWidth = TUPROLOG_LOGO.width * 0.3
it.fitHeight = TUPROLOG_LOGO.height * 0.3
}
dialog.contentText = """
|Running on:
| - 2P-Kt v${Info.VERSION}
| - JVM v${System.getProperty("java.version")}
| - JavaFX v${System.getProperties().get("javafx.runtime.version")}
""".trimMargin()
dialog.showAndWait()
}
}
23 changes: 23 additions & 0 deletions ide/src/main/kotlin/it/unibo/tuprolog/ui/gui/Resources.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package it.unibo.tuprolog.ui.gui

import javafx.scene.image.Image

val JAVA_KEYWORDS_LIGHT: String by lazy {
PrologIDEApplication::class.java.getResource("java-keywords-light.css").toExternalForm()
}

val JAVA_KEYWORDS_DARK: String by lazy {
PrologIDEApplication::class.java.getResource("java-keywords-dark.css").toExternalForm()
}

val LIGHT_CODE_AREA: String by lazy {
PrologIDEApplication::class.java.getResource("light-code-area.css").toExternalForm()
}

val DARK_CODE_AREA: String by lazy {
PrologIDEApplication::class.java.getResource("dark-code-area.css").toExternalForm()
}

val TUPROLOG_LOGO: Image by lazy {
PrologIDEApplication::class.java.getResource("2p-logo.png").let { Image(it.openStream()) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<?import javafx.scene.control.Tab?>
<?import org.fxmisc.richtext.CodeArea?>
<fx:root type="Tab" text="Untitled Tab" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1"
onSelectionChanged="#onTabSelectionChanged" closable="true">
onSelectionChanged="#onTabSelectionChanged"
closable="true">
<content>
<CodeArea fx:id="codeArea" onKeyTyped="#onKeyTypedOnCodeArea" onKeyPressed="#onKeyPressedOnCodeArea" onMouseClicked="#onMousePressedOnCodeArea" prefHeight="200.0" prefWidth="200.0" />
</content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem fx:id="btnAbout" disable="true" mnemonicParsing="false" text="About 2P" />
<MenuItem fx:id="btnAbout" mnemonicParsing="false" onAction="#onAbout" text="About 2P" />
</items>
</Menu>
</menus>
Expand Down

0 comments on commit bbc9aa4

Please sign in to comment.