Merge branch '56-fix-checkstyle-erros-for-javafx-application-flashy' into 'master'

Resolve "Fix checkstyle erros for JavaFX application Flashy"

Closes #56

See merge request it1901/groups-2021/gr2141/gr2141!40
This commit is contained in:
Hanne Lindbäck Fyrand
2021-11-12 09:08:58 +00:00
27 changed files with 604 additions and 245 deletions
+5
View File
@@ -0,0 +1,5 @@
{
"recommendations": [
"shengchen.vscode-checkstyle"
]
}
+2 -1
View File
@@ -1,3 +1,4 @@
{
"java.configuration.updateBuildConfiguration": "automatic"
"java.configuration.updateBuildConfiguration": "automatic",
"java.checkstyle.configuration": "${workspaceFolder}\\flashy\\checkstyle.xml"
}
+317
View File
@@ -0,0 +1,317 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<!--
Checkstyle configuration that checks the Google coding conventions from Google Java Style
that can be found at https://google.github.io/styleguide/javaguide.html
Checkstyle is very configurable. Be sure to read the documentation at
http://checkstyle.org (or in your downloaded distribution).
To completely disable a check, just comment it out or delete it from the file.
To suppress certain violations please review suppression filters.
Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
-->
<module name = "Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="warning"/>
<property name="fileExtensions" value="java, properties, xml"/>
<!-- Excludes all 'module-info.java' files -->
<!-- See https://checkstyle.org/config_filefilters.html -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>
<!-- https://checkstyle.org/config_filters.html#SuppressionFilter -->
<module name="SuppressionFilter">
<property name="file" value="${org.checkstyle.google.suppressionfilter.config}"
default="checkstyle-suppressions.xml" />
<property name="optional" value="true"/>
</module>
<!-- Checks for whitespace -->
<!-- See http://checkstyle.org/config_whitespace.html -->
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="LineLength">
<property name="fileExtensions" value="java"/>
<property name="max" value="100"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>
<module name="TreeWalker">
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
<property name="format"
value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
<property name="message"
value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
</module>
<module name="AvoidEscapedUnicodeCharacters">
<property name="allowEscapesForControlCharacters" value="true"/>
<property name="allowByTailComment" value="true"/>
<property name="allowNonPrintableEscapes" value="true"/>
</module>
<module name="AvoidStarImport"/>
<module name="OneTopLevelClass"/>
<module name="NoLineWrap">
<property name="tokens" value="PACKAGE_DEF, IMPORT, STATIC_IMPORT"/>
</module>
<module name="EmptyBlock">
<property name="option" value="TEXT"/>
<property name="tokens"
value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
</module>
<module name="NeedBraces">
<property name="tokens"
value="LITERAL_DO, LITERAL_ELSE, LITERAL_FOR, LITERAL_IF, LITERAL_WHILE"/>
</module>
<module name="LeftCurly">
<property name="tokens"
value="ANNOTATION_DEF, CLASS_DEF, CTOR_DEF, ENUM_CONSTANT_DEF, ENUM_DEF,
INTERFACE_DEF, LAMBDA, LITERAL_CASE, LITERAL_CATCH, LITERAL_DEFAULT,
LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF,
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, METHOD_DEF,
OBJBLOCK, STATIC_INIT"/>
</module>
<module name="RightCurly">
<property name="id" value="RightCurlySame"/>
<property name="tokens"
value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE,
LITERAL_DO"/>
</module>
<module name="RightCurly">
<property name="id" value="RightCurlyAlone"/>
<property name="option" value="alone"/>
<property name="tokens"
value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT,
INSTANCE_INIT, ANNOTATION_DEF, ENUM_DEF"/>
</module>
<module name="WhitespaceAround">
<property name="allowEmptyConstructors" value="true"/>
<property name="allowEmptyLambdas" value="true"/>
<property name="allowEmptyMethods" value="true"/>
<property name="allowEmptyTypes" value="true"/>
<property name="allowEmptyLoops" value="true"/>
<property name="tokens"
value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR,
BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAMBDA, LAND,
LCURLY, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY,
LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SWITCH, LITERAL_SYNCHRONIZED,
LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN,
NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR,
SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND"/>
<message key="ws.notFollowed"
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
<message key="ws.notPreceded"
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
</module>
<module name="OneStatementPerLine"/>
<module name="MultipleVariableDeclarations"/>
<module name="ArrayTypeStyle"/>
<module name="MissingSwitchDefault"/>
<module name="FallThrough"/>
<module name="UpperEll"/>
<module name="ModifierOrder"/>
<module name="EmptyLineSeparator">
<property name="tokens"
value="PACKAGE_DEF, IMPORT, STATIC_IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF,
STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
<property name="allowNoEmptyLineBetweenFields" value="true"/>
</module>
<module name="SeparatorWrap">
<property name="id" value="SeparatorWrapDot"/>
<property name="tokens" value="DOT"/>
<property name="option" value="nl"/>
</module>
<module name="SeparatorWrap">
<property name="id" value="SeparatorWrapComma"/>
<property name="tokens" value="COMMA"/>
<property name="option" value="EOL"/>
</module>
<module name="SeparatorWrap">
<!-- ELLIPSIS is EOL until https://github.com/google/styleguide/issues/258 -->
<property name="id" value="SeparatorWrapEllipsis"/>
<property name="tokens" value="ELLIPSIS"/>
<property name="option" value="EOL"/>
</module>
<module name="SeparatorWrap">
<!-- ARRAY_DECLARATOR is EOL until https://github.com/google/styleguide/issues/259 -->
<property name="id" value="SeparatorWrapArrayDeclarator"/>
<property name="tokens" value="ARRAY_DECLARATOR"/>
<property name="option" value="EOL"/>
</module>
<module name="SeparatorWrap">
<property name="id" value="SeparatorWrapMethodRef"/>
<property name="tokens" value="METHOD_REF"/>
<property name="option" value="nl"/>
</module>
<module name="PackageName">
<property name="format" value="^[a-z0-9]+(\.[a-z0-9]*)*$"/>
<message key="name.invalidPattern"
value="Package name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="TypeName">
<property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF"/>
<message key="name.invalidPattern"
value="Type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="MemberName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
<message key="name.invalidPattern"
value="Member name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="ParameterName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="LambdaParameterName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Lambda parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="CatchParameterName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="LocalVariableName">
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
<message key="name.invalidPattern"
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="ClassTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
<message key="name.invalidPattern"
value="Class type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="MethodTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
<message key="name.invalidPattern"
value="Method type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="InterfaceTypeParameterName">
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
<message key="name.invalidPattern"
value="Interface type name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="NoFinalizer"/>
<module name="GenericWhitespace">
<message key="ws.followed"
value="GenericWhitespace ''{0}'' is followed by whitespace."/>
<message key="ws.preceded"
value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
<message key="ws.illegalFollow"
value="GenericWhitespace ''{0}'' should followed by whitespace."/>
<message key="ws.notPreceded"
value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
</module>
<module name="Indentation">
<property name="basicOffset" value="2"/>
<property name="braceAdjustment" value="0"/>
<property name="caseIndent" value="2"/>
<property name="throwsIndent" value="4"/>
<property name="lineWrappingIndentation" value="4"/>
<property name="arrayInitIndent" value="2"/>
</module>
<module name="AbbreviationAsWordInName">
<property name="ignoreFinal" value="false"/>
<property name="allowedAbbreviationLength" value="1"/>
<property name="tokens"
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, ANNOTATION_DEF, ANNOTATION_FIELD_DEF,
PARAMETER_DEF, VARIABLE_DEF, METHOD_DEF"/>
</module>
<module name="OverloadMethodsDeclarationOrder"/>
<module name="VariableDeclarationUsageDistance"/>
<module name="CustomImportOrder">
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="separateLineBetweenGroups" value="true"/>
<property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE"/>
<property name="tokens" value="IMPORT, STATIC_IMPORT, PACKAGE_DEF"/>
</module>
<module name="MethodParamPad">
<property name="tokens"
value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF,
SUPER_CTOR_CALL, ENUM_CONSTANT_DEF"/>
</module>
<module name="NoWhitespaceBefore">
<property name="tokens"
value="COMMA, SEMI, POST_INC, POST_DEC, DOT, ELLIPSIS, METHOD_REF"/>
<property name="allowLineBreaks" value="true"/>
</module>
<module name="ParenPad">
<property name="tokens"
value="ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_CALL, CTOR_DEF, DOT, ENUM_CONSTANT_DEF,
EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW,
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, METHOD_CALL,
METHOD_DEF, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL, LAMBDA"/>
</module>
<module name="OperatorWrap">
<property name="option" value="NL"/>
<property name="tokens"
value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR,
LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF "/>
</module>
<module name="AnnotationLocation">
<property name="id" value="AnnotationLocationMostCases"/>
<property name="tokens"
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
</module>
<module name="AnnotationLocation">
<property name="id" value="AnnotationLocationVariables"/>
<property name="tokens" value="VARIABLE_DEF"/>
<property name="allowSamelineMultipleAnnotations" value="true"/>
</module>
<module name="NonEmptyAtclauseDescription"/>
<module name="InvalidJavadocPosition"/>
<module name="JavadocTagContinuationIndentation"/>
<module name="JavadocParagraph"/>
<module name="AtclauseOrder">
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
<property name="target"
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
</module>
<module name="JavadocMethod">
<property name="scope" value="public"/>
<property name="allowMissingParamTags" value="true"/>
<property name="allowMissingReturnTag" value="true"/>
<property name="allowedAnnotations" value="Override, Test"/>
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/>
</module>
<module name="MissingJavadocMethod">
<property name="scope" value="public"/>
<property name="minLineCount" value="2"/>
<property name="allowedAnnotations" value="Override, Test"/>
<property name="tokens" value="METHOD_DEF, CTOR_DEF, ANNOTATION_FIELD_DEF"/>
</module>
<module name="MethodName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
<message key="name.invalidPattern"
value="Method name ''{0}'' must match pattern ''{1}''."/>
</module>
<module name="SingleLineJavadoc">
<property name="ignoreInlineTags" value="false"/>
</module>
<module name="EmptyCatchBlock">
<property name="exceptionVariableName" value="expected"/>
</module>
<module name="CommentsIndentation">
<property name="tokens" value="SINGLE_LINE_COMMENT, BLOCK_COMMENT_BEGIN"/>
</module>
<!-- https://checkstyle.org/config_filters.html#SuppressionXpathFilter -->
<module name="SuppressionXpathFilter">
<property name="file" value="${org.checkstyle.google.suppressionxpathfilter.config}"
default="checkstyle-xpath-suppressions.xml" />
<property name="optional" value="true"/>
</module>
</module>
</module>
@@ -1,19 +1,20 @@
package it1901.groups2021.gr2141.core.domainlogic;
import java.util.List;
import java.util.Random;
import java.util.prefs.Preferences;
import it1901.groups2021.gr2141.core.models.CardContent;
import it1901.groups2021.gr2141.core.models.CardDeck;
import it1901.groups2021.gr2141.core.state.Observable;
import java.util.List;
import java.util.Random;
import java.util.prefs.Preferences;
/**
* A class handling card navigation from a CardDeck
* A class handling card navigation from a CardDeck.
*/
public class FlashcardProvider extends Observable<FlashcardProvider> {
private static final Preferences prefs = Preferences.userRoot().node(FlashcardProvider.class.getName());
private static final Preferences preferences = Preferences.userRoot()
.node(FlashcardProvider
.class.getName());
private CardDeck deck;
private int cardIndex;
@@ -26,16 +27,16 @@ public class FlashcardProvider extends Observable<FlashcardProvider> {
/**
* Default constructor.
*
* @param deck the initial carddeck to register to the provider.
* @param deck the initial cardDeck to register to the provider.
*/
public FlashcardProvider(CardDeck deck) {
this.setCardDeck(deck);
this.cardIndex = 0;
this.cardShowsFront = true;
this.showOrderIsFlippedMode = prefs.getBoolean("showOrderIsFlippedMode", false);
this.cardOrderIsRandomMode = prefs.getBoolean("cardOrderIsRandomMode", false);
this.firstLastWrapAroundMode = prefs.getBoolean("firstLastWrapAroundMode", true);
this.showOrderIsFlippedMode = preferences.getBoolean("showOrderIsFlippedMode", false);
this.cardOrderIsRandomMode = preferences.getBoolean("cardOrderIsRandomMode", false);
this.firstLastWrapAroundMode = preferences.getBoolean("firstLastWrapAroundMode", true);
}
private void updateSubscribers() {
@@ -104,22 +105,13 @@ public class FlashcardProvider extends Observable<FlashcardProvider> {
this.cardIndex = cardIndex;
if (firstLastWrapAroundMode)
if (firstLastWrapAroundMode) {
this.cardIndex = Math.floorMod(this.cardIndex, this.deck.getNumberOfCards());
}
cardShowsFront = true;
updateSubscribers();
}
// used for later iterations
// public void turnToFirstCard() {
// turnToCard(0);
// }
// public void turnToLastCard() {
// turnToCard(this.deck.getNumberOfCards() - 1);
// }
/**
* Turn to the next card in the stack.
*
@@ -190,7 +182,7 @@ public class FlashcardProvider extends Observable<FlashcardProvider> {
*/
public void toggleShowOrderIsFlippedMode() {
this.showOrderIsFlippedMode = !this.showOrderIsFlippedMode;
prefs.putBoolean("showOrderIsFlippedMode", this.showOrderIsFlippedMode);
preferences.putBoolean("showOrderIsFlippedMode", this.showOrderIsFlippedMode);
updateSubscribers();
}
@@ -201,7 +193,7 @@ public class FlashcardProvider extends Observable<FlashcardProvider> {
*/
public void toggleCardOrderIsRandomMode() {
this.cardOrderIsRandomMode = !this.cardOrderIsRandomMode;
prefs.putBoolean("cardOrderIsRandomMode", this.cardOrderIsRandomMode);
preferences.putBoolean("cardOrderIsRandomMode", this.cardOrderIsRandomMode);
updateSubscribers();
}
@@ -212,7 +204,7 @@ public class FlashcardProvider extends Observable<FlashcardProvider> {
*/
public void toggleFirstLastWrapAroundMode() {
this.firstLastWrapAroundMode = !this.firstLastWrapAroundMode;
prefs.putBoolean("firstLastWrapAroundMode", this.firstLastWrapAroundMode);
preferences.putBoolean("firstLastWrapAroundMode", this.firstLastWrapAroundMode);
updateSubscribers();
}
@@ -234,6 +226,6 @@ public class FlashcardProvider extends Observable<FlashcardProvider> {
"showOrderIsFlippedMode",
"cardOrderIsRandomMode",
"firstLastWrapAroundMode"
).forEach(prefs::remove);
).forEach(preferences::remove);
}
}
@@ -5,7 +5,6 @@ import java.util.List;
/**
* Data model representing the content inside a {@link Flashcard Flashcard}.
*
* Usually consist of one or more lines of text.
*/
public class CardContent {
@@ -16,9 +15,9 @@ public class CardContent {
* @param lines The lines of text.
*/
public CardContent(List<String> lines) {
if (lines == null || lines.size() == 0)
if (lines == null || lines.size() == 0) {
throw new IllegalArgumentException("Lines can not be null/empty");
}
this.lines = lines;
}
@@ -27,17 +26,17 @@ public class CardContent {
* @param text The lines of text.
*/
public CardContent(String text) {
if (text == null || text.length() == 0)
if (text == null || text.length() == 0) {
throw new IllegalArgumentException("Text can not be null/empty");
}
this.lines = Arrays.asList(text.split("\n"));
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof CardContent))
if (!(obj instanceof CardContent)) {
return false;
}
return this.getLines().equals(((CardContent) obj).getLines());
}
@@ -1,33 +1,32 @@
package it1901.groups2021.gr2141.core.models;
import it1901.groups2021.gr2141.core.state.Observable;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import it1901.groups2021.gr2141.core.state.Observable;
/**
* Data model representing a deck/collection of {@link Flashcard Flashcard}s.
*/
public class CardDeck extends Observable<CardDeck> {
private List<Flashcard> flashcards;
/**
* Create an empty new instance
* Create an empty new instance.
*/
public CardDeck() {
this.flashcards = new ArrayList<>();
}
/**
* Create an instance from a list of {@link Flashcard Flashcard}s
* Create an instance from a list of {@link Flashcard Flashcards}.
*
* @param flashcards A list of {@link Flashcard Flashcard} instances
*/
public CardDeck(List<Flashcard> flashcards) {
if (flashcards == null)
if (flashcards == null) {
throw new IllegalArgumentException("Flashcards can not be null");
}
// By wrapping the cards into a new list, the list becomes mutable
this.flashcards = new ArrayList<>(flashcards);
}
@@ -39,9 +38,9 @@ public class CardDeck extends Observable<CardDeck> {
@Override
public boolean equals(Object obj) {
if (!(obj instanceof CardDeck))
if (!(obj instanceof CardDeck)) {
return false;
}
return this.getFlashcards().equals(((CardDeck) obj).getFlashcards());
}
@@ -51,9 +50,8 @@ public class CardDeck extends Observable<CardDeck> {
@Override
public String toString() {
return "{\n" +
String.join("\n", flashcards.stream().map((f) -> " " + f.toString()).collect(Collectors.toList())) +
"\n}";
return "{\n" + String.join("\n", flashcards.stream().map((f) -> " "
+ f.toString()).collect(Collectors.toList())) + "\n}";
}
/**
@@ -83,9 +81,9 @@ public class CardDeck extends Observable<CardDeck> {
* @param card The new flashcard to add.
*/
public void add(Flashcard card) {
if (card == null)
if (card == null) {
throw new IllegalArgumentException("Flashcard can not be null");
}
flashcards.add(card);
updateSubscribers();
}
@@ -98,11 +96,12 @@ public class CardDeck extends Observable<CardDeck> {
* @param card The new flashcard to add.
*/
public void add(int index, Flashcard card) {
if (card == null)
if (card == null) {
throw new IllegalArgumentException("Flashcard can not be null");
if (index < 0 || flashcards.size() < index)
}
if (index < 0 || flashcards.size() < index) {
throw new IllegalArgumentException("Index is out of bounds");
}
flashcards.add(index, card);
updateSubscribers();
}
@@ -115,12 +114,12 @@ public class CardDeck extends Observable<CardDeck> {
* @param card The updated flashcard.
*/
public void update(int index, Flashcard card) {
if (card == null)
if (card == null) {
throw new IllegalArgumentException("Flashcard can not be null");
if (index < 0 || index > flashcards.size())
}
if (index < 0 || index > flashcards.size()) {
throw new IllegalArgumentException("Can not update card at index: " + index);
}
flashcards.remove(index);
flashcards.add(index, card);
updateSubscribers();
@@ -133,9 +132,9 @@ public class CardDeck extends Observable<CardDeck> {
* @param index The index of the card to remove
*/
public void remove(int index) {
if (index < 0 || index > flashcards.size())
if (index < 0 || index > flashcards.size()) {
throw new IllegalArgumentException("Can not remove card at index: " + index);
}
flashcards.remove(index);
updateSubscribers();
}
@@ -4,7 +4,6 @@ import java.util.List;
/**
* Data model representing a flashcard.
*
* Has a frontside and a backside, which both consist of {@link CardContent CardContent}.
*/
public class Flashcard {
@@ -12,20 +11,21 @@ public class Flashcard {
private CardContent back;
/**
* Default constructor to generate a new flashcard
* Default constructor to generate a new flashcard.
*
* @param front The front side of the card
* @param back The back side of the card
*/
public Flashcard(CardContent front, CardContent back) {
if (front == null || back == null)
if (front == null || back == null) {
throw new IllegalArgumentException("CardContent can not be null");
}
this.front = front;
this.back = back;
}
/**
* A helping constructor to generate Flashcards from lines of text
* A helping constructor to generate Flashcards from lines of text.
*
* @param front The (text) lines on the front side of the card
* @param back The (text) lines on the back side of the card
@@ -35,25 +35,27 @@ public class Flashcard {
*/
public static Flashcard of(List<String> front, List<String> back) {
if (
front == null ||
back == null ||
front.stream().allMatch((e) -> e.equals("")) ||
(back.stream().allMatch((e) -> e.equals("")))
) throw new IllegalArgumentException("Front and back can not be null");
front == null
|| back == null
|| front.stream().allMatch((e) -> e.equals(""))
|| (back.stream().allMatch((e) -> e.equals("")))
) {
throw new IllegalArgumentException("Front and back can not be null");
}
return new Flashcard(new CardContent(front), new CardContent(back));
}
/**
* A helping constructor to generate Flashcards from strings
* A helping constructor to generate Flashcards from strings.
*
* @param front The text on the front side of the card
* @param back The text on the back side of the card
* @return A new flashcard
*/
public static Flashcard of(String front, String back) {
if (front == null || back == null)
if (front == null || back == null) {
throw new IllegalArgumentException("Front and back can not be null");
}
return new Flashcard(new CardContent(front), new CardContent(back));
}
@@ -64,16 +66,17 @@ public class Flashcard {
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Flashcard))
if (!(obj instanceof Flashcard)) {
return false;
}
Flashcard card2 = (Flashcard) obj;
return this.getFront().equals(card2.getFront()) && this.getBack().equals(card2.getBack());
}
@Override
public String toString() {
return "[" + String.join("/", this.front.getLines()) + "] [" + String.join("/", this.back.getLines()) + "]";
return "[" + String.join("/", this.front.getLines())
+ "] [" + String.join("/", this.back.getLines()) + "]";
}
/**
@@ -1,4 +1,4 @@
/**
* Data models used within the application to represent real life constructs
* Data models used within the application to represent real life constructs.
*/
package it1901.groups2021.gr2141.core.models;
@@ -1,33 +1,31 @@
package it1901.groups2021.gr2141.core.models.serializers;
import it1901.groups2021.gr2141.core.models.CardContent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import it1901.groups2021.gr2141.core.models.CardContent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Deserializer for {@link it1901.groups2021.gr2141.core.models.CardContent CardContent}
* Deserializer for {@link it1901.groups2021.gr2141.core.models.CardContent CardContent}.
*/
public class CardContentDeserializer extends StdDeserializer<CardContent> {
/**
* Constructor sets card content deserializer to null
* Constructor sets card content deserializer to null.
*/
public CardContentDeserializer() {
this(null);
}
/**
* Initialize super object
* @param t
*/
/**
* Initialize super object.
* @param t Deserialize object type.
*/
public CardContentDeserializer(Class<CardContent> t) {
super(t);
}
@@ -40,14 +38,14 @@ public class CardContentDeserializer extends StdDeserializer<CardContent> {
}
/**
* Deserialization logic
* Deserialization logic.
*/
CardContent deserialize(JsonNode node) {
List<String> lines = new ArrayList<>();
for (JsonNode n : node.get("lines"))
for (JsonNode n : node.get("lines")) {
lines.add(n.asText());
}
return new CardContent(lines);
}
}
@@ -1,40 +1,46 @@
package it1901.groups2021.gr2141.core.models.serializers;
import it1901.groups2021.gr2141.core.models.CardContent;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import it1901.groups2021.gr2141.core.models.CardContent;
import java.io.IOException;
/**
* Serializer for {@link it1901.groups2021.gr2141.core.models.CardContent CardContent}
* Serializer for {@link it1901.groups2021.gr2141.core.models.CardContent CardContent}.
*/
public class CardContentSerializer extends StdSerializer<CardContent> {
/**
* Constructor sets card content serializer to null
* Constructor sets card content serializer to null.
*/
public CardContentSerializer() {
this(null);
}
/**
* Initialize super object
* @param t
*/
/**
* Initialize super object.
* @param t Serialize object type.
*/
public CardContentSerializer(Class<CardContent> t) {
super(t);
}
@Override
public void serialize(CardContent cardContent, JsonGenerator jgenerator, SerializerProvider provider)
throws IOException {
public void serialize(CardContent cardContent,
JsonGenerator jgenerator,
SerializerProvider provider)
throws IOException {
jgenerator.writeStartObject();
jgenerator.writeFieldName("lines");
jgenerator.writeStartArray();
for (String line : cardContent.getLines())
for (String line : cardContent.getLines()) {
jgenerator.writeString(line);
}
jgenerator.writeEndArray();
jgenerator.writeEndObject();
@@ -1,21 +1,19 @@
package it1901.groups2021.gr2141.core.models.serializers;
import it1901.groups2021.gr2141.core.models.CardDeck;
import it1901.groups2021.gr2141.core.models.Flashcard;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import it1901.groups2021.gr2141.core.models.CardDeck;
import it1901.groups2021.gr2141.core.models.Flashcard;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Deserializer for {@link it1901.groups2021.gr2141.core.models.CardDeck CardDeck}
* Deserializer for {@link it1901.groups2021.gr2141.core.models.CardDeck CardDeck}.
*/
public class CardDeckDeserializer extends StdDeserializer<CardDeck> {
private FlashcardDeserializer flashcardDeserializer = new FlashcardDeserializer();
@@ -27,29 +25,32 @@ public class CardDeckDeserializer extends StdDeserializer<CardDeck> {
this(null);
}
/**
* Initialize super object
* @param t
*/
/**
* Initialize super object.
* @param t Deserialize object type.
*/
public CardDeckDeserializer(Class<CardDeck> t) {
super(t);
}
@Override
public CardDeck deserialize(JsonParser jparser, DeserializationContext context) throws IOException, JacksonException {
public CardDeck deserialize(JsonParser jparser,
DeserializationContext context)
throws IOException, JacksonException {
JsonNode node = jparser.getCodec().readTree(jparser);
return deserialize(node);
}
/**
* Deserialization logic
* Deserialization logic.
*/
CardDeck deserialize(JsonNode node) {
List<Flashcard> cards = new ArrayList<>();
for (JsonNode n : node.get("flashcards"))
for (JsonNode n : node.get("flashcards")) {
cards.add(flashcardDeserializer.deserialize(n));
}
return new CardDeck(cards);
}
}
@@ -1,40 +1,44 @@
package it1901.groups2021.gr2141.core.models.serializers;
import it1901.groups2021.gr2141.core.models.CardDeck;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import it1901.groups2021.gr2141.core.models.CardDeck;
import java.io.IOException;
/**
* Serializer for {@link it1901.groups2021.gr2141.core.models.CardDeck CardDeck}
* Serializer for {@link it1901.groups2021.gr2141.core.models.CardDeck CardDeck}.
*/
public class CardDeckSerializer extends StdSerializer<CardDeck> {
/**
* Constructor sets card deck serializer to null
* Constructor sets card deck serializer to null.
*/
public CardDeckSerializer() {
this(null);
}
/**
* Initialize super object
* @param t
/**
* Initialize super object.
* @param t Serialize object type.
*/
public CardDeckSerializer(Class<CardDeck> t) {
super(t);
}
@Override
public void serialize(CardDeck cardDeck, JsonGenerator jgenerator, SerializerProvider provider) throws IOException {
public void serialize(CardDeck cardDeck,
JsonGenerator jgenerator,
SerializerProvider provider)
throws IOException {
jgenerator.writeStartObject();
jgenerator.writeFieldName("flashcards");
jgenerator.writeStartArray();
for (var flashcard : cardDeck.getFlashcards())
for (var flashcard : cardDeck.getFlashcards()) {
jgenerator.writeObject(flashcard);
}
jgenerator.writeEndArray();
jgenerator.writeEndObject();
}
@@ -1,47 +1,48 @@
package it1901.groups2021.gr2141.core.models.serializers;
import it1901.groups2021.gr2141.core.models.Flashcard;
import it1901.groups2021.gr2141.core.models.CardContent;
import java.io.IOException;
import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import it1901.groups2021.gr2141.core.models.CardContent;
import it1901.groups2021.gr2141.core.models.Flashcard;
import java.io.IOException;
/**
* Deserializer for {@link it1901.groups2021.gr2141.core.models.Flashcard Flashcard}
* Deserializer for {@link it1901.groups2021.gr2141.core.models.Flashcard Flashcard}.
*/
public class FlashcardDeserializer extends StdDeserializer<Flashcard> {
private CardContentDeserializer cardContentDeserializer = new CardContentDeserializer();
/**
* Constructor sets flashcard deserializer to null
* Constructor sets flashcard deserializer to null.
*/
public FlashcardDeserializer() {
this(null);
}
/**
/**
* Initialize super object
* @param t
* @param t Deserialize object type.
*/
public FlashcardDeserializer(Class<Flashcard> t) {
super(t);
}
@Override
public Flashcard deserialize(JsonParser jparser, DeserializationContext context) throws IOException, JacksonException {
public Flashcard deserialize(JsonParser jparser,
DeserializationContext context)
throws IOException, JacksonException {
JsonNode node = jparser.getCodec().readTree(jparser);
return deserialize(node);
}
/**
* Deserialization logic
* Deserialization logic.
*/
Flashcard deserialize(JsonNode node) {
CardContent front = cardContentDeserializer.deserialize(node.get("front"));
@@ -1,35 +1,37 @@
package it1901.groups2021.gr2141.core.models.serializers;
import it1901.groups2021.gr2141.core.models.Flashcard;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import it1901.groups2021.gr2141.core.models.Flashcard;
import java.io.IOException;
/**
* Serializer for {@link it1901.groups2021.gr2141.core.models.Flashcard Flashcard}
* Serializer for {@link it1901.groups2021.gr2141.core.models.Flashcard Flashcard}.
*/
public class FlashcardSerializer extends StdSerializer<Flashcard> {
/**
* Constructor sets flashcard serializer to null
* Constructor sets flashcard serializer to null.
*/
public FlashcardSerializer() {
this(null);
}
/**
/**
* Initialize super object
* @param t
* @param t Serialize object type.
*/
public FlashcardSerializer(Class<Flashcard> t) {
super(t);
}
@Override
public void serialize(Flashcard flashcard, JsonGenerator jgenerator, SerializerProvider provider) throws IOException {
public void serialize(Flashcard flashcard,
JsonGenerator jgenerator,
SerializerProvider provider)
throws IOException {
jgenerator.writeStartObject();
jgenerator.writeFieldName("front");
jgenerator.writeObject(flashcard.getFront());
@@ -2,19 +2,19 @@ package it1901.groups2021.gr2141.core.models.serializers;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.module.SimpleModule;
import it1901.groups2021.gr2141.core.models.CardContent;
import it1901.groups2021.gr2141.core.models.CardDeck;
import it1901.groups2021.gr2141.core.models.Flashcard;
/**
* Uses simple module from the jackson library, to serialize and deserialize data
* Uses simple module from the jackson library, to serialize and deserialize data.
*/
public class ModelSerializingModule extends SimpleModule {
private static final String NAME = "FlashcardModule";
/**
* Model that initializes serializing and deserializing
* Model that initializes serializing and deserializing.
*
*/
public ModelSerializingModule() {
@@ -1,14 +1,15 @@
package it1901.groups2021.gr2141.core.state;
import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Consumer;
import java.util.ArrayList;
/**
* A class that lets its subclasses execute a set of subscriber functions every
* time something changes.
*/
public abstract class Observable<T> {
private Collection<Consumer<T>> subscribers = new ArrayList<>();
/**
@@ -1,24 +1,25 @@
package it1901.groups2021.gr2141.core.storage;
import java.io.IOException;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import com.fasterxml.jackson.databind.ObjectMapper;
import it1901.groups2021.gr2141.core.models.CardDeck;
import it1901.groups2021.gr2141.core.models.serializers.ModelSerializingModule;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* A class which handles saving/loading
* {@link it1901.groups2021.gr2141.core.models.CardDeck CardDeck}s.
* {@link it1901.groups2021.gr2141.core.models.CardDeck CardDecks}.
*/
public final class CardDeckStorage {
private static final ObjectMapper mapper = new ObjectMapper().registerModule(new ModelSerializingModule());
private static final ObjectMapper mapper
= new ObjectMapper().registerModule(new ModelSerializingModule());
private static Path dataDirectory = getUserDataDirectory();
/**
@@ -27,18 +28,24 @@ public final class CardDeckStorage {
* @param dataDirectory The path to the new data directory.
*/
public static void setUserDataDirectory(Path dataDirectory) {
if (dataDirectory == null)
if (dataDirectory == null) {
throw new IllegalArgumentException("dataDirectory can not be null");
}
CardDeckStorage.dataDirectory = dataDirectory;
};
}
private CardDeckStorage() {}
/**
* Constructor that prevents creating a new instance
* of CardDeckStorage.
*/
private CardDeckStorage() {
}
/**
* @return Name of operating system
*/
protected static String getOSName() {
protected static String getOsName() {
return (System.getProperty("os.name")).toLowerCase();
}
@@ -51,7 +58,7 @@ public final class CardDeckStorage {
/**
* @return Data directory for all UNIX-like systems. This is the default
* location according to the XDG-specification
* location according to the XDG-specification.
*
* @see <a href=
* "https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html">specifications.freedesktop.org</a>
@@ -69,18 +76,18 @@ public final class CardDeckStorage {
* @see #readDeck(int)
*/
public static Path getUserDataDirectory() {
String OS = getOSName();
String os = getOsName();
Path dataDir;
if (OS.contains("win"))
if (os.contains("win")) {
dataDir = getWindowsDataRootPath();
else
} else {
dataDir = getUnixDataRootPath();
}
dataDir = dataDir.resolve("flashy");
if (!dataDir.toFile().exists())
if (!dataDir.toFile().exists()) {
dataDir.toFile().mkdirs();
}
return dataDir;
}
@@ -98,16 +105,17 @@ public final class CardDeckStorage {
private static int getNextDeckID() {
var i = 0;
while (dataDirectory.resolve("deck-" + i + ".json").toFile().exists())
while (dataDirectory.resolve("deck-" + i + ".json").toFile().exists()) {
i++;
}
return i;
}
/**
* Write a card deck to the next available id
* Write a card deck to the next available id.
*
* @param deck
* @throws IOException if deck is not found
* @param deck the CardDeck.
* @throws IOException if deck is not found.
*/
public static void writeDeck(CardDeck deck) throws IOException {
writeDeck(deck, getNextDeckID());
@@ -117,21 +125,21 @@ public final class CardDeckStorage {
* Write a card deck with a specified. This will overwrite the deck already
* saved, if it exists.
*
* @param deck The deck to be saved
* @param deck The deck to be saved.
* @param id The id to write the deck to.
* @see #writeDeckToFile(File, CardDeck)
* @throws IOException if deck is not found
* @throws IllegalArgumentException when id is less than 0
*/
public static void writeDeck(CardDeck deck, int id) throws IOException {
if (id < 0)
if (id < 0) {
throw new IllegalArgumentException("ID can not be negative!");
}
File file = dataDirectory.resolve("deck-" + Integer.toString(id) + ".json").toFile();
if (!file.exists())
if (!file.exists()) {
file.createNewFile();
}
writeDeckToFile(file, deck);
}
@@ -151,7 +159,7 @@ public final class CardDeckStorage {
* Reads all saved CardDecks.
*
* @see #readDeck(int)
* @return A list of all the CardDecks on disk.
* @return A list of all the CardDecks on disk
* @throws IOException if deck is not found
*/
public static List<CardDeck> readAllDecks() throws IOException {
@@ -51,10 +51,10 @@ public class CardDeckStorageTest {
cdsMock.when(() -> CardDeckStorage.getWindowsDataRootPath()).thenReturn(tempDir.toPath());
cdsMock.when(() -> CardDeckStorage.getUnixDataRootPath()).thenReturn(tempDir.toPath().resolve("anotherFolder"));
cdsMock.when(() -> CardDeckStorage.getOSName()).thenReturn("win-10");
cdsMock.when(() -> CardDeckStorage.getOsName()).thenReturn("win-10");
assertEquals(tempDir.toPath().resolve("flashy"), CardDeckStorage.getUserDataDirectory());
cdsMock.when(() -> CardDeckStorage.getOSName()).thenReturn("linux");
cdsMock.when(() -> CardDeckStorage.getOsName()).thenReturn("linux");
assertEquals(tempDir.toPath().resolve("anotherFolder/flashy"), CardDeckStorage.getUserDataDirectory());
}
}
@@ -1,16 +1,15 @@
package it1901.groups2021.gr2141.ui;
import it1901.groups2021.gr2141.core.storage.CardDeckStorage;
import it1901.groups2021.gr2141.ui.controllers.Controller;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import it1901.groups2021.gr2141.core.storage.CardDeckStorage;
import javafx.fxml.Initializable;
import it1901.groups2021.gr2141.ui.controllers.Controller;
/**
* Root UI controller
* Root UI controller.
*/
public class AppController extends Controller implements Initializable {
private static void setupStorageListener() {
@@ -1,21 +1,26 @@
package it1901.groups2021.gr2141.ui;
import java.io.IOException;
import java.util.List;
import it1901.groups2021.gr2141.core.domainlogic.FlashcardProvider;
import it1901.groups2021.gr2141.core.models.CardDeck;
import it1901.groups2021.gr2141.core.models.Flashcard;
import it1901.groups2021.gr2141.core.storage.CardDeckStorage;
import java.io.IOException;
import java.util.List;
/**
* A singleton containing the state of the whole application.
*/
public final class AppState {
private static FlashcardProvider flashCardProvider;
private AppState() {}
/**
* Constructor that prevents creating a new instance
* of AppState.
*/
private AppState() {
}
/**
* Initialize the FlashcardProvider with default values.
@@ -1,22 +1,23 @@
package it1901.groups2021.gr2141.ui;
import javafx.application.Application;
import javafx.stage.Stage;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
/**
* Root of the application.
*/
public class Flashy extends Application {
/**
* Starting the application
* @param args
*
* @param args Command line arguments.
*/
public static void main(String[] args) {
launch(args);
@@ -30,7 +31,8 @@ public class Flashy extends Application {
Parent parent = fxmlLoader.load();
Scene scene = new Scene(parent);
stage.getIcons().add(new Image(getClass().getResourceAsStream("/it1901/groups2021/gr2141/ui/graphics/logo.png")));
stage.getIcons().add(new Image(getClass()
.getResourceAsStream("/it1901/groups2021/gr2141/ui/graphics/logo.png")));
scene.getStylesheets().add(getClass().getResource("styling/Flashy.css").toExternalForm());
stage.setTitle("Flashy!");
stage.setScene(scene);
@@ -1,17 +1,15 @@
package it1901.groups2021.gr2141.ui.controllers;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
import javafx.fxml.Initializable;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
/**
* CardArea controller of the application UI.
*/
public class CardAreaController extends Controller implements Initializable {
@FXML
@@ -23,7 +21,7 @@ public class CardAreaController extends Controller implements Initializable {
getFlashcardProvider().subscribe((newFlashCardModel) -> showCurrentCardContent());
}
/**
/**
* Updates the card shown in the UI
*/
public void showCurrentCardContent() {
@@ -34,7 +32,7 @@ public class CardAreaController extends Controller implements Initializable {
/**
* Flips the card. This is connected to an FXML element.
*
* @param event
* @param event a MouseEvent.
*/
@FXML
public void handleFlipCardMouse(MouseEvent event) {
@@ -11,7 +11,7 @@ public class CardNavigationController extends Controller {
/**
* Flips the card by pressing the button.
*
* @param event
* @param event an ActionEvent.
*/
@FXML
public void handleFlipCardButton(ActionEvent event) {
@@ -21,24 +21,28 @@ public class CardNavigationController extends Controller {
/**
* Turns to the next card in the deck.
*
* @param event
* @param event an ActionEvent.
*/
@FXML
public void handleTurnToNextCard(ActionEvent event) {
try {
getFlashcardProvider().turnToNextCard();
} catch (IllegalArgumentException e) {}
} catch (IllegalArgumentException e) {
System.out.println("You are on the last card!");
}
}
/**
* Turns to the previous card in the deck.
*
* @param event
* @param event an ActionEvent.
*/
@FXML
public void handleTurnToPreviousCard(ActionEvent event) {
try {
getFlashcardProvider().turnToPreviousCard();
} catch (IllegalArgumentException e) {}
} catch (IllegalArgumentException e) {
System.out.println("You are on the first card!");
}
}
}
@@ -1,13 +1,13 @@
package it1901.groups2021.gr2141.ui.controllers;
import it1901.groups2021.gr2141.core.models.Flashcard;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import javafx.event.ActionEvent;
/**
* Menu controller of the application UI.
*/
public class MenuController extends Controller {
@FXML
@@ -19,14 +19,15 @@ public class MenuController extends Controller {
/**
* Creates a new card and adds it to the active deck.
*
* @param event
* @param event an ActionEvent.
*/
@FXML
public void handleCreateFlashCard(ActionEvent event) {
if (writeFront.getText().isEmpty() || writeBack.getText().isEmpty())
if (writeFront.getText().isEmpty() || writeBack.getText().isEmpty()) {
return;
getFlashcardProvider().getCardDeck().add(Flashcard.of(writeFront.getText(), writeBack.getText()));
}
getFlashcardProvider().getCardDeck()
.add(Flashcard.of(writeFront.getText(), writeBack.getText()));
clearTextFields();
}
@@ -2,16 +2,14 @@ package it1901.groups2021.gr2141.ui.controllers;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.Initializable;
import javafx.fxml.FXML;
import javafx.scene.control.ToggleButton;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ToggleButton;
/**
* Navbar controller of the application UI.
*/
public class NavbarController extends Controller implements Initializable {
@FXML
@@ -31,30 +29,33 @@ public class NavbarController extends Controller implements Initializable {
private void setToggleButtonValues() {
btnToggleRandomMode.setSelected(getFlashcardProvider().isCardOrderIsRandomMode());
btnToggleShowOtherSide.setSelected(getFlashcardProvider().isShowOrderIsFlippedMode());
btnToggleFirstLastWrapAroundMode.setSelected(getFlashcardProvider().isFirstLastWrapAroundMode());
btnToggleFirstLastWrapAroundMode.setSelected(getFlashcardProvider()
.isFirstLastWrapAroundMode());
}
/**
/**
* @see it1901.groups2021.gr2141.core.domainlogic.FlashcardProvider#isShowOrderIsFlippedMode
* @param event
* @param event an ActionEvent.
*/
@FXML
public void handleToggleShowOtherSide(ActionEvent event) {
getFlashcardProvider().toggleShowOrderIsFlippedMode();
}
/**
* @see it1901.groups2021.gr2141.core.domainlogic.FlashcardProvider#isCardOrderIsRandomMode for more details.
* @param event
/**
* @see it1901.groups2021.gr2141.core.domainlogic.FlashcardProvider#isCardOrderIsRandomMode
* for more details.
* @param event an ActionEvent.
*/
@FXML
public void handleToggleCardOrderIsRandom(ActionEvent event) {
getFlashcardProvider().toggleCardOrderIsRandomMode();
}
/**
* @see it1901.groups2021.gr2141.core.domainlogic.FlashcardProvider#isFirstLastWrapAroundMode for more details.
* @param event
/**
* @see it1901.groups2021.gr2141.core.domainlogic.FlashcardProvider#isFirstLastWrapAroundMode
* for more details.
* @param event an ActionEvent.
*/
@FXML
public void handleToggleFirstLastWrapAroundMode(ActionEvent event) {
@@ -5,12 +5,13 @@ import it1901.groups2021.gr2141.ui.Flashy;
/**
* A starting point of the application.
*/
public class FlashyLauncher {
/**
* Should be used as the starting point when the application is packaged into a JAR file.
*
* @param args
* @param args Command line arguments.
*/
public static void main(String[] args) {
Flashy.main(args);
+12 -1
View File
@@ -234,6 +234,17 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
</configuration>
</plugin>
</plugins>
</build>
@@ -285,7 +296,7 @@
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<configLocation>google_checks.xml</configLocation>
<configLocation>checkstyle.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>false</failsOnError>