Skip to content

Commit

Permalink
finalized. build gradle fixed,
Browse files Browse the repository at this point in the history
Forgotten edit method codes added . Runtime components missing error fixed, now application can be run either with gradle or from INTELIJ .
  • Loading branch information
BartuHacilar committed May 7, 2023
1 parent 75cb3c6 commit 5d09bc6
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 30 deletions.
48 changes: 44 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,60 @@
plugins {
id 'java'
id 'application'
id 'org.javamodularity.moduleplugin' version '1.8.12'
id 'org.openjfx.javafxplugin' version '0.0.13'
id 'org.beryx.jlink' version '2.25.0'
}

javafx {
version = '20'
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
group 'com.ce216'
version '1.0-SNAPSHOT'

repositories {
mavenCentral()
}

ext {
junitVersion = '5.9.1'
}

sourceCompatibility = '17'
targetCompatibility = '17'

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

application {
mainModule = 'com.ce216.dictionary'
mainClass = 'com.ce216.dictionary.App'
}

javafx {
version = '19'
modules = ['javafx.controls', 'javafx.fxml']
}

dependencies {
implementation('org.kordamp.bootstrapfx:bootstrapfx-core:0.4.0')

testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}

test {
useJUnitPlatform()
}

jlink {
imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip")
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'app'
}
}

jlinkZip {
group = 'distribution'
}


159 changes: 143 additions & 16 deletions src/main/java/com/ce216/dictionary/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
import javafx.stage.Stage;

import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

