diff --git a/src/me/teridax/jcash/Logging.java b/src/me/teridax/jcash/Logging.java index f1a17a0..998f985 100644 --- a/src/me/teridax/jcash/Logging.java +++ b/src/me/teridax/jcash/Logging.java @@ -7,6 +7,8 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; 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 */ @@ -45,7 +47,7 @@ public final class Logging { * @param level the level to set the handler to */ private static void createConsoleLogger(Level level) { - var ch = new ConsoleHandler(); + ConsoleHandler ch = new ConsoleHandler(); ch.setLevel(level); LOGGER.addHandler(ch); } @@ -60,15 +62,15 @@ public final class Logging { */ private static void createFileLogger(Level level) { // setup log file name - var now = LocalDateTime.now(); - var dateTime = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT).format(now); - var logFileName = LOG_FOLDER_NAME + dateTime + ".log"; + LocalDateTime now = LocalDateTime.now(); + String dateTime = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT).format(now); + String logFileName = LOG_FOLDER_NAME + dateTime + ".log"; // setup the folder for the logs initializeLogFolder(); try { - var fh = new FileHandler(logFileName); + FileHandler fh = new FileHandler(logFileName); fh.setLevel(level); LOGGER.addHandler(fh); } catch (Exception e) { @@ -81,7 +83,7 @@ public final class Logging { * If the folder does not exist, the function will create a new folder. */ private static void initializeLogFolder() { - var folderPath = Path.of(LOG_FOLDER_NAME); + Path folderPath = of(LOG_FOLDER_NAME); if (Files.isDirectory(folderPath)) return; diff --git a/src/me/teridax/jcash/gui/account/AccountController.java b/src/me/teridax/jcash/gui/account/AccountController.java index 49b8c37..c092147 100644 --- a/src/me/teridax/jcash/gui/account/AccountController.java +++ b/src/me/teridax/jcash/gui/account/AccountController.java @@ -25,6 +25,11 @@ public class AccountController { 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) { this.profile = profile; this.view.setProfile(profile); @@ -32,6 +37,9 @@ public class AccountController { this.createListeners(); } + /** + * Create listeners for GUI components + */ private void createListeners() { this.view.getAccountSelection().addActionListener(e -> changeAccount()); this.view.getLogout().addActionListener(e -> logout()); @@ -40,16 +48,25 @@ public class AccountController { this.view.getTransfer().addActionListener(e -> transferMoney()); } + /** + * Open dialog to deposit money + */ private void depositMoney() { new DepositController(profile.getPrimaryAccount()); this.view.updateAccountVariables(profile); } + /** + * Open dialog to transfer money + */ private void transferMoney() { new TransferController(profile.getPrimaryAccount(), data.getBms()); this.view.updateAccountVariables(profile); } + /** + * Open dialog to take off money + */ private void takeoffMoney() { new TakeoffController(profile.getPrimaryAccount()); this.view.updateAccountVariables(profile); @@ -60,6 +77,9 @@ public class AccountController { Main.getInstance().logout(); } + /** + * Change the selected account. + */ private void changeAccount() { var description = ((String) this.view.getAccountSelection().getSelectedItem()); Logging.LOGGER.fine("Changing primary account selected: " + description); diff --git a/src/me/teridax/jcash/gui/account/AccountData.java b/src/me/teridax/jcash/gui/account/AccountData.java index f936082..b602907 100644 --- a/src/me/teridax/jcash/gui/account/AccountData.java +++ b/src/me/teridax/jcash/gui/account/AccountData.java @@ -2,6 +2,9 @@ package me.teridax.jcash.gui.account; import me.teridax.jcash.banking.management.BankingManagementSystem; +/** + * Data storage class for account management + */ public class AccountData { private BankingManagementSystem bms; diff --git a/src/me/teridax/jcash/gui/account/AccountView.java b/src/me/teridax/jcash/gui/account/AccountView.java index 094f75e..030fd14 100644 --- a/src/me/teridax/jcash/gui/account/AccountView.java +++ b/src/me/teridax/jcash/gui/account/AccountView.java @@ -40,6 +40,10 @@ public class AccountView extends JPanel { 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) { this.updateAccountVariables(profile); @@ -137,8 +141,15 @@ public class AccountView extends JPanel { 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) { Logging.LOGGER.finer("Updating account view"); + // temporarily extract data var bank = profile.getBank(); var account = profile.getPrimaryAccount(); var owner = profile.getOwner(); @@ -152,6 +163,8 @@ public class AccountView extends JPanel { this.balance.setText(StringDecoder.getNumberFormat().format(account.getBalance()) + " €"); + // update account type specific fields + this.type.setText(translate(account.getClass().getSimpleName())); if (account instanceof CurrentAccount) { this.typeSpecialLabel.setText(translate("Overdraft")); diff --git a/src/me/teridax/jcash/gui/deposit/DepositController.java b/src/me/teridax/jcash/gui/deposit/DepositController.java index 55a574e..ea19cab 100644 --- a/src/me/teridax/jcash/gui/deposit/DepositController.java +++ b/src/me/teridax/jcash/gui/deposit/DepositController.java @@ -9,21 +9,30 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import java.text.ParseException; +/** + * Class for controlling the deposit operation via a dialog. + */ public class DepositController { private final DepositView view; + /** + * Account to deposit money to. + */ private final Account account; - private final DepositData data; public DepositController(Account account) { this.account = account; - this.data = new DepositData(account.getBalance()); - this.view = new DepositView(this.data.getMaxValue()); + this.view = new DepositView(account.getBalance()); this.view.getDeposit().addActionListener(e -> depositMoney()); this.view.getCancel().addActionListener(e -> view.dispose()); this.view.getValue().getDocument().addDocumentListener(new DocumentListener() { + + /** + * Validate the amount to deposit and update display + * variables. + */ private void validateInputState() { var balance = account.getBalance(); try { @@ -55,6 +64,10 @@ public class DepositController { 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() { try { var amount = view.getAmount(); diff --git a/src/me/teridax/jcash/gui/deposit/DepositData.java b/src/me/teridax/jcash/gui/deposit/DepositData.java deleted file mode 100644 index 71187fd..0000000 --- a/src/me/teridax/jcash/gui/deposit/DepositData.java +++ /dev/null @@ -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; - } -} diff --git a/src/me/teridax/jcash/gui/deposit/DepositView.java b/src/me/teridax/jcash/gui/deposit/DepositView.java index a9f2f4f..bb5e49b 100644 --- a/src/me/teridax/jcash/gui/deposit/DepositView.java +++ b/src/me/teridax/jcash/gui/deposit/DepositView.java @@ -11,12 +11,28 @@ import java.text.ParseException; 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 { + /** + * Window to use + */ private JDialog dialog; private JButton cancel; + /** + * Button for applying the deposit operation + */ private JButton deposit; + /** + * Displays the validated value to deposit + */ private JLabel enteredValue; + /** + * Displays the account balance after the deposit operation + */ private JLabel balanceAfterDeposit; private JFormattedTextField value; @@ -119,6 +135,12 @@ public class DepositView { 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 { if (value.getText().isBlank()) throw new InvalidInputException("currency value is blank or has been invalid whilst entered"); @@ -147,6 +169,11 @@ public class DepositView { 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) { enteredValue.setText(StringDecoder.getNumberFormat().format(amount)); balanceAfterDeposit.setText(StringDecoder.getNumberFormat().format(after)); diff --git a/src/me/teridax/jcash/gui/login/LoginController.java b/src/me/teridax/jcash/gui/login/LoginController.java index dfa7c61..cad96ef 100644 --- a/src/me/teridax/jcash/gui/login/LoginController.java +++ b/src/me/teridax/jcash/gui/login/LoginController.java @@ -7,10 +7,6 @@ import me.teridax.jcash.gui.Utils; import java.awt.event.ActionEvent; 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 { private final LoginView view; diff --git a/src/me/teridax/jcash/gui/login/LoginData.java b/src/me/teridax/jcash/gui/login/LoginData.java index 32d02d0..403ad5b 100644 --- a/src/me/teridax/jcash/gui/login/LoginData.java +++ b/src/me/teridax/jcash/gui/login/LoginData.java @@ -46,10 +46,6 @@ public class LoginData { return account; } - public BankingManagementSystem getBms() { - return bms; - } - public void setBms(BankingManagementSystem bms) { this.bms = bms; } diff --git a/src/me/teridax/jcash/gui/login/LoginView.java b/src/me/teridax/jcash/gui/login/LoginView.java index 0dcf11c..2dc2677 100644 --- a/src/me/teridax/jcash/gui/login/LoginView.java +++ b/src/me/teridax/jcash/gui/login/LoginView.java @@ -1,6 +1,5 @@ package me.teridax.jcash.gui.login; -import me.teridax.jcash.decode.StringDecoder; import me.teridax.jcash.gui.IconProvider; 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.lang.Translator.translate; +/** + * GUI class for login into an account + */ public class LoginView extends JPanel { /** @@ -18,6 +20,10 @@ public class LoginView extends JPanel { * N = log10(2^32-1) = 9,632959861146281 */ 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 iban; @@ -37,7 +43,7 @@ public class LoginView extends JPanel { var loginPane = new JPanel(new GridBagLayout()); loginPane.setOpaque(true); 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.add(new JScrollPane(content), BorderLayout.CENTER); @@ -66,6 +72,8 @@ public class LoginView extends JPanel { this.pin = new JPasswordField(); 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.setBackground(Color.CYAN); diff --git a/src/me/teridax/jcash/gui/takeoff/TakeoffController.java b/src/me/teridax/jcash/gui/takeoff/TakeoffController.java index 45fb9e0..a778a4d 100644 --- a/src/me/teridax/jcash/gui/takeoff/TakeoffController.java +++ b/src/me/teridax/jcash/gui/takeoff/TakeoffController.java @@ -10,22 +10,32 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import java.text.ParseException; +/** + * Controller class for handling bank account take off. + */ public class TakeoffController { + /** + * Account to take off + */ private final Account account; + /** + * GUI object + */ private final TakeoffView view; - private final TakeoffData data; public TakeoffController(Account account) { this.account = account; + // add overdraft on top of the maximum amount + // a user is allowed to take off var overdraft = 0.0; if (account instanceof CurrentAccount) { overdraft += ((CurrentAccount) account).getOverdraft(); } - this.data = new TakeoffData(account.getBalance()); - this.view = new TakeoffView(this.data.getMaxValue() + overdraft); + TakeoffData data = new TakeoffData(account.getBalance()); + this.view = new TakeoffView(data.getMaxValue() + overdraft); this.view.getTakeoff().addActionListener(e -> takeOff()); this.view.getCancel().addActionListener(e -> view.dispose()); diff --git a/src/me/teridax/jcash/gui/takeoff/TakeoffData.java b/src/me/teridax/jcash/gui/takeoff/TakeoffData.java index d3c694b..4f08105 100644 --- a/src/me/teridax/jcash/gui/takeoff/TakeoffData.java +++ b/src/me/teridax/jcash/gui/takeoff/TakeoffData.java @@ -1,7 +1,13 @@ package me.teridax.jcash.gui.takeoff; +/** + * Data class for taking off value from a certain account + */ public class TakeoffData { + /** + * Maximum value a user is allowed to take off + */ private final double maxValue; public TakeoffData(double maxValue) {