Added practistList to Application

This commit is contained in:
osp1 2020-04-28 13:33:40 +01:00
parent c8840bb251
commit 0b8d11f207
3 changed files with 80 additions and 53 deletions

View file

@ -35,74 +35,80 @@ import java.util.Scanner;
* @version 0.1 Initial development
*/
public class Application extends javafx.application.Application {
private static Scene scene;
private static Scene scene;
private JsonProcessing jsonProcessing = new JsonProcessing();
private Scanner scanner = new Scanner(System.in);
private JsonProcessing jsonProcessing = new JsonProcessing();
private Scanner scanner = new Scanner(System.in);
public static LinkedList<DictionaryEntry> dictionary = new LinkedList<>();
public static LinkedList<DictionaryEntry> dictionary = new LinkedList<>();
public static LinkedList<DictionaryEntry> practiseList = new LinkedList<>();
/**
*
* @param stage
* @throws IOException
*/
@Override
public void start(Stage stage) throws IOException {
File jsonFileLocation = null;
/**
*
* @param stage
* @throws IOException
*/
@Override
public void start(Stage stage) throws IOException {
File jsonFileLocation = null;
while(jsonFileLocation ==null) {
FileChooser fileChooser = new FileChooser();
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Json Files", "*.json"));
fileChooser.setTitle("Open Json File");
jsonFileLocation = fileChooser.showOpenDialog(stage);
}
while(jsonFileLocation ==null) {
FileChooser fileChooser = new FileChooser();
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Json Files", "*.json"));
fileChooser.setTitle("Open Json File");
jsonFileLocation = fileChooser.showOpenDialog(stage);
}
final File jsonFileFinalLocation = jsonFileLocation;
dictionary = jsonProcessing.readInJson(jsonFileFinalLocation);
final File jsonFileFinalLocation = jsonFileLocation;
dictionary = jsonProcessing.readInJson(jsonFileFinalLocation);
for (DictionaryEntry entry : dictionary) {
if (entry.isPracticeWord()) {
practiseList.add(entry);
}
}
// dictionary.add(new DictionaryEntry("abbey", "abaty", "nm", false));
// dictionary.add(new DictionaryEntry("believe", "credu", "verb", true));
// dictionary.add(new DictionaryEntry("concert", "cyngerdd", "nm", false));
// dictionary.add(new DictionaryEntry("disease", "clefyd", "nm", true));
// dictionary.add(new DictionaryEntry("extremely", "dros ben", "other", false));
// dictionary.add(new DictionaryEntry("flu", "ffliw", "nm", false));
scene = new Scene(loadFXML("dictionary"));
stage.setScene(scene);
scene = new Scene(loadFXML("dictionary"));
stage.setScene(scene);
// stage.setOnCloseRequest(e -> {
// jsonProcessing.writeOutJson(jsonFileLocation, dictionary);
// Platform.exit();
// System.exit(0);
// });
stage.show();
}
stage.show();
}
/**
*
* @param fxml
* @throws IOException
*/
static void setRoot(String fxml) throws IOException {
scene.setRoot(loadFXML(fxml));
}
/**
*
* @param fxml
* @throws IOException
*/
static void setRoot(String fxml) throws IOException {
scene.setRoot(loadFXML(fxml));
}
/**
*
* @param fxml
* @return
* @throws IOException
*/
private static Parent loadFXML(String fxml) throws IOException {
/**
*
* @param fxml
* @return
* @throws IOException
*/
private static Parent loadFXML(String fxml) throws IOException {
// FXMLLoader fxmlLoader = new FXMLLoader(Application.class.getResource(fxml + ".fxml"));
FXMLLoader fxmlLoader = new FXMLLoader(new URL("file:src/main/resources/uk/ac/aber/cs22120/group20/" + fxml + ".fxml"));
return fxmlLoader.load();
}
FXMLLoader fxmlLoader = new FXMLLoader(new URL("file:src/main/resources/uk/ac/aber/cs22120/group20/" + fxml + ".fxml"));
return fxmlLoader.load();
}
/**
*
* @param args
*/
public static void main(String[] args) {
launch();
}
/**
*
* @param args
*/
public static void main(String[] args) {
launch();
}
}

View file

@ -25,6 +25,7 @@ import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
/**
@ -148,9 +149,17 @@ public class DictionaryController implements Initializable {
if (mouseEvent.getClickCount() == 1 && (!row.isEmpty())) {
if (row.getItem().isPracticeWord()) {
Application.dictionary.get(list.indexOf(row.getItem())).setPracticeWord(false);
ArrayList<DictionaryEntry> toRemove = new ArrayList<DictionaryEntry>();
for (DictionaryEntry entry : Application.practiseList) {
if (entry.equals(row.getItem())) {
toRemove.add(entry);
}
}
Application.practiseList.removeAll(toRemove);
// row.getItem().setPracticeWord(false);
} else if (!row.getItem().isPracticeWord()) {
Application.dictionary.get(list.indexOf(row.getItem())).setPracticeWord(true);
Application.practiseList.add(row.getItem());
// row.getItem().setPracticeWord(true);
}
table.getSelectionModel().clearSelection();

View file

@ -22,6 +22,7 @@ import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
/**
@ -70,10 +71,11 @@ public class PracticeListController implements Initializable {
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
// list.addAll(Application.dictionary);
for (DictionaryEntry entry : Application.dictionary) {
if (entry.isPracticeWord())
list.add(entry);
}
list.addAll(Application.practiseList);
// for (DictionaryEntry entry : Application.dictionary) {
// if (entry.isPracticeWord())
// list.add(entry);
// }
FilteredList<DictionaryEntry> filteredList = new FilteredList<>(list, p -> true); // Wrap list in a FilteredList
@ -132,7 +134,17 @@ public class PracticeListController implements Initializable {
list.remove(row.getItem());
table.refresh();
}
}
ArrayList<DictionaryEntry> toRemove = new ArrayList<DictionaryEntry>();
for (DictionaryEntry entry : Application.practiseList) {
if (entry.equals(row.getItem())) {
toRemove.add(entry);
list.remove(row.getItem());
}
}
Application.practiseList.removeAll(toRemove);
table.getSelectionModel().clearSelection();
}
});