public class MainController {
Expand Down Expand Up @@ -797,6 +801,43 @@ public void Edit() throws IOException {

// Check if the user input is for updating the key or value
if (!wordd.isEmpty() && !worddd.isEmpty()) {
languageMap.remove(word);

// Delete the word and its translation from the language file
String dosyaname = Dil_Dosya.get(languagePair);
Path path = Paths.get("src/main/resources/languages/" + dosyaname);
Charset charset = StandardCharsets.UTF_8;
List<String> fileContent = new ArrayList<>();
try (BufferedReader reader = Files.newBufferedReader(path, charset)) {
String line;
boolean orthfound=false;
while ((line = reader.readLine()) != null) {

if (line.contains("<orth>" + word + "</orth>")){
orthfound=true;
}
if ( !orthfound) {
fileContent.add(line);
}
if (line.contains("</entry>")) {
if(orthfound){
fileContent.add(line);
orthfound=false;
}



}
}
fileContent.add("<entry>");
fileContent.add("<orth>"+wordd+"</orth>");
fileContent.add("<quote>"+worddd+"</quote>");
fileContent.add("</entry>");

}
Files.write(path, fileContent, charset);


// Update the language map with the edited key
languageMap.put(wordd, languageMap.get(word));
languageMap.remove(word);
Expand All @@ -805,20 +846,89 @@ public void Edit() throws IOException {
languageMap.put(wordd,worddd);
}
else if(!wordd.isEmpty() && worddd.isEmpty()){
languageMap.put(wordd, languageMap.get(word));
String Translationtemp;
Translationtemp=languageMap.get(word);
languageMap.remove(word);

// Delete the word and its translation from the language file
String dosyaname = Dil_Dosya.get(languagePair);
Path path = Paths.get("src/main/resources/languages/" + dosyaname);
Charset charset = StandardCharsets.UTF_8;
List<String> fileContent = new ArrayList<>();
try (BufferedReader reader = Files.newBufferedReader(path, charset)) {
String line;
boolean orthfound=false;
while ((line = reader.readLine()) != null) {

if (line.contains("<orth>" + word + "</orth>")){
orthfound=true;
}
if ( !orthfound) {
fileContent.add(line);
}
if (line.contains("</entry>")) {
if(orthfound){
fileContent.add(line);
orthfound=false;
}



}
}
fileContent.add("<entry>");
fileContent.add("<orth>"+wordd+"</orth>");
fileContent.add("<quote>"+Translationtemp+"</quote>");
fileContent.add("</entry>");

}
Files.write(path, fileContent, charset);


languageMap.put(wordd, Translationtemp);
languageMap.remove(word);
EditTextArea1.setText(wordd);
}
else if(wordd.isEmpty() && !worddd.isEmpty()){
languageMap.remove(word);

// Delete the word and its translation from the language file
String dosyaname = Dil_Dosya.get(languagePair);
Path path = Paths.get("src/main/resources/languages/" + dosyaname);
Charset charset = StandardCharsets.UTF_8;
List<String> fileContent = new ArrayList<>();
try (BufferedReader reader = Files.newBufferedReader(path, charset)) {
String line;
boolean orthfound=false;
while ((line = reader.readLine()) != null) {

if (line.contains("<orth>" + word + "</orth>")){
orthfound=true;
}
if ( !orthfound) {
fileContent.add(line);
}
if (line.contains("</entry>")) {
if(orthfound){
fileContent.add(line);
orthfound=false;
}



}
}
fileContent.add("<entry>");
fileContent.add("<orth>"+word+"</orth>");
fileContent.add("<quote>"+worddd+"</quote>");
fileContent.add("</entry>");

}
Files.write(path, fileContent, charset);

languageMap.put(word,worddd);
}
/*else if (!worddd.isEmpty()) {
// Update the language map with the edited value
languageMap.put(word, worddd);
// Update the UI to reflect the changes
EditTextArea1.setText(worddd);
}
*/

else {
System.out.println("Please enter a value for either the key or value field.");
return;
Expand Down Expand Up @@ -872,16 +982,33 @@ public void Delete() throws IOException {

// Delete the word and its translation from the language file
String dosyaname = Dil_Dosya.get(languagePair);
File file = new File("src/main/resources/languages/" + dosyaname);
ArrayList<String> fileContent = new ArrayList<>(Files.readAllLines(file.toPath()));
for (int i = 0; i < fileContent.size(); i++) {
if (fileContent.get(i).contains("<orth>" + word + "</orth>")||fileContent.get(i).contains("<quote>" + word + "</quote>")) {
fileContent.remove(i);
fileContent.remove(i); // Remove the corresponding translation too
break;
Path path = Paths.get("src/main/resources/languages/" + dosyaname);
Charset charset = StandardCharsets.UTF_8;
List<String> fileContent = new ArrayList<>();
try (BufferedReader reader = Files.newBufferedReader(path, charset)) {
String line;
boolean entryFound = false;
boolean orthfound=false;
while ((line = reader.readLine()) != null) {

if (line.contains("<orth>" + word + "</orth>")){
orthfound=true;
}
if ( !orthfound) {
fileContent.add(line);
}
if (line.contains("</entry>")) {
if(orthfound){
fileContent.add(line);
orthfound=false;
}



}
}
}
Files.write(file.toPath(), fileContent);
Files.write(path, fileContent, charset);

System.out.println("Word deleted.");
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/ce216/dictionary/TEIParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;

Expand All @@ -25,9 +26,8 @@ public static HashMap<String,String> Parsing(int Selected) {
// Loop through files and read data into HashMaps

String fileName = fileNames[Selected];
System.out.println(com.ce216.dictionary.TEIParser.class.getResource("/languages/" + fileName));
InputStream inputStream = com.ce216.dictionary.TEIParser.class.getClassLoader().getResourceAsStream("languages/" + fileName);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
URL url = TEIParser.class.getResource("/languages/" + fileName);
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8));

String currentOrth = null;
String line;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module com.ce216.dictionary {
requires javafx.controls;
requires javafx.fxml;
requires java.base;




opens com.ce216.dictionary to javafx.fxml;
exports com.ce216.dictionary;
}
17 changes: 10 additions & 7 deletions src/main/resources/languages/eng-ita.tei
Original file line number Diff line number Diff line change
Expand Up @@ -52660,13 +52660,6 @@
</entry>
<entry>
<form>
<orth>zodiac</orth>
</form>
<sense>
<cit type="trans">
<quote>zodiaco</quote>
</cit>
</sense>
</entry>
<entry>
<form>
Expand All @@ -52681,3 +52674,13 @@
</body>
</text>
</TEI>
<entry>
<orth>zodiacomert</orth>
<quote>zodiacomerdo</quote>
</entry>
<entry>
</entry>
<entry>
<orth>zodiacbartu</orth>
<quote>zodiackral</quote>
</entry>

0 comments on commit 5d09bc6

Please sign in to comment.