Skip to content

Commit

Permalink
Feat: Refactor and restructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyah committed May 15, 2026
1 parent ffeafb0 commit d5abacf
Show file tree
Hide file tree
Showing 5 changed files with 484 additions and 121 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.dashboard;

/**
* Enum representing actions done in an instance of {@link DashBoardView}.
* */
public enum DashBoardActions {
/**
* Buying shares.
* */
BUY_SHARES,

/**
* Selling shares.
* */
SELL_SHARES,

/**
* Decreasing quantity of shares to buy/sell by five.
* */
DECREASE_5,

/**
* Decreasing quantity of shares to buy/sell by one.
* */
DECREASE_1,

/**
* Increasing quantity of shares to buy/sell by one.
* */
INCREASE_1,

/**
* Increasing quantity of shares to buy/sell by five.
* */
INCREASE_5;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,40 @@
import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController;
import javafx.scene.control.Button;
import javafx.scene.control.TextFormatter;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
* Controller for {@link DashBoardView}.
* */
public class DashBoardController extends ViewController<DashBoardView> {

private Player player;
private Exchange exchange;
private List<Stock> stockList;
/**
* This player instance.
* */
private final Player player;

/**
* This exchange instance.
* */
private final Exchange exchange;

/**
* List of stocks in the program.
* */
private final List<Stock> stockList;

/**
* Time range chosen.
*
* @see DashBoardTimeRange
* */
private DashBoardTimeRange selectedTimeRange;

/**
* Selected search keyword.
* */
private String selectedFilter;

/**
Expand All @@ -39,12 +60,24 @@ public DashBoardController(final DashBoardView viewElement,
super(viewElement, eventManager);
}

/**
* Sets the current stock of the view.
*
* @param stock the stock to set.
* @param amountOwned the amount of shares owned in this stock.
* */
private void handleStockSelection(final Stock stock, final float amountOwned) {
getViewElement().setCurrentStock(stock, amountOwned);
getViewElement().updateGraph(selectedTimeRange);
}

private void populateStockList(String filter) {
/**
* Updates the sidebar including the list of relevant stocks
* based on a search filter.
*
* @param filter the keyword to search for.
* */
private void populateStockList(final String filter) {
getViewElement().clearStockList();
String search = filter.toLowerCase();
for (Stock s : stockList) {
Expand Down Expand Up @@ -87,6 +120,9 @@ private void populateStockList(String filter) {
}
}

/**
* {@inheritDoc}.
* */
@Override
protected void initInteractions() {
populateStockList("");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,56 @@
package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.dashboard;

/**
* Controls what time range the player has chosen for the dashboard.
* */
public enum DashBoardTimeRange {

/**
* One week (a single change).
* */
ONE_WEEK("1 Week", 1),

/**
* 22 weeks (default).
* */
DEFAULT("22 Weeks (Default)", 22),

/**
* One month.
* */
ONE_MONTH("1 Month", 4),

/**
* One year.
* */
ONE_YEAR("1 Year", 52);

/**
* The label, used in the dropdown menu.
* */
private final String label;

/**
* Weeks used for calculating and updating graph and percentages.
* */
private final int weeks;

/**
* Constructor.
*
* @param label the label for this enum.
* @param weeks the amount of weeks.
* */
DashBoardTimeRange(final String label, final int weeks) {
this.label = label; this.weeks = weeks;
this.label = label;
this.weeks = weeks;
}

/**
* Getter method for amount of weeks a constant represent.
*
* @return weeks.
* */
public int getWeeks() {
return weeks;
}
Expand Down
Loading

0 comments on commit d5abacf

Please sign in to comment.