From 76d7807c4418815ae135ced65c1f3ad96987de26 Mon Sep 17 00:00:00 2001 From: cemal Date: Tue, 7 Nov 2023 15:24:38 +0100 Subject: [PATCH] Added file import --- src/main/kotlin/Main.kt | 103 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 5c3f6cf..f28950e 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -12,15 +12,23 @@ import androidx.compose.ui.unit.dp import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Check import androidx.compose.material.icons.filled.Close +import javax.swing.JFileChooser +import javax.swing.filechooser.FileNameExtensionFilter +import java.io.File + @Composable -fun HomePage(onGlossaireClick: () -> Unit) { +fun HomePage( + onGlossaireClick: () -> Unit, + onCodeAVerifierClick: () -> Unit +) { Column( modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally + ) { Text("Quali'Nomme", style = MaterialTheme.typography.h3) @@ -33,7 +41,7 @@ fun HomePage(onGlossaireClick: () -> Unit) { Text("Glossaire") } - Button(onClick = { /* Action de Code à Vérifier */ }) { + Button(onClick = onCodeAVerifierClick ) { Text("Code à Vérifier") } @@ -53,14 +61,24 @@ fun App() { when (currentPage.value) { "accueil" -> { HomePage( - onGlossaireClick = { currentPage.value = "glossaire" } - + onGlossaireClick = { currentPage.value = "glossaire" }, + onCodeAVerifierClick = { currentPage.value = "choixLangage" } ) } "glossaire" -> { glossairePage( onAjouterMotClick = { currentPage.value = "formulaire" }, - onImporterClick = { /* Action d'import */ }, + onImporterClick = { + val fileChooser = JFileChooser() + fileChooser.fileFilter = FileNameExtensionFilter("CSV Files", "csv") + val returnVal = fileChooser.showOpenDialog(null) + if (returnVal == JFileChooser.APPROVE_OPTION) { + val file = fileChooser.selectedFile + println("Opening: " + file.name + ".") + } else { + println("Open command cancelled by user.") + } + }, onExporterClick = { /* Action d'export */ }, onRetourClick = { currentPage.value = "accueil" } ) @@ -68,11 +86,86 @@ fun App() { "formulaire" -> { FormulairePage(onAnnulerClick = { currentPage.value = "glossaire" }) } + "choixLangage" -> { + ChoixLangagePage( + onRetourClick = { currentPage.value = "accueil" }, + onPythonClick = { + val fileChooser = JFileChooser() + fileChooser.fileFilter = FileNameExtensionFilter("Python Files", "py") + val returnVal = fileChooser.showOpenDialog(null) + if (returnVal == JFileChooser.APPROVE_OPTION) { + val file = fileChooser.selectedFile + println("Opening: " + file.name + ".") + } else { + println("Open command cancelled by user.") + } + }, + onJavaClick = { + val fileChooser = JFileChooser() + fileChooser.fileFilter = FileNameExtensionFilter("Java Files", "java") + val returnVal = fileChooser.showOpenDialog(null) + if (returnVal == JFileChooser.APPROVE_OPTION) { + val file = fileChooser.selectedFile + println("Opening: " + file.name + ".") + } else { + println("Open command cancelled by user.") + } + }, + onJavaScriptClick = { + val fileChooser = JFileChooser() + fileChooser.fileFilter = FileNameExtensionFilter("JavaScript Files", "js") + val returnVal = fileChooser.showOpenDialog(null) + if (returnVal == JFileChooser.APPROVE_OPTION) { + val file = fileChooser.selectedFile + println("Opening: " + file.name + ".") + } else { + println("Open command cancelled by user.") + } + } + ) + } // ... Ajoutez d'autres cas pour les pages "glossaire," "code a verifier," et "comparer" } } } + +@Composable +fun ChoixLangagePage( + onRetourClick: () -> Unit, + onPythonClick: () -> Unit, + onJavaClick: () -> Unit, + onJavaScriptClick: () -> Unit +) { + Column( + modifier = Modifier + .fillMaxSize() // Fills the maximum available width + .padding(16.dp), + verticalArrangement = Arrangement.spacedBy(8.dp), + horizontalAlignment = Alignment.CenterHorizontally + + ) { + Text(text = "Choix du langage", style = MaterialTheme.typography.h5) + + Button(onClick = onPythonClick) { + Text("Python") + } + + Button(onClick = onJavaClick) { + Text("Java") + } + + Button(onClick = onJavaScriptClick) { + Text("JavaScript") + } + + Button(onClick = onRetourClick) { + Text("Retour") + } + } + +} + @Composable fun glossairePage( onAjouterMotClick: () -> Unit,