Applied changes for SE.QA.09 compliance in live search

Applied changes to ensure compliance with the SE.QA.09 Java Coding Standards
This commit is contained in:
law39 2020-04-24 16:03:41 +01:00
parent 069e6df96a
commit 51d6b9692f
7 changed files with 58 additions and 58 deletions

View file

@ -36,7 +36,7 @@
<artifactId>javafx-maven-plugin</artifactId> <artifactId>javafx-maven-plugin</artifactId>
<version>0.0.1</version> <version>0.0.1</version>
<configuration> <configuration>
<mainClass>uk.ac.aber.cs22120.group20.App</mainClass> <mainClass>uk.ac.aber.cs22120.group20.Application</mainClass>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>

View file

@ -6,7 +6,6 @@
*/ */
package uk.ac.aber.cs22120.group20; package uk.ac.aber.cs22120.group20;
import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
@ -30,7 +29,7 @@ import java.util.LinkedList;
* *
* @version 0.1 Initial development * @version 0.1 Initial development
*/ */
public class App extends Application { public class Application extends javafx.application.Application {
private static Scene scene; private static Scene scene;
public static LinkedList<DictionaryEntry> dictionary = new LinkedList<>(); public static LinkedList<DictionaryEntry> dictionary = new LinkedList<>();
@ -69,7 +68,7 @@ public class App extends Application {
* @throws IOException * @throws IOException
*/ */
private static Parent loadFXML(String fxml) throws IOException { private static Parent loadFXML(String fxml) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml")); FXMLLoader fxmlLoader = new FXMLLoader(Application.class.getResource(fxml + ".fxml"));
return fxmlLoader.load(); return fxmlLoader.load();
} }

View file

@ -7,7 +7,6 @@
package uk.ac.aber.cs22120.group20; package uk.ac.aber.cs22120.group20;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList; import javafx.collections.transformation.FilteredList;
@ -16,7 +15,6 @@ import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.util.Callback;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
@ -38,7 +36,7 @@ import uk.ac.aber.cs22120.group20.json.DictionaryEntry;
* @author Waylen Watts [ncw] * @author Waylen Watts [ncw]
* @version 0.1 Initial development. * @version 0.1 Initial development.
* @see DictionaryEntry * @see DictionaryEntry
* @see App * @see Application
*/ */
public class DictionaryController implements Initializable { public class DictionaryController implements Initializable {
public static Stage primaryStage = null; public static Stage primaryStage = null;
@ -70,18 +68,24 @@ public class DictionaryController implements Initializable {
*/ */
@FXML @FXML
private void switchToPrimary() throws IOException { private void switchToPrimary() throws IOException {
App.setRoot("primary"); Application.setRoot("primary");
} }
/** /**
* Sets up the table and loads the words into it. * Initializes the table of dictionary entries.
* <p>
* 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 url
* @param resourceBundle * @param resourceBundle
*
* @see Application
* @see DictionaryEntry
*/ */
@Override @Override
public void initialize(URL url, ResourceBundle resourceBundle) { public void initialize(URL url, ResourceBundle resourceBundle) {
list.addAll(App.dictionary); list.addAll(Application.dictionary);
table.setRowFactory(tv -> { table.setRowFactory(tv -> {
TableRow<DictionaryEntry> row = new TableRow<DictionaryEntry>() { TableRow<DictionaryEntry> row = new TableRow<DictionaryEntry>() {
@Override @Override
@ -99,17 +103,17 @@ public class DictionaryController implements Initializable {
row.setOnMouseClicked(mouseEvent -> { row.setOnMouseClicked(mouseEvent -> {
if (mouseEvent.getClickCount() == 1 && (!row.isEmpty())) { if (mouseEvent.getClickCount() == 1 && (!row.isEmpty())) {
if (row.getItem().isPracticeWord()) { if (row.getItem().isPracticeWord()) {
App.dictionary.get(list.indexOf(row.getItem())).setPracticeWord(false); Application.dictionary.get(list.indexOf(row.getItem())).setPracticeWord(false);
// row.getItem().setPracticeWord(false); // row.getItem().setPracticeWord(false);
} } else if (!row.getItem().isPracticeWord()) {
else if (!row.getItem().isPracticeWord()) { Application.dictionary.get(list.indexOf(row.getItem())).setPracticeWord(true);
App.dictionary.get(list.indexOf(row.getItem())).setPracticeWord(true);
// row.getItem().setPracticeWord(true); // row.getItem().setPracticeWord(true);
} }
table.getSelectionModel().clearSelection(); table.getSelectionModel().clearSelection();
} }
}); });
return row;} return row;
}
); );
welsh.setCellValueFactory(dictionaryEntryStringCellDataFeatures -> { welsh.setCellValueFactory(dictionaryEntryStringCellDataFeatures -> {
if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals("nm")) { if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals("nm")) {
@ -124,8 +128,7 @@ public class DictionaryController implements Initializable {
english.setCellValueFactory(dictionaryEntryStringCellDataFeatures -> { english.setCellValueFactory(dictionaryEntryStringCellDataFeatures -> {
if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals("verb")) { if (dictionaryEntryStringCellDataFeatures.getValue().getWordType().equals("verb")) {
return new SimpleStringProperty("to " + dictionaryEntryStringCellDataFeatures.getValue().getEnglish()); return new SimpleStringProperty("to " + dictionaryEntryStringCellDataFeatures.getValue().getEnglish());
} } else {
else {
return new SimpleStringProperty(dictionaryEntryStringCellDataFeatures.getValue().getEnglish()); return new SimpleStringProperty(dictionaryEntryStringCellDataFeatures.getValue().getEnglish());
} }
}); });
@ -134,28 +137,28 @@ public class DictionaryController implements Initializable {
FilteredList<DictionaryEntry> filteredList = new FilteredList<>(list, p -> true); // Wrap list in a FilteredList FilteredList<DictionaryEntry> filteredList = new FilteredList<>(list, p -> true); // Wrap list in a FilteredList
searchBox.textProperty().addListener((observable, oldValue, newValue) -> { searchBox.textProperty().addListener((observable, oldSearchTerm, newSearchTerm) -> {
filteredList.setPredicate(dictionaryEntry -> { // returns true on a filter match, false if no match filteredList.setPredicate(dictionaryEntry -> { // returns true on a filter match, false if no match
boolean returnVal = false; boolean result = false;
table.refresh(); // This fixes the table highlighting issue table.refresh(); // This fixes the table highlighting issue
if (newValue == null || newValue.isEmpty()) { // If filter text is empty, display all dictionary entries if (newSearchTerm == null || newSearchTerm.isEmpty()) { // If filter text is empty, display all dictionary entries
returnVal = true; result = true;
} else { } else {
// need all same case for compare. // need all same case for compare.
String lowerCaseFilter = newValue.toLowerCase(); final String lowerCaseSearchFilter = newSearchTerm.toLowerCase();
if (dictionaryEntry.getWelsh().toLowerCase().contains(lowerCaseFilter)) { if (dictionaryEntry.getWelsh().toLowerCase().contains(lowerCaseSearchFilter)) {
returnVal = true; // Filter matches Welsh result = true; // Filter matches Welsh
} else if (dictionaryEntry.getEnglish().toLowerCase().contains(lowerCaseFilter)) { } else if (dictionaryEntry.getEnglish().toLowerCase().contains(lowerCaseSearchFilter)) {
returnVal = true; // Filter matches English result = true; // Filter matches English
} else if (dictionaryEntry.getWordType().toLowerCase().contains(lowerCaseFilter)) { } else if (dictionaryEntry.getWordType().toLowerCase().contains(lowerCaseSearchFilter)) {
returnVal = true; // Filter matches Word Type result = true; // Filter matches Word Type
} else if (dictionaryEntry.getWordType().equals("verb") && ("to " + dictionaryEntry.getEnglish()).toLowerCase().contains(lowerCaseFilter)) { } else if (dictionaryEntry.getWordType().equals("verb") && ("to " + dictionaryEntry.getEnglish()).toLowerCase().contains(lowerCaseSearchFilter)) {
returnVal = true; // Filter matches ['to' + a word] or [a word] if word is a verb result = true; // Filter matches ['to' + a word] or [a word] if word is a verb
} }
} }
return returnVal; return result;
}); });
}); });

View file

@ -25,12 +25,12 @@ import javafx.fxml.FXML;
* @author Tom Perry [top1] * @author Tom Perry [top1]
* @author Waylen Watts [ncw] * @author Waylen Watts [ncw]
* @version 0.1 Initial development * @version 0.1 Initial development
* @see App * @see Application
*/ */
public class PrimaryController { public class PrimaryController {
@FXML @FXML
private void switchToSecondary() throws IOException { private void switchToSecondary() throws IOException {
App.setRoot("secondary"); Application.setRoot("secondary");
} }
} }

View file

@ -21,12 +21,12 @@ import javafx.fxml.FXML;
* @author Tom Perry [top1] * @author Tom Perry [top1]
* @author Waylen Watts [ncw] * @author Waylen Watts [ncw]
* @version 0.1 Initial development * @version 0.1 Initial development
* @see App * @see Application
*/ */
public class SecondaryController { public class SecondaryController {
@FXML @FXML
private void switchToDictionary() throws IOException { private void switchToDictionary() throws IOException {
App.setRoot("dictionary"); Application.setRoot("dictionary");
} }
} }

View file

@ -6,9 +6,7 @@
*/ */
package uk.ac.aber.cs22120.group20.json; package uk.ac.aber.cs22120.group20.json;
import javafx.beans.property.SimpleBooleanProperty; import uk.ac.aber.cs22120.group20.Application;
import javafx.beans.property.SimpleStringProperty;
import uk.ac.aber.cs22120.group20.App;
import uk.ac.aber.cs22120.group20.DictionaryController; import uk.ac.aber.cs22120.group20.DictionaryController;
/** /**
@ -38,7 +36,7 @@ public class DictionaryEntry {
* @param welsh welsh translation of the word * @param welsh welsh translation of the word
* @param wordType type of word * @param wordType type of word
* @param practiceWord determines if the entry is in the practice list * @param practiceWord determines if the entry is in the practice list
* @see App * @see Application
* @see DictionaryController * @see DictionaryController
*/ */
public DictionaryEntry(String english, String welsh, String wordType, Boolean practiceWord) { public DictionaryEntry(String english, String welsh, String wordType, Boolean practiceWord) {