From 6ff4a152bef688d3910eafcb24147e877658a4a6 Mon Sep 17 00:00:00 2001 From: pawelsa Date: Sun, 24 May 2026 19:19:04 +0200 Subject: [PATCH 01/23] chore: JavaDocs for model. --- .../java/edu/ntnu/idi/idatt/Launcher.java | 6 ++ .../edu/ntnu/idi/idatt/model/Exchange.java | 19 ++-- .../idi/idatt/model/enums/NewspaperEnum.java | 32 +++++++ .../idi/idatt/model/market/Newspaper.java | 40 +++++++++ .../ntnu/idi/idatt/model/market/Stock.java | 66 ++++++++++++-- .../idi/idatt/model/portfolio/Portfolio.java | 44 +++++++++- .../ntnu/idi/idatt/model/portfolio/Share.java | 42 +++++++-- .../idatt/model/transaction/Transaction.java | 22 +++-- .../model/transaction/TransactionArchive.java | 29 +++++-- .../service/transaction/SaleCalculator.java | 14 ++- .../ntnu/idi/idatt/session/UserSession.java | 87 +++++++++++++++++++ .../idi/idatt/storage/SessionManager.java | 7 +- .../ntnu/idi/idatt/storage/StockParser.java | 3 - .../storage/util/TransactionAdapter.java | 20 +++++ .../util/TransactionCalculatorAdapter.java | 20 +++++ 15 files changed, 414 insertions(+), 37 deletions(-) diff --git a/src/main/java/edu/ntnu/idi/idatt/Launcher.java b/src/main/java/edu/ntnu/idi/idatt/Launcher.java index a7030b1..568ea1b 100644 --- a/src/main/java/edu/ntnu/idi/idatt/Launcher.java +++ b/src/main/java/edu/ntnu/idi/idatt/Launcher.java @@ -14,8 +14,14 @@ static void main() { Application.launch(Millions.class); } + /** + * Class for JavaFX startup. + */ public static final class Millions extends Application { + /** + * JavaFX entry point. + */ @Override public void start(Stage stage) { stage.setWidth(1440); diff --git a/src/main/java/edu/ntnu/idi/idatt/model/Exchange.java b/src/main/java/edu/ntnu/idi/idatt/model/Exchange.java index db005da..2680bc6 100644 --- a/src/main/java/edu/ntnu/idi/idatt/model/Exchange.java +++ b/src/main/java/edu/ntnu/idi/idatt/model/Exchange.java @@ -41,20 +41,28 @@ public Exchange(String name, List stocks) { } /** - * - * Getters - * - * @return - their corresponding variables. + * Getter for name. + * + * @return String; */ - public String getName() { return name; } + /** + * Getter for week. + * + * @return int; + */ public int getWeek() { return week; } + /** + * Getter for all stocks. + * + * @return List of Stocks. + */ public List getStocks() { return stockMap.values().stream().toList(); } @@ -189,6 +197,7 @@ public Transaction sell(Share share, Player player) { * *

* Adds a new price to each of the stock array. + * Progresses week counter. *

* * @see Stock diff --git a/src/main/java/edu/ntnu/idi/idatt/model/enums/NewspaperEnum.java b/src/main/java/edu/ntnu/idi/idatt/model/enums/NewspaperEnum.java index bc48f3e..11b8c22 100644 --- a/src/main/java/edu/ntnu/idi/idatt/model/enums/NewspaperEnum.java +++ b/src/main/java/edu/ntnu/idi/idatt/model/enums/NewspaperEnum.java @@ -1,5 +1,14 @@ package edu.ntnu.idi.idatt.model.enums; +/** + * Newspaper enum. + * + *

+ * Creates static events that can occur within Newspaper. + *

+ * + * @see Newspaper + */ public enum NewspaperEnum { NEW_PRODUCT( "New product announced!", @@ -83,6 +92,9 @@ public enum NewspaperEnum { private final double trend; private final double volatility; // How violently the price moves factor + /** + * Constructor for NewspaperEnum + */ NewspaperEnum(String title, String description, double trend, double volatility) { this.title = title; this.description = description; @@ -90,18 +102,38 @@ public enum NewspaperEnum { this.volatility = volatility; } + /** + * Getter for title + * + * @return String; + */ public String getTitle() { return title; } + /** + * Getter for description + * + * @return String; + */ public String getDescription() { return description; } + /** + * Getter for trend + * + * @return double; + */ public double getTrend() { return trend; } + /** + * Getter for volatility + * + * @return double; + */ public double getVolatility() { return volatility; } diff --git a/src/main/java/edu/ntnu/idi/idatt/model/market/Newspaper.java b/src/main/java/edu/ntnu/idi/idatt/model/market/Newspaper.java index 2271042..95681cf 100644 --- a/src/main/java/edu/ntnu/idi/idatt/model/market/Newspaper.java +++ b/src/main/java/edu/ntnu/idi/idatt/model/market/Newspaper.java @@ -6,11 +6,34 @@ import edu.ntnu.idi.idatt.model.enums.NewspaperEnum; +//TODO: junit + +/** + * Newspaper class + * + *

+ * This class is used together with Stock, + * to provide a event-based context for the + * prices. + *

+ * + * @see Stock + */ public class Newspaper { ArrayList news = new ArrayList<>(List.of(NewspaperEnum.NONE_EVENT)); private static double chance = 0.05; // In percent + /** + * Method for creating news. + * + *

+ * Creates news and adds them to the + * news ArrayList. + *

+ * + * @return NewspaperEnum of NONE or random event. + */ public NewspaperEnum makeNews() { Random r = new Random(); double roll = r.nextDouble(); @@ -27,14 +50,31 @@ public NewspaperEnum makeNews() { return event; } + /** + * Method for checking if Newspaper has new news. + * + * @return true/false depending if a real event exists. + */ public boolean hasNewNews() { return news.getLast().equals(NewspaperEnum.NONE_EVENT) ? false : true; } + /** + * Getter for news arraylist. + */ public ArrayList getNews() { return news; } + /** + * Method for converting the arraylist to formatted strings. + * + *

+ * Converts NewspaperEnum to fitting String format. + *

+ * + * @return List of strings. + */ public List getNewsStrings() { ArrayList strings = new ArrayList<>(); diff --git a/src/main/java/edu/ntnu/idi/idatt/model/market/Stock.java b/src/main/java/edu/ntnu/idi/idatt/model/market/Stock.java index 74b9dd0..92fddbd 100644 --- a/src/main/java/edu/ntnu/idi/idatt/model/market/Stock.java +++ b/src/main/java/edu/ntnu/idi/idatt/model/market/Stock.java @@ -50,15 +50,19 @@ public Stock(String symbol, String company, List prices) { } /** - * Getters - * - * @return - Their corresponding variables. + * Getter for symbol + * + * @return String; */ - public String getSymbol() { return symbol; } + /** + * Getter for company + * + * @return String; + */ public String getCompany() { return company; } @@ -105,7 +109,15 @@ public BigDecimal getLatestPriceChange() { return prices.get(size - 1).subtract(prices.get(size - 2)); } - // TODO: JAVADOCS, JUNIT + /** + * Method for calculating the latest price change in percent. + * + *

+ * CurrentPrice/PreviousPrice * 100 + *

+ * + * @return BigDecimal of the change. + */ public BigDecimal getLatestPriceChangePercent() { if (prices.isEmpty() || prices.size() == 1) { return BigDecimal.ZERO; @@ -133,17 +145,39 @@ public void addNewSalesPrice(BigDecimal price) { prices.add(price); } - // TODO: JavaDocs ETC + /** + * Getter for newspaper + * + * @return Newspaper; + */ public Newspaper getNewspaper() { return newspaper; } + /** + * Method for calculating the price factor. + * + *

+ * Calculates the factor which is multiplied + * with current price to calculate the next week's price. + *

+ * + * @return factor (double) + */ private double calculatePriceFactor() { double noice = (new Random().nextGaussian() + 0.2) * volatility; return 0.01 /* positive trend */ + trend + momentum + noice; } + /** + * Method for calibrating the next price factor components + * + *

+ * Balances and controlls how the components making + * up the price factor adjust with each week. + *

+ */ private void calibrateNextPriceFactor() { momentum = calculatePriceFactor() * 0.35; @@ -160,6 +194,15 @@ private void calibrateNextPriceFactor() { } + /** + * Method for advancing stock price. + * + *

+ * Calculates next stock price based on + * current week's price and the price factor. + * Calls calibration when finished. + *

+ */ public void advancePrice() { BigDecimal currentPrice = this.getSalesPrice(); BigDecimal priceFactor = currentPrice.multiply(BigDecimal.valueOf(this.calculatePriceFactor())); @@ -171,7 +214,16 @@ public void advancePrice() { this.calibrateNextPriceFactor(); } - // TODO: JavaDocs + /** + * toString method. + * + *

+ * Converts stock to a String form used + * in diverse GUI components. + *

+ * + * @return String; + */ @Override public String toString() { return this.getCompany() + " (" + this.getSymbol() + ")"; diff --git a/src/main/java/edu/ntnu/idi/idatt/model/portfolio/Portfolio.java b/src/main/java/edu/ntnu/idi/idatt/model/portfolio/Portfolio.java index c255340..1d37e10 100644 --- a/src/main/java/edu/ntnu/idi/idatt/model/portfolio/Portfolio.java +++ b/src/main/java/edu/ntnu/idi/idatt/model/portfolio/Portfolio.java @@ -43,7 +43,15 @@ public boolean removeShare(Share share) { return shares.remove(share); } - // TODO: JavaDocs, Junit + /** + * Removes all shares. + * + *

+ * Used only for reseeding the shares to + * match the instances of Exchange after loading + * from JSON. + *

+ */ public void removeShares() { shares.clear(); } @@ -67,25 +75,52 @@ public List getShares(String symbol) { return shares.stream().filter(s -> s.getStock().getSymbol().equals(symbol)).toList(); } - // TODO: JAVADOCS, JUNIT + /** + * Method for obtaining total amount of owned stock. + * + * @param symbol - The stock symbol of the corresponding shares. + * @return BigDecimal of amount. + */ public BigDecimal getOwnedAmount(String symbol) { return getShares(symbol).stream().map(s -> s.getQuantity()) .reduce(BigDecimal.ZERO, BigDecimal::add); } + /** + * Getter for total amount of owned shares. + * + * @return BigDecimal total amount. + */ public BigDecimal getOwnedAmount() { return getShares().stream().map(s -> s.getQuantity()) .reduce(BigDecimal.ZERO, BigDecimal::add); } + /** + * Method for obtaining profit from specified shares. + * + * @param symbol - Symbol of the specified Stock. + * @return BigDecimal of total profit. + */ public BigDecimal getProfitFromStock(String symbol) { return getShares(symbol).stream().map(s -> s.getProfit()).reduce(BigDecimal.ZERO, BigDecimal::add); } + /** + * Method for obtaining profit from all shares. + * + * @return total portfolio profit. + */ public BigDecimal getProfitFromStock() { return getShares().stream().map(s -> s.getProfit()).reduce(BigDecimal.ZERO, BigDecimal::add); } + /** + * Method for obtaining the profit percent change from a specified share. + * + * @param symbol - The symbol of the specified Stock. + * @return BigDecimal of profit percent change. + */ public BigDecimal getChangeFromStock(String symbol) { BigDecimal profitTotal = getProfitFromStock(symbol); BigDecimal costTotal = getShares(symbol).stream().map(s -> s.getTotalPurchasePrice()) @@ -97,6 +132,11 @@ public BigDecimal getChangeFromStock(String symbol) { return profitTotal.divide(costTotal, 2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)); } + /** + * Method for obtaining the profit percent change for all shares. + * + * @return BigDecimal of portfolio percent change. + */ public BigDecimal getChangeFromStock() { BigDecimal profitTotal = getProfitFromStock(); BigDecimal costTotal = getShares().stream().map(s -> s.getTotalPurchasePrice()) diff --git a/src/main/java/edu/ntnu/idi/idatt/model/portfolio/Share.java b/src/main/java/edu/ntnu/idi/idatt/model/portfolio/Share.java index 186cb43..c828dd6 100644 --- a/src/main/java/edu/ntnu/idi/idatt/model/portfolio/Share.java +++ b/src/main/java/edu/ntnu/idi/idatt/model/portfolio/Share.java @@ -35,32 +35,64 @@ public Share(Stock stock, BigDecimal quantity, BigDecimal purchasePrice) { } /** - * Getters - * - * @return - Their corresponding variables. + * Getter for stock. + * + * @return Stock; */ - public Stock getStock() { return stock; } + /** + * Getter for quantity. + * + * @return BigDecimal; + */ public BigDecimal getQuantity() { return quantity; } + /** + * Getter for purchasePrice. + * + * @return BigDecimal; + */ public BigDecimal getPurchasePrice() { return purchasePrice; } - // TODO: JAVADOCS, JUNIT + /** + * Method for obtaining the total purchase price. + * + * @return BigDecimal (purchasePrice * quantity) + */ public BigDecimal getTotalPurchasePrice() { return purchasePrice.multiply(quantity); } + /** + * Method for obtaining the share current profit. + * + *

+ * SaleCalculator.calculateGross() - getTotalPurchasePrice() + *

+ * + * @see Player (Net worth calculation) + * @return BigDecimal current profit. + */ public BigDecimal getProfit() { return new SaleCalculator(this).calculateGross().subtract(getTotalPurchasePrice()); } + /** + * Method for obtaining the share profit change percent. + * + *

+ * profit/getTotalPurchasePrice * 100 + *

+ * + * @return BigDecimal profit percent change + */ public BigDecimal getProfitPercent() { return getProfit().divide(getTotalPurchasePrice(), 2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)); } diff --git a/src/main/java/edu/ntnu/idi/idatt/model/transaction/Transaction.java b/src/main/java/edu/ntnu/idi/idatt/model/transaction/Transaction.java index e42a892..50a31cd 100644 --- a/src/main/java/edu/ntnu/idi/idatt/model/transaction/Transaction.java +++ b/src/main/java/edu/ntnu/idi/idatt/model/transaction/Transaction.java @@ -37,25 +37,37 @@ public abstract class Transaction { } /** - * - * Getters + * Getter for share. * - * @return - their corresponding variable - * + * @return Share; */ - public Share getShare() { return share; } + /** + * Getter for week. + * + * @return int; + */ public int getWeek() { return week; } + /** + * Getter for calculator. + * + * @return TransactionCalculator; + */ public TransactionCalculator getCalculator() { return calculator; } + /** + * Getter for commited. + * + * @return boolean; + */ public boolean isCommited() { return commited; } diff --git a/src/main/java/edu/ntnu/idi/idatt/model/transaction/TransactionArchive.java b/src/main/java/edu/ntnu/idi/idatt/model/transaction/TransactionArchive.java index 6112c89..a861539 100644 --- a/src/main/java/edu/ntnu/idi/idatt/model/transaction/TransactionArchive.java +++ b/src/main/java/edu/ntnu/idi/idatt/model/transaction/TransactionArchive.java @@ -44,7 +44,11 @@ public List getTransactions(int week) { return transactions.stream().filter(transaction -> transaction.getWeek() == week).toList(); } - // TODO: java, junit + /** + * Getter for all transactions done. + * + * @return List of transactions. + */ public List getTransactions() { return transactions; } @@ -61,7 +65,11 @@ public List getPurchases(int week) { .toList(); } - // TODO: java, junit + /** + * Getter for all purchases. + * + * @return List of Purchase. + */ public List getPurchases() { return getTransactions().stream().filter(t -> t instanceof Purchase) .map(t -> (Purchase) t) @@ -80,7 +88,11 @@ public List getSales(int week) { .toList(); } - // TODO: java, junit + /** + * Getter for all sales. + * + * @return List of Sale. + */ public List getSales() { return getTransactions().stream().filter(t -> t instanceof Sale) .map(t -> (Sale) t) @@ -88,9 +100,14 @@ public List getSales() { } /** - * Part 2 - * - * @return + * Method for counting amount of distinct weeks. + *

+ * Calculates how many weeks atleast one Transaction has been done. + * Used to calculate player statuses. + *

+ * + * @see Player + * @return int amount of distinct weeks. */ public int countDistinctWeeks() { return (int) transactions.stream() diff --git a/src/main/java/edu/ntnu/idi/idatt/service/transaction/SaleCalculator.java b/src/main/java/edu/ntnu/idi/idatt/service/transaction/SaleCalculator.java index f9552fa..bcbc17d 100644 --- a/src/main/java/edu/ntnu/idi/idatt/service/transaction/SaleCalculator.java +++ b/src/main/java/edu/ntnu/idi/idatt/service/transaction/SaleCalculator.java @@ -3,7 +3,6 @@ import edu.ntnu.idi.idatt.model.portfolio.Share; import java.math.BigDecimal; -import java.math.RoundingMode; /** * SaleCalculator class @@ -68,7 +67,7 @@ public BigDecimal calculateTax() { } /** - * Method that calculates the total profit of a sold share + * Method that calculates the total price of a sold share * * @return - BigDecimal of gross value - commision fee - tax */ @@ -77,7 +76,16 @@ public BigDecimal calculateTotal() { return calculateGross().subtract(calculateCommision()).subtract(calculateTax()); } - // TODO: Javadocs, junit + /** + * Method for calculating the total profit for a sold share. + * + *

+ * Calculates the gross - total purchase price in respect + * to the net worth calculation method. + *

+ * + * @see Player + */ public BigDecimal calculateProfit() { return calculateGross().subtract(purchasePrice.multiply(quantity)); } diff --git a/src/main/java/edu/ntnu/idi/idatt/session/UserSession.java b/src/main/java/edu/ntnu/idi/idatt/session/UserSession.java index 8531f80..09d85ac 100644 --- a/src/main/java/edu/ntnu/idi/idatt/session/UserSession.java +++ b/src/main/java/edu/ntnu/idi/idatt/session/UserSession.java @@ -8,6 +8,16 @@ import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleObjectProperty; +/** + * Class for managing current session. + *

+ * This class is the connector between the game model + * and user interface. Contains hooks for obtaining real time + * game state values. + * + * This is a singleton class. + *

+ */ public class UserSession { // Singleton instance @@ -17,6 +27,11 @@ public class UserSession { private UserSession() { } + /** + * Static getter for instance. + * + * @return UserSession; + */ public static UserSession getInstance() { if (INSTANCE == null) { INSTANCE = new UserSession(); @@ -27,19 +42,39 @@ public static UserSession getInstance() { private Player player; private Exchange exchange; + /** + * Getter for player. + * + * @return Player; + */ public Player getPlayer() { return player; } + /** + * Setter for player. + * + * @param player - Session player. + */ public void setPlayer(Player player) { this.player = player; updateGameState(); // Startup hook } + /** + * Getter for exchange. + * + * @return Exchange; + */ public Exchange getExchange() { return exchange; } + /** + * Setter for exchange. + * + * @param exchange - Session exchange. + */ public void setExchange(Exchange exchange) { this.exchange = exchange; updateGameState(); // Startup hook @@ -49,18 +84,41 @@ public void setExchange(Exchange exchange) { private final SimpleObjectProperty netWorthProperty = new SimpleObjectProperty<>(BigDecimal.ZERO); private final SimpleIntegerProperty weekProperty = new SimpleIntegerProperty(); + /** + * Getter for moneyProperty. + * + * @return SimpleObjectProperty; + */ public SimpleObjectProperty moneyProperty() { return moneyProperty; } + /** + * Getter for netWorthProperty. + * + * @return SimpleObjectProperty + */ public SimpleObjectProperty netWorthProperty() { return netWorthProperty; } + /** + * Getter for weekProperty. + * + * @return SimpleIntegerProperty + */ public SimpleIntegerProperty weekProperty() { return weekProperty; } + /** + * Method used for updating the game state. + *

+ * Updates the user interface model from diverse + * places through the code to synchronize model <-> UI. + * Saves current session. + *

+ */ public void updateGameState() { if (player == null || exchange == null) { @@ -73,24 +131,53 @@ public void updateGameState() { SessionManager.saveSession(); } + /** + * Getter for current session bundle. + * + * @return SessionBubndle. + */ public SessionBundle getSession() { return new SessionBundle(player, exchange); } + /** + * SessionBundle class. + * + *

+ * Wrapper class for easier creating big JSON models + * in arrays to serialize and deserialize. + *

+ */ public class SessionBundle { private Player player; private Exchange exchange; + /** + * Constructor for SessionBundle. + * + * @param player - Player object. + * @param exchange - Exchange object. + */ public SessionBundle(Player player, Exchange exchange) { this.player = player; this.exchange = exchange; } + /** + * Getter for player. + * + * @return Player; + */ public Player getPlayer() { return player; } + /** + * Getter for exchange. + * + * @return Exchange; + */ public Exchange getExchange() { return exchange; } diff --git a/src/main/java/edu/ntnu/idi/idatt/storage/SessionManager.java b/src/main/java/edu/ntnu/idi/idatt/storage/SessionManager.java index 9bf250c..ad6ed08 100644 --- a/src/main/java/edu/ntnu/idi/idatt/storage/SessionManager.java +++ b/src/main/java/edu/ntnu/idi/idatt/storage/SessionManager.java @@ -34,6 +34,7 @@ *

* Utilizes gson serialization and deserialization to manage * player and game state. + *

*/ public class SessionManager { @@ -64,6 +65,8 @@ public static void newSession(Player player, Exchange exchange) { /** * Method for saving current session. + * + * @throws RuntimeException on failed save. */ public static void saveSession() { // don't save if current session is null accidentally @@ -129,7 +132,9 @@ public static boolean loadSession(String playerName) { } /** - * Method to remove current session + * Method to remove current session. + * + * @throws RuntimeException on failed removal. */ public static void removeSession() { // don't save if current session is null accidentally diff --git a/src/main/java/edu/ntnu/idi/idatt/storage/StockParser.java b/src/main/java/edu/ntnu/idi/idatt/storage/StockParser.java index 74c2739..0e88de3 100644 --- a/src/main/java/edu/ntnu/idi/idatt/storage/StockParser.java +++ b/src/main/java/edu/ntnu/idi/idatt/storage/StockParser.java @@ -3,13 +3,10 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; -import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.math.BigDecimal; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/edu/ntnu/idi/idatt/storage/util/TransactionAdapter.java b/src/main/java/edu/ntnu/idi/idatt/storage/util/TransactionAdapter.java index acc53be..ebd0218 100644 --- a/src/main/java/edu/ntnu/idi/idatt/storage/util/TransactionAdapter.java +++ b/src/main/java/edu/ntnu/idi/idatt/storage/util/TransactionAdapter.java @@ -14,8 +14,21 @@ import edu.ntnu.idi.idatt.model.transaction.Sale; import edu.ntnu.idi.idatt.model.transaction.Transaction; +/** + * Transaction adapter class. + *

+ * Guides Gson serializer/deserializer how to handle abstract object types. + *

+ */ public class TransactionAdapter implements JsonSerializer, JsonDeserializer { + /** + * Method for serialization of Transactions. + * + * @param t - Current transaction. + * @param typeOfT - Type of transaction. + * @param context - Serialization information. + */ @Override public JsonElement serialize(Transaction t, Type typeOfT, JsonSerializationContext context) { @@ -30,6 +43,13 @@ public JsonElement serialize(Transaction t, Type typeOfT, JsonSerializationConte return obj; } + /** + * Method for deserialization of Transactions. + * + * @param json - Current transaction json text. + * @param typeOfT - type of transaction. + * @param context - Deserialization information. + */ @Override public Transaction deserialize(JsonElement json, Type typeOfT, diff --git a/src/main/java/edu/ntnu/idi/idatt/storage/util/TransactionCalculatorAdapter.java b/src/main/java/edu/ntnu/idi/idatt/storage/util/TransactionCalculatorAdapter.java index 89f3204..d44e23f 100644 --- a/src/main/java/edu/ntnu/idi/idatt/storage/util/TransactionCalculatorAdapter.java +++ b/src/main/java/edu/ntnu/idi/idatt/storage/util/TransactionCalculatorAdapter.java @@ -14,9 +14,22 @@ import edu.ntnu.idi.idatt.service.transaction.SaleCalculator; import edu.ntnu.idi.idatt.service.transaction.TransactionCalculator; +/** + * TransactionCalculator adapter class. + *

+ * Guides Gson serializer/deserializer how to handle abstract object types. + *

+ */ public class TransactionCalculatorAdapter implements JsonSerializer, JsonDeserializer { + /** + * Method for serialization of TransactionCalculators. + * + * @param calc - Current calculator. + * @param typeOfT - Type of calculator. + * @param context - Serialization information. + */ @Override public JsonElement serialize(TransactionCalculator calc, Type typeOfT, JsonSerializationContext context) { @@ -31,6 +44,13 @@ public JsonElement serialize(TransactionCalculator calc, Type typeOfT, JsonSeria return obj; } + /** + * Method for deserialization of TransactioNCalculators.. + * + * @param json - Current calculator json text. + * @param typeOfT - type of calculator. + * @param context - Deserialization information. + */ @Override public TransactionCalculator deserialize(JsonElement json, Type typeOfT, From a00e72eb6cf5e5ae2a54261ba522f52e4cbd4322 Mon Sep 17 00:00:00 2001 From: pawelsa Date: Sun, 24 May 2026 20:57:29 +0200 Subject: [PATCH 02/23] chore: JavaDocs for UI structures. --- .../edu/ntnu/idi/idatt/view/SceneFactory.java | 71 ++++++++++++ .../view/components/AbstractController.java | 12 ++ .../idatt/view/components/AbstractViewUI.java | 62 ++++++++++ .../ntnu/idi/idatt/view/components/Model.java | 8 ++ .../components/elements/IconComponent.java | 22 +++- .../elements/NewspaperComponent.java | 33 ------ .../components/elements/RecieptComponent.java | 22 +++- .../elements/SearchBarComponent.java | 26 +++++ .../components/elements/ShareComponent.java | 20 ++++ .../components/elements/StockComponent.java | 20 ++++ .../elements/TextValueComponent.java | 24 ++++ .../elements/TransactionComponent.java | 16 ++- .../primitives/ActionEventHandler.java | 7 ++ .../idi/idatt/view/components/ui/UIAlert.java | 19 ++++ .../view/components/ui/UICompositor.java | 83 ++++++++++++++ .../idatt/view/components/ui/UIFactory.java | 106 ++++++++++++++++++ .../ntnu/idi/idatt/view/util/CssUtils.java | 38 +++++++ .../idi/idatt/view/util/ResourceUtils.java | 8 ++ 18 files changed, 560 insertions(+), 37 deletions(-) delete mode 100644 src/main/java/edu/ntnu/idi/idatt/view/components/elements/NewspaperComponent.java diff --git a/src/main/java/edu/ntnu/idi/idatt/view/SceneFactory.java b/src/main/java/edu/ntnu/idi/idatt/view/SceneFactory.java index a7d5d3e..1ef5a6a 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/SceneFactory.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/SceneFactory.java @@ -29,8 +29,19 @@ import java.util.ArrayDeque; import java.util.Deque; +/** + * Factory class for creating MVC scenes. + * + *

+ * Initializes MVC objects to bind together + * MVC models. + *

+ */ public class SceneFactory { + /** + * Functional interface for saving factory methods. + */ @FunctionalInterface public interface MVCInitInterface { Parent execute(); @@ -39,6 +50,9 @@ public interface MVCInitInterface { private static Deque navigation = new ArrayDeque<>(); private static boolean navigatingBack = false; + /** + * Method for going back to previous MVC instance. + */ public static void goBack() { if (navigation.size() > 1) { navigation.pop(); @@ -48,22 +62,42 @@ public static void goBack() { } } + /** + * Method for refreshing current MVC instance. + *

+ * Used for refreshing static components after + * updating game model. + *

+ */ public static void reloadCurrent() { navigatingBack = true; SceneManager.switchTo(navigation.peek().execute()); navigatingBack = false; } + /** + * Method to save current MVC instance + */ private static void mark(MVCInitInterface initializer) { if (!navigatingBack) { navigation.push(initializer); } } + /** + * Method for checking if current MVC instance is final. + * + * @return boolean; + */ public static boolean isFinal() { return navigation.size() == 1; } + /** + * Initialization method for Start View. + * + * @return View's root. + */ public static Parent createStartView() { navigation.clear(); @@ -79,6 +113,11 @@ public static Parent createStartView() { } + /** + * Initialization method for Portfolio View. + * + * @return View's root. + */ public static Parent createPortfolioView() { mark(() -> createPortfolioView()); @@ -93,6 +132,11 @@ public static Parent createPortfolioView() { return view.getInstance(); } + /** + * Initialization method for Exchange View. + * + * @return View's root. + */ public static Parent createExchangeView() { mark(() -> createExchangeView()); @@ -108,6 +152,12 @@ public static Parent createExchangeView() { } + /** + * Initialization method for Stock View. + * + * @param symbol - Symbol of stock for the view. + * @return View's root. + */ public static Parent createStockView(String symbol) { mark(() -> createStockView(symbol)); @@ -123,6 +173,11 @@ public static Parent createStockView(String symbol) { return view.getInstance(); } + /** + * Initialization method for Transaction View. + * + * @return View's root. + */ public static Parent createTransactionView() { mark(() -> createTransactionView()); @@ -137,6 +192,12 @@ public static Parent createTransactionView() { return view.getInstance(); } + /** + * Initialization method for Newspaper View. + * + * @param symbol - Symbol of stock for view. + * @return View's root. + */ public static Parent createNewspaperView(String symbol) { mark(() -> createNewspaperView(symbol)); @@ -152,6 +213,16 @@ public static Parent createNewspaperView(String symbol) { return view.getInstance(); } + /** + * Initialization method for Finish View. + * + *

+ * Deletes current session on visit, + * working as a destructor from controller. + *

+ * + * @return View's root. + */ public static Parent createFinishView() { FinishModel model = new FinishModel(); diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/AbstractController.java b/src/main/java/edu/ntnu/idi/idatt/view/components/AbstractController.java index a334769..de916a7 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/AbstractController.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/AbstractController.java @@ -1,9 +1,21 @@ package edu.ntnu.idi.idatt.view.components; +/** + * Abstract class for controller. + * + *

+ * Works as indicator to bind together with a proper model object. + *

+ * + * @see Model + */ public abstract class AbstractController { protected final M model; + /** + * Default AbstractController constructor. + */ public AbstractController(M model) { this.model = model; } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/AbstractViewUI.java b/src/main/java/edu/ntnu/idi/idatt/view/components/AbstractViewUI.java index 1f45c17..93a9574 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/AbstractViewUI.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/AbstractViewUI.java @@ -10,6 +10,13 @@ import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; +/** + * Abstract View UI class. + * + *

+ * Creates a view layout to simplify further view creation for child classes. + *

+ */ public abstract class AbstractViewUI extends AbstractView { private VBox navigation; @@ -18,6 +25,15 @@ public abstract class AbstractViewUI extends AbstractView { private VBox menu; private SimpleBooleanProperty isMenuVisible = new SimpleBooleanProperty(false); + /** + * Constructor for AbstactViewUI. + * + *

+ * Binds the abstract classes into + * the root StackPane. + * Binds together smaller modules which are persistent across all views. + *

+ */ public AbstractViewUI() { HBox wrapper = new HBox(); BorderPane layout = new BorderPane(); @@ -55,6 +71,9 @@ public AbstractViewUI() { this.getInstance().getChildren().addAll(wrapper, disableMenu, menu); } + /** + * Method for creating initial view wrappers. + */ public void createUIComponents() { navigation = new VBox(); navigation.setMaxHeight(Double.MAX_VALUE); @@ -77,28 +96,71 @@ public void createUIComponents() { menu.setMaxWidth(300); } + /** + * Abstract method for content creation. + * + * @return Root node of content. + */ public abstract Parent createContent(); + /** + * Abstract method for navigation creation. + * + * @return Root node of navigation. + */ public abstract Parent createNavigation(); + /** + * Abstract method for header creation. + * + * @return Root node of header. + */ public abstract Parent createHeader(); + /** + * Abstract method for toolbar creation. + * + * @return Root node of toolbar. + */ public abstract Parent createToolbar(); + /** + * Abstract method for menu creation. + * + * @return Root node of menu. + */ public abstract Parent createMenu(); + /** + * Getter for navigation. + * + * @return VBox; + */ public VBox getNavigation() { return navigation; } + /** + * Getter for header. + * + * @return HBox; + */ public HBox getHeader() { return header; } + /** + * Getter for toolbar. + * + * @return HBox; + */ public HBox getToolbar() { return toolbar; } + /** + * Method for toggling the visibility of the menu. + */ public void toggleMenu() { isMenuVisible.set(!isMenuVisible.get()); } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/Model.java b/src/main/java/edu/ntnu/idi/idatt/view/components/Model.java index 2465fd7..0687baa 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/Model.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/Model.java @@ -1,4 +1,12 @@ package edu.ntnu.idi.idatt.view.components; +/** + * Interface Model + * + *

+ * Used as an indicator to bind to controllers + * with the right model. + *

+ */ public interface Model { } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/IconComponent.java b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/IconComponent.java index a3ef67a..3931106 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/IconComponent.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/IconComponent.java @@ -6,15 +6,30 @@ import javafx.scene.image.ImageView; import javafx.scene.layout.StackPane; +/** + * Icon Component class. + * + *

+ * JavaFX Component for handeling repetative tasks. + * Creates a clickable icon with optional description. + *

+ */ public class IconComponent extends StackPane { private Button icon; + /** + * Constructor for IconComponent + * + * @param image - Icon image + * @param description - String describing icon button. + * @param size - width and height of the icon image. + */ public IconComponent(Image image, String description, int size) { ImageView iv = new ImageView(); iv.setImage(image); - iv.setFitHeight(size); // TODO: Fix? + iv.setFitHeight(size); iv.setFitWidth(size); icon = new Button(description, iv); @@ -25,6 +40,11 @@ public IconComponent(Image image, String description, int size) { this.getChildren().add(icon); } + /** + * Method for handeling icon click. + * + * @param handler - Functional interface. + */ public void onIconClick(ActionEventHandler handler) { this.icon.setOnAction(e -> handler.handle()); } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/NewspaperComponent.java b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/NewspaperComponent.java deleted file mode 100644 index 8661c9b..0000000 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/NewspaperComponent.java +++ /dev/null @@ -1,33 +0,0 @@ -package edu.ntnu.idi.idatt.view.components.elements; - -import edu.ntnu.idi.idatt.model.portfolio.Share; -import edu.ntnu.idi.idatt.view.components.ui.UICompositor; -import javafx.geometry.Insets; -import javafx.geometry.Pos; -import javafx.scene.control.Label; -import javafx.scene.layout.HBox; -import javafx.scene.layout.VBox; - -public class NewspaperComponent extends HBox { - private final Label newsTitle; - private final Label newsText; - - public NewspaperComponent(Share share) { - this.setPadding(new Insets(30)); - this.getStyleClass().add("newspaper-article"); - - newsTitle = new Label("Earthquake in Norway"); - newsText = new Label("Intel are crashing"); - newsTitle.getStyleClass().add("newspaper-title"); - newsText.getStyleClass().add("newspaper-med-text"); - - UICompositor shareComponent = new UICompositor.Builder() - .parent(new VBox()) - .growWithAlignment(Pos.TOP_CENTER) - .addAllContent(newsTitle, newsText) - .build(); - - this.getChildren().add(shareComponent.makeUI()); - } - -} diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/RecieptComponent.java b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/RecieptComponent.java index fc156d1..16e39d4 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/RecieptComponent.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/RecieptComponent.java @@ -10,18 +10,31 @@ import edu.ntnu.idi.idatt.view.components.primitives.ActionEventHandler; import edu.ntnu.idi.idatt.view.components.ui.UICompositor; import edu.ntnu.idi.idatt.view.util.CssUtils; -import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.control.Button; import javafx.scene.control.Label; -import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; +/** + * Reciept component class + * + *

+ * JavaFX Component for handeling repetative tasks. + * Creates a reciept based on a transaction. + *

+ * + * @see Transaction + */ public class RecieptComponent extends VBox { private Button doneButton; + /** + * Constructor for RecieptComponent + * + * @param transaction - transaction object to create a reciept for. + */ public RecieptComponent(Transaction transaction) { Label title = new Label("Reciept"); @@ -97,6 +110,11 @@ public RecieptComponent(Transaction transaction) { } + /** + * Method for handeling exit button click. + * + * @param handler - Functional interface. + */ public void onExitButton(ActionEventHandler handler) { doneButton.setOnMouseClicked((e) -> handler.handle()); } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/SearchBarComponent.java b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/SearchBarComponent.java index c089f87..1c671dd 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/SearchBarComponent.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/SearchBarComponent.java @@ -8,11 +8,24 @@ import javafx.scene.image.Image; import javafx.scene.layout.HBox; +/** + * Searchbar component class. + * + *

+ * JavaFX Component for handeling repetative tasks. + * Creates a searchbar with search icon. + *

+ */ public class SearchBarComponent extends HBox { private final StringProperty query = new SimpleStringProperty(); private final IconComponent searchIcon; + /** + * Constructor for SearchBarComponent. + * + * @param placeholder - The placeholder text for empty searchbar. + */ public SearchBarComponent(String placeholder) { HBox wrapper = new HBox(); @@ -34,10 +47,23 @@ public SearchBarComponent(String placeholder) { this.getChildren().addAll(wrapper); } + /** + * Getter for query content. + *

+ * Returns the current input of the searchbar. + *

+ * + * @return String; + */ public String getQuery() { return query.get(); } + /** + * Method for handeling search icon click. + * + * @param handler - Functional interface. + */ public void onSearchQuery(ActionEventHandler handler) { this.searchIcon.onIconClick(() -> handler.handle()); } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/ShareComponent.java b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/ShareComponent.java index 486b994..ca44eee 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/ShareComponent.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/ShareComponent.java @@ -13,11 +13,26 @@ import java.util.List; import java.util.function.Consumer; +/** + * Share Component class. + * + *

+ * JavaFX Component for handeling repetative tasks. + * Creates a visual representation of a standalone share with a sell button. + *

+ * + * @see Share + */ public class ShareComponent extends HBox { private final Share share; private Button sellButton; + /** + * Constructor for ShareComponent. + * + * @param share - Share to create the component for. + */ public ShareComponent(Share share) { this.share = share; @@ -57,6 +72,11 @@ public ShareComponent(Share share) { this.getChildren().add(shareComponent.makeUI()); } + /** + * Method for handeling sell button click. + * + * @param handler - Functional interface with share reference. + */ public void onShareSellButton(Consumer handler) { sellButton.setOnAction((e) -> handler.accept(share)); } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/StockComponent.java b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/StockComponent.java index fe29fdc..4298b60 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/StockComponent.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/StockComponent.java @@ -12,10 +12,25 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; +/** + * Stock Component class. + * + *

+ * JavaFX Component for handeling repetative tasks. + * Creates a visual representation of a standalone Stock given. + *

+ * + * @see Stock + */ public class StockComponent extends HBox { private final Stock stock; + /** + * Constructor for StockComponent + * + * @param stock - Stock component to create the component for. + */ public StockComponent(Stock stock) { this.stock = stock; this.setMaxSize(Double.MAX_VALUE, 100); @@ -62,6 +77,11 @@ public StockComponent(Stock stock) { this.getChildren().addAll(stockComponent.makeUI()); } + /** + * Method for handeling component click. + * + * @param handler - Functional interface with reference to the stock symbol. + */ public void onStockClick(Consumer handler) { this.setOnMouseClicked((e) -> handler.accept(stock.getSymbol())); } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/TextValueComponent.java b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/TextValueComponent.java index 21b8617..4cc7fb4 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/TextValueComponent.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/TextValueComponent.java @@ -5,11 +5,25 @@ import javafx.scene.control.Label; import javafx.scene.layout.HBox; +/** + * Text-Value Component class. + * + *

+ * JavaFX Component for handeling repetative tasks. + * Creates two labels with the right side (value) being available for color + * styling. + *

+ */ public class TextValueComponent extends HBox { private final SimpleStringProperty value = new SimpleStringProperty(); private final SimpleStringProperty color = new SimpleStringProperty(); + /** + * Constructor for TextValueComponent. + * + * @param prefix - Content of the first label (left side) + */ public TextValueComponent(String prefix) { Label prefixLabel = new Label(prefix); Label valueLabel = new Label(); @@ -25,10 +39,20 @@ public TextValueComponent(String prefix) { this.getChildren().addAll(prefixLabel, valueLabel); } + /** + * Getter for valueProperty + * + * @return SimpleStringProperty; + */ public SimpleStringProperty valueProperty() { return value; } + /** + * Getter for colorProperty. + * + * @return SimpleStringProperty; + */ public SimpleStringProperty colorProperty() { return color; } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/TransactionComponent.java b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/TransactionComponent.java index 4939ebd..9d022e8 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/elements/TransactionComponent.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/elements/TransactionComponent.java @@ -8,7 +8,6 @@ import edu.ntnu.idi.idatt.model.transaction.Transaction; import edu.ntnu.idi.idatt.service.transaction.PurchaseCalculator; import edu.ntnu.idi.idatt.service.transaction.SaleCalculator; -import edu.ntnu.idi.idatt.service.transaction.TransactionCalculator; import edu.ntnu.idi.idatt.view.components.ui.UICompositor; import edu.ntnu.idi.idatt.view.util.CssUtils; import javafx.geometry.Insets; @@ -16,8 +15,23 @@ import javafx.scene.control.Label; import javafx.scene.layout.VBox; +/** + * Transaction component class. + * + *

+ * JavaFX Component for handeling repetative tasks. + * Creates a visual representation of a given transaction. + *

+ * + * @see Transaction + */ public class TransactionComponent extends VBox { + /** + * Constructor for TransactionComponent + * + * @param transaction - Transaction to create component for. + */ public TransactionComponent(Transaction transaction) { Stock stock = transaction.getShare().getStock(); diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/primitives/ActionEventHandler.java b/src/main/java/edu/ntnu/idi/idatt/view/components/primitives/ActionEventHandler.java index a42993d..14bea01 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/primitives/ActionEventHandler.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/primitives/ActionEventHandler.java @@ -1,5 +1,12 @@ package edu.ntnu.idi.idatt.view.components.primitives; +/** + * ActionEventHandler functional interface. + * + *

+ * Made for handling simple operations without any parameters. + *

+ */ @FunctionalInterface public interface ActionEventHandler { void handle(); diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/ui/UIAlert.java b/src/main/java/edu/ntnu/idi/idatt/view/components/ui/UIAlert.java index 78c7341..a6d9556 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/ui/UIAlert.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/ui/UIAlert.java @@ -4,12 +4,22 @@ import javafx.scene.control.Alert.AlertType; import javafx.scene.control.ButtonType; +/** + * Class for creating UI confirmation alerts. + */ public class UIAlert { Alert alert = new Alert(AlertType.CONFIRMATION); ButtonType confirm = new ButtonType("Confirm"); ButtonType cancel = new ButtonType("Cancel"); + /** + * Constructor for UIAlert. + * + * @param title - Window name + * @param header - context + * @content - description of context + */ public UIAlert(String title, String header, String content) { alert.setTitle(title); alert.setHeaderText(header); @@ -18,6 +28,15 @@ public UIAlert(String title, String header, String content) { alert.getButtonTypes().setAll(confirm, cancel); } + /** + * Method for displaying and waiting for response from alert. + * + *

+ * Waits for confirmation, turns to false in case of no response. + *

+ * + * @return boolean Confirm/Cancelled. + */ public boolean displayAwaitResponse() { ButtonType type = alert.showAndWait().orElse(cancel); return type == confirm ? true : false; diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/ui/UICompositor.java b/src/main/java/edu/ntnu/idi/idatt/view/components/ui/UICompositor.java index ebf229c..aeab185 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/ui/UICompositor.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/ui/UICompositor.java @@ -13,27 +13,62 @@ import javafx.scene.layout.Region; import javafx.scene.layout.VBox; +/** + * UICompositor class + * + *

+ * Builder class for simpler UI layout creation. + *

+ */ public class UICompositor { private final Pane parent; + /** + * Constructor for UICompositor. + * + * @param builder - UICompositor.Builder object. + */ public UICompositor(Builder builder) { this.parent = builder.parent; } + /** + * Method for obtaining the root element. + * + * @return root pane. + */ public Parent makeUI() { return parent; } + /** + * Builder class for UICompositor instances. + */ public static class Builder { private Pane parent; private Deque wrappers = new ArrayDeque<>(); + /** + * Setter for UICompositor parent/root element. + * + * @param parent - Root element + * @return Builder - self + */ public Builder parent(Pane parent) { this.parent = parent; return this; } + /** + * Method for streching a node and positioning within. + * + *

+ * Works for HBox and VBox instances. + * + * @param position - Position of inner nodes. + * @return builder - self. + */ public Builder growWithAlignment(Pos position) { Pane root = getRoot(); if (root instanceof HBox) { @@ -49,27 +84,55 @@ public Builder growWithAlignment(Pos position) { return this; } + /** + * Method for obtaining newest layout node on the stack. + * + * @return newest element on the stack. + */ private Pane getRoot() { return wrappers.isEmpty() ? parent : wrappers.peek(); } + /** + * Method for adding content to newest stack element. + * + * @param child - Node/content + * @return bulder - self. + */ public Builder addContent(Parent child) { Pane root = getRoot(); root.getChildren().add(child); return this; } + /** + * Method for adding multiple contents to newest stack element. + * + * @param children - array of nodes/content. + * @return builder - self. + */ public Builder addAllContent(Parent... children) { Pane root = getRoot(); root.getChildren().addAll(List.of(children)); return this; } + /** + * Method for adding a layer to the stack. + * + * @param wrapper - Pane type. + * @return builder - self. + */ public Builder wrap(Pane wrapper) { wrappers.push(wrapper); return this; } + /** + * Method for adding newest stack element to previous on stack element. + * + * @return builder - self. + */ public Builder unwrap() { Pane current = wrappers.pop(); @@ -81,11 +144,26 @@ public Builder unwrap() { return this; } + /** + * Method for changing newest stack element properties. + * + * @param handle - Functional interface with reference to newest stack element. + * @return builder - self. + */ public Builder properties(Consumer handle) { handle.accept(getRoot()); return this; } + /** + * Method for adding filler to newest stack element. + * + *

+ * Creates a filler for layered stack elements type HBox, VBox. + *

+ * + * @return builder = self. + */ public Builder filler() { Pane root = getRoot(); @@ -100,6 +178,11 @@ public Builder filler() { return this; } + /** + * Method for applying the builder method. + * + * @return instance of created UICompositor. + */ public UICompositor build() { return new UICompositor(this); } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/ui/UIFactory.java b/src/main/java/edu/ntnu/idi/idatt/view/components/ui/UIFactory.java index 365580f..b6c6120 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/components/ui/UIFactory.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/ui/UIFactory.java @@ -21,12 +21,46 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; +/** + * Factory class for creating UI elements. + * + *

+ * Simplifies the repetative work to create + * equal layouts across multiple views. + *

+ * + * @see AbstractViewUI + */ public class UIFactory { + /** + * Wrapper for creating simple header. + * + *

+ * Creates a simple header containing a searchbar. + *

+ * + * @param placeholder - Placeholder for searchbar. + * @param onSearchQuery - Input functional interface of searchbar. + * @return header element. + */ public static Parent createHeader(String placeholder, Consumer onSearchQuery) { return createDefaultHeader(placeholder, onSearchQuery); } + /** + * Wrapper for creating extended header. + * + *

+ * Creates a header with searchbar with sorting ability. + *

+ * + * @param placeholder - Placeholder for searchbar. + * @param onSearchQuery - Input functional interface of searchbar. + * @param sortItems - List of available sorting labels. + * @param sortHandlers - List of functional interfaces to react to the items. + * @return header element. + */ public static Parent createHeader(String placeholder, Consumer onSearchQuery, List sortItems, ActionEventHandler... sortHandlers) { @@ -47,6 +81,18 @@ public static Parent createHeader(String placeholder, Consumer onSearchQ return createDefaultHeader(placeholder, onSearchQuery, menu); } + /** + * Method for creating all headers. + * + *

+ * This method is used for creating all headers through the public wrappers. + *

+ * + * @param placeholder - Placeholder for searchbar. + * @param onSearchQuery - Input functional interface of searchbar. + * @param addons - Parent objects to add to the left site header + * @return header element. + */ private static Parent createDefaultHeader(String placeholder, Consumer onSearchQuery, Parent... addons) { SearchBarComponent bar = new SearchBarComponent(placeholder); @@ -66,16 +112,51 @@ private static Parent createDefaultHeader(String placeholder, Consumer o return header.makeUI(); } + /** + * Wrapper for creating navigation with title. + * + *

+ * Creates a navigation with a title. + *

+ * + * @param title - Title string. + * @param buttonLables - List of button names. + * @param handlers - Array of functional interfaces for button clicks. + * @return navigation element. + */ public static Parent createNavigation(String title, List buttonLables, ActionEventHandler... handlers) { Label titleLabel = new Label(title); return createDefaultNavigation(titleLabel, buttonLables, handlers); } + /** + * Wrapper for creating navigation with title label. + * + *

+ * Creates a navigation with a title label. + *

+ * + * @param titleLabel - Label title object. + * @param buttonLables - List of button names. + * @param handlers - Array of functional interfaces for button clicks. + * @return navigation element. + */ public static Parent createNavigation(Label titleLabel, List buttonLables, ActionEventHandler... handlers) { return createDefaultNavigation(titleLabel, buttonLables, handlers); } + /** + * Method for creating all navigations. + *

+ * This method creates all navigations through the public wrappers. + *

+ * + * @param titleLabel - Label title object. + * @param buttonLables - List of button names. + * @param handlers - Array of functional interfaces for button clicks. + * @return navigation element. + */ private static Parent createDefaultNavigation(Label titleLabel, List buttonLables, ActionEventHandler... handlers) { if (buttonLables.size() != handlers.length) { @@ -115,6 +196,18 @@ private static Parent createDefaultNavigation(Label titleLabel, List but } + /** + * Method for creating menu element. + * + *

+ * Creates a menu with clickable buttons. + *

+ * + * @param title - Title of the menu. + * @param buttonLables - List of button names. + * @param handlers - Array of functional interfaces for button clicks. + * @return menu element. + */ public static Parent createMenu(String title, List buttonLables, ActionEventHandler... handlers) { if (buttonLables.size() != handlers.length) { System.out.println("Failed to build menu!"); @@ -156,6 +249,19 @@ public static Parent createMenu(String title, List buttonLables, ActionE } + /** + * Method for creating toolbar. + * + *

+ * Creates a toolbar with UserSession value displays and event handlers. + *

+ * + * @see UserSession + * + * @param menuHandle - Functional interface to menu button click. + * @param quitHandle - Functional interface to exit button click. + * @return toolbar element. + */ public static Parent createToolbar(ActionEventHandler menuHandle, ActionEventHandler quitHandle) { Label balance = new Label(); balance.textProperty().bind( diff --git a/src/main/java/edu/ntnu/idi/idatt/view/util/CssUtils.java b/src/main/java/edu/ntnu/idi/idatt/view/util/CssUtils.java index 4615da6..9aaf549 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/util/CssUtils.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/util/CssUtils.java @@ -4,6 +4,14 @@ import javafx.scene.Parent; +/** + * Utility CSS class. + * + *

+ * Creates static access to widely CSS tools and + * styles to simplify CSS appliance. + *

+ */ public class CssUtils { public static final String BIG_TEXT_32 = "big-text-32"; @@ -12,19 +20,49 @@ public class CssUtils { public static final String RED = "red"; public static final String GREEN = "green"; + /** + * Method for applying a css styling. + * + * @param parent - Parent object to apply for. + * @param cssClass - String of css class. + */ public static void apply(Parent parent, String cssClass) { parent.getStyleClass().add(cssClass); } + /** + * Method for setting one css styling. + * + * @param parent - Parent object to apply for. + * @param cssClass - String of css class. + */ public static void set(Parent parent, String cssClass) { parent.getStyleClass().clear(); parent.getStyleClass().add(cssClass); } + /** + * Method for generating colors based on value. + * + *

+ * Returns red or green if a value is below or over/equal zero correspondingly. + *

+ * + * @param value - BigDecimal value. + */ public static String generateValueColors(BigDecimal value) { return value.compareTo(BigDecimal.ZERO) >= 0 ? GREEN : RED; } + /** + * Method for generating colors based on value. + * + *

+ * Returns red or green if a value is below or over/equal zero correspondingly. + *

+ * + * @param value - double value. + */ public static String generateValueColors(double value) { return value >= 0 ? GREEN : RED; } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/util/ResourceUtils.java b/src/main/java/edu/ntnu/idi/idatt/view/util/ResourceUtils.java index d40bfce..df65fc5 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/util/ResourceUtils.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/util/ResourceUtils.java @@ -2,6 +2,14 @@ import javafx.scene.image.Image; +/** + * Utility resource class. + * + *

+ * Creates static instances of components + * used often throughout diverse JavaFX classes. + *

+ */ public class ResourceUtils { public static final Image MENU_ICON = new Image(ResourceUtils.class.getResource("/icons/user.png").toExternalForm()); public static final Image SEARCH_ICON = new Image( From 5256d3a2978657978e3e5b51173852cfe6329662 Mon Sep 17 00:00:00 2001 From: pawelsa Date: Sun, 24 May 2026 22:28:25 +0200 Subject: [PATCH 03/23] chore: JavaDocs for views. --- .../idi/idatt/view/entry/StartController.java | 19 ++++ .../ntnu/idi/idatt/view/entry/StartModel.java | 50 +++++++++++ .../ntnu/idi/idatt/view/entry/StartView.java | 24 ++++++ .../primary/exchange/ExchangeController.java | 46 ++++++++++ .../view/primary/exchange/ExchangeModel.java | 8 ++ .../view/primary/exchange/ExchangeView.java | 44 ++++++++++ .../view/primary/finish/FinishController.java | 71 +++++++++++++++ .../view/primary/finish/FinishModel.java | 7 ++ .../idatt/view/primary/finish/FinishView.java | 19 ++++ .../newspaper/NewspaperController.java | 14 +++ .../primary/newspaper/NewspaperModel.java | 8 ++ .../view/primary/newspaper/NewspaperView.java | 47 ++++++++++ .../portfolio/PortfolioController.java | 75 +++++++++++++++- .../primary/portfolio/PortfolioModel.java | 23 +++++ .../view/primary/portfolio/PortfolioView.java | 52 +++++++++++ .../portfolio/sections/PlayerInfoSection.java | 41 +++++++++ .../portfolio/viewmodel/PlayerInfoModel.java | 38 ++++++++ .../view/primary/stock/StockController.java | 86 ++++++++++++++++++- .../idatt/view/primary/stock/StockModel.java | 25 ++++++ .../idatt/view/primary/stock/StockView.java | 58 +++++++++++++ .../stock/sections/PriceInfoSection.java | 37 ++++++++ .../primary/stock/sections/TradeSection.java | 47 ++++++++++ .../stock/viewmodel/PriceInfoModel.java | 41 +++++++++ .../primary/stock/viewmodel/TradeModel.java | 36 ++++++++ .../transactions/TransactionController.java | 41 +++++++++ .../transactions/TransactionModel.java | 8 ++ .../primary/transactions/TransactionView.java | 44 ++++++++++ 27 files changed, 1004 insertions(+), 5 deletions(-) diff --git a/src/main/java/edu/ntnu/idi/idatt/view/entry/StartController.java b/src/main/java/edu/ntnu/idi/idatt/view/entry/StartController.java index 8fdb8d4..84a9c5e 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/entry/StartController.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/entry/StartController.java @@ -16,14 +16,25 @@ import edu.ntnu.idi.idatt.view.components.AbstractController; import javafx.stage.FileChooser; +/** + * Class for Start MVC Controller. + */ public class StartController extends AbstractController { private File csv; + /** + * Constructor for StartController. + * + * @param model - StartModel instance. + */ public StartController(StartModel model) { super(model); } + /** + * Method to obtain a user specified CSV file. + */ public void obtainCSVFile() { csv = new FileChooser().showOpenDialog(null); if (csv != null) { @@ -31,6 +42,14 @@ public void obtainCSVFile() { } } + /** + * Method for initializing the game. + * + *

+ * Handles initial logic and fills the UserSession + * with the new instance. + *

+ */ public void initializeGame() { model.getError().set(" "); // Empty buffers diff --git a/src/main/java/edu/ntnu/idi/idatt/view/entry/StartModel.java b/src/main/java/edu/ntnu/idi/idatt/view/entry/StartModel.java index 36710de..93bb8d5 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/entry/StartModel.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/entry/StartModel.java @@ -6,6 +6,9 @@ import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; +/** + * Model class for Start MVC. + */ public class StartModel implements Model { private final StringProperty name = new SimpleStringProperty(); @@ -17,40 +20,87 @@ public class StartModel implements Model { private boolean firstNewGame = false; private final BooleanProperty predefinedCSV = new SimpleBooleanProperty(true); + /** + * Constructor for StartModel. + *

+ * Creates a listener that checks if user was not found in the persistent + * storage. + *

+ */ public StartModel() { newGame.addListener((obs) -> { firstNewGame = true; }); } + /** + * Getter for name propery. + * + * @return StringProperty; + */ public StringProperty getName() { return name; } + /** + * Getter for balance property. + * + * @return StringProperty; + */ public StringProperty getBalance() { return balance; } + /** + * Getter for error property. + * + * @return StringProperty; + */ public StringProperty getError() { return error; } + /** + * Getter for FileName property. + * + * @return StringProperty; + */ public StringProperty getFileName() { return fileName; } + /** + * Getter for newGame property. + * + * @return BooleanProperty; + */ public BooleanProperty isNewGame() { return newGame; } + /** + * Getter for first game status. + * + * @return boolean; + */ public boolean isFirstNewGame() { return firstNewGame; } + /** + * Setter for first game status. + * + * @param val - boolean. + */ public void setFirstNewGame(boolean val) { firstNewGame = val; } + /** + * Getter for predefinedCSV property. + * + * @return BooleanProperty; + */ public BooleanProperty isPredefinedCSV() { return predefinedCSV; } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/entry/StartView.java b/src/main/java/edu/ntnu/idi/idatt/view/entry/StartView.java index 0c7bc3c..080bbcc 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/entry/StartView.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/entry/StartView.java @@ -16,6 +16,9 @@ import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; +/** + * View class for StartView MVC. + */ public class StartView extends AbstractView { // Globlal variables for model implementation @@ -31,11 +34,20 @@ public class StartView extends AbstractView { private Button csvButton; private Button startButton; + /** + * Constructor for StartView. + */ public StartView() { super(new StackPane()); this.getInstance().getStyleClass().add("dark"); } + /** + * Overriden method for createContent() + * + * @see AbstractView; + * @return root node. + */ @Override public Parent createContent() { VBox root = new VBox(); @@ -121,6 +133,12 @@ public Parent createContent() { return root; } + /** + * Setter for StartModel. + *

+ * Binds observable properties and model data. + *

+ */ public void setModel(StartModel model) { this.nameField.textProperty().bindBidirectional(model.getName()); this.balanceField.textProperty().bindBidirectional(model.getBalance()); @@ -133,6 +151,12 @@ public void setModel(StartModel model) { this.importCsvWrapper.visibleProperty().bind(csvPredefinedCheckBox.selectedProperty().not()); } + /** + * Setter for StartController. + *

+ * Responds to actions and events for interactibility. + *

+ */ public void setController(StartController controller) { this.csvButton.setOnAction(e -> controller.obtainCSVFile()); this.startButton.setOnAction(e -> controller.initializeGame()); diff --git a/src/main/java/edu/ntnu/idi/idatt/view/primary/exchange/ExchangeController.java b/src/main/java/edu/ntnu/idi/idatt/view/primary/exchange/ExchangeController.java index dd8f981..d197f9c 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/primary/exchange/ExchangeController.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/primary/exchange/ExchangeController.java @@ -17,8 +17,18 @@ import javafx.scene.paint.Color; import javafx.util.Duration; +/** + * Controller class for Exchange MVC. + */ public class ExchangeController extends AbstractController { + /** + * SortAction Enum + * + *

+ * Defines the different sorting actions available. + *

+ */ public enum SortAction { NONE, GAINERS, @@ -28,6 +38,14 @@ public enum SortAction { private UserSession session = UserSession.getInstance(); private ArrayList stocksSorted = new ArrayList<>(); + /** + * Constructor for ExchangeController. + *

+ * Loads initial stocks for the exchange view. + *

+ * + * @param model - ExchangeModel reference. + */ public ExchangeController(ExchangeModel model) { super(model); List initialStocksLoad = session.getExchange().getStocks(); @@ -35,6 +53,14 @@ public ExchangeController(ExchangeModel model) { setStocksModel(initialStocksLoad); } + /** + * Method for setting new stocks to the exchange. + *

+ * Turns stocks into StockComponents. + *

+ * + * @param stockList - List of stocks to set to the model list. + */ public void setStocksModel(List stockList) { model.getStockList().clear(); for (Stock stock : stockList) { @@ -49,6 +75,11 @@ public void setStocksModel(List stockList) { } } + /** + * Method that applies glow effect to StockComponent with new news. + * + * @param component - The chosen StockComponent. + */ public void applyNewspaperGlow(StockComponent component) { DropShadow glow = new DropShadow(7, Color.WHITE); @@ -65,6 +96,11 @@ public void applyNewspaperGlow(StockComponent component) { timeline.play(); } + /** + * Method to handle searchbar query. + * + * @param query - Input from searchbar. + */ public void handleSearchQuery(String query) { if (query == null || query.isBlank()) { setStocksModel(stocksSorted); // Get back to "no search" @@ -78,6 +114,11 @@ public void handleSearchQuery(String query) { } + /** + * Method for sorting stocks. + * + * @param action - Instance of chosen SortAction enum. + */ public void sortStocksBy(SortAction action) { stocksSorted.clear(); @@ -104,6 +145,11 @@ public void sortStocksBy(SortAction action) { } + /** + * Method for redirecting view based on stock symbol. + * + * @param symbol - Stock symbol. + */ public void redirectView(String symbol) { SceneManager.switchTo(SceneFactory.createStockView(symbol)); } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/primary/exchange/ExchangeModel.java b/src/main/java/edu/ntnu/idi/idatt/view/primary/exchange/ExchangeModel.java index 4495ea9..6a2e48f 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/primary/exchange/ExchangeModel.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/primary/exchange/ExchangeModel.java @@ -5,10 +5,18 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; +/** + * Model class for the Exchange MVC. + */ public class ExchangeModel implements Model { private final ObservableList stockList = FXCollections.observableArrayList(); + /** + * Getter for the stock list. + * + * @return ObservableList; + */ public ObservableList getStockList() { return stockList; } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/primary/exchange/ExchangeView.java b/src/main/java/edu/ntnu/idi/idatt/view/primary/exchange/ExchangeView.java index 8476959..029d3c8 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/primary/exchange/ExchangeView.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/primary/exchange/ExchangeView.java @@ -17,12 +17,20 @@ import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; +/** + * View class for Exchange MVC. + */ public class ExchangeView extends AbstractViewUI { Consumer searchQueryHandler; Consumer sortHandle; private VBox root; + /** + * Override of createContent() method. + * + * @see AbstractViewUI + */ @Override public Parent createContent() { root = new VBox(); @@ -42,6 +50,11 @@ public Parent createContent() { return wrapper; } + /** + * Override of the createNavigation() method. + * + * @see AbstractViewUI + */ @Override public Parent createNavigation() { return UIFactory.createNavigation( @@ -49,6 +62,11 @@ public Parent createNavigation() { List.of()); } + /** + * Override of createHeader() method. + * + * @see AbstractViewUI + */ @Override public Parent createHeader() { return UIFactory.createHeader("Search for stocks", @@ -62,12 +80,22 @@ public Parent createHeader() { () -> sortHandle.accept(SortAction.LOSERS)); } + /** + * Override of the createToolbar() method. + * + * @see AbstractViewUI + */ @Override public Parent createToolbar() { return UIFactory.createToolbar(() -> this.toggleMenu(), () -> SceneManager.switchTo(SceneFactory.createStartView())); } + /** + * Override of the createMenu() method. + * + * @see AbstractViewUI + */ @Override public Parent createMenu() { return UIFactory.createMenu("Account", @@ -77,10 +105,26 @@ public Parent createMenu() { } + /** + * Setter for the ExchangeModel. + *

+ * Connects view to the model data. + *

+ * + * @param model - ExchangeModel instance. + */ public void setModel(ExchangeModel model) { Bindings.bindContent(root.getChildren(), model.getStockList()); } + /** + * Setter for the ExchangeController. + *

+ * Handles events of view nodes for interactibility + *

+ * + * @param controller - ExchangeController instance. + */ public void setController(ExchangeController controller) { searchQueryHandler = (query) -> controller.handleSearchQuery(query); sortHandle = (sortAction) -> controller.sortStocksBy(sortAction); diff --git a/src/main/java/edu/ntnu/idi/idatt/view/primary/finish/FinishController.java b/src/main/java/edu/ntnu/idi/idatt/view/primary/finish/FinishController.java index 232afe2..4ad3014 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/primary/finish/FinishController.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/primary/finish/FinishController.java @@ -10,15 +10,31 @@ import edu.ntnu.idi.idatt.view.util.CssUtils; import javafx.scene.Parent; +/** + * Controller class of Finish MVC. + */ public class FinishController extends AbstractController { private UserSession session = UserSession.getInstance(); + /** + * Constructor for FinishController. + *

+ * Initializes finalized game state. + *

+ */ public FinishController(FinishModel model) { super(model); makeFinishedGameState(); } + /** + * Method for creating a finalized gamestate. + * + *

+ * Sells all holdings and updates the game state a final time. + *

+ */ public void makeFinishedGameState() { // Sell all shares @@ -33,35 +49,70 @@ public void makeFinishedGameState() { } + /** + * Method for getting formatted week. + * + * @return Week string. + */ public String getWeek() { return String.format("Week: %d", session.getExchange().getWeek()); } + /** + * Method for getting formatted transaction amount. + * + * @return transaction amount string. + */ public String getTransactionAmount() { return String.format("Transactions made: %d", session.getPlayer().getTransactionArchive().getTransactions().size()); } + /** + * Method for getting formatted player status. + * + * @return player status string. + */ public String getPlayerStatus() { return String.format("Player status: %s", session.getPlayer().getStatus()); } + /** + * Method for getting formatted player name. + * + * @return player name string. + */ public String getPlayerName() { return String.format("Player name: %s", session.getPlayer().getName()); } + /** + * Method for getting formatted total net worth. + * + * @return total net worth string. + */ public String getTotalNetWorth() { return String.format("Total net worth: %.2f $", session.getPlayer().getMoney()); } + /** + * Method for calculating total profits. + * + * @return BigDecimal profits; + */ private BigDecimal calculateProfits() { BigDecimal profit = session.getPlayer().getMoney().subtract( session.getPlayer().getStartingMoney()); return profit; } + /** + * Method for calculating total return on investements. + * + * @return BigDecimal return of investements; + */ private BigDecimal calculateROI() { BigDecimal profit = session.getPlayer().getMoney().subtract( session.getPlayer().getStartingMoney()); @@ -72,19 +123,39 @@ private BigDecimal calculateROI() { return returnOfInvestement; } + /** + * Method for getting formatted total profits. + * + * @return total profits string. + */ public String getProfits() { return String.format("Total profits: %.2f $", calculateProfits()); } + /** + * Method for getting formatted return of investement. + * + * @return return of investement string. + */ public String getROI() { return String.format("Return of investement: %.2f %%", calculateROI()); } + /** + * Method for applying color to profit label. + * + * @param profitsLabel - Profit label. + */ public void setProfitsColor(Parent profitsLabel) { CssUtils.apply(profitsLabel, CssUtils.generateValueColors(calculateProfits())); } + /** + * Method for applying color to return of investement label. + * + * @param roiLabel - return of investement label. + */ public void setRoiColor(Parent roiLabel) { CssUtils.apply(roiLabel, CssUtils.generateValueColors(calculateROI())); } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/primary/finish/FinishModel.java b/src/main/java/edu/ntnu/idi/idatt/view/primary/finish/FinishModel.java index 77f4d14..0b958cd 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/primary/finish/FinishModel.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/primary/finish/FinishModel.java @@ -2,6 +2,13 @@ import edu.ntnu.idi.idatt.view.components.Model; +/** + * Model class for Finish MVC. + * + *

+ * No contents, just to suit the MVC model creation. + *

+ */ public class FinishModel implements Model { } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/primary/finish/FinishView.java b/src/main/java/edu/ntnu/idi/idatt/view/primary/finish/FinishView.java index 5190dbc..ab69c37 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/primary/finish/FinishView.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/primary/finish/FinishView.java @@ -17,8 +17,14 @@ import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; +/** + * View class of Finish MVC. + */ public class FinishView extends AbstractView { + /** + * Constructor for FinishView. + */ public FinishView() { StackPane root = new StackPane(); super(root); @@ -36,6 +42,11 @@ public FinishView() { Button newGame; Button exit; + /** + * Override of the createContent() method. + * + * @see AbstractView + */ @Override public Parent createContent() { @@ -79,6 +90,14 @@ public Parent createContent() { } + /** + * Method for setting the FinishController. + *

+ * Handles events and actions of the view. + *

+ * + * @param controller - FinishController instance. + */ public void setController(FinishController controller) { playerName.setText(controller.getPlayerName()); playerStatus.setText(controller.getPlayerStatus()); diff --git a/src/main/java/edu/ntnu/idi/idatt/view/primary/newspaper/NewspaperController.java b/src/main/java/edu/ntnu/idi/idatt/view/primary/newspaper/NewspaperController.java index 23904da..8b9069b 100644 --- a/src/main/java/edu/ntnu/idi/idatt/view/primary/newspaper/NewspaperController.java +++ b/src/main/java/edu/ntnu/idi/idatt/view/primary/newspaper/NewspaperController.java @@ -7,12 +7,21 @@ import java.util.ArrayList; +/** + * Controller class for Newspaper MVC. + */ public class NewspaperController extends AbstractController { private final ArrayList