Skip to content

Commit

Permalink
Feat: Attempt at Navbar component with dedicated fxml
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Apr 15, 2026
1 parent 484bcd3 commit ddc77eb
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 98 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ntnu.systemutvikling.team6.controller.components;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;

public class NavbarController extends BaseController {
@FXML protected TextField frontSearchField;
@FXML private Button loginButton;
@FXML private Button profileButton;

@Override
protected void authTokenisSet() {
boolean loggedIn = super.isLoggedin();
if (loggedIn){
loginButton.setVisible(false);
loginButton.setManaged(false);
profileButton.setVisible(true);
profileButton.setManaged(true);
profileButton.setText(authToken.getCurrentUser().getDisplayName().substring(0,2));
} else {
loginButton.setVisible(true);
loginButton.setManaged(true);
profileButton.setVisible(false);
profileButton.setManaged(false);
}

}
@FXML
private void handleFrontSearch(ActionEvent event){
String query = frontSearchField.getText().trim();

if (query.isEmpty()) {
return;
}

LoaderScene.LoadScene("availableOrganization", event, null, query);
}

@FXML
private void switchToFrontPage(ActionEvent event) {
System.out.println("Click!");
LoaderScene.LoadScene("FrontPage", event, null, null);
}

@FXML
private void switchToProfilePage(ActionEvent event) {
System.out.println("Click!");
LoaderScene.LoadScene("aboutPage", event, null, null);
}

@FXML
private void switchToLoginPage(ActionEvent event) {
System.out.println("Click!");
LoaderScene.LoadScene("aboutPage", event, null, null);
}
}

This file was deleted.

111 changes: 46 additions & 65 deletions helpmehelpapplication/src/main/resources/fxml/components/navbar.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -12,78 +12,59 @@
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.RowConstraints?>

<GridPane style="-fx-background-color: #2f8f8b;" xmlns="http://javafx.com/javafx/25" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ntnu.systemutvikling.team6.controller.components.NavbarFooterController">
<?import javafx.scene.Cursor?>
<?import javafx.scene.shape.Rectangle?>
<GridPane HBox.hgrow="ALWAYS" style="-fx-background-color: #2f8f8b;" xmlns="http://javafx.com/javafx/25" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ntnu.systemutvikling.team6.controller.components.NavbarController">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" percentWidth="33.3333" />
<ColumnConstraints hgrow="ALWAYS" percentWidth="33.3333" />
<ColumnConstraints hgrow="ALWAYS" percentWidth="33.3333" />
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0" percentWidth="30.0" prefWidth="100.0" />
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0" percentWidth="30.0" prefWidth="100.0" />
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>

<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<!-- Venstre: logo + navn -->
<HBox alignment="CENTER_LEFT" spacing="12.0">
<padding>
<Insets left="14.0" />
</padding>
<children>
<Button mnemonicParsing="false" onAction="#switchToFrontPage" style="-fx-background-color: transparent; -fx-padding: 0;">
<graphic>
<ImageView fitHeight="42.0" fitWidth="56.0" preserveRatio="true">
<image>
<Image url="@../../images/Logo.png" />
</image>
</ImageView>
</graphic>
</Button>
<ImageView fitHeight="54.0" fitWidth="67.0" pickOnBounds="true" preserveRatio="true" translateX="10.0">
<image>
<Image url="@../../images/Logo.png" />
</image>
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</ImageView>
<Label text="Help" textFill="WHITE" translateX="100.0">
<font>
<Font name="System Bold" size="20.0" />
</font>
</Label>
<Label text="Me" textFill="#c8e6c9" translateX="145.0">
<font>
<Font name="System Bold" size="20.0" />
</font>
</Label>
<Label text="Help" textFill="WHITE" translateX="176.0">
<font>
<Font name="System Bold" size="20.0" />
</font>
</Label>

<HBox alignment="CENTER_LEFT" spacing="0.0">
<StackPane prefHeight="150.0" prefWidth="200.0" GridPane.columnIndex="1">
<children>
<TextField minHeight="-Infinity" prefWidth="200.0" promptText="Search" style="-fx-background-radius: 15;" fx:id="frontSearchField" onAction="#handleFrontSearch" />
<HBox fx:id="authBox" alignment="CENTER_RIGHT" GridPane.columnIndex="2" translateX="132">
<padding><Insets right="20.0" /></padding>
<children>
<Label style="-fx-text-fill: #FFFFFF;" text="Help" textFill="WHITE">
<font>
<Font name="System Bold" size="19.0" />
</font>
</Label>
<Label style="-fx-text-fill: #C8E6C9;" text="Me" textFill="#c8e6c9">
<font>
<Font name="System Bold" size="19.0" />
</font>
</Label>
<Label style="-fx-text-fill: #FFFFFF;" text="Help" textFill="WHITE">
<font>
<Font name="System Bold" size="19.0" />
</font>
</Label>
<Button fx:id="loginButton" text="Login"
onAction="#switchToLoginPage"
prefHeight="34.0" prefWidth="120.0"
style="-fx-background-color: #1F4FD8; -fx-text-fill: white; -fx-background-radius: 17; -fx-font-weight: bold;" />
<Button fx:id="profileButton" onAction="#switchToProfilePage"
visible="false" managed="false"
style="-fx-background-color: transparent;">
</Button>
</children>
</HBox>
</children>
</HBox>

<!-- Midten: search -->
<StackPane alignment="CENTER" GridPane.columnIndex="1">
<children>
<TextField fx:id="donationSearchField" onAction="#handleSearch" prefHeight="34.0" prefWidth="360.0" promptText="Search" style="-fx-background-color: white; -fx-background-radius: 17; -fx-border-radius: 17; -fx-padding: 0 12 0 12;" />
</children>
</StackPane>

<!-- Høyre: login -->
<HBox alignment="CENTER_RIGHT" GridPane.columnIndex="2">
<padding>
<Insets right="20.0" />
</padding>
<children>
<Button fx:id="loginButton" text="Login"
onAction="#switchToLoginPage"
prefHeight="34.0" prefWidth="120.0"
style="-fx-background-color: #1F4FD8; -fx-text-fill: white; -fx-background-radius: 17; -fx-font-weight: bold;" />
<Button fx:id="profileButton" onAction="#switchToProfilePage"
visible="false" managed="false"
style="-fx-background-color: white;">
</Button>
</children>
</HBox>

</children>
<rowConstraints>
<RowConstraints />
</rowConstraints>
</GridPane>
</GridPane>

0 comments on commit ddc77eb

Please sign in to comment.