Skip to content

Commit

Permalink
Merge branch 'feature/ide' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	settings.gradle.kts
  • Loading branch information
gciatto committed Oct 22, 2020
2 parents d78b2a3 + 4ee3ba7 commit 1473791
Show file tree
Hide file tree
Showing 30 changed files with 1,926 additions and 7 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Giovanni Ciatto (giovanni.ciatto@unibo.it, giovanni.ciatto@gmail.com)
Enrico Siboni (enrico.siboni3@studio.unibo.it)
Paolo Verdini (paolo.verdini@studio.unibo.it, paolopiano1997@gmail.com)
Manuel Bonarrigo (manuel.bonarrigo@studio.unibo.it)
Sofia Montebugnoli (sofia.montebugnoli2@studio.unibo.it)
Davide Greco (davide.greco4@studio.unibo.it)
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ val githubToken = getPropertyOrWarnForAbsence("githubToken")
val npmToken = getPropertyOrWarnForAbsence("npmToken")

val allSubprojects = allprojects.map { it.name }.toSet()
val jvmSubprojects = setOf("parser-jvm", "examples")
val jvmSubprojects = setOf("parser-jvm", "examples", "ide")
val jsSubprojects = setOf("parser-js")
val docSubprojects = setOf("documentation")

Expand Down
24 changes: 24 additions & 0 deletions buildSrc/src/main/kotlin/Libs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ object Libs {
const val kotlin_test_junit: String = "org.jetbrains.kotlin:kotlin-test-junit:" +
Versions.org_jetbrains_kotlin

/**
* https://openjdk.java.net/projects/openjfx/
*/
const val javafx_base: String = "org.openjfx:javafx-base:" + Versions.org_openjfx

/**
* https://openjdk.java.net/projects/openjfx/
*/
const val javafx_controls: String = "org.openjfx:javafx-controls:" + Versions.org_openjfx

/**
* https://openjdk.java.net/projects/openjfx/
*/
const val javafx_graphics: String = "org.openjfx:javafx-graphics:" + Versions.org_openjfx

/**
* http://www.antlr.org
*/
Expand Down Expand Up @@ -122,6 +137,10 @@ object Libs {
"de.fayard.buildSrcVersions:de.fayard.buildSrcVersions.gradle.plugin:" +
Versions.de_fayard_buildsrcversions_gradle_plugin

const val org_openjfx_javafxplugin_gradle_plugin: String =
"org.openjfx.javafxplugin:org.openjfx.javafxplugin.gradle.plugin:" +
Versions.org_openjfx_javafxplugin_gradle_plugin

const val com_eden_orchidplugin_gradle_plugin: String =
"com.eden.orchidPlugin:com.eden.orchidPlugin.gradle.plugin:" +
Versions.com_eden_orchidplugin_gradle_plugin
Expand Down Expand Up @@ -153,6 +172,11 @@ object Libs {
const val jackson_core: String = "com.fasterxml.jackson.core:jackson-core:" +
Versions.jackson_core

/**
* https://github.com/FXMisc/RichTextFX/#richtextfx
*/
const val richtextfx: String = "org.fxmisc.richtext:richtextfx:" + Versions.richtextfx

/**
* http://plantuml.sourceforge.net
*/
Expand Down
13 changes: 9 additions & 4 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import kotlin.String
import org.gradle.plugin.use.PluginDependenciesSpec
import org.gradle.plugin.use.PluginDependencySpec

Expand All @@ -12,12 +11,14 @@ import org.gradle.plugin.use.PluginDependencySpec
* YOU are responsible for updating manually the dependency version.
*/
object Versions {
const val com_fasterxml_jackson_dataformat: String = "2.11.2"
const val com_fasterxml_jackson_dataformat: String = "2.11.3"

const val io_github_javaeden_orchid: String = "0.21.1"

const val org_jetbrains_kotlin: String = "1.4.10"

const val org_openjfx: String = "15" // "11.0.2" // available: "15"

const val org_antlr: String = "4.8-1"

const val org_danilopianini_git_sensitive_semantic_versioning_gradle_plugin: String = "0.2.2"
Expand All @@ -32,17 +33,21 @@ object Versions {

const val de_fayard_buildsrcversions_gradle_plugin: String = "0.7.0"

const val org_openjfx_javafxplugin_gradle_plugin: String = "0.0.9"

const val com_eden_orchidplugin_gradle_plugin: String = "0.21.1"

const val org_jetbrains_dokka_gradle_plugin: String = "0.10.1" // available: "1.4.10"

const val com_jfrog_bintray_gradle_plugin: String = "1.8.5"

const val jackson_datatype_jsr310: String = "2.11.2"
const val jackson_datatype_jsr310: String = "2.11.3"

const val clikt_multiplatform: String = "2.8.0"

const val jackson_core: String = "2.11.2"
const val jackson_core: String = "2.11.3"

const val richtextfx: String = "0.10.5"

const val plantuml: String = "1.2020.2" // available: "8059"

Expand Down
87 changes: 87 additions & 0 deletions ide/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import com.github.breadmoirai.githubreleaseplugin.GithubReleaseExtension
import com.github.breadmoirai.githubreleaseplugin.GithubReleaseTask
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

val javaVersion: String by project
val ktFreeCompilerArgsJvm: String by project
val githubToken: String? by project
val arguments: String? by project

plugins {
application
java
kotlin("jvm")
id("org.openjfx.javafxplugin") version Versions.org_openjfx_javafxplugin_gradle_plugin
id("com.github.johnrengelman.shadow") version Versions.com_github_johnrengelman_shadow_gradle_plugin
}

javafx {
version = Versions.org_openjfx
modules = listOf("javafx.controls", "javafx.fxml", "javafx.graphics")
}

application {
// mainModule.set("2p-ide")
mainClassName = "it.unibo.tuprolog.ui.gui.Main"
}

val linuxOnly by configurations.creating { isTransitive = true }

dependencies {
api(project(":solve-classic"))
api(project(":parser-theory"))
api(kotlin("stdlib-jdk8"))
api(Libs.richtextfx)

runtimeOnly("${Libs.javafx_graphics}:win")
runtimeOnly("${Libs.javafx_graphics}:linux")
runtimeOnly("${Libs.javafx_graphics}:mac")

testImplementation(kotlin("test-junit"))
}

configure<JavaPluginConvention> {
targetCompatibility = JavaVersion.valueOf("VERSION_1_$javaVersion")
sourceCompatibility = JavaVersion.valueOf("VERSION_1_$javaVersion")
}

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.$javaVersion"
freeCompilerArgs = ktFreeCompilerArgsJvm.split(";").toList()
}
}

val shadowJar = tasks.getByName<ShadowJar>("shadowJar") {
manifest {
attributes("Main-Class" to application.mainClassName)
}
archiveBaseName.set("${rootProject.name}-${project.name}")
archiveVersion.set(project.version.toString())
archiveClassifier.set("redist")
sourceSets.main {
runtimeClasspath.filter { it.exists() }
.map { if (it.isDirectory) it else zipTree(it) }
.forEach {
from(it)
}
}
from(files("${rootProject.projectDir}/LICENSE"))

dependsOn("classes")

doLast {
println("Generated: ${archiveFile.get()}")
}
}

if (!githubToken.isNullOrBlank()) {
rootProject.configure<GithubReleaseExtension> {
releaseAssets(*(releaseAssets.toList() + shadowJar).toTypedArray())
}

rootProject.tasks.withType(GithubReleaseTask::class) {
dependsOn(shadowJar)
}
}
10 changes: 10 additions & 0 deletions ide/src/main/java/it/unibo/tuprolog/ui/gui/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package it.unibo.tuprolog.ui.gui;

/**
* https://stackoverflow.com/questions/52569724/javafx-11-create-a-jar-file-with-gradle
*/
public class Main {
public static void main(String[] args) {
PrologIDEApplication.main(args);
}
}
50 changes: 50 additions & 0 deletions ide/src/main/kotlin/it/unibo/tuprolog/ui/gui/AssignmentView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package it.unibo.tuprolog.ui.gui

import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.core.TermFormatter
import it.unibo.tuprolog.core.Var
import it.unibo.tuprolog.core.format
import javafx.fxml.FXML
import javafx.fxml.FXMLLoader
import javafx.scene.control.Label
import javafx.scene.layout.BorderPane
import javafx.scene.layout.HBox
import java.io.IOException

class AssignmentView(
variable: Var,
value: Term,
formatter: TermFormatter = TermFormatter.prettyExpressions()
) : HBox() {

companion object {
private const val FXML = "AssignmentView.fxml"
}

init {
val loader = FXMLLoader(AssignmentView::class.java.getResource(FXML))
loader.setController(this)
loader.setRoot(this)

try {
loader.load<BorderPane>()
} catch (e: IOException) {
throw IllegalStateException(e)
}

this.variable.text = variable.format(formatter)
this.value.text = value.format(formatter)
}

constructor(assignment: Pair<Var, Term>, formatter: TermFormatter = TermFormatter.prettyExpressions()) :
this(assignment.first, assignment.second, formatter)

@FXML
lateinit var variable: Label

@FXML
lateinit var operator: Label

@FXML
lateinit var value: Label
}
79 changes: 79 additions & 0 deletions ide/src/main/kotlin/it/unibo/tuprolog/ui/gui/FileTabView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package it.unibo.tuprolog.ui.gui

import javafx.event.Event
import javafx.fxml.FXML
import javafx.fxml.FXMLLoader
import javafx.scene.control.Tab
import javafx.scene.input.KeyEvent
import javafx.scene.input.MouseEvent
import javafx.scene.layout.BorderPane
import org.fxmisc.richtext.CodeArea
import org.fxmisc.richtext.LineNumberFactory
import java.io.File
import java.io.IOException

@Suppress("UNUSED_PARAMETER")
class FileTabView(
private val file: File,
private val model: PrologIDEModel,
private val ideController: PrologIDEController,
initialText: String = ""
) : Tab() {

companion object {
private const val FXML = "FileTabView.fxml"
}

private val syntaxColoring: SyntaxColoring

init {
val loader = FXMLLoader(FileTabView::class.java.getResource(FXML))
loader.setController(this)
loader.setRoot(this)

try {
loader.load<BorderPane>()
} catch (e: IOException) {
throw IllegalStateException(e)
}

codeArea.appendText(initialText)

codeArea.paragraphGraphicFactory = LineNumberFactory.get(codeArea)

syntaxColoring = SyntaxColoring(codeArea)
syntaxColoring.activate()

text = file.name
}

@FXML
lateinit var codeArea: CodeArea

// @FXML
// lateinit var btnClose: Button

@FXML
fun onTabSelectionChanged(e: Event) {
if (isSelected) {
model.selectFile(file)
}
}

@FXML
fun onMousePressedOnCodeArea(e: MouseEvent) {
ideController.onMouseClickedOnCurrentFile(e)
}

@FXML
fun onKeyTypedOnCodeArea(e: KeyEvent) {
model.setFile(file, codeArea.text)
ideController.onKeyTypedOnCurrentFile(e)
}

@FXML
fun onKeyPressedOnCodeArea(e: KeyEvent) {
model.setFile(file, codeArea.text)
ideController.onKeyPressedOnCurrentFile(e)
}
}
30 changes: 30 additions & 0 deletions ide/src/main/kotlin/it/unibo/tuprolog/ui/gui/LibraryView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package it.unibo.tuprolog.ui.gui

import it.unibo.tuprolog.solve.library.AliasedLibrary
import javafx.scene.control.TreeItem

class LibraryView(library: AliasedLibrary) : TreeItem<String>(library.alias) {
init {
isExpanded = false

val functionsChild = TreeItem("Functions")
val predicatesChild = TreeItem("Predicates")
val operatorsChild = TreeItem("Operators")

children.addAll(functionsChild, predicatesChild, operatorsChild)

val rules = library.theory.rules.asSequence().map { it.head.indicator }
val primitives = library.primitives.keys.asSequence().map { it.toIndicator() }
val predicates = (rules + primitives).distinct().map { it.toString() }.sorted()

predicatesChild.children.addAll(predicates.map { TreeItem(it) })

val functions = library.functions.keys.asSequence().map { it.toIndicator() }.map { it.toString() }

functionsChild.children.addAll(functions.map { TreeItem(it) })

val operators = library.operators.asSequence().map { "'${it.functor}', ${it.specifier} (${it.priority})" }

operatorsChild.children.addAll(operators.map { TreeItem(it) })
}
}
15 changes: 15 additions & 0 deletions ide/src/main/kotlin/it/unibo/tuprolog/ui/gui/ListCellView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package it.unibo.tuprolog.ui.gui

import javafx.scene.Node
import javafx.scene.control.ListCell

class ListCellView<T : Any>(private val viewGenerator: (T) -> Node) : ListCell<T>() {
override fun updateItem(item: T?, empty: Boolean) {
super.updateItem(item, empty)
graphic = if (empty || item == null) {
null
} else {
viewGenerator(item)
}
}
}
Loading

0 comments on commit 1473791

Please sign in to comment.