diff --git a/src/main/kotlin/main/Form.kt b/src/main/kotlin/main/Form.kt index fa57ae3..96b824e 100644 --- a/src/main/kotlin/main/Form.kt +++ b/src/main/kotlin/main/Form.kt @@ -189,7 +189,7 @@ fun formPage(glossary: Glossary, onCancelClick: () -> Unit) { ) { listToShow.forEach { word -> - + item { Box( modifier = Modifier diff --git a/src/main/kotlin/main/Glossary.kt b/src/main/kotlin/main/Glossary.kt index 01a67c8..1d2ae44 100644 --- a/src/main/kotlin/main/Glossary.kt +++ b/src/main/kotlin/main/Glossary.kt @@ -26,6 +26,8 @@ import java.io.File import java.io.FileInputStream import java.io.FileWriter import java.io.IOException +import javax.swing.JFileChooser +import javax.swing.filechooser.FileSystemView data class Glossary(val name: String, val jsonFilePath: String) @@ -354,6 +356,21 @@ fun selectFile(extensions: Set, onFileSelected: (String) -> Unit) { frame.dispose() } + +fun selectDirectory(onDirectorySelected: (String) -> Unit) { + val fileChooser = JFileChooser(FileSystemView.getFileSystemView().homeDirectory) + fileChooser.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY + + val returnValue = fileChooser.showDialog(null, "Select") + if (returnValue == JFileChooser.APPROVE_OPTION) { + val selectedDirectory = fileChooser.selectedFile.absolutePath + println("Selected directory: $selectedDirectory") + onDirectorySelected(selectedDirectory) + } else { + println("Open command cancelled by user.") + } +} + fun exportToCSV(glossary: Glossary, csvFilePath: String) { val glossary = loadDatasFromFile(glossary.jsonFilePath) val csvContent = buildString { diff --git a/src/main/kotlin/main/Main.kt b/src/main/kotlin/main/Main.kt index 1de9d3b..9dbf6c6 100644 --- a/src/main/kotlin/main/Main.kt +++ b/src/main/kotlin/main/Main.kt @@ -10,7 +10,6 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp import androidx.compose.ui.window.* -import main.AppState.selectedGlossary import java.awt.FileDialog import java.awt.Frame import java.io.File @@ -182,6 +181,13 @@ fun app() { choixLangagePage( languageManager, onBackClick = { currentPage.value = "accueil" }, + onKotlinClick = { + selectDirectory() { onDirectorySelected -> + mostUsedWordList = directoryParse(onDirectorySelected) // Change by parser functions + println("Kotlin directory selected: $onDirectorySelected") + currentPage.value = "occurrence" + } + }, onPythonClick = { selectFile(pythonExtensions) { filePath -> println("Python file selected: $filePath") // Change by parser functions @@ -194,7 +200,7 @@ fun app() { }, onJavaScriptClick = { selectFile(jsExtensions) { filePath -> - mostUsedWordList = parser(filePath) // Change by parser functions + mostUsedWordList = parserJS(filePath) // Change by parser functions isJavaScriptFileSelected = true } }, diff --git a/src/main/kotlin/main/Verify.kt b/src/main/kotlin/main/Verify.kt index 56e1a14..1c96504 100644 --- a/src/main/kotlin/main/Verify.kt +++ b/src/main/kotlin/main/Verify.kt @@ -16,6 +16,7 @@ import main.component.dropdownButtonComponent fun choixLangagePage( languageManager: LanguageManager, onBackClick: () -> Unit, + onKotlinClick: () -> Unit, onPythonClick: () -> Unit, onJavaClick: () -> Unit, onJavaScriptClick: () -> Unit, @@ -42,6 +43,19 @@ fun choixLangagePage( horizontalAlignment = Alignment.CenterHorizontally ) { + Button( + onClick = onKotlinClick, + modifier = Modifier + .width(150.dp), + colors = ButtonDefaults.buttonColors( + backgroundColor = customRedColor, + contentColor = Color.White + ), + enabled = true + ) { + Text("Kotlin") + } + Button( onClick = onPythonClick, modifier = Modifier diff --git a/src/main/kotlin/main/parser.kt b/src/main/kotlin/main/parser.kt index 333a5dd..34632d2 100644 --- a/src/main/kotlin/main/parser.kt +++ b/src/main/kotlin/main/parser.kt @@ -1,8 +1,6 @@ package main -import androidx.compose.ui.text.toLowerCase import java.io.File -import java.util.* fun delStrings(line : String) : String { @@ -45,11 +43,13 @@ fun splitLanguages(file : String){ } } + + } -fun parser(fileName : String) : MutableMap { +fun parserJS(fileName : String) : MutableMap { val delimiter1 = " " val regex = "[^a-zA-Z^éà]".toRegex() val array = mutableListOf() @@ -70,3 +70,41 @@ fun parser(fileName : String) : MutableMap { } +fun ktWords(code : Map) : Map{ + val js = File("src/main/kotlin/main/sampleKt.txt").readText().split(",") + + return code.filter { it.key !in js } +} +fun parserKt(fileName : String) : MutableMap { + val delimiter1 = " " + val regex = "[^a-zA-Z^éà]".toRegex() + val array = mutableListOf() + + val line = delStrings(File(fileName).readText()).replace(regex, " ") + line.split(delimiter1).forEach { + + if (it != "") { + array.add(it) + } + } + val map = ktWords(array.groupingBy { it }.eachCount()) + + return map.toMutableMap() +} + + +fun directoryParse(directory : String) : MutableMap { + val files = File(directory).walk().filter { it.isFile }.toList() + val map = mutableMapOf() + files.forEach { + + + if (it.extension == "kt" && it.toString().contains("bin") == false) { + println(it.absolutePath) + val map2 = parserKt(it.toString()) + map2.forEach { (t, u) -> map[t] = map.getOrDefault(t, 0) + u } + } + + } + return map +} diff --git a/src/main/kotlin/main/sampleKt.txt b/src/main/kotlin/main/sampleKt.txt new file mode 100644 index 0000000..9469ef6 --- /dev/null +++ b/src/main/kotlin/main/sampleKt.txt @@ -0,0 +1 @@ +androidx,abstract,actual,annotation,anonymous,apply,as,as?,assert,break,by,byte,catch,char,class,companion,const,constructor,continue,crossinline,data,delegate,do,double,dynamic,else,enum,expect,external,false,field,file,final,finally,float,for,fun,get,if,implements,import,in,infix,init,inline,inner,interface,internal,is,it,lateinit,long,module,native,new,noinline,null,object,open,operator,out,override,package,private,protected,public,receiver,reified,return,sealed,set,short,super,suspend,tailrec,this,throw,true,try,typealias,typeof,val,var,vararg,when,where,while,abstract,actual,annotation,anonymous,apply,as,as?,assert,break,by,byte,catch,char,class,companion,const,constructor,continue,crossinline,data,delegate,do,double,dynamic,else,enum,expect,external,false,field,file,final,finally,float,for,fun,get,if,implements,import,in,infix,init,inline,inner,interface,internal,is,it,lateinit,long,module,native,new,noinline,null,object,open,operator,out,override,package,private,protected,public,receiver,reified,return,sealed,set,short,super,suspend,tailrec,this,throw,true,try,typealias,typeof,val,var,vararg,when,where,while,AccessibleObject,BitSet,Calendar,Date,GregorianCalendar,Locale,Objects,Observable,Optional,Random,Timer,TimeZone,UUID,Vector,AbstractCollection,AbstractList,AbstractMap,AbstractQueue,AbstractSequentialList,AbstractSet,ArrayList,Arrays,Base64,Calendar,Collections,Comparator,Date,DateFormat,DateFormatSymbols,DecimalFormat,EnumMap,EnumSet,GregorianCalendar,HashMap,HashSet,Hashtable,IdentityHashMap,LinkedHashMap,LinkedHashSet,LinkedList,ListResourceBundle,Locale,Objects,Observable,Optional,PriorityQueue,Properties,PropertyPermission,Random,ResourceBundle,Scanner,SimpleTimeZone,Stack,StringTokenizer,Timer,TimeZone,TreeMap,TreeSet,UUID,Vector,WeakHashMap,AssertionError,Exception,RuntimeException,ArithmeticException,ArrayIndexOutOfBoundsException,ClassCastException,ClassNotFoundException,CloneNotSupportedException,EnumConstantNotPresentException,IllegalAccessException,IllegalArgumentException,IllegalMonitorStateException,IllegalStateException,IllegalThreadStateException,IndexOutOfBoundsException,InstantiationException,InterruptedException,NegativeArraySizeException,NoSuchFieldException,NoSuchMethodException,NullPointerException,NumberFormatException,ReflectiveOperationException,SecurityException,StringIndexOutOfBoundsException,TypeNotPresentException,UnsupportedOperationException \ No newline at end of file diff --git a/src/test/kotlin/ParserTest.kt b/src/test/kotlin/ParserTest.kt index 11dbd24..fabb1d9 100644 --- a/src/test/kotlin/ParserTest.kt +++ b/src/test/kotlin/ParserTest.kt @@ -63,11 +63,11 @@ class ParserTest { val puissance4File = "src/test/resources/puissance4.html" // Call the parser function - parser(puissance4File) + parserJS(puissance4File) // Verify the output by capturing the printed content val printedContent = captureStandardOutput { - parser(puissance4File) + parserJS(puissance4File) } // Assert the expected output based on the content of your sample HTML file