Work on SettingsWindow and Server

This commit is contained in:
bryce
2024-11-03 21:40:40 +13:00
parent 58f3773392
commit 8a5488f331
16 changed files with 194 additions and 27 deletions

View File

@@ -25,6 +25,11 @@
<artifactId>javafx-fxml</artifactId> <artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version> <version>${javafx.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>${javafx.version}</version> <!-- Update to the JavaFX version you are using -->
</dependency>
<!-- Other dependencies can be added here as needed --> <!-- Other dependencies can be added here as needed -->
</dependencies> </dependencies>

View File

@@ -131,7 +131,7 @@ public class MainLayout extends BorderPane {
this.setCenter(galleryLayout); this.setCenter(galleryLayout);
} }
private void switchToSettingsLayout() { private void switchToSettingsLayout() {
SettingsLayout settingsLayout = new SettingsLayout(); SettingsWindow settingsLayout = new SettingsWindow();
this.setCenter(settingsLayout); this.setCenter(settingsLayout);
} }
} }

View File

@@ -1,26 +0,0 @@
package com.example.bricklog.view;
import javafx.geometry.Insets;
//import javafx.geometry.Pos;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
public class SettingsLayout extends VBox {
public SettingsLayout() {
this.setSpacing(10);
this.setPadding(new Insets(20));
Label settingsTitle = new Label("Settings");
settingsTitle.setStyle("-fx-font-size: 20px; -fx-font-weight: bold;");
// Example settings: toggle for sound, username input
CheckBox soundToggle = new CheckBox("Enable Sound");
TextField usernameField = new TextField();
usernameField.setPromptText("Enter your username");
this.getChildren().addAll(settingsTitle, soundToggle, usernameField);
}
}

View File

@@ -0,0 +1,118 @@
package com.example.bricklog.view;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import static javafx.scene.paint.Color.WHITE;
import javafx.scene.text.Font;
public class SettingsWindow extends BorderPane {
private final StackPane contentPane;
private final VBox generalSettings;
private final VBox serverSettings;
private final Label connectionStatus;
public SettingsWindow() {
// Menu on the left side for navigation
VBox menu = new VBox();
menu.setSpacing(10);
menu.setPadding(new Insets(10));
menu.setStyle("-fx-background-color: #f0f0f0;");
// Labels for the menu
Label generalLabel = new Label("General");
generalLabel.setStyle("-fx-font-weight: bold; cursor: hand;");
generalLabel.setOnMouseClicked(event -> showGeneralSettings());
Label serverLabel = new Label("Server");
serverLabel.setStyle("-fx-font-weight: bold; cursor: hand;");
serverLabel.setOnMouseClicked(event -> showServerSettings());
menu.getChildren().addAll(generalLabel, serverLabel);
this.setLeft(menu);
// StackPane to hold different settings panels
contentPane = new StackPane();
this.setCenter(contentPane);
// Define General Settings panel
generalSettings = new VBox(10);
generalSettings.setPadding(new Insets(15));
generalSettings.setAlignment(Pos.TOP_LEFT);
Label themeLabel = new Label("Theme:");
CheckBox darkTheme = new CheckBox("Dark Theme");
Label layoutLabel = new Label("Layout:");
CheckBox compactLayout = new CheckBox("Compact Layout");
generalSettings.getChildren().addAll(themeLabel, darkTheme, layoutLabel, compactLayout);
// Define Server Settings panel
serverSettings = new VBox(10);
serverSettings.setPadding(new Insets(15));
serverSettings.setAlignment(Pos.TOP_LEFT);
// Connection Status Label
connectionStatus = new Label("Server Status: Not Connected");
connectionStatus.setFont(new Font("Arial", 14));
connectionStatus.setTextFill(WHITE);
connectionStatus.setStyle("-fx-background-color: lightpink; -fx-padding: 5;");
connectionStatus.setAlignment(Pos.CENTER);
connectionStatus.setMaxWidth(Double.MAX_VALUE);
// Server IP field & Connect button
Label ipLabel = new Label("Server IP:");
TextField ipField = new TextField();
ipField.setPromptText("Enter server IP address...");
Button connectButton = new Button("Connect");
connectButton.setOnAction(event -> connectToServer(ipField.getText()));
serverSettings.getChildren().addAll(connectionStatus, ipLabel, ipField, connectButton);
// Add panels to contentPane and show the default panel
contentPane.getChildren().addAll(generalSettings, serverSettings);
showGeneralSettings(); // Default to showing the general settings
}
// Method to show the General Settings panel
private void showGeneralSettings() {
generalSettings.setVisible(true);
generalSettings.toFront();
serverSettings.setVisible(false);
}
// Method to show the Server Settings panel
private void showServerSettings() {
serverSettings.setVisible(true);
serverSettings.toFront();
generalSettings.setVisible(false);
}
// Method to connect to the server
private void connectToServer(String ipAddress) {
boolean isConnected = simulateServerConnection(ipAddress); // Replace with real connection logic
if (isConnected) {
connectionStatus.setText("Connected");
connectionStatus.setStyle("-fx-background-color: lightgreen; -fx-padding: 5;");
} else {
connectionStatus.setText("Not Connected");
connectionStatus.setStyle("-fx-background-color: lightpink; -fx-padding: 5;");
}
}
// Simulated connection logic for demonstration purposes
private boolean simulateServerConnection(String ipAddress) {
// Here, add logic for real server connection. For now, a simple placeholder:
return !ipAddress.isEmpty() && ipAddress.equals("127.0.0.1");
}
}

