Skip to content

Commit

Permalink
half baked stock app implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
einaskoi committed Apr 17, 2026
1 parent 9f84d65 commit 200474e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package edu.ntnu.idi.idatt2003.gruppe42.Controller;

import edu.ntnu.idi.idatt2003.gruppe42.Model.Stock;
import edu.ntnu.idi.idatt2003.gruppe42.Model.StockFileHandler;

import java.io.IOException;
import java.nio.file.Path;
import java.util.List;

public class StockController {

private List<Stock> market;

public StockController() {
try {
List<Stock> market = StockFileHandler.readFromFile(Path.of("stocks.csv"));
} catch (IOException e) {
System.out.println("File not found.");
}
}

public List<Stock> getMarket() {
return market;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
import edu.ntnu.idi.idatt2003.gruppe42.Model.Apps;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.RowConstraints;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.*;

/**
* View for the desktop.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package edu.ntnu.idi.idatt2003.gruppe42.View.Popups;

import edu.ntnu.idi.idatt2003.gruppe42.Controller.StockController;
import edu.ntnu.idi.idatt2003.gruppe42.Model.Stock;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;

/**
* A popup for the Stock app.
*/
public class StockPopup extends Popup {

private StockController stockController;

/**
* Constructs a new Stock popup.
*
Expand All @@ -15,6 +23,30 @@ public class StockPopup extends Popup {
*/
public StockPopup(int width, int height, int x, int y) {
super(width, height, x, y);
// Add Stock specific content here
stockController = new StockController();
System.out.println("Market size: " + stockController.getMarket().size());

TextField searchField = new TextField();

ListView<Stock> resultList = new ListView<>();
resultList.getItems().addAll(stockController.getMarket());

resultList.setCellFactory(lv -> new ListCell<Stock>() {
@Override
protected void updateItem(Stock stock, boolean empty) {
super.updateItem(stock, empty);
if (empty || stock == null) {
setGraphic(null);
} else {
Label nameLabel = new Label(stock.getCompany());

HBox row = new HBox(10, nameLabel);
row.setAlignment(Pos.CENTER_LEFT);
setGraphic(row);
}
}
});

content.getChildren().addAll(searchField, resultList);
}
}
19 changes: 19 additions & 0 deletions src/main/resources/stocks.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Companies by Market Cap
# Ticker,Name,Price

BAN,Banana Inc.,191.27
APL,Apple Inc.,276.43
TIR,Tire Inc.,404.68
OIL,Oil Inc.,204.62
SPC,Space Inc. (Class A),311.20
WND,Turbine Inc. (Class C),311.62
NUC,Nuclear Inc.,343.35
CAR,Car Inc.,426.52
HYD,Hydro,501.05
TIP,Q-tip Inc.,128.75
TED,Teddy Bear Inc.,1014.43
UNI,NTNU,311.14
COM,Communication Inc.,155.28
MON,Monsters Inc.,329.54
AIR,Plane Inc.,240.70
ATB,Bus Inc.,539.52

0 comments on commit 200474e

Please sign in to comment.