From 0bcd37a860ea8ce79b20f10d809ee47327264ba4 Mon Sep 17 00:00:00 2001 From: osp1 Date: Thu, 30 Apr 2020 22:13:39 +0100 Subject: [PATCH] Removed headers on Dictionary and PracticeList. --- .../group20/javafx/DictionaryController.java | 19 ++- .../javafx/PracticeListController.java | 119 ++++++++++-------- 2 files changed, 85 insertions(+), 53 deletions(-) diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/DictionaryController.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/DictionaryController.java index 8af3ebd..11047c1 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/DictionaryController.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/DictionaryController.java @@ -7,6 +7,8 @@ package uk.ac.aber.cs221.group20.javafx; import javafx.beans.property.SimpleStringProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; @@ -18,6 +20,8 @@ import javafx.scene.control.TableView; import javafx.scene.control.TextField; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import uk.ac.aber.cs221.group20.json.DictionaryEntry; @@ -128,7 +132,19 @@ public class DictionaryController extends SharedCodeController { */ public void initialize() { setup(); - + table.widthProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observableValue, Number number, Number t1) { + Pane tableHeader = (Pane) table.lookup("TableHeaderRow"); + if (tableHeader != null && tableHeader.isVisible()) { + tableHeader.setMaxHeight(0); + tableHeader.setMinHeight(0); + tableHeader.setPrefHeight(0); + tableHeader.setVisible(false); + tableHeader.setManaged(false); + } + } + }); english.setComparator(new Comparator() { @Override public int compare(String s, String t1) { @@ -191,6 +207,7 @@ public class DictionaryController extends SharedCodeController { return row; } ); + welsh.setCellValueFactory(dictionaryEntryStringCellDataFeatures -> { if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals(DictionaryEntry.wordTypeEnum.nm)) { return new SimpleStringProperty(dictionaryEntryStringCellDataFeatures.getValue().getWelsh() + " {nm}"); diff --git a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/PracticeListController.java b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/PracticeListController.java index 2a13b36..a13824a 100644 --- a/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/PracticeListController.java +++ b/src/Welsh Vocabulary Tutor/src/main/java/uk/ac/aber/cs221/group20/javafx/PracticeListController.java @@ -7,6 +7,8 @@ package uk.ac.aber.cs221.group20.javafx; import javafx.beans.property.SimpleStringProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; @@ -15,6 +17,7 @@ import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.scene.image.Image; import javafx.scene.image.ImageView; +import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import uk.ac.aber.cs221.group20.json.DictionaryEntry; @@ -62,19 +65,16 @@ public class PracticeListController extends SharedCodeController { if (isSortedByEnglish) { if (welsh.getSortType().equals(TableColumn.SortType.ASCENDING)) { alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-50.png")); - } - else if (welsh.getSortType().equals(TableColumn.SortType.DESCENDING)) { + } else if (welsh.getSortType().equals(TableColumn.SortType.DESCENDING)) { alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-reversed-50.png")); } table.getSortOrder().clear(); table.getSortOrder().add(welsh); isSortedByEnglish = false; - } - else { + } else { if (english.getSortType().equals(TableColumn.SortType.ASCENDING)) { alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-50.png")); - } - else if (english.getSortType().equals(TableColumn.SortType.DESCENDING)) { + } else if (english.getSortType().equals(TableColumn.SortType.DESCENDING)) { alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-reversed-50.png")); } table.getSortOrder().clear(); @@ -83,7 +83,7 @@ public class PracticeListController extends SharedCodeController { } table.sort(); searchBox.textProperty().setValue(searchBox.textProperty().getValue() + " "); - searchBox.textProperty().setValue(searchBox.textProperty().getValue().substring(0, searchBox.textProperty().getValue().length()-1)); + searchBox.textProperty().setValue(searchBox.textProperty().getValue().substring(0, searchBox.textProperty().getValue().length() - 1)); searchBox.positionCaret(searchBox.textProperty().getValue().length()); } @@ -117,31 +117,45 @@ public class PracticeListController extends SharedCodeController { *

* An observable list of DictionaryEntries is loaded from the Application class into a local instance of ObservableList. * It also sets up Lambda expressions related to live searching functionality and the display of DictionaryEntries. + *

+ * // * @param url + * // * @param resourceBundle * - // * @param url - // * @param resourceBundle * @see Application * @see DictionaryEntry */ public void initialize() { setup(); + table.widthProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observableValue, Number number, Number t1) { + Pane tableHeader = (Pane) table.lookup("TableHeaderRow"); + if (tableHeader != null && tableHeader.isVisible()) { + tableHeader.setMaxHeight(0); + tableHeader.setMinHeight(0); + tableHeader.setPrefHeight(0); + tableHeader.setVisible(false); + tableHeader.setManaged(false); + } + } + }); english.setComparator(new Comparator() { - @Override - public int compare(String s, String t1) { - s = s.toLowerCase(); - t1 = t1.toLowerCase(); - if (s.startsWith("to ")) { - return s.substring(3).compareTo(t1); - } - if (t1.startsWith("to ")) { - return s.compareTo(t1.substring(3)); - } - return s.compareTo(t1); - } - }); + @Override + public int compare(String s, String t1) { + s = s.toLowerCase(); + t1 = t1.toLowerCase(); + if (s.startsWith("to ")) { + return s.substring(3).compareTo(t1); + } + if (t1.startsWith("to ")) { + return s.compareTo(t1.substring(3)); + } + return s.compareTo(t1); + } + }); - currentPageIcon.setImage(new Image(getClass().getResourceAsStream("/assets/icons/white_icons/50px/rating-50.png"))); + currentPageIcon.setImage(new Image(getClass().getResourceAsStream("/assets/icons/white_icons/50px/rating-50.png"))); currentPageText.setText("Practice List"); alphaSort.setImage(new Image("file:src/main/resources/assets/icons/black_icons/50px/sort-alpha-up-50.png")); @@ -161,32 +175,35 @@ public class PracticeListController extends SharedCodeController { // if (dictionaryEntry.isPracticeWord()) { // setStyle("-fx-background-color: gray;"); // } else { - setStyle(" "); + setStyle(" "); // } } } }; - row.setOnMouseClicked(mouseEvent -> { - if (mouseEvent.getClickCount() == 1 && (!row.isEmpty())) { - if (row.getItem().isPracticeWord()) { - Application.dictionary.get(list.indexOf(row.getItem())).setPracticeWord(false); - ArrayList toRemove = new ArrayList(); - for (DictionaryEntry entry : Application.practiceList) { - if (entry.equals(row.getItem())) { - toRemove.add(entry); - } - } - Application.practiceList.removeAll(toRemove); -// row.getItem().setPracticeWord(false); - } else if (!row.getItem().isPracticeWord()) { - Application.dictionary.get(list.indexOf(row.getItem())).setPracticeWord(true); - Application.practiceList.add(row.getItem()); -// row.getItem().setPracticeWord(true); - } - table.getSelectionModel().clearSelection(); - } - }); - return row; + row.setOnMouseClicked(mouseEvent -> { + if (mouseEvent.getClickCount() == 1 && (!row.isEmpty())) { + for (DictionaryEntry entry : Application.dictionary) { + if (entry.equals(row.getItem())) { + entry.setPracticeWord(false); + list.remove(row.getItem()); + table.refresh(); + } + + } + + ArrayList toRemove = new ArrayList(); + for (DictionaryEntry entry : Application.practiceList) { + if (entry.equals(row.getItem())) { + toRemove.add(entry); + list.remove(row.getItem()); + } + } + Application.practiceList.removeAll(toRemove); + table.getSelectionModel().clearSelection(); + } + } + ); + return row; } ); welsh.setCellValueFactory(dictionaryEntryStringCellDataFeatures -> { @@ -222,15 +239,13 @@ public class PracticeListController extends SharedCodeController { if (isSortedByEnglish) { if (dictionaryEntry.getEnglish().toLowerCase().startsWith(lowerCaseSearchFilter)) { result = true; // Filter matches English - } - else if(lowerCaseSearchFilter.startsWith("to ")){ + } else if (lowerCaseSearchFilter.startsWith("to ")) { if (dictionaryEntry.getWordType().equals(DictionaryEntry.wordTypeEnum.verb) && ("to " + dictionaryEntry.getEnglish()).toLowerCase().startsWith(lowerCaseSearchFilter)) { result = true; // Filter matches ['to' + a word] or [a word] if word is a verb } } - } - else { - if (dictionaryEntry.getWelsh().toLowerCase().startsWith(lowerCaseSearchFilter)) { + } else { + if (dictionaryEntry.getWelsh().toLowerCase().startsWith(lowerCaseSearchFilter)) { result = true; // Filter matches Welsh } } @@ -244,9 +259,9 @@ public class PracticeListController extends SharedCodeController { table.setItems(sortedList); - if(isSortedByEnglish){ + if (isSortedByEnglish) { table.getSortOrder().add(english); - } else{ + } else { table.getSortOrder().add(welsh); } }