View File

@@ -1,3 +1,4 @@
com\example\bricklog\BrickLogClientApplication.class com\example\bricklog\BrickLogClientApplication.class
com\example\bricklog\view\MainLayout.class com\example\bricklog\view\MainLayout.class
com\example\bricklog\view\SettingsWindow.class
com\example\bricklog\view\GalleryLayout.class com\example\bricklog\view\GalleryLayout.class

View File

@@ -0,0 +1,19 @@
-- Create a new database called 'bricklog_db'
CREATE DATABASE bricklog_db
GO
-- Grant Permissions & Flush
GRANT ALL PERMISSIONS TO bl_server IDENTIFIED BY l3g0D3t41l$h3r3
GO
-- Create a new table called 'collection_table' in schema 'bricklog_db'
-- Create the table in the specified schema
CREATE TABLE lego_builds (
id INT NOT NULL PRIMARY KEY, -- Lego Build ID can be used here (hence not Auto_increment)
builder VARCHAR(255) NOT NULL,
buildName VARCHAR(255) NOT NULL,
is_kitset BOOLEAN NOT NULL,
buildDescription VARCHAR(1000) NOT NULL,
record_created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
GO

View File

@@ -0,0 +1,7 @@
sql/
target/
*.log
*.class
.idea/
*.iml
*.DS_Store

View File

@@ -0,0 +1,14 @@
# Use a base image that includes JDK
FROM openjdk:21-jdk-slim
# Set the working directory
WORKDIR /app
# Copy the built JAR file into the container
COPY target/BrickLog-Server-0.1.jar app.jar
# Expose the port your application runs on
EXPOSE 8080
# Command to run the application
ENTRYPOINT ["java", "-jar", "app.jar"]

View File

@@ -0,0 +1,29 @@
version: '0.1'
services:
bricklog-server:
build:
context: ./BrickLog-Server
dockerfile: Dockerfile
ports:
- "8080:8080" # Adjust based on your server's port
environment:
- SPRING_DATASOURCE_URL=jdbc:mariadb://db:3306/bricklog
- SPRING_DATASOURCE_USERNAME=bl_server
- SPRING_DATASOURCE_PASSWORD=l3g0D3t41l$h3r3
depends_on:
- db # Ensure the database starts before the server
db:
image: mysql:8.0
restart: always
environment:
MYSQL_DATABASE: bricklog
MYSQL_ROOT_PASSWORD: root # Set a strong password in production
ports:
- "3306:3306" # Expose MySQL port
volumes:
- db_data:/var/lib/mysql # Persist database data
volumes:
db_data: