Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public String getStory(String loggedInUser) {
* Fetches the character content.
*
* @param characterName the character name of the users chosen character when handeling the characters.csv.
* @param filepath referes to the filepath from which the data is extracted from
* */
public List<List<String>> characterContent(String characterName, String filepath){
characterContent = user.userContent(characterName, filepath);
Expand Down
12 changes: 11 additions & 1 deletion task_gamification/src/task_gamification/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public class User {
* Creates a new user adding the user related content to the users.csv
*
* @param filePath The file path where user data is stored.
* @param loggedInUser The username of the currently logged-in user.
* @param newUserContent The username and data of the currently logged-in user.
* This includes the chosen character, XP, Level, creation date,
* password and e-mail-address.
* */
public boolean createNewUser(String filePath, List<String> newUserContent){

Expand Down Expand Up @@ -76,6 +78,12 @@ public boolean authenticate(String userName){
return containsUsername;
}

/**
* Authenticates a username with the content in users.csv
*
* @param userName The username of the currently logged-in user.
* @param password a password chosen by the user for login.
* */
public boolean passwordAuthentification(String userName, String password) {

csvReader = new CSVReader();
Expand Down Expand Up @@ -191,6 +199,7 @@ public String getEMail(String loggedInUser) {
* Fetches the user content.
*
* @param userName The username of the currently logged-in user when handeling the users.csv
* @param filePath The path where user date is stored.
* */
public List<List<String>> userContent(String userName, String filePath){

Expand All @@ -212,6 +221,7 @@ public List<List<String>> userContent(String userName, String filePath){
* Fetches the user highscore as requested in "Implementierung 4.".
*
* @param loggedInUser The username of the currently logged-in user when handeling the users.csv
* @param filePath The path where user date is stored.
* */
public int getUserHighscore(String loggedInUser, String filePath) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import javax.swing.*;

/**
* Helperclass to implement fixed sizes and positions for the panels.
*/
public class ComponentSizePanel extends JPanel {

// size and position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import javax.swing.*;

/**
* Helperclass to implement fixed sizes and positions for the small frames.
*/
public class ComponentSizesSmallFrame extends JFrame {

// size and position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import javax.swing.JPanel;

/**
* Helper method to add new JPanels to the MainFrame
* Helperclass to add new JPanels to the MainFrame
*/
public class ShowPanel {
private JPanel contentPanel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import javax.swing.*;

/**
* Helperclass for easier implementation of UI-Components.
*/
public class UIComponentHelper {
/**
* Creates a JLabel with specified properties.
Expand Down Expand Up @@ -74,7 +77,8 @@ public static JComboBox<String> createComboBox(String[] items, int x, int y, int
* @param height The height of the password field.
* @return The created JSpinner object.
*/
public static JSpinner createSpinner(int minValue, int maxValue, int stepSize, int initialValue, int x, int y, int width, int height) {
public static JSpinner createSpinner(int minValue, int maxValue, int stepSize,
int initialValue, int x, int y, int width, int height) {
JSpinner spinner = new JSpinner(new SpinnerNumberModel(initialValue, minValue, maxValue, stepSize));
spinner.setBounds(x, y, width, height);
return spinner;
Expand Down
14 changes: 14 additions & 0 deletions task_gamification/src/task_gamification/helpers/Userlog.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import java.util.Arrays;
import java.util.List;

/**
* Class to handel all methods related to userlog entry.
*/
public class Userlog {

private LocalDateTime startTime, endTime;
Expand All @@ -32,6 +35,12 @@ public class Userlog {
private String userlogFilePath = FilePaths.USERLOG_FILE_PATH,
userFilePath = FilePaths.USER_FILE_PATH;

/**
* Creates a entry in the userlog with the username and login-time.
*
* @param loggedInUser username of the user currently logged-in.
* @return success
*/
public boolean startUserlog(String loggedInUser) {

startTime = LocalDateTime.now();
Expand All @@ -58,6 +67,11 @@ public boolean startUserlog(String loggedInUser) {

}

/**
* Adds missing data to userlog (end time, duration, score).
*
* @throws IOException
*/
public void endUserlog() throws IOException {

user = new User();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ private void checkInputData() {

newUser.createNewUser(userFilePath, newUserContent);

// start logging current session in userlog
Userlog userlog = new Userlog();
userlog.startUserlog(usernameTextField.getText());

Expand Down
29 changes: 20 additions & 9 deletions task_gamification/src/task_gamification/main/Login.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ private void addLabelsToPane() {
usernameLabel = UIComponentHelper.createLabel("Username",
CENTER_X - (LABEL_WIDTH + TEXT_FIELD_WIDTH) / 2, CENTER_Y - 70, LABEL_WIDTH, LABEL_HEIGHT);
passwordLabel = UIComponentHelper.createLabel("Password",
CENTER_X - (LABEL_WIDTH + TEXT_FIELD_WIDTH) / 2, usernameLabel.getY() + (LABEL_HEIGHT / 2) + 20, LABEL_WIDTH, LABEL_HEIGHT);
CENTER_X - (LABEL_WIDTH + TEXT_FIELD_WIDTH) / 2, usernameLabel.getY() + (LABEL_HEIGHT / 2) + 20,
LABEL_WIDTH, LABEL_HEIGHT);
loginPane.add(usernameLabel);
loginPane.add(passwordLabel);
}
Expand Down Expand Up @@ -107,17 +108,21 @@ private void addButtonsToPane() {
*/
private void loginAction(ActionEvent e) {
if (usernameTextField.getText().isEmpty() && passwordField.getPassword().length == 0) {
JOptionPane.showMessageDialog(this, "Please enter a valid username and password", "ERROR", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(this, "Please enter a valid username and password",
"ERROR", JOptionPane.ERROR_MESSAGE);
} else if (usernameTextField.getText().isEmpty()) {
JOptionPane.showMessageDialog(this, "Please enter a username", "ERROR", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(this, "Please enter a username",
"ERROR", JOptionPane.ERROR_MESSAGE);
} else if (passwordField.getPassword().length == 0) {
JOptionPane.showMessageDialog(this, "Please enter a password", "ERROR", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(this, "Please enter a password",
"ERROR", JOptionPane.ERROR_MESSAGE);
} else {
userLogin = new User();
boolean containsUsername = userLogin.passwordAuthentification(usernameTextField.getText(), Arrays.toString(passwordField.getPassword()));
boolean containsUsername = userLogin.passwordAuthentification(usernameTextField.getText(),
Arrays.toString(passwordField.getPassword()));

if (containsUsername) {

// start logging current session in userlog
userlog = new Userlog();
userlog.startUserlog(usernameTextField.getText());

Expand All @@ -126,7 +131,9 @@ private void loginAction(ActionEvent e) {
new MainFrame(usernameTextField.getText());
});
} else {
JOptionPane.showMessageDialog(this, "Sorry, the username and password don't seem to match. Please try again.", "ERROR", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(this,
"Sorry, the username and password don't seem to match. Please try again.",
"ERROR", JOptionPane.ERROR_MESSAGE);
}
}
}
Expand All @@ -146,8 +153,12 @@ private void backAction(ActionEvent e) {
* Adds text fields for username and password to the login panel.
*/
private void addTextFieldsToPane() {
usernameTextField = UIComponentHelper.createTextField(CENTER_X - (LABEL_WIDTH + TEXT_FIELD_WIDTH) / 2 + LABEL_WIDTH, usernameLabel.getY(), TEXT_FIELD_WIDTH, LABEL_HEIGHT);
passwordField = UIComponentHelper.createPasswordField(CENTER_X - (LABEL_WIDTH + TEXT_FIELD_WIDTH) / 2 + LABEL_WIDTH, passwordLabel.getY(), TEXT_FIELD_WIDTH, LABEL_HEIGHT);
usernameTextField = UIComponentHelper.createTextField(
CENTER_X - (LABEL_WIDTH + TEXT_FIELD_WIDTH) / 2 + LABEL_WIDTH, usernameLabel.getY(),
TEXT_FIELD_WIDTH, LABEL_HEIGHT);
passwordField = UIComponentHelper.createPasswordField(
CENTER_X - (LABEL_WIDTH + TEXT_FIELD_WIDTH) / 2 + LABEL_WIDTH, passwordLabel.getY(),
TEXT_FIELD_WIDTH, LABEL_HEIGHT);
loginPane.add(usernameTextField);
loginPane.add(passwordField);
}
Expand Down
12 changes: 12 additions & 0 deletions task_gamification/src/task_gamification/task_manager/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import task_gamification.helpers.GetFilePath;
import java.util.List;

/**
* Class managing all methods related to level management.
*/
public class Level{

private int userIndex, userXP, currentLevelXP, nextLevelXP, progressValue, levelXP;
Expand Down Expand Up @@ -58,6 +61,12 @@ public int getLevelXP(String level) {

}

/**
* Updates the users level.
*
* @param loggedInUser The username of the currently logged-in user.
* @param newLevel The users new level.
*/
public void updateUserLevel(String loggedInUser, int newLevel) {

try {
Expand All @@ -80,6 +89,9 @@ public void updateUserLevel(String loggedInUser, int newLevel) {

/**
* Calculates progress value for progress bar.
*
* @param currentLevel The users current level.
* @param userXP The users current XP.
*/
public int getProgressValue(int currentLevel, int userXP) {
currentLevelXP = getLevelXP(String.valueOf(currentLevel));
Expand Down
37 changes: 0 additions & 37 deletions task_gamification/src/task_gamification/task_manager/Story.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ private void removeTaskFromData(List<List<String>> taskData) {
* @param message The message to display as a success message.
*/
private void showSuccessMessage(String message) {
JOptionPane.showMessageDialog(this, message, "Task Operation", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(this, message, "Task Operation",
JOptionPane.INFORMATION_MESSAGE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package task_gamification.task_manager;

/**
* enum for all possible TaskModes
*/
public enum TaskMode {
ADD,
EDIT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ private void initializeGUI() {
add(storyScrollPane);
}

/**
* Fetches the data from the about.csv inkluding cresits info.
* @return about
*/
private String getAbout() {
csvReader = new CSVReader();
aboutContent = csvReader.readCSV(aboutFilePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public GeneralSettingsPanel(String loggedInUser, MainFrame mainFrame) {
addLogoutButton();
}

/**
* Creates username label and output.
* @param loggedInUser The username of the currently logged-in user.
*/
private void addUsernameLabel(String loggedInUser) {
JLabel userLabel = UIComponentHelper.createLabel("Username:", CENTER_X - (W_FRAME / 2) + 30,
30, LABEL_WIDTH, LABEL_HEIGHT);
Expand All @@ -54,6 +58,10 @@ private void addUsernameLabel(String loggedInUser) {
add(usernameLabel);
}

/**
* Creates creation date label and output.
* @param loggedInUser The username of the currently logged-in user.
*/
private void addCreationDateLabel(String loggedInUser) {
JLabel creationLabel = UIComponentHelper.createLabel("Created at:", CENTER_X - (W_FRAME / 2) + 30,
60, LABEL_WIDTH, LABEL_HEIGHT);
Expand All @@ -64,6 +72,10 @@ private void addCreationDateLabel(String loggedInUser) {
add(creationDateLabel);
}

/**
* Creates email label and output.
* @param loggedInUser The username of the currently logged-in user.
*/
private void addEmailLabel(String loggedInUser) {
JLabel emailLabel = UIComponentHelper.createLabel("E-Mail:", CENTER_X - (W_FRAME / 2) + 30, 90,
LABEL_WIDTH, LABEL_HEIGHT);
Expand All @@ -74,6 +86,10 @@ private void addEmailLabel(String loggedInUser) {
add(emailAddressLabel);
}

/**
* Creates a logout button. Which will lead the user back to the create user frame
* and finalise userlog for the running session.
*/
private void addLogoutButton() {
JButton logoutButton = ButtonHelper.newButton("Logout", "logout", e -> {

Expand Down
4 changes: 4 additions & 0 deletions task_gamification/src/task_gamification/views/ToDoPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ private void configurePaneBounds() {
H_FRAME - insets.bottom - insets.top);
}

/**
* Sets up the scroll pane.
* @return
*/
private JScrollPane setupScrollPane() {
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBounds(CENTER_X - (W_FRAME/2) + 30, 30, W_FRAME - 60, H_FRAME - 150);
Expand Down
Loading