diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/StockController.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/StockController.java new file mode 100644 index 0000000..980b124 --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/StockController.java @@ -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 market; + + public StockController() { + try { + List market = StockFileHandler.readFromFile(Path.of("stocks.csv")); + } catch (IOException e) { + System.out.println("File not found."); + } + } + + public List getMarket() { + return market; + } +} diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/DesktopView.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/DesktopView.java index ad94a51..c7700ff 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/DesktopView.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/DesktopView.java @@ -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. diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Popups/StockPopup.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Popups/StockPopup.java index 059fe80..9f6baef 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Popups/StockPopup.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Popups/StockPopup.java @@ -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. * @@ -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 resultList = new ListView<>(); + resultList.getItems().addAll(stockController.getMarket()); + + resultList.setCellFactory(lv -> new ListCell() { + @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); } } diff --git a/src/main/resources/stocks.csv b/src/main/resources/stocks.csv new file mode 100644 index 0000000..a0948ff --- /dev/null +++ b/src/main/resources/stocks.csv @@ -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 \ No newline at end of file