Skip to content

Final fixes #68

Merged
merged 8 commits into from
May 26, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Creates static events that can occur within Newspaper.
* </p>
*
* @see Newspaper
* {@link Newspaper}
*/
public enum NewspaperEnum {
NEW_PRODUCT(
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/edu/ntnu/idi/idatt/model/portfolio/Share.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public BigDecimal getTotalPurchasePrice() {
* SaleCalculator.calculateGross() - getTotalPurchasePrice()
* </p>
*
* @see Player (Net worth calculation)
* {@link Player}
*
* @return BigDecimal current profit.
*/
public BigDecimal getProfit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public List<Sale> getSales() {
* Used to calculate player statuses.
* </p>
*
* @see Player
* {@link Player}
*
* @return int amount of distinct weeks.
*/
public int countDistinctWeeks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public BigDecimal calculateTotal() {
* to the net worth calculation method.
* </p>
*
* @see Player
* {@link Player}
*/
public BigDecimal calculateProfit() {
return calculateGross().subtract(purchasePrice.multiply(quantity));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/edu/ntnu/idi/idatt/session/UserSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void setExchange(Exchange exchange) {
/**
* Getter for moneyProperty.
*
* @return SimpleObjectProperty<BigDecimal>;
* @return {@code SimpleObjectProperty<BigDecimal>}
*/
public SimpleObjectProperty<BigDecimal> moneyProperty() {
return moneyProperty;
Expand All @@ -98,7 +98,7 @@ public SimpleObjectProperty<BigDecimal> moneyProperty() {
/**
* Getter for netWorthProperty.
*
* @return SimpleObjectProperty<BigDecimal>
* @return {@code SimpleObjectProperty<BigDecimal>}
*/
public SimpleObjectProperty<BigDecimal> netWorthProperty() {
return netWorthProperty;
Expand Down Expand Up @@ -126,7 +126,7 @@ public SimpleStringProperty statusProperty() {
* Method used for updating the game state.
* <p>
* Updates the user interface model from diverse
* places through the code to synchronize model <-> UI.
* places through the code to synchronize model with UI.
* Saves current session.
* </p>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/ntnu/idi/idatt/view/SceneFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public static Parent createExchangeView() {
* </p>
*
* @param clean - should it reset the page stack.
* @rteturn View's root
* @return View's root
*/
public static Parent createExchangeView(boolean clean) {
return createDefaultExchangeView(clean);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package edu.ntnu.idi.idatt.view.components;

import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.geometry.Pos;
import javafx.scene.Parent;
Expand All @@ -9,6 +12,7 @@
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.util.Duration;

/**
* Abstract View UI class.
Expand Down Expand Up @@ -59,12 +63,12 @@ public AbstractViewUI() {
disableMenu.setVisible(false);

disableMenu.setOnMouseClicked(e -> {
menu.setVisible(false);
animationMenu(false);
disableMenu.setVisible(false);
});

isMenuVisible.addListener((observer, oldVal, newVal) -> {
menu.setVisible(true);
animationMenu(true);
disableMenu.setVisible(true);
});

Expand Down Expand Up @@ -165,4 +169,25 @@ public void toggleMenu() {
isMenuVisible.set(!isMenuVisible.get());
}

/**
* Method for animating the menu.
*
* @param val - in = true, out = false
*/
private void animationMenu(boolean val) {
Timeline animation;
if (val) {
menu.setVisible(true);
menu.setTranslateX(menu.getWidth()); // Fix issue from menu initialization
// (hide before starting to appear no matter what)
animation = new Timeline(new KeyFrame(Duration.millis(200),
new KeyValue(menu.translateXProperty(), 0)));
} else {
animation = new Timeline(new KeyFrame(Duration.millis(200),
new KeyValue(menu.translateXProperty(), menu.getWidth())));
animation.setOnFinished((e) -> menu.setVisible(false));
}
animation.play();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import edu.ntnu.idi.idatt.view.util.CssUtils;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
Expand Down Expand Up @@ -74,6 +75,9 @@ public StockComponent(Stock stock) {
.unwrap()
.build();

// Add click cursor
this.setCursor(Cursor.HAND);

this.getChildren().addAll(stockComponent.makeUI());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class UIAlert {
/**
* Constructor for UIAlert.
*
* @param title - Window name
* @param header - context
* @content - description of context
* @param title - Window name
* @param header - context
* @param content - description of context
*/
public UIAlert(String title, String header, String content) {
alert.setTitle(title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import edu.ntnu.idi.idatt.session.UserSession;
import edu.ntnu.idi.idatt.view.SceneFactory;
import edu.ntnu.idi.idatt.view.components.AbstractViewUI;
import edu.ntnu.idi.idatt.view.components.elements.IconComponent;
import edu.ntnu.idi.idatt.view.components.elements.SearchBarComponent;
import edu.ntnu.idi.idatt.view.components.primitives.ActionEventHandler;
Expand All @@ -33,7 +34,7 @@
* equal layouts across multiple views.
* </p>
*
* @see AbstractViewUI
* {@link AbstractViewUI}
*/
public class UIFactory {

Expand Down Expand Up @@ -191,7 +192,10 @@ private static Parent createDefaultNavigation(Label titleLabel, List<String> but
.properties(nav -> nav.setPadding(new Insets(40)))
.addContent(titleLabel);

buttons.forEach(b -> navigationBuilder.addContent(b));
buttons.forEach(b -> {
navigationBuilder.addContent(b);
CssUtils.fadeInAnimation(b);
});

navigationBuilder
.filler();
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/edu/ntnu/idi/idatt/view/entry/StartView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import edu.ntnu.idi.idatt.view.components.AbstractView;
import edu.ntnu.idi.idatt.view.util.CssUtils;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Parent;
Expand Down Expand Up @@ -45,7 +46,7 @@ public StartView() {
/**
* Overriden method for createContent()
*
* @see AbstractView;
* @see AbstractView
* @return root node.
*/
@Override
Expand Down Expand Up @@ -145,6 +146,8 @@ public void setModel(StartModel model) {
this.errorLabel.textProperty().bind(model.getError());
this.fileLabel.textProperty().bind(model.getFileName());
this.newGameWrapper.visibleProperty().bind(model.isNewGame());
this.newGameWrapper.visibleProperty()
.addListener((obs) -> this.newGameWrapper.getChildren().forEach(c -> CssUtils.fadeInAnimation(c)));
this.csvPredefinedCheckBox.selectedProperty().bindBidirectional(model.isPredefinedCSV());

// Binding importCsvWrapper visibleProperty here for convenience
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import edu.ntnu.idi.idatt.view.SceneManager;
import edu.ntnu.idi.idatt.view.components.AbstractController;
import edu.ntnu.idi.idatt.view.components.elements.StockComponent;
import edu.ntnu.idi.idatt.view.util.CssUtils;
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
Expand Down Expand Up @@ -80,35 +81,14 @@ public void setStocksModel(List<Stock> stockList) {
StockComponent stockComponent = new StockComponent(stock);

if (stock.getNewspaper().hasNewNews()) {
applyNewspaperGlow(stockComponent);
CssUtils.applyNewspaperGlow(stockComponent);
}

stockComponent.onStockClick((symbol) -> redirectView(symbol));
model.getStockList().add(stockComponent);
}
}

/**
* 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);

Timeline timeline = new Timeline(
new KeyFrame(Duration.ZERO,
new KeyValue(glow.radiusProperty(), 10)),
new KeyFrame(Duration.seconds(0.5),
new KeyValue(glow.radiusProperty(), 50)));

timeline.setAutoReverse(true);
timeline.setCycleCount(Animation.INDEFINITE);

component.setEffect(glow);
timeline.play();
}

/**
* Method to handle searchbar query.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ExchangeModel implements Model {
/**
* Getter for the stock list.
*
* @return ObservableList<StockComponent>;
* @return {@code ObservableList<StockComponent>}
*/
public ObservableList<StockComponent> getStockList() {
return stockList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ private BigDecimal calculateProfits() {
private BigDecimal calculateROI() {
BigDecimal profit = session.getPlayer().getMoney().subtract(
session.getPlayer().getStartingMoney());
BigDecimal profitPercent = profit.divide(session.getPlayer().getStartingMoney()).setScale(2, RoundingMode.HALF_UP);
BigDecimal profitPercent = profit.divide(session.getPlayer().getStartingMoney());

BigDecimal returnOfInvestement = profitPercent.multiply(new BigDecimal("100"));
BigDecimal returnOfInvestement = profitPercent.multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP);

return returnOfInvestement;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class NewspaperModel implements Model {
/**
* Getter for newsList.
*
* @return ObservableList<Label>
* @return {@code ObservableList<Label>}
*/
public ObservableList<Label> getNewsList() {
return newsList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Parent createNavigation() {
* Leaving empty, since it's not used.
* </p>
*
* @see AbstractViewUI.
* @see AbstractViewUI
*/
@Override
public Parent createHeader() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
import edu.ntnu.idi.idatt.view.components.elements.ShareComponent;
import edu.ntnu.idi.idatt.view.components.ui.UIAlert;
import edu.ntnu.idi.idatt.view.util.CssUtils;
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.GaussianBlur;
import javafx.scene.paint.Color;
import javafx.util.Duration;

import java.math.BigDecimal;
import java.util.ArrayList;
Expand All @@ -31,6 +38,7 @@ public class PortfolioController extends AbstractController<PortfolioModel> {
* </p>
*/
public enum SortAction {
NEWS,
OLDEST,
NEWEST,
PROFIT,
Expand Down Expand Up @@ -71,6 +79,13 @@ public void setShareModel(List<Share> shareList) {
model.getShareList().clear();
for (Share share : shareList) {
ShareComponent shareComponent = new ShareComponent(share);

if (share.getStock().getNewspaper().hasNewNews()) {
CssUtils.applyNewspaperGlow(shareComponent);
}

CssUtils.fadeInAnimation(shareComponent);

shareComponent.onShareSellButton((sellShare) -> holdingSale(sellShare));
shareComponent.onShareClick((stockSymbol) -> SceneManager.switchTo(SceneFactory.createStockView(stockSymbol)));
model.getShareList().add(shareComponent);
Expand Down Expand Up @@ -135,6 +150,7 @@ public void showReciept(Sale sale) {
});

model.instanceChildren().add(reciept);
CssUtils.fadeInAnimation(reciept);
}

/**
Expand Down Expand Up @@ -249,6 +265,13 @@ public void sortSharesBy(SortAction action) {

switch (action) {

case NEWS: {
sharesSorted.clear();
sharesSorted.addAll(session.getPlayer().getPortfolio().getShares()
.stream().filter(share -> share.getStock().getNewspaper().hasNewNews()).toList());
break;
}

case OLDEST: {
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class PortfolioModel implements Model {
/**
* Getter for the shareList property.
*
* @return ObservableList<ShareComponent>;
* @return {@code ObservableList<ShareComponent>}
*/
public ObservableList<ShareComponent> getShareList() {
return shareList;
Expand Down Expand Up @@ -52,7 +52,7 @@ public PlayerInfoModel playerInfoModel() {
/**
* Getter for the view's root instance effects.
*
* @return SimpleObjectProperty<Effect>;
* @return {@code SimpleObjectProperty<Effect>}
*/
public SimpleObjectProperty<Effect> instanceEffects() {
return instanceEffects;
Expand All @@ -61,7 +61,7 @@ public SimpleObjectProperty<Effect> instanceEffects() {
/**
* Getter for the view's root instance children.
*
* @return SimpleObjectProperty<Node>;
* @return {@code SimpleObjectProperty<Node>}
*/
public ObservableList<Node> instanceChildren() {
return instanceChildren;
Expand Down
Loading
Loading