Added Flashcard and removed unused classes
This commit is contained in:
parent
72790a5ffb
commit
7dda924cd7
5 changed files with 166 additions and 28 deletions
|
@ -0,0 +1,114 @@
|
|||
package uk.ac.aber.cs22120.group20.javafx;
|
||||
|
||||
import javafx.animation.*;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.shape.Rectangle;
|
||||
import javafx.scene.text.Text;
|
||||
import javafx.scene.transform.Rotate;
|
||||
import javafx.util.Duration;
|
||||
import uk.ac.aber.cs22120.group20.javafx.Application;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FlashcardController {
|
||||
int index = 0;
|
||||
Node card;
|
||||
|
||||
@FXML
|
||||
private Text counter;
|
||||
@FXML
|
||||
private Text wordType;
|
||||
@FXML
|
||||
private Rectangle flashcard;
|
||||
@FXML
|
||||
private Text testWord;
|
||||
|
||||
@FXML
|
||||
private ImageView left_arrow;
|
||||
@FXML
|
||||
private ImageView right_arrow;
|
||||
|
||||
@FXML
|
||||
private void initialize() {
|
||||
testWord.setText(Application.practiseList.getFirst().getWelsh());
|
||||
wordType.setText("Welsh");
|
||||
|
||||
updateCounter();
|
||||
card = flashcard;
|
||||
|
||||
Image left = new Image("file:src/main/resources/assets/icons/black_icons/50px/left-50.png");
|
||||
Image right = new Image("file:src/main/resources/assets/icons/black_icons/50px/right-50.png");
|
||||
|
||||
left_arrow.setImage(left);
|
||||
right_arrow.setImage(right);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleFlashcardClick() {
|
||||
RotateTransition rotator = RotateCard(card);
|
||||
rotator.play();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handlePreviousCard() {
|
||||
|
||||
if (index > 0) {
|
||||
index--;
|
||||
}
|
||||
updateCounter();
|
||||
testWord.setText(Application.practiseList.get(index).getWelsh());
|
||||
wordType.setText("Welsh");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleNextCard() {
|
||||
if (index < Application.practiseList.size()-1) {
|
||||
index++;
|
||||
}
|
||||
updateCounter();
|
||||
|
||||
testWord.setText(Application.practiseList.get(index).getWelsh());
|
||||
wordType.setText("Welsh");
|
||||
}
|
||||
|
||||
private void updateCounter() {
|
||||
counter.setText((index + 1) + "/" + Application.practiseList.size());
|
||||
}
|
||||
|
||||
private RotateTransition RotateCard(Node card) {
|
||||
|
||||
RotateTransition rotate = new RotateTransition(Duration.millis(1000), card);
|
||||
testWord.setVisible(false);
|
||||
wordType.setVisible(false);
|
||||
|
||||
rotate.setAxis(Rotate.Y_AXIS);
|
||||
rotate.setFromAngle(0);
|
||||
rotate.setToAngle(180);
|
||||
rotate.setInterpolator(Interpolator.LINEAR);
|
||||
rotate.setCycleCount(1);
|
||||
rotate.setOnFinished(event -> {
|
||||
|
||||
testWord.setText("Welsh word: \t" + Application.practiseList.get(index).getWelsh());
|
||||
if (wordType.getText().equals("Welsh")) {
|
||||
testWord.setText(Application.practiseList.get(index).getEnglish());
|
||||
wordType.setText("English");
|
||||
} else {
|
||||
testWord.setText(Application.practiseList.get(index).getWelsh());
|
||||
wordType.setText("Welsh");
|
||||
}
|
||||
testWord.setVisible(true);
|
||||
wordType.setVisible(true);
|
||||
});
|
||||
return rotate;
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void switchToAddWord() throws IOException {
|
||||
Application.setRoot("addword");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package uk.ac.aber.cs22120.group20.javafx;
|
||||
|
||||
import java.io.IOException;
|
||||
import javafx.fxml.FXML;
|
||||
/**
|
||||
* Placeholder Controller
|
||||
*/
|
||||
public class PrimaryController {
|
||||
|
||||
@FXML
|
||||
private void switchToSecondary() throws IOException {
|
||||
App.setRoot("secondary");
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package uk.ac.aber.cs22120.group20.javafx;
|
||||
|
||||
import java.io.IOException;
|
||||
import javafx.fxml.FXML;
|
||||
/**
|
||||
* Placeholder Controller
|
||||
*/
|
||||
public class SecondaryController {
|
||||
|
||||
@FXML
|
||||
private void switchToPrimary() throws IOException {
|
||||
App.setRoot("primary");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.StackPane?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.shape.Rectangle?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
|
||||
<VBox alignment="center" spacing="10" stylesheets="@styles.css" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="uk.ac.aber.cs22120.group20.javafx.FlashcardController">
|
||||
<padding>
|
||||
<Insets bottom="10" left="25" right="25" top="25" />
|
||||
</padding>
|
||||
<children>
|
||||
<StackPane onMouseClicked="#handleFlashcardClick">
|
||||
<children>
|
||||
<Rectangle fx:id="flashcard" arcHeight="80" arcWidth="80" fill="white" height="360" stroke="black" width="550" />
|
||||
<Text fx:id="testWord" textAlignment="CENTER">
|
||||
<font>
|
||||
<Font size="55" />
|
||||
</font>
|
||||
</Text>
|
||||
|
||||
<VBox alignment="BOTTOM_CENTER">
|
||||
<Text fx:id="wordType" fill="dimgray">
|
||||
<font>
|
||||
<Font size="20" />
|
||||
</font>
|
||||
</Text>
|
||||
</VBox>
|
||||
</children>
|
||||
</StackPane>
|
||||
<HBox alignment="BASELINE_CENTER" spacing="190">
|
||||
<children>
|
||||
<ImageView fx:id="left_arrow" onMouseClicked="#handlePreviousCard" visible="true" />
|
||||
<Text fx:id="counter"><font> <Font size="20" /></font></Text>
|
||||
<ImageView fx:id="right_arrow" onMouseClicked="#handleNextCard" />
|
||||
</children>
|
||||
</HBox>
|
||||
<Button mnemonicParsing="false" onAction="#switchToAddWord" text="Add Word Screen" />
|
||||
</children>
|
||||
</VBox>
|
|
@ -0,0 +1,7 @@
|
|||
.button {
|
||||
-fx-text-fill: blue;
|
||||
}
|
||||
|
||||
#counter {
|
||||
-fx-text-fill: blue;
|
||||
}
|
Reference in a new issue