Skip to content

Commit

Permalink
Merge pull request #134 from einaskoi/einar/checksyleErrors2
Browse files Browse the repository at this point in the history
fix checkstyle and add javadoc to tests
  • Loading branch information
peretr authored May 18, 2026
2 parents a899d96 + 8766b03 commit ab32da4
Show file tree
Hide file tree
Showing 22 changed files with 645 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ private void loadStylesheets() {
}
}


private Button buildCloseButton() {
Button button = new Button();
button.setShape(new Circle(6));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@
import edu.ntnu.idi.idatt2003.gruppe42.view.Popup;

/**
* A popup for the app store app.
* A popup window for the App Store application.
*
* <p>This popup is responsible for displaying available applications and related
* store functionality.
*/
public class AppStoreApp extends Popup {

/**
* Constructs a new app store popup.
* Constructs a new App Store popup.
*
* <p>Initializes the popup with default size and position, and builds its UI content.
*/
public AppStoreApp() {
super(500, 450, 100, 100, App.APPSTORE);
buildContent();
}

/**
* Builds the UI content for the App Store popup.
*
* <p>This method is responsible for constructing and populating all visual
* components inside the popup.
*/
private void buildContent() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;

/** Bank app popup showing portfolio summary. */
/**
* Bank application popup showing the player's portfolio and financial summary.
*
* <p>Displays total net worth, cash, invested value, return percentage, and a detailed
* list of owned shares with live market values and gains.
*/
public class BankApp extends Popup {

private static final String POSITIVE_STYLE = "stock-price-positive";
Expand All @@ -33,7 +38,11 @@ public class BankApp extends Popup {

private Consumer<Share> onShareSelected;

/** Constructs the Bank app. */
/**
* Constructs the Bank app popup.
*
* <p>Initializes the portfolio list view and builds the UI layout.
*/
public BankApp() {
super(600, 550, 220, 100, App.BANK);

Expand Down Expand Up @@ -123,7 +132,14 @@ private VBox summaryItem(String title, Label valueLabel) {
return box;
}

/** Refreshes summary with latest figures. */
/**
* Updates the financial summary values displayed in the UI.
*
* @param netWorth the player's total net worth
* @param cash the available cash balance
* @param invested the total invested amount
* @param startingMoney the initial starting capital used to calculate return percentage
*/
public void updateStatus(double netWorth, double cash, double invested, double startingMoney) {
Platform.runLater(() -> {
netWorthLabel.setText(formatUsd(netWorth));
Expand All @@ -137,12 +153,15 @@ public void updateStatus(double netWorth, double cash, double invested, double s
});
}

/** @return the portfolio list view. */
public ListView<Share> getPortfolioList() {
return portfolioList;
}

/** Sets the share selection callback. */
/**
* Sets a callback triggered when a share is selected in the portfolio list.
*
* @param onShareSelected consumer handling the selected share
*/
public void setOnShareSelected(Consumer<Share> onShareSelected) {
this.onShareSelected = onShareSelected;
}
Expand All @@ -161,7 +180,11 @@ private static String formatUsd(double amount) {
return "$" + String.format("%,.2f", amount);
}

/** Renders a single share holding row. */
/**
* List cell representing a single share holding in the portfolio.
*
* <p>Displays symbol, company name, quantity, prices, market value, and gain/loss.
*/
private class ShareCell extends ListCell<Share> {

private static final double COL_SYMBOL_MIN = 120;
Expand Down Expand Up @@ -251,6 +274,12 @@ private void addCellContent() {
grid.add(gainBox, 3, 0);
}

/**
* Updates the cell content for a given share.
*
* @param share the share to display
* @param empty whether the cell is empty
*/
@Override
protected void updateItem(Share share, boolean empty) {
super.updateItem(share, empty);
Expand All @@ -271,7 +300,7 @@ private void populateLabels(Share share) {
BigDecimal marketValue = currentPrice.multiply(quantity);
BigDecimal totalCost = purchasePrice.multiply(quantity);
BigDecimal gain = marketValue.subtract(totalCost);
BigDecimal gainPercent = computeGainPercent(gain, totalCost);
final BigDecimal gainPercent = computeGainPercent(gain, totalCost);

symbolLabel.setText(share.getStock().getSymbol());
companyLabel.setText(share.getStock().getCompany());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;

/** File picker app. */
/**
* File picker popup used to browse the local file system and select CSV files.
*
* <p>The picker provides navigation (back, forward, up), a quick access sidebar,
* and a selectable file list filtered to CSV files.</p>
*/
public class FilePickerApp extends Popup {

private static final String FILTER = ".csv";

private final Button backButton = new Button("←");
private final Button forwardButton = new Button("→");
private final Button upButton = new Button("↑");
Expand All @@ -47,14 +50,21 @@ public class FilePickerApp extends Popup {
private File selectedFile;
private Consumer<Path> onFileConfirmed;

/**
* Constructs a new file picker popup.
* Initializes UI and loads the initial directory view.
*/
public FilePickerApp() {
super(580, 420, 80, 60, App.FILEPICKER);
buildLayout();
wireToolbar();
populateDir(currentDir);
}


/**
* Builds the full layout of the file picker including sidebar,
* toolbar, file list, and bottom action bar.
*/
private void buildLayout() {
backButton.getStyleClass().add("fp-toolbar-button");
forwardButton.getStyleClass().add("fp-toolbar-button");
Expand Down Expand Up @@ -84,7 +94,11 @@ private void buildLayout() {
String[] names = { "Home", "Desktop", "Documents", "Downloads" };
for (int i = 0; i < QUICK_ACCESS.length; i++) {
File dir = QUICK_ACCESS[i];
if (!dir.exists()) continue;

if (!dir.exists()) {
continue;
}

Button btn = new Button(icons[i] + " " + names[i]);
btn.getStyleClass().add("fp-sidebar-item");
btn.setMaxWidth(Double.MAX_VALUE);
Expand Down Expand Up @@ -130,7 +144,7 @@ private void buildLayout() {

HBox nameRow = new HBox(8, new Label("File name:"), selectedField, filterLabel);
nameRow.setAlignment(Pos.CENTER_LEFT);
((Label) nameRow.getChildren().get(0)).getStyleClass().add("fp-bottom-label");
(nameRow.getChildren().get(0)).getStyleClass().add("fp-bottom-label");

HBox buttonRow = new HBox(6, openButton, cancelButton);
buttonRow.setAlignment(Pos.CENTER_RIGHT);
Expand All @@ -145,6 +159,11 @@ private void buildLayout() {
content.setPrefSize(580, 420);
}

/**
* Builds the column header row for the file list.
*
* @return header HBox containing column labels
*/
private HBox buildColumnHeader() {
Label nameCol = new Label("Name");
Label typeCol = new Label("Type");
Expand All @@ -162,7 +181,9 @@ private HBox buildColumnHeader() {
return header;
}


/**
* Wires toolbar navigation actions (back, up, address bar input).
*/
private void wireToolbar() {
backButton.setOnAction(e -> {
if (prevDir != null) {
Expand All @@ -180,11 +201,17 @@ private void wireToolbar() {
});
addressBar.setOnAction(e -> {
File typed = new File(addressBar.getText());
if (typed.isDirectory()) populateDir(typed);
if (typed.isDirectory()) {
populateDir(typed);
}
});
}


/**
* Populates the file list with entries from the given directory.
*
* @param dir directory to display
*/
private void populateDir(final File dir) {
currentDir = dir;
addressBar.setText(dir.getAbsolutePath());
Expand All @@ -195,7 +222,9 @@ private void populateDir(final File dir) {
openButton.setDisable(true);

File[] entries = dir.listFiles();
if (entries == null) return;
if (entries == null) {
return;
}

Arrays.stream(entries)
.filter(f -> f.isDirectory() || f.getName().endsWith(FILTER))
Expand All @@ -205,10 +234,16 @@ private void populateDir(final File dir) {
.forEach(f -> fileList.getChildren().add(buildRow(f)));
}

/**
* Builds a UI row representing a file or directory.
*
* @param file file or directory to render
* @return HBox representing the row
*/
private HBox buildRow(final File file) {
String icon = file.isDirectory() ? "📁" : "📄";
String type = file.isDirectory() ? "Folder" : "CSV File";
String size = file.isDirectory() ? ""
final String type = file.isDirectory() ? "Folder" : "CSV File";
final String size = file.isDirectory() ? ""
: formatSize(file.length());

Label iconLabel = new Label(icon);
Expand Down Expand Up @@ -256,31 +291,52 @@ private HBox buildRow(final File file) {
return row;
}

/**
* Confirms the currently selected file and triggers callback.
*/
private void confirm() {
if (selectedFile != null && onFileConfirmed != null) {
onFileConfirmed.accept(selectedFile.toPath());
hide();
}
}

/**
* Clears the current selection highlight from the file list.
*/
private void clearSelection() {
fileList.getChildren()
.forEach(n -> n.getStyleClass().remove("fp-row-selected"));
}

/**
* Formats file size into human-readable units.
*
* @param bytes file size in bytes
* @return formatted string (B, KB, MB)
*/
private static String formatSize(final long bytes) {
if (bytes < 1024) return bytes + " B";
if (bytes < 1024 * 1024) return (bytes / 1024) + " KB";
if (bytes < 1024) {
return bytes + " B";
}
if (bytes < 1024 * 1024) {
return (bytes / 1024) + " KB";
}
return (bytes / (1024 * 1024)) + " MB";
}


/** Sets onFileConfirmed callback. */
/**
* Sets callback executed when a file is confirmed.
*
* @param callback consumer receiving selected file path
*/
public void setOnFileConfirmed(final Consumer<Path> callback) {
this.onFileConfirmed = callback;
}

/** Shows the picker. */
/**
* Shows the file picker and refreshes the directory view.
*/
@Override
public void show() {
selectedFile = null;
Expand All @@ -290,7 +346,7 @@ public void show() {
super.show();
}

/** Hides the picker. */
/** Hides the file picker. */
@Override
public void hide() {
super.hide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;

/** Modal shown on game over. */
/**
* Game over modal popup shown when the player has lost all lives.
*
* <p>Displays a final message and provides a restart option.</p>
*/
public class GameOverApp extends Popup {

private final Button startOverButton = new Button("Start Over");

/**
* Constructs the Game Over popup.
*
* <p>Initializes UI components and disables the close button to prevent
* accidental dismissal.</p>
*/
public GameOverApp() {
super(500, 360, 0, 0, App.GAMEOVER);

Expand All @@ -27,6 +37,10 @@ public GameOverApp() {
buildLayout();
}

/**
* Builds the internal layout of the game over screen,
* including title, message, and restart button.
*/
private void buildLayout() {
Label title = new Label("Game Over");
title.getStyleClass().add("game-over-title");
Expand All @@ -45,14 +59,15 @@ private void buildLayout() {
content.getChildren().setAll(inner);
}

/** @return start over button. */
public Button getStartOverButton() {
return startOverButton;
}

/** Shows the app. */
/**
* Shows the Game Over popup.
*/
@Override
public void show(){
public void show() {
super.show();
}
}
Loading

0 comments on commit ab32da4

Please sign in to comment.