Added status panel and adjusted layout of main frame panels.
This commit is contained in:
@@ -22,6 +22,13 @@ public final class GUIConstants {
|
||||
ConnectToServerPanel
|
||||
}
|
||||
|
||||
public static enum Status {
|
||||
Connected,
|
||||
Connecting,
|
||||
Disconnected,
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents kinds of themes.
|
||||
*/
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
*/
|
||||
package gui.src.frames;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.*;
|
||||
|
||||
import data.src.ControllerToView.ControllerToViewData;
|
||||
import data.src.ControllerToView.ControllerToViewData.ControllerEvent;
|
||||
import gui.src.constants.GUIConstants;
|
||||
import gui.src.constants.GUIConstants.Panel;
|
||||
import gui.src.constants.GUIConstants.Theme;
|
||||
import gui.src.interfaces.Themeable;
|
||||
@@ -16,28 +16,22 @@ import gui.src.menubar.MenuBar;
|
||||
import gui.src.panels.ControllingPanel;
|
||||
import gui.src.panels.MonitoringPanel;
|
||||
import gui.src.panels.ConnectToServerPanel.ConnectToServerPanel;
|
||||
import gui.src.panels.StatusPanel;
|
||||
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.*;
|
||||
|
||||
public final class MainFrame extends JFrame implements Themeable {
|
||||
|
||||
private static MainFrame instance;
|
||||
|
||||
private MainFrame() {
|
||||
|
||||
this.setTitle("Firewall Dashboard");
|
||||
|
||||
this.setJMenuBar(MenuBar.getMenuBar());
|
||||
|
||||
this.setPanel(Panel.ConnectToServerPanel);
|
||||
|
||||
this.setSize(800, 400);
|
||||
|
||||
this.setLocation(300, 200);
|
||||
|
||||
this.setSize(1400, 700);
|
||||
this.setMinimumSize(new Dimension(700, 500));
|
||||
this.setLocation(100, 100);
|
||||
this.setVisible(true);
|
||||
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
}
|
||||
|
||||
@@ -49,21 +43,31 @@ public final class MainFrame extends JFrame implements Themeable {
|
||||
}
|
||||
|
||||
private void setPanel(JPanel panel) {
|
||||
this.setLayout(new GridBagLayout());
|
||||
this.getContentPane().removeAll();
|
||||
this.getContentPane().setLayout(new GridBagLayout());
|
||||
|
||||
GridBagConstraints constraints = new GridBagConstraints();
|
||||
// Status Panel
|
||||
GridBagConstraints statusConstraints = new GridBagConstraints();
|
||||
statusConstraints.gridx = 0;
|
||||
statusConstraints.gridy = 0;
|
||||
statusConstraints.anchor = GridBagConstraints.NORTHWEST;
|
||||
statusConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||||
statusConstraints.weightx = 1;
|
||||
statusConstraints.insets = new Insets(5,5,0,0);
|
||||
this.getContentPane().add(StatusPanel.getInstance(), statusConstraints);
|
||||
|
||||
constraints.gridwidth = 1;
|
||||
constraints.gridheight = 1;
|
||||
// Main Panel
|
||||
GridBagConstraints mainConstraints = new GridBagConstraints();
|
||||
mainConstraints.gridx = 0;
|
||||
mainConstraints.gridy = 2;
|
||||
mainConstraints.anchor = GridBagConstraints.CENTER;
|
||||
mainConstraints.weighty = 0.1;
|
||||
this.getContentPane().add(panel, mainConstraints);
|
||||
|
||||
constraints.gridx = 0;
|
||||
constraints.gridy = 0;
|
||||
|
||||
constraints.anchor = GridBagConstraints.CENTER;
|
||||
|
||||
this.add(panel, constraints);
|
||||
this.update(this.getGraphics());
|
||||
}
|
||||
|
||||
|
||||
public void setPanel(Panel kindOfPanel) {
|
||||
try {
|
||||
switch (kindOfPanel) {
|
||||
@@ -110,6 +114,8 @@ public final class MainFrame extends JFrame implements Themeable {
|
||||
switch (controllerEvent) {
|
||||
case ConnectToServerWasSuccessful: {
|
||||
ConnectToServerPanel.getInstance().enableFields();
|
||||
StatusPanel.getInstance().setStatus(GUIConstants.Status.Connected);
|
||||
this.setPanel(Panel.MonitoringPanel);
|
||||
}break;
|
||||
default: {
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
/**
|
||||
* @author Aaron Moser
|
||||
* @date 03.12.2023
|
||||
*/
|
||||
package gui.src.panels.ConnectToServerPanel;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import data.src.ControllerToView.ControllerToViewData;
|
||||
import data.src.ControllerToView.ControllerToViewData.ControllerEvent;
|
||||
import data.src.ViewToController.ConnectToServerData;
|
||||
import data.src.ViewToController.ViewToControllerData;
|
||||
import data.src.ViewToController.ViewToControllerData.ViewEvent;
|
||||
import gui.src.constants.GUIConstants.Panel;
|
||||
import gui.src.frames.MainFrame;
|
||||
import queues.src.ControllerToViewQueue;
|
||||
import queues.src.ViewToControllerQueue;
|
||||
|
||||
public class ConnectToServerButtonListener implements ActionListener {
|
||||
|
||||
private JTextField ipAddressTextField;
|
||||
private JTextField portTextField;
|
||||
|
||||
public ConnectToServerButtonListener(JTextField ipAddressTextField, JTextField portTextField) {
|
||||
this.ipAddressTextField = ipAddressTextField;
|
||||
this.portTextField = portTextField;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println("Connect to server button was pressed.");
|
||||
|
||||
ConnectToServerPanel.getInstance().disableFields();
|
||||
|
||||
// Reads in fields text
|
||||
String ipAddress = this.ipAddressTextField.getText();
|
||||
int port = Integer.valueOf(this.portTextField.getText());
|
||||
|
||||
String trustStorePath = "cacerts";
|
||||
String trustStorePassword = "qwerty";
|
||||
|
||||
// Sends data to queue
|
||||
ViewToControllerQueue.getInstance().add(new ConnectToServerData(
|
||||
ipAddress,
|
||||
port,
|
||||
trustStorePath,
|
||||
trustStorePassword
|
||||
));
|
||||
}
|
||||
}
|
||||
52
src/main/java/gui/src/panels/StatusPanel.java
Normal file
52
src/main/java/gui/src/panels/StatusPanel.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* @author Aaron Moser
|
||||
* @date 09.12.2023
|
||||
*/
|
||||
package gui.src.panels;
|
||||
|
||||
import gui.src.constants.GUIConstants;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class StatusPanel extends JPanel {
|
||||
private static StatusPanel instance;
|
||||
private final JLabel statusLabel;
|
||||
|
||||
private StatusPanel() {
|
||||
this.statusLabel = new JLabel("Status: Disconnected");
|
||||
|
||||
this.setLayout(new GridBagLayout());
|
||||
|
||||
GridBagConstraints gridBagConstraints = new GridBagConstraints();
|
||||
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
||||
gridBagConstraints.weightx = 1;
|
||||
gridBagConstraints.weighty = 1;
|
||||
gridBagConstraints.insets = new Insets(0, 0, 0, 0);
|
||||
this.add(this.statusLabel, gridBagConstraints);
|
||||
}
|
||||
|
||||
public static StatusPanel getInstance() {
|
||||
if (null == instance) {
|
||||
instance = new StatusPanel();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void setStatus(GUIConstants.Status status) {
|
||||
switch (status) {
|
||||
case GUIConstants.Status.Connected: {
|
||||
this.statusLabel.setText("Status: " + "Connected");
|
||||
}break;
|
||||
case GUIConstants.Status.Connecting: {
|
||||
this.statusLabel.setText("Status: " + "Connecting");
|
||||
}break;
|
||||
case GUIConstants.Status.Disconnected: {
|
||||
this.statusLabel.setText("Status: " + "Disconnected");
|
||||
}break;
|
||||
default: {
|
||||
|
||||
}break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user