From b4a21ed1928de3d0887db83272d9722776f0641e Mon Sep 17 00:00:00 2001 From: Per Eric Trapnes Date: Mon, 18 May 2026 16:20:50 +0200 Subject: [PATCH] implimented events with stocks and mail app --- .../AppControllers/MailController.java | 43 ++++--- .../AppControllers/StockAppController.java | 44 +++++-- .../gruppe42/Controller/PopupsController.java | 43 ++++++- .../gruppe42/Controller/StockController.java | 114 +++++++++++++----- .../DesktopComponentFactory.java | 51 +++++--- .../DesktopViewController.java | 31 +++-- .../idatt2003/gruppe42/Model/EventBus.java | 25 ++++ .../idi/idatt2003/gruppe42/Model/Message.java | 6 +- .../idi/idatt2003/gruppe42/Model/News.java | 30 +++++ .../idatt2003/gruppe42/Model/StockEvent.java | 3 + .../View/Views/Components/StockGraph.java | 2 +- src/main/resources/css/desktop.css | 2 +- 12 files changed, 308 insertions(+), 86 deletions(-) create mode 100644 src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/EventBus.java create mode 100644 src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/News.java create mode 100644 src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/StockEvent.java diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/MailController.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/MailController.java index 184b32b..3fa60a5 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/MailController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/MailController.java @@ -1,5 +1,6 @@ package edu.ntnu.idi.idatt2003.gruppe42.Controller.AppControllers; +import edu.ntnu.idi.idatt2003.gruppe42.Controller.TimeAndWeatherController; import edu.ntnu.idi.idatt2003.gruppe42.Model.Day; import edu.ntnu.idi.idatt2003.gruppe42.Model.Message; import javafx.beans.binding.Bindings; @@ -14,22 +15,27 @@ public class MailController implements AppController { private final ObservableList messages = FXCollections.observableArrayList(); private final IntegerBinding unreadCount; + private final TimeAndWeatherController timeAndWeatherController; + private int week; + private String day; + private int time; /** * Constructs the MailController and sets up the unread count binding. */ - public MailController() { + public MailController(TimeAndWeatherController timeAndWeatherController) { + this.timeAndWeatherController = timeAndWeatherController; unreadCount = Bindings.createIntegerBinding(() -> (int) messages.stream().filter(m -> !m.isSeen()).count(), messages ); // Ensure unreadCount updates when a message's seen property changes - messages.addListener((ListChangeListener) c -> { - while (c.next()) { - if (c.wasAdded()) { - for (Message m : c.getAddedSubList()) { - m.seenProperty().addListener((obs, oldVal, newVal) -> unreadCount.invalidate()); + messages.addListener((ListChangeListener) change -> { + while (change.next()) { + if (change.wasAdded()) { + for (Message message : change.getAddedSubList()) { + message.seenProperty().addListener((obs, oldVal, newVal) -> unreadCount.invalidate()); } } } @@ -51,22 +57,25 @@ public IntegerBinding unreadCountProperty() { return unreadCount; } + + public void createMessage(String author, String title, String message) { + updateDateTime(); + messages.add(0, new Message(author, title, message, week, day, time)); + } + /** - * Creates and adds a new message to the inbox. - * - * @param author the sender - * @param title the subject - * @param message the content - * @param week the week - * @param day the day - * @param time the time + * Clears all messages from the inbox. */ - public void createMessage(String author, String title, String message, int week, Day day, int time) { - messages.add(new Message(author, title, message, week, day, time)); + public void clearMessages() { + messages.clear(); + } + public void updateDateTime() { + week = timeAndWeatherController.weekIndexProperty().get(); + day = timeAndWeatherController.getDayOfWeekString(); + time = timeAndWeatherController.hourProperty().get(); } @Override public void nextTick() { - // No specific tick logic currently needed for mail } } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/StockAppController.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/StockAppController.java index 293061b..1120409 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/StockAppController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/AppControllers/StockAppController.java @@ -152,15 +152,39 @@ protected void updateItem(final Stock stock, final boolean empty) { /** Sets weekend status. */ public void setWeekend(final boolean weekend) { this.isWeekend = weekend; + Platform.runLater(this::updateTradeUI); + } + + /** Updates the Trade button and spinner state. */ + private void updateTradeUI() { Button tradeButton = stockApp.getConfirmButton(); - if (weekend) { + var spinner = stockApp.getQuantitySpinner(); + + if (isWeekend) { + tradeButton.setDisable(true); tradeButton.getStyleClass().add("trade-button-weekend"); tradeButton.setOpacity(0.45); - stockApp.getQuantitySpinner().setDisable(true); + spinner.setDisable(true); + return; + } + + spinner.setDisable(false); + tradeButton.getStyleClass().remove("trade-button-weekend"); + + if (currentStock != null) { + boolean isBankrupt = currentStock.getSalesPrice().compareTo(BigDecimal.ZERO) <= 0; + boolean isBuying = spinner.getValue() > 0; + + if (isBankrupt && isBuying) { + tradeButton.setDisable(true); + tradeButton.setOpacity(0.5); + } else { + tradeButton.setDisable(false); + tradeButton.setOpacity(1.0); + } } else { - tradeButton.getStyleClass().remove("trade-button-weekend"); + tradeButton.setDisable(false); tradeButton.setOpacity(1.0); - stockApp.getQuantitySpinner().setDisable(false); } } @@ -189,6 +213,11 @@ private void handleTransaction() { if (value == 0) { return; } + + if (value > 0 && currentStock.getSalesPrice().compareTo(BigDecimal.ZERO) <= 0) { + return; // Buying bankrupt stock disabled + } + BigDecimal quantity = new BigDecimal(Math.abs(value)); if (value > 0) { try{ @@ -237,12 +266,13 @@ private void handleSell(final Stock stock, final BigDecimal quantity) { /** Updates receipt view. */ private void updateReceipt() { if (currentStock != null) { - Platform.runLater(() -> + Platform.runLater(() -> { stockApp.getReceipt().update( currentStock, new BigDecimal(stockApp.getQuantitySpinner().getValue()) - ) - ); + ); + updateTradeUI(); + }); } } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/PopupsController.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/PopupsController.java index 166046f..2c28b66 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/PopupsController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/PopupsController.java @@ -24,6 +24,15 @@ public PopupsController(List popups) { private void initPopup(Popup popup) { makeDraggable(popup); popup.getCloseButton().setOnAction(event -> hide(popup.getType())); + + // Keep in bounds when parent resizes + Pane root = popup.getRoot(); + root.parentProperty().addListener((obs, oldP, newP) -> { + if (newP instanceof Pane parent) { + parent.widthProperty().addListener((o, ov, nv) -> keepInBounds(popup)); + parent.heightProperty().addListener((o, ov, nv) -> keepInBounds(popup)); + } + }); } /** Shows a popup. */ @@ -34,7 +43,10 @@ public boolean show(App type) { popups.stream() .filter(popup -> popup.getType().equals(type)) .findFirst() - .ifPresent(Popup::show); + .ifPresent(popup -> { + popup.show(); + keepInBounds(popup); + }); audioManager.playSFX(Audio.OPEN_APP); return true; } @@ -62,6 +74,9 @@ private void makeDraggable(Popup popup) { double[] offset = new double[2]; popup.getHeader().setOnMousePressed(event -> { + root.layoutXProperty().unbind(); + root.layoutYProperty().unbind(); + if (root.getParent() instanceof Pane parent) { Point2D local = parent.sceneToLocal(event.getSceneX(), event.getSceneY()); offset[0] = local.getX() - root.getLayoutX(); @@ -75,8 +90,13 @@ private void makeDraggable(Popup popup) { Point2D local = parent.sceneToLocal(event.getSceneX(), event.getSceneY()); double newX = local.getX() - offset[0]; double newY = local.getY() - offset[1]; - double maxX = parent.getWidth() - root.getWidth(); - double maxY = parent.getHeight() - root.getHeight(); + + double width = root.getWidth() > 0 ? root.getWidth() : root.prefWidth(-1); + double height = root.getHeight() > 0 ? root.getHeight() : root.prefHeight(-1); + + double maxX = Math.max(0, parent.getWidth() - width); + double maxY = Math.max(0, parent.getHeight() - height); + root.setLayoutX(Math.max(0, Math.min(newX, maxX))); root.setLayoutY(Math.max(0, Math.min(newY, maxY))); } @@ -84,6 +104,23 @@ private void makeDraggable(Popup popup) { }); } + private void keepInBounds(Popup popup) { + Pane root = popup.getRoot(); + if (root.layoutXProperty().isBound()) { + return; + } + if (root.getParent() instanceof Pane parent) { + double width = root.getWidth() > 0 ? root.getWidth() : root.prefWidth(-1); + double height = root.getHeight() > 0 ? root.getHeight() : root.prefHeight(-1); + + double maxX = Math.max(0, parent.getWidth() - width); + double maxY = Math.max(0, parent.getHeight() - height); + + root.setLayoutX(Math.max(0, Math.min(root.getLayoutX(), maxX))); + root.setLayoutY(Math.max(0, Math.min(root.getLayoutY(), maxY))); + } + } + /** Adds popups. */ public void addPopups(List popups) { popups.forEach(this::addPopup); 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 index e1389b9..7091f31 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/StockController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/StockController.java @@ -1,58 +1,118 @@ package edu.ntnu.idi.idatt2003.gruppe42.Controller; +import edu.ntnu.idi.idatt2003.gruppe42.Controller.AppControllers.MailController; +import edu.ntnu.idi.idatt2003.gruppe42.Model.EventBus; import edu.ntnu.idi.idatt2003.gruppe42.Model.Stock; +import edu.ntnu.idi.idatt2003.gruppe42.Model.StockEvent; import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.ArrayList; +import java.util.List; import java.util.Random; public class StockController { - private Stock stock; - private int timeframe; + + private static final int STEEP_THRESHOLD = 46; + private static final int EVENT_MAGNITUDE = 90; + private static final double NOISE_RANGE = 8.0; + private static final int MIN_TREND_FRAMES = 10; + + private final Stock stock; + + private int trendTimeframe; + private int trendFramesRemaining; private int trend; private int delay; private int time; private Random random; - private double timeMultiplier; private BigDecimal price; private BigDecimal startPrice; - private BigDecimal offset; - private BigDecimal priceChange; - + private BigDecimal pendingShock; - public StockController(Stock stock) { + public StockController(final Stock stock) { this.stock = stock; - time = 0; - random = new Random(); - timeMultiplier = (random.nextDouble() + 0.1) / 20; - startPrice = stock.getSalesPrice(); - - price = startPrice; - priceChange = new BigDecimal(random.nextInt(startPrice.intValue()/2)); + this.time = 0; + this.delay = 0; + this.random = new Random(); + this.startPrice = stock.getSalesPrice(); + this.price = startPrice; + nextTrend(); } public BigDecimal updatePrice() { - BigDecimal marketFluctuation = BigDecimal.valueOf(Math.sin(timeMultiplier * time)) - .multiply(priceChange) - .add(startPrice); + BigDecimal noise = BigDecimal.valueOf((random.nextDouble() * 2 - 1) * NOISE_RANGE); + + if (isDelay()) { + delay--; + if (delay == 0 && pendingShock != null) { + price = price.add(pendingShock); + pendingShock = null; + } + + if (price.compareTo(BigDecimal.ZERO) > 0) { + price = price.add(noise); + } + + if (price.compareTo(BigDecimal.ZERO) < 0) { + price = BigDecimal.ZERO; + } + return price.setScale(2, RoundingMode.HALF_UP); + } + + if (price.compareTo(BigDecimal.ZERO) > 0 || (isTrajectorySteep() && trend > 0)) { + BigDecimal trendStep = BigDecimal.valueOf(trend) + .divide(BigDecimal.valueOf(trendTimeframe), 6, RoundingMode.HALF_UP); - double speculatorFluctuation = random.nextDouble(2) - 1; - offset = BigDecimal.valueOf(speculatorFluctuation*30); + price = price.add(trendStep).add(noise); + } - time += 1; - price = marketFluctuation; + if (price.compareTo(BigDecimal.ZERO) < 0) { + price = BigDecimal.ZERO; + } - return price.add(offset); + trendFramesRemaining--; + time++; + + if (trendFramesRemaining <= 0) { + nextTrend(); + } + + return price.setScale(2, RoundingMode.HALF_UP); } - public void handleEvent() { + private void nextTrend() { + trend = random.nextInt(101) - 50; + trendTimeframe = random.nextInt(120) + MIN_TREND_FRAMES; + trendFramesRemaining = trendTimeframe; + + if (isTrajectorySteep()) { + prepareEvent(); + delay = 20; + } else { + delay = 0; + pendingShock = null; + } + } + private void prepareEvent() { + int direction = trend > 0 ? 1 : -1; + double scaledMagnitude = EVENT_MAGNITUDE * ((double) Math.abs(trend) / 50.0); + pendingShock = BigDecimal.valueOf(direction * scaledMagnitude); + EventBus.get() + .publish(new StockEvent(stock.getCompany(), trend)); } - public boolean isTrajectorySteep() { - return true; + private boolean isTrajectorySteep() { + return Math.abs(trend) > STEEP_THRESHOLD; } - public boolean isDelay() { + private boolean isDelay() { return delay > 0; } -} + + public BigDecimal getPrice() { + return price; + } + +} \ No newline at end of file diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/ViewControllers/DesktopComponentFactory.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/ViewControllers/DesktopComponentFactory.java index 1ce0450..0b90deb 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/ViewControllers/DesktopComponentFactory.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/ViewControllers/DesktopComponentFactory.java @@ -48,7 +48,37 @@ public Node createAppButton(final App type) { button.getStyleClass().add("app-button"); button.setMinSize(0, 0); - button.parentProperty().addListener((observable, oldParent, newParent) -> { + Node appNode = button; + + if (type == App.MAIL) { + StackPane container = new StackPane(); + + Circle badge = new Circle(10, Color.RED); + Label countLabel = new Label(); + countLabel.setTextFill(Color.WHITE); + countLabel.setFont(Font.font("System", FontWeight.BOLD, 10)); + countLabel.textProperty().bind(mailController.unreadCountProperty().asString()); + + StackPane badgeUI = new StackPane(badge, countLabel); + badgeUI.setMouseTransparent(true); + badgeUI.setAlignment(Pos.CENTER); + badgeUI.visibleProperty().bind(mailController.unreadCountProperty().greaterThan(0)); + + container.getChildren().addAll(button, badgeUI); + StackPane.setAlignment(badgeUI, Pos.TOP_RIGHT); + StackPane.setMargin(badgeUI, new Insets(-10, -10, 0, 0)); + + // Bind container size to button size so badge is aligned to button corners + container.prefWidthProperty().bind(button.prefWidthProperty()); + container.prefHeightProperty().bind(button.prefHeightProperty()); + container.maxWidthProperty().bind(button.prefWidthProperty()); + container.maxHeightProperty().bind(button.prefHeightProperty()); + + appNode = container; + } + + final Node finalNode = appNode; + finalNode.parentProperty().addListener((observable, oldParent, newParent) -> { if (newParent instanceof Region region) { button.prefWidthProperty().bind( Bindings.min( @@ -79,24 +109,7 @@ public Node createAppButton(final App type) { }); if (type == App.MAIL) { - StackPane container = new StackPane(); - - Circle badge = new Circle(10, Color.RED); - Label countLabel = new Label(); - countLabel.setTextFill(Color.WHITE); - countLabel.setFont(Font.font("System", FontWeight.BOLD, 10)); - countLabel.textProperty().bind(mailController.unreadCountProperty().asString()); - - StackPane badgeUI = new StackPane(badge, countLabel); - badgeUI.setMouseTransparent(true); - badgeUI.setAlignment(Pos.CENTER); - badgeUI.visibleProperty().bind(mailController.unreadCountProperty().greaterThan(0)); - - container.getChildren().addAll(button, badgeUI); - StackPane.setAlignment(badgeUI, Pos.TOP_RIGHT); - StackPane.setMargin(badgeUI, new Insets(-5, -5, 0, 0)); - - return container; + return appNode; } return button; diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/ViewControllers/DesktopViewController.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/ViewControllers/DesktopViewController.java index bfebd27..b601ff9 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/ViewControllers/DesktopViewController.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Controller/ViewControllers/DesktopViewController.java @@ -10,7 +10,10 @@ import edu.ntnu.idi.idatt2003.gruppe42.Controller.PopupsController; import edu.ntnu.idi.idatt2003.gruppe42.Controller.TimeAndWeatherController; import edu.ntnu.idi.idatt2003.gruppe42.Model.App; +import edu.ntnu.idi.idatt2003.gruppe42.Model.EventBus; +import edu.ntnu.idi.idatt2003.gruppe42.Model.News; import edu.ntnu.idi.idatt2003.gruppe42.Model.Player; +import edu.ntnu.idi.idatt2003.gruppe42.Model.StockEvent; import edu.ntnu.idi.idatt2003.gruppe42.View.Apps.AppStoreApp; import edu.ntnu.idi.idatt2003.gruppe42.View.Apps.BankApp; import edu.ntnu.idi.idatt2003.gruppe42.View.Apps.FilePickerApp; @@ -43,16 +46,15 @@ public final class DesktopViewController { private final Player player; private final TimeAndWeatherController timeAndWeatherController; private final MarketController marketController; - private StockAppController stockAppController; - private SettingsAppController settingsAppController; private final MailController mailController; private final DesktopDialogController dialogController; private final DesktopComponentFactory componentFactory; private final WeekendReportApp weekendReportApp = new WeekendReportApp(); private final WarningApp warningApp = new WarningApp(); private final GameOverApp gameOverApp = new GameOverApp(); + private StockAppController stockAppController; - private DesktopView desktopView = null; + private final DesktopView desktopView; /** Constructs the controller. */ public DesktopViewController( @@ -66,7 +68,7 @@ public DesktopViewController( gameController.addAppController(timeAndWeatherController); this.marketController = new MarketController(userSelectedPath); - this.mailController = new MailController(); + this.mailController = new MailController(timeAndWeatherController); gameController.addAppController(mailController); this.popupsController = popupsController; @@ -78,7 +80,7 @@ public DesktopViewController( this.dialogController.setDesktopView(desktopView); this.dialogController.setOnAdvanceWeek(this::doAdvanceWeek); - List popups = initializeApps(gameController, userSelectedPath); + List popups = initializeApps(gameController); this.popupsController.addPopups(popups); setupPopupOverlay(popups); @@ -88,9 +90,20 @@ public DesktopViewController( int startDay = timeAndWeatherController.dayIndexProperty().get(); stockAppController.setWeekend(startDay == SATURDAY_INDEX || startDay == SUNDAY_INDEX); + + EventBus.get() + .subscribe( + StockEvent.class, + event -> + Platform.runLater( + () -> { + News news = new News(event.company(), event.trend()); + mailController.createMessage( + news.generateAuthor(), event.company(), news.generateNews()); + })); } - private List initializeApps(GameController gameController, Path userSelectedPath) { + private List initializeApps(GameController gameController) { AppStoreApp appStoreApp = new AppStoreApp(); gameController.addAppController(new AppStoreController(appStoreApp)); @@ -108,14 +121,15 @@ private List initializeApps(GameController gameController, Path userSelec SettingsApp settingsApp = (SettingsApp) popupsController.getPopup(App.SETTINGS); FilePickerApp filePickerApp = (FilePickerApp) popupsController.getPopup(App.FILEPICKER); - settingsAppController = new SettingsAppController(settingsApp, filePickerApp); + SettingsAppController settingsAppController = + new SettingsAppController(settingsApp, filePickerApp); settingsAppController.setLoggedIn(true); settingsAppController.setOnGradientChanged(cfg -> desktopView.getDesktopPane().setStyle( SettingsApp.buildCssGradient(cfg.colorA(), cfg.colorB(), cfg.direction()))); - settingsAppController.setOnPlayerNameChanged(name -> player.setName(name)); + settingsAppController.setOnPlayerNameChanged(player::setName); settingsAppController.setOnLogout(this::handleLogout); settingsAppController.setOnPowerOff(Platform::exit); @@ -223,6 +237,7 @@ private void handleAdvanceWeek() { private void doAdvanceWeek() { marketController.advanceWeek(); timeAndWeatherController.advanceWeek(); + mailController.clearMessages(); } private void showMarketClosedWarning() { diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/EventBus.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/EventBus.java new file mode 100644 index 0000000..5c7fa20 --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/EventBus.java @@ -0,0 +1,25 @@ +package edu.ntnu.idi.idatt2003.gruppe42.Model; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; + +public class EventBus { + private static final EventBus INSTANCE = new EventBus(); + private final Map, List>> listeners = new HashMap<>(); + + public static EventBus get() { return INSTANCE; } + + @SuppressWarnings("unchecked") + public void subscribe(Class type, Consumer listener) { + listeners.computeIfAbsent(type, k -> new ArrayList<>()) + .add((Consumer) listener); + } + + public void publish(Object event) { + List> handlers = listeners.get(event.getClass()); + if (handlers != null) handlers.forEach(h -> h.accept(event)); + } +} \ No newline at end of file diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Message.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Message.java index 255960d..3ce0d4a 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Message.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/Message.java @@ -11,7 +11,7 @@ public class Message { private final String title; private final String content; private final int week; - private final Day day; + private final String day; private final int time; private final BooleanProperty seen = new SimpleBooleanProperty(false); @@ -25,7 +25,7 @@ public class Message { * @param day the day the message was sent * @param time the time (hour) the message was sent */ - public Message(String author, String title, String content, int week, Day day, int time) { + public Message(String author, String title, String content, int week, String day, int time) { this.author = author; this.title = title; this.content = content; @@ -50,7 +50,7 @@ public int getWeek() { return week; } - public Day getDay() { + public String getDay() { return day; } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/News.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/News.java new file mode 100644 index 0000000..b6f5e67 --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/News.java @@ -0,0 +1,30 @@ +package edu.ntnu.idi.idatt2003.gruppe42.Model; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class News { + private final String company; + private final int trend; + private final Random random = new Random(); + public News(String company, int trend){ + this.company = company; + this.trend = trend; + } + public String generateAuthor(){ + List authors = new ArrayList<>(); + authors.add("market@stocks.com"); + return authors.get(random.nextInt(authors.size())); + } + public String generateNews(){ + if (trend > 0) { + List goodNews = new ArrayList<>(); + goodNews.add("Turns out the product of " + company +" is good for the enviroment"); + return goodNews.get(random.nextInt(goodNews.size())); + } + List badNews = new ArrayList<>(); + badNews.add("Turns out the product of " + company +" is bad for the enviroment"); + return badNews.get(random.nextInt(badNews.size())); + } +} diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/StockEvent.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/StockEvent.java new file mode 100644 index 0000000..ec059b9 --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Model/StockEvent.java @@ -0,0 +1,3 @@ +package edu.ntnu.idi.idatt2003.gruppe42.Model; + +public record StockEvent(String company, int trend) {} \ No newline at end of file diff --git a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/Components/StockGraph.java b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/Components/StockGraph.java index 15693f8..081e58d 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/Components/StockGraph.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/gruppe42/View/Views/Components/StockGraph.java @@ -89,7 +89,7 @@ public boolean getVisibility() { /** * Sets the visibility. * - * @param value the new value + * @param visible the new value */ public void setVisibility(final boolean visible) { isVisible = visible; diff --git a/src/main/resources/css/desktop.css b/src/main/resources/css/desktop.css index 04f6c5d..f8f6502 100644 --- a/src/main/resources/css/desktop.css +++ b/src/main/resources/css/desktop.css @@ -36,6 +36,6 @@ -fx-cursor: hand; } -.app-button:hover { +.app-button:hover, .app-button:pressed { -fx-background-color: #e0e0e0; }