Skip to content

Commit

Permalink
feat: Style and layout enchancements
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelsa committed May 25, 2026
1 parent e153764 commit a54e919
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public RecieptComponent(Transaction transaction) {
CssUtils.apply(title, CssUtils.BIG_TEXT_32);

Label operation = new Label();
String operationString = "Transaction type: %s, week: %d";
String operationString = "Transaction type: %s";

Label week = new Label(String.format("Week: %s", transaction.getWeek()));

Label shareName = new Label(String.format("Share: %s", transaction.getShare().getStock().toString()));
Label shareAmount = new Label(String.format("Amount: %.3f", transaction.getShare().getQuantity()));
Expand All @@ -60,14 +62,14 @@ public RecieptComponent(Transaction transaction) {

Label profits = new Label();

List<Label> labels = List.of(shareName, operation, shareAmount,
List<Label> labels = List.of(week, shareName, operation, shareAmount,
gross, tax, comission, total, profits);

labels.forEach(l -> CssUtils.apply(l, CssUtils.MED_TEXT_16));

if (transaction instanceof Purchase) {
PurchaseCalculator calc = (PurchaseCalculator) transaction.getCalculator();
operation.setText(String.format(operationString, "Purchase", transaction.getWeek()));
operation.setText(String.format(operationString, "Purchase"));
gross.setText(String.format(grossString, calc.calculateGross()));
tax.setText(String.format(taxString, calc.calculateTax()));
comission.setText(String.format(comissionString, calc.calculateCommision()));
Expand All @@ -91,6 +93,7 @@ public RecieptComponent(Transaction transaction) {
.growWithAlignment(Pos.CENTER)
.addAllContent(title,
operation,
week,
new Label(" "), // Small filler
shareName,
shareAmount,
Expand All @@ -104,6 +107,7 @@ public RecieptComponent(Transaction transaction) {

this.getChildren().add(uiReciept.makeUI());
this.getStyleClass().add("dark");
this.setStyle("-fx-background-radius: 20;");
this.setMaxSize(700, 500);
this.setPrefWidth(700);
StackPane.setAlignment(this, Pos.CENTER);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
package edu.ntnu.idi.idatt.view.components.elements;

import edu.ntnu.idi.idatt.view.components.primitives.ActionEventHandler;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.layout.HBox;

/**
* Searchbar component class.
*
* <p>
* JavaFX Component for handeling repetative tasks.
* Creates a searchbar with search icon.
* Creates a searchbar.
* </p>
*/
public class SearchBarComponent extends HBox {

private final StringProperty query = new SimpleStringProperty();
private final IconComponent searchIcon;
private final SimpleStringProperty query = new SimpleStringProperty();

/**
* Constructor for SearchBarComponent.
Expand All @@ -28,44 +25,26 @@ public class SearchBarComponent extends HBox {
*/
public SearchBarComponent(String placeholder) {

HBox wrapper = new HBox();
wrapper.getStyleClass().add("searchbar");
wrapper.setAlignment(Pos.CENTER);
this.setAlignment(Pos.CENTER);

TextField searchBar = new TextField();
searchBar.getStyleClass().add("searchbar-field");
searchBar.setPromptText(placeholder);
searchBar.setMaxHeight(Double.MAX_VALUE);
searchBar.textProperty().bindBidirectional(query);
searchBar.setFocusTraversable(false);
searchBar.setPadding(new Insets(10));
searchBar.setMinWidth(300);

Image image = new Image(this.getClass().getResource("/icons/search.png").toExternalForm());
searchIcon = new IconComponent(image, null, 32);

wrapper.getChildren().addAll(searchBar, searchIcon);

this.getChildren().addAll(wrapper);
}

/**
* Getter for query content.
* <p>
* Returns the current input of the searchbar.
* </p>
*
* @return String;
*/
public String getQuery() {
return query.get();
this.getChildren().addAll(searchBar);
}

/**
* Method for handeling search icon click.
* Getter for query property.
*
* @param handler - Functional interface.
* @return SimpleStringProperty;
*/
public void onSearchQuery(ActionEventHandler handler) {
this.searchIcon.onIconClick(() -> handler.handle());
public SimpleStringProperty getQuery() {
return query;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package edu.ntnu.idi.idatt.view.components.elements;

import edu.ntnu.idi.idatt.model.portfolio.Share;
import edu.ntnu.idi.idatt.view.components.primitives.ActionEventHandler;
import edu.ntnu.idi.idatt.view.components.ui.UICompositor;
import edu.ntnu.idi.idatt.view.util.CssUtils;
import javafx.geometry.Insets;
Expand Down Expand Up @@ -41,15 +40,15 @@ public ShareComponent(Share share) {

this.setMaxSize(Double.MAX_VALUE, 300);
this.setPadding(new Insets(30));
this.getStyleClass().add("rowBox");
CssUtils.apply(this, CssUtils.GRAY);

Label title = new Label(share.getStock().toString());
Label quantity = new Label("Owned shares: " + share.getQuantity().toString());
Label latestValueLabel = new Label("Net profit:");
Label latestValue = new Label(String.format("%.2f $", share.getProfit()));
Label latestValueChange = new Label(String.format("%.2f %%", share.getProfitPercent()));

sellButton = new Button("Sell");
sellButton = new Button("Sell Share");

List<Label> labels = List.of(title, quantity, latestValueLabel, latestValue, latestValueChange);
labels.forEach(e -> e.getStyleClass().add("portfolio-box-text"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ public TransactionComponent(Transaction transaction) {
this.setPadding(new Insets(40));
this.setAlignment(Pos.TOP_CENTER);

// TODO: CHANGE AND IN STOCKComponent
this.setStyle("-fx-background-color: #404950;");
CssUtils.apply(this, CssUtils.GRAY);

CssUtils.apply(title, CssUtils.BIG_TEXT_32);
CssUtils.apply(name, CssUtils.BIG_TEXT_32);
CssUtils.apply(name, CssUtils.MED_TEXT_24);
List<Label> labels = List.of(totalValue, taxComissionValue, grossValue, amountOfShares, saleProfit);
labels.forEach(l -> CssUtils.apply(l, CssUtils.MED_TEXT_16));

Expand Down
Loading

0 comments on commit a54e919

Please sign in to comment.