added more javadoc
This commit is contained in:
parent
2fd1fc2b22
commit
787b806f9a
|
@ -7,6 +7,8 @@ import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
|
||||||
|
import static java.nio.file.Path.of;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for providing a global logger for the entire application instance at runtime
|
* Utility class for providing a global logger for the entire application instance at runtime
|
||||||
*/
|
*/
|
||||||
|
@ -45,7 +47,7 @@ public final class Logging {
|
||||||
* @param level the level to set the handler to
|
* @param level the level to set the handler to
|
||||||
*/
|
*/
|
||||||
private static void createConsoleLogger(Level level) {
|
private static void createConsoleLogger(Level level) {
|
||||||
var ch = new ConsoleHandler();
|
ConsoleHandler ch = new ConsoleHandler();
|
||||||
ch.setLevel(level);
|
ch.setLevel(level);
|
||||||
LOGGER.addHandler(ch);
|
LOGGER.addHandler(ch);
|
||||||
}
|
}
|
||||||
|
@ -60,15 +62,15 @@ public final class Logging {
|
||||||
*/
|
*/
|
||||||
private static void createFileLogger(Level level) {
|
private static void createFileLogger(Level level) {
|
||||||
// setup log file name
|
// setup log file name
|
||||||
var now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
var dateTime = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT).format(now);
|
String dateTime = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT).format(now);
|
||||||
var logFileName = LOG_FOLDER_NAME + dateTime + ".log";
|
String logFileName = LOG_FOLDER_NAME + dateTime + ".log";
|
||||||
|
|
||||||
// setup the folder for the logs
|
// setup the folder for the logs
|
||||||
initializeLogFolder();
|
initializeLogFolder();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var fh = new FileHandler(logFileName);
|
FileHandler fh = new FileHandler(logFileName);
|
||||||
fh.setLevel(level);
|
fh.setLevel(level);
|
||||||
LOGGER.addHandler(fh);
|
LOGGER.addHandler(fh);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -81,7 +83,7 @@ public final class Logging {
|
||||||
* If the folder does not exist, the function will create a new folder.
|
* If the folder does not exist, the function will create a new folder.
|
||||||
*/
|
*/
|
||||||
private static void initializeLogFolder() {
|
private static void initializeLogFolder() {
|
||||||
var folderPath = Path.of(LOG_FOLDER_NAME);
|
Path folderPath = of(LOG_FOLDER_NAME);
|
||||||
|
|
||||||
if (Files.isDirectory(folderPath))
|
if (Files.isDirectory(folderPath))
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -25,6 +25,11 @@ public class AccountController {
|
||||||
this.data = new AccountData();
|
this.data = new AccountData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the profile and BMS used to manage banking.
|
||||||
|
* @param profile the profile used to manage the account
|
||||||
|
* @param bms the BMS used access other banking accounts
|
||||||
|
*/
|
||||||
public void setProfile(Profile profile, BankingManagementSystem bms) {
|
public void setProfile(Profile profile, BankingManagementSystem bms) {
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
this.view.setProfile(profile);
|
this.view.setProfile(profile);
|
||||||
|
@ -32,6 +37,9 @@ public class AccountController {
|
||||||
this.createListeners();
|
this.createListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create listeners for GUI components
|
||||||
|
*/
|
||||||
private void createListeners() {
|
private void createListeners() {
|
||||||
this.view.getAccountSelection().addActionListener(e -> changeAccount());
|
this.view.getAccountSelection().addActionListener(e -> changeAccount());
|
||||||
this.view.getLogout().addActionListener(e -> logout());
|
this.view.getLogout().addActionListener(e -> logout());
|
||||||
|
@ -40,16 +48,25 @@ public class AccountController {
|
||||||
this.view.getTransfer().addActionListener(e -> transferMoney());
|
this.view.getTransfer().addActionListener(e -> transferMoney());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open dialog to deposit money
|
||||||
|
*/
|
||||||
private void depositMoney() {
|
private void depositMoney() {
|
||||||
new DepositController(profile.getPrimaryAccount());
|
new DepositController(profile.getPrimaryAccount());
|
||||||
this.view.updateAccountVariables(profile);
|
this.view.updateAccountVariables(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open dialog to transfer money
|
||||||
|
*/
|
||||||
private void transferMoney() {
|
private void transferMoney() {
|
||||||
new TransferController(profile.getPrimaryAccount(), data.getBms());
|
new TransferController(profile.getPrimaryAccount(), data.getBms());
|
||||||
this.view.updateAccountVariables(profile);
|
this.view.updateAccountVariables(profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open dialog to take off money
|
||||||
|
*/
|
||||||
private void takeoffMoney() {
|
private void takeoffMoney() {
|
||||||
new TakeoffController(profile.getPrimaryAccount());
|
new TakeoffController(profile.getPrimaryAccount());
|
||||||
this.view.updateAccountVariables(profile);
|
this.view.updateAccountVariables(profile);
|
||||||
|
@ -60,6 +77,9 @@ public class AccountController {
|
||||||
Main.getInstance().logout();
|
Main.getInstance().logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the selected account.
|
||||||
|
*/
|
||||||
private void changeAccount() {
|
private void changeAccount() {
|
||||||
var description = ((String) this.view.getAccountSelection().getSelectedItem());
|
var description = ((String) this.view.getAccountSelection().getSelectedItem());
|
||||||
Logging.LOGGER.fine("Changing primary account selected: " + description);
|
Logging.LOGGER.fine("Changing primary account selected: " + description);
|
||||||
|
|
|
@ -2,6 +2,9 @@ package me.teridax.jcash.gui.account;
|
||||||
|
|
||||||
import me.teridax.jcash.banking.management.BankingManagementSystem;
|
import me.teridax.jcash.banking.management.BankingManagementSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data storage class for account management
|
||||||
|
*/
|
||||||
public class AccountData {
|
public class AccountData {
|
||||||
|
|
||||||
private BankingManagementSystem bms;
|
private BankingManagementSystem bms;
|
||||||
|
|
|
@ -40,6 +40,10 @@ public class AccountView extends JPanel {
|
||||||
setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
|
setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The profile to manage via the GUI.
|
||||||
|
* @param profile the profile to manage
|
||||||
|
*/
|
||||||
public void setProfile(Profile profile) {
|
public void setProfile(Profile profile) {
|
||||||
this.updateAccountVariables(profile);
|
this.updateAccountVariables(profile);
|
||||||
|
|
||||||
|
@ -137,8 +141,15 @@ public class AccountView extends JPanel {
|
||||||
return takeoff;
|
return takeoff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the accessible class fields of the primary account
|
||||||
|
* into the text fields. Also updates the combo box for
|
||||||
|
* all associated accounts.
|
||||||
|
* @param profile the profile to update from
|
||||||
|
*/
|
||||||
public void updateAccountVariables(Profile profile) {
|
public void updateAccountVariables(Profile profile) {
|
||||||
Logging.LOGGER.finer("Updating account view");
|
Logging.LOGGER.finer("Updating account view");
|
||||||
|
// temporarily extract data
|
||||||
var bank = profile.getBank();
|
var bank = profile.getBank();
|
||||||
var account = profile.getPrimaryAccount();
|
var account = profile.getPrimaryAccount();
|
||||||
var owner = profile.getOwner();
|
var owner = profile.getOwner();
|
||||||
|
@ -152,6 +163,8 @@ public class AccountView extends JPanel {
|
||||||
|
|
||||||
this.balance.setText(StringDecoder.getNumberFormat().format(account.getBalance()) + " €");
|
this.balance.setText(StringDecoder.getNumberFormat().format(account.getBalance()) + " €");
|
||||||
|
|
||||||
|
// update account type specific fields
|
||||||
|
|
||||||
this.type.setText(translate(account.getClass().getSimpleName()));
|
this.type.setText(translate(account.getClass().getSimpleName()));
|
||||||
if (account instanceof CurrentAccount) {
|
if (account instanceof CurrentAccount) {
|
||||||
this.typeSpecialLabel.setText(translate("Overdraft"));
|
this.typeSpecialLabel.setText(translate("Overdraft"));
|
||||||
|
|
|
@ -9,21 +9,30 @@ import javax.swing.event.DocumentEvent;
|
||||||
import javax.swing.event.DocumentListener;
|
import javax.swing.event.DocumentListener;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for controlling the deposit operation via a dialog.
|
||||||
|
*/
|
||||||
public class DepositController {
|
public class DepositController {
|
||||||
|
|
||||||
private final DepositView view;
|
private final DepositView view;
|
||||||
|
/**
|
||||||
|
* Account to deposit money to.
|
||||||
|
*/
|
||||||
private final Account account;
|
private final Account account;
|
||||||
private final DepositData data;
|
|
||||||
|
|
||||||
public DepositController(Account account) {
|
public DepositController(Account account) {
|
||||||
this.account = account;
|
this.account = account;
|
||||||
|
|
||||||
this.data = new DepositData(account.getBalance());
|
this.view = new DepositView(account.getBalance());
|
||||||
this.view = new DepositView(this.data.getMaxValue());
|
|
||||||
|
|
||||||
this.view.getDeposit().addActionListener(e -> depositMoney());
|
this.view.getDeposit().addActionListener(e -> depositMoney());
|
||||||
this.view.getCancel().addActionListener(e -> view.dispose());
|
this.view.getCancel().addActionListener(e -> view.dispose());
|
||||||
this.view.getValue().getDocument().addDocumentListener(new DocumentListener() {
|
this.view.getValue().getDocument().addDocumentListener(new DocumentListener() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the amount to deposit and update display
|
||||||
|
* variables.
|
||||||
|
*/
|
||||||
private void validateInputState() {
|
private void validateInputState() {
|
||||||
var balance = account.getBalance();
|
var balance = account.getBalance();
|
||||||
try {
|
try {
|
||||||
|
@ -55,6 +64,10 @@ public class DepositController {
|
||||||
this.view.showDialog();
|
this.view.showDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deposit the last valid value to the account.
|
||||||
|
* This method may display error dialogs when no money can be deposited.
|
||||||
|
*/
|
||||||
private void depositMoney() {
|
private void depositMoney() {
|
||||||
try {
|
try {
|
||||||
var amount = view.getAmount();
|
var amount = view.getAmount();
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
package me.teridax.jcash.gui.deposit;
|
|
||||||
|
|
||||||
public class DepositData {
|
|
||||||
|
|
||||||
private double maxValue;
|
|
||||||
|
|
||||||
public DepositData(double maxValue) {
|
|
||||||
this.maxValue = maxValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getMaxValue() {
|
|
||||||
return maxValue;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -11,12 +11,28 @@ import java.text.ParseException;
|
||||||
|
|
||||||
import static me.teridax.jcash.lang.Translator.translate;
|
import static me.teridax.jcash.lang.Translator.translate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* View class for displaying a dialog prompting the user to
|
||||||
|
* enter a valid amount to deposit at their account
|
||||||
|
*/
|
||||||
public class DepositView {
|
public class DepositView {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Window to use
|
||||||
|
*/
|
||||||
private JDialog dialog;
|
private JDialog dialog;
|
||||||
private JButton cancel;
|
private JButton cancel;
|
||||||
|
/**
|
||||||
|
* Button for applying the deposit operation
|
||||||
|
*/
|
||||||
private JButton deposit;
|
private JButton deposit;
|
||||||
|
/**
|
||||||
|
* Displays the validated value to deposit
|
||||||
|
*/
|
||||||
private JLabel enteredValue;
|
private JLabel enteredValue;
|
||||||
|
/**
|
||||||
|
* Displays the account balance after the deposit operation
|
||||||
|
*/
|
||||||
private JLabel balanceAfterDeposit;
|
private JLabel balanceAfterDeposit;
|
||||||
private JFormattedTextField value;
|
private JFormattedTextField value;
|
||||||
|
|
||||||
|
@ -119,6 +135,12 @@ public class DepositView {
|
||||||
this.dialog.setContentPane(new JPanel(new GridBagLayout()));
|
this.dialog.setContentPane(new JPanel(new GridBagLayout()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the amount of money that should be deposited
|
||||||
|
* This value derives from the input of the user.
|
||||||
|
* @return the value to deposit
|
||||||
|
* @throws InvalidInputException if the user entered something invalid
|
||||||
|
*/
|
||||||
public double getAmount() throws InvalidInputException {
|
public double getAmount() throws InvalidInputException {
|
||||||
if (value.getText().isBlank())
|
if (value.getText().isBlank())
|
||||||
throw new InvalidInputException("currency value is blank or has been invalid whilst entered");
|
throw new InvalidInputException("currency value is blank or has been invalid whilst entered");
|
||||||
|
@ -147,6 +169,11 @@ public class DepositView {
|
||||||
this.dialog.dispose();
|
this.dialog.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the supplied amount to the preview GUI fields.
|
||||||
|
* @param amount the value to display for value to deposit
|
||||||
|
* @param after the value to display for balance after deposit
|
||||||
|
*/
|
||||||
public void setCommittedValue(double amount, double after) {
|
public void setCommittedValue(double amount, double after) {
|
||||||
enteredValue.setText(StringDecoder.getNumberFormat().format(amount));
|
enteredValue.setText(StringDecoder.getNumberFormat().format(amount));
|
||||||
balanceAfterDeposit.setText(StringDecoder.getNumberFormat().format(after));
|
balanceAfterDeposit.setText(StringDecoder.getNumberFormat().format(after));
|
||||||
|
|
|
@ -7,10 +7,6 @@ import me.teridax.jcash.gui.Utils;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static javax.swing.JOptionPane.ERROR_MESSAGE;
|
|
||||||
import static javax.swing.JOptionPane.showMessageDialog;
|
|
||||||
import static me.teridax.jcash.lang.Translator.translate;
|
|
||||||
|
|
||||||
public class LoginController {
|
public class LoginController {
|
||||||
|
|
||||||
private final LoginView view;
|
private final LoginView view;
|
||||||
|
|
|
@ -46,10 +46,6 @@ public class LoginData {
|
||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BankingManagementSystem getBms() {
|
|
||||||
return bms;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBms(BankingManagementSystem bms) {
|
public void setBms(BankingManagementSystem bms) {
|
||||||
this.bms = bms;
|
this.bms = bms;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package me.teridax.jcash.gui.login;
|
package me.teridax.jcash.gui.login;
|
||||||
|
|
||||||
import me.teridax.jcash.decode.StringDecoder;
|
|
||||||
import me.teridax.jcash.gui.IconProvider;
|
import me.teridax.jcash.gui.IconProvider;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
@ -11,6 +10,9 @@ import static me.teridax.jcash.gui.Utils.addGridBagRow;
|
||||||
import static me.teridax.jcash.gui.Utils.addHeading;
|
import static me.teridax.jcash.gui.Utils.addHeading;
|
||||||
import static me.teridax.jcash.lang.Translator.translate;
|
import static me.teridax.jcash.lang.Translator.translate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GUI class for login into an account
|
||||||
|
*/
|
||||||
public class LoginView extends JPanel {
|
public class LoginView extends JPanel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,6 +20,10 @@ public class LoginView extends JPanel {
|
||||||
* N = log10(2^32-1) = 9,632959861146281
|
* N = log10(2^32-1) = 9,632959861146281
|
||||||
*/
|
*/
|
||||||
private static final int MAX_PIN_DECIMAL_DIGITS = 9;
|
private static final int MAX_PIN_DECIMAL_DIGITS = 9;
|
||||||
|
/**
|
||||||
|
* Number of pixels the banner image should be in width
|
||||||
|
*/
|
||||||
|
public static final int BANNER_WIDTH = 400;
|
||||||
|
|
||||||
private JFormattedTextField blz;
|
private JFormattedTextField blz;
|
||||||
private JFormattedTextField iban;
|
private JFormattedTextField iban;
|
||||||
|
@ -37,7 +43,7 @@ public class LoginView extends JPanel {
|
||||||
var loginPane = new JPanel(new GridBagLayout());
|
var loginPane = new JPanel(new GridBagLayout());
|
||||||
loginPane.setOpaque(true);
|
loginPane.setOpaque(true);
|
||||||
content.add(loginPane, BorderLayout.CENTER);
|
content.add(loginPane, BorderLayout.CENTER);
|
||||||
content.add(Box.createHorizontalStrut(400), BorderLayout.WEST);
|
content.add(Box.createHorizontalStrut(BANNER_WIDTH), BorderLayout.WEST);
|
||||||
|
|
||||||
this.setLayout(new BorderLayout(32, 32));
|
this.setLayout(new BorderLayout(32, 32));
|
||||||
this.add(new JScrollPane(content), BorderLayout.CENTER);
|
this.add(new JScrollPane(content), BorderLayout.CENTER);
|
||||||
|
@ -66,6 +72,8 @@ public class LoginView extends JPanel {
|
||||||
this.pin = new JPasswordField();
|
this.pin = new JPasswordField();
|
||||||
this.login = new JButton(translate("Login"));
|
this.login = new JButton(translate("Login"));
|
||||||
|
|
||||||
|
// customize login button
|
||||||
|
// this may not work with every swing look and feel
|
||||||
this.login.setFont(new Font("Circus", Font.PLAIN, 28));
|
this.login.setFont(new Font("Circus", Font.PLAIN, 28));
|
||||||
this.login.setBackground(Color.CYAN);
|
this.login.setBackground(Color.CYAN);
|
||||||
|
|
||||||
|
|
|
@ -10,22 +10,32 @@ import javax.swing.event.DocumentEvent;
|
||||||
import javax.swing.event.DocumentListener;
|
import javax.swing.event.DocumentListener;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller class for handling bank account take off.
|
||||||
|
*/
|
||||||
public class TakeoffController {
|
public class TakeoffController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Account to take off
|
||||||
|
*/
|
||||||
private final Account account;
|
private final Account account;
|
||||||
|
/**
|
||||||
|
* GUI object
|
||||||
|
*/
|
||||||
private final TakeoffView view;
|
private final TakeoffView view;
|
||||||
private final TakeoffData data;
|
|
||||||
|
|
||||||
public TakeoffController(Account account) {
|
public TakeoffController(Account account) {
|
||||||
this.account = account;
|
this.account = account;
|
||||||
|
|
||||||
|
// add overdraft on top of the maximum amount
|
||||||
|
// a user is allowed to take off
|
||||||
var overdraft = 0.0;
|
var overdraft = 0.0;
|
||||||
if (account instanceof CurrentAccount) {
|
if (account instanceof CurrentAccount) {
|
||||||
overdraft += ((CurrentAccount) account).getOverdraft();
|
overdraft += ((CurrentAccount) account).getOverdraft();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.data = new TakeoffData(account.getBalance());
|
TakeoffData data = new TakeoffData(account.getBalance());
|
||||||
this.view = new TakeoffView(this.data.getMaxValue() + overdraft);
|
this.view = new TakeoffView(data.getMaxValue() + overdraft);
|
||||||
|
|
||||||
this.view.getTakeoff().addActionListener(e -> takeOff());
|
this.view.getTakeoff().addActionListener(e -> takeOff());
|
||||||
this.view.getCancel().addActionListener(e -> view.dispose());
|
this.view.getCancel().addActionListener(e -> view.dispose());
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
package me.teridax.jcash.gui.takeoff;
|
package me.teridax.jcash.gui.takeoff;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data class for taking off value from a certain account
|
||||||
|
*/
|
||||||
public class TakeoffData {
|
public class TakeoffData {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum value a user is allowed to take off
|
||||||
|
*/
|
||||||
private final double maxValue;
|
private final double maxValue;
|
||||||
|
|
||||||
public TakeoffData(double maxValue) {
|
public TakeoffData(double maxValue) {
|
||||||
|
|
Loading…
Reference in New Issue