Created some subfolders for better structure, added buttons to status panel to switch between monitoring and controlling panel.

This commit is contained in:
WickedJack99
2023-12-30 17:38:25 +01:00
parent d7c40c6c2a
commit 50e27c362c
6 changed files with 152 additions and 57 deletions

View File

@@ -3,7 +3,7 @@
* @date 31.10.2023
*/
package gui.src.panels;
package gui.src.panels.ControllingPanel;
import javax.swing.JPanel;

View File

@@ -1,52 +0,0 @@
/**
* @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;
}
}
}

View File

@@ -0,0 +1,39 @@
/**
* @author Aaron Moser
* @date 30.12.2023
* @lastChange 30.12.2023
*/
package gui.src.panels.StatusPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import gui.src.constants.GUIConstants.Panel;
import gui.src.frames.MainFrame;
public class ControllingButton extends JButton implements ActionListener {
private static ControllingButton instance = null;
private ControllingButton() {
this.setText("Controlling");
this.addActionListener(this);
}
public static ControllingButton getInstance() {
if (instance == null) {
instance = new ControllingButton();
}
return instance;
}
@Override
public void actionPerformed(ActionEvent e) {
this.setEnabled(false);
MonitoringButton.getInstance().setEnabled(true);
MainFrame.getInstance().setPanel(Panel.ControllingPanel);
}
}

View File

@@ -0,0 +1,39 @@
/**
* @author Aaron Moser
* @date 30.12.2023
* @lastChange 30.12.2023
*/
package gui.src.panels.StatusPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import gui.src.constants.GUIConstants.Panel;
import gui.src.frames.MainFrame;
public class MonitoringButton extends JButton implements ActionListener {
private static MonitoringButton instance = null;
private MonitoringButton() {
this.setText("Monitoring");
this.addActionListener(this);
}
public static MonitoringButton getInstance() {
if (instance == null) {
instance = new MonitoringButton();
}
return instance;
}
@Override
public void actionPerformed(ActionEvent e) {
this.setEnabled(false);
ControllingButton.getInstance().setEnabled(true);
MainFrame.getInstance().setPanel(Panel.MonitoringPanel);
}
}

View File

@@ -0,0 +1,73 @@
/**
* @author Aaron Moser
* @date 09.12.2023
* @lastChange 30.12.2023
*/
package gui.src.panels.StatusPanel;
import gui.src.constants.GUIConstants;
import javax.swing.*;
import java.awt.*;
public class StatusPanel extends JPanel {
private static StatusPanel instance;
private final JPanel flowPanel;
private final JLabel statusLabel;
private final JButton monitoringButton;
private final JButton controllingButton;
private StatusPanel() {
this.statusLabel = new JLabel("Status: Disconnected");
this.monitoringButton = MonitoringButton.getInstance();
this.controllingButton = ControllingButton.getInstance();
this.monitoringButton.setVisible(false);
this.controllingButton.setVisible(false);
this.flowPanel = new JPanel();
this.flowPanel.setLayout(new FlowLayout());
this.flowPanel.add(this.statusLabel);
this.flowPanel.add(this.monitoringButton);
this.flowPanel.add(this.controllingButton);
GridBagConstraints flowPanelConstraints = new GridBagConstraints();
flowPanelConstraints.anchor = GridBagConstraints.WEST;
flowPanelConstraints.weightx = 1;
flowPanelConstraints.weighty = 1;
flowPanelConstraints.insets = new Insets(0, 0, 0, 0);
this.setLayout(new GridBagLayout());
this.add(this.flowPanel, flowPanelConstraints);
}
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");
this.monitoringButton.setVisible(true);
this.controllingButton.setVisible(true);
this.monitoringButton.setEnabled(false);
}break;
case GUIConstants.Status.Connecting: {
this.statusLabel.setText("Status: " + "Connecting");
}break;
case GUIConstants.Status.Disconnected: {
this.statusLabel.setText("Status: " + "Disconnected");
this.monitoringButton.setVisible(false);
this.controllingButton.setVisible(false);
}break;
default: {
}break;
}
}
}

View File

@@ -43,8 +43,4 @@ public class NetworkModel {
}//break;
}
}
public void clearConnections() {
}
}