First functional Composable

This commit is contained in:
Stef Tervelde
2024-11-14 16:32:28 +01:00
parent d98cab9f85
commit 9405e4ac12
4 changed files with 109 additions and 3 deletions
+18 -3
View File
@@ -10,6 +10,7 @@ group = rootProject.group
repositories{
mavenCentral()
google()
maven { url = uri("https://jogamp.org/deployment/maven") }
}
@@ -18,6 +19,9 @@ sourceSets{
java{
srcDirs("src")
}
kotlin{
srcDirs("src")
}
resources{
srcDirs("src","../build/shared/")
}
@@ -45,9 +49,11 @@ compose.desktop {
linux {
iconFile = project.file("../build/linux/processing.png")
}
buildTypes.release.proguard{
optimize = false
}
// Allow swing to use the system look and feel
jvmArgs(
"-Dapple.awt.application.appearance=system"
)
}
}
}
@@ -60,6 +66,15 @@ dependencies {
implementation(project(":core"))
runtimeOnly(project(":java"))
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.ui)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(compose.desktop.currentOs)
}
tasks.register<Copy>("addCore"){
+3
View File
@@ -430,6 +430,9 @@ public class Platform {
return new File(home);
}else{
// TODO make platform independent
// Windows: C:\Program Files\Eclipse Adoptium\jdk-17*
// macOS/Linux: /usr/lib/jvm/, /opt/, /Library/Java/JavaVirtualMachines/
return new File("/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home");
}
}
+4
View File
@@ -71,6 +71,8 @@ import processing.app.laf.PdeMenuItemUI;
import processing.app.syntax.*;
import processing.core.*;
import static processing.app.ui.JVMManagerKt.addJDKManger;
/**
* Main editor panel for the Processing Development Environment.
@@ -218,6 +220,8 @@ public abstract class Editor extends JFrame implements RunnerListener {
header = createHeader();
upper.add(header);
addJDKManger(upper);
textarea = createTextArea();
textarea.setRightClickPopup(new TextAreaPopup());
textarea.setHorizontalOffset(JEditTextArea.leftHandGutter);
+84
View File
@@ -0,0 +1,84 @@
package processing.app.ui
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.awt.ComposePanel
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import processing.app.Language
import processing.app.Platform
import java.awt.BorderLayout
import java.awt.Desktop
import java.io.File
import java.net.URI
import javax.swing.Box
import javax.swing.SwingUtilities
fun addJDKManger(parent: Box){
SwingUtilities.invokeLater {
val composePanel = ComposePanel().apply {
setContent {
JDKManager()
}
}
parent.apply {
add(composePanel, BorderLayout.EAST)
}
}
}
// If the user does not have a valid JDK installed on their system, this function will display a message and a button to download the JDK
// Temporary workaround until we ship Processing with a JDK again
@Composable
fun JDKManager(){
val home = Platform.getJavaHome()
val valid = File(home, "bin/java").exists()
if(valid) return
val color = Theme.getColor("editor.gradient.bottom")
val os = System.getProperty("os.name")
val arch = System.getProperty("os.arch")
val platform = when {
os.contains("Windows") -> "windows"
os.contains("Mac") -> "mac"
else -> "linux"
}
Row(modifier = Modifier
.background(color = Color(color.rgb))
.padding(8.dp)
.fillMaxWidth()
) {
Text(Language.text("editor.status.missing.jvm"))
Spacer(modifier = Modifier.weight(1f))
Button(onClick = { openWebpage(URI("https://api.adoptium.net/v3/installer/latest/17/ga/${platform}/${arch}/jre/hotspot/normal/eclipse?project=jdk")) }) {
Text(
text = "Open a link",
color = Color.Black
)
}
}
}
fun openWebpage(uri: URI?): Boolean {
val desktop = Desktop.getDesktop() ?: return false
if (desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(uri)
return true
} catch (e: Exception) {
e.printStackTrace()
}
}
return false
}