This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/src/main/java/envoy/client/ui/SettingsScreen.java

157 lines
4.8 KiB
Java

package envoy.client.ui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
/**
* Project: <strong>envoy-client</strong><br>
* File: <strong>SettingsScreen.java</strong><br>
* Created: <strong>31 Oct 2019</strong><br>
*
* @author Leon Hofmeister
*/
public class SettingsScreen extends JDialog {
private static final long serialVersionUID = -4476913491263077107L;
private final JPanel contentPanel = new JPanel();
public static boolean enterToSend = true;
// TODO: Add a JPanel with all the Information necessary:
// change (Picture,Username, Email, Password) and toggle(light/dark mode,
// "ctrl+enter"/"enter"
// to send a message directly)
/**
* Open the Settings screen.
* Only suited for Dev/Error mode.
* Avoid usage.
*
* @since Envoy v0.1-alpha
*/
public static void open() { open(new SettingsScreen()); }
/**
* Opens the Settings screen.<br>
* Use preferably since everyone is already initialised.<br>
* It personalises the screen more.
*
* @param username The name of the User
* @param Email The Email that is associated with that Account
* @since Envoy v0.1-alpha
*/
public static void open(String username) {// , String Email) {AUSKLAMMERN, WENN ANMELDUNG PER
// EMAIL IMPLEMENTIERT IST!
open(new SettingsScreen(username));
}
public static void open(SettingsScreen dialog) {
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setModal(true);
dialog.setVisible(true);
}
/**
* Builds the Settings screen.<br>
* Use only as Dev/Error Mode.<br>
* Avoid usage.
*
* @since Envoy v0.1-alpha
*/
public SettingsScreen() {
setBackground(Color.BLACK);
setBounds(100, 100, 450, 300);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBackground(Color.BLACK);
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(new BorderLayout(0, 0));
{
JPanel buttonPane = new JPanel();
buttonPane.setBackground(Color.BLACK);
getContentPane().add(buttonPane, BorderLayout.SOUTH);
buttonPane.setLayout(new BorderLayout(0, 0));
{
JButton okButton = new JButton("Save");
okButton.setActionCommand("OK");
buttonPane.add(okButton, BorderLayout.EAST);
getRootPane().setDefaultButton(okButton);
okButton.addActionListener((evt) -> {
// Hier später die Daten abspeichern, wenn Datenmodell implementiert ist
dispose();
});
}
{
JButton cancelButton = new JButton("Cancel");
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton, BorderLayout.WEST);
cancelButton.addActionListener((evt) -> { dispose(); });
}
}
}
/**
* Builds the Settings screen.<br>
* Use preferreably since everyone is already initialised.<br>
* It personalises the screen more.
*
* @param Username The name of the User
* @param Email The Email that is associated with that Account
* @since Envoy v0.1-alpha
*/
public SettingsScreen(String Username) {// , String Email, String hashedPwd) {AUSKLAMMERN, WENN ANMELDUNG PER EMAIL
// IMPLEMENTIERT IST!
setBackground(Color.BLACK);
setBounds(100, 100, 450, 300);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBackground(Color.BLACK);
contentPanel.setLayout(new FlowLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
{
JPanel buttonPane = new JPanel();
buttonPane.setBackground(Color.BLACK);
getContentPane().add(buttonPane, BorderLayout.SOUTH);
buttonPane.setLayout(new BorderLayout(0, 0));
{
JButton okButton = new JButton("Save");
okButton.setActionCommand("OK");
buttonPane.add(okButton, BorderLayout.EAST);
getRootPane().setDefaultButton(okButton);
okButton.addActionListener((evt) -> {
// Hier später die Daten abspeichern, wenn Datenmodell implementiert ist
dispose();
});
}
{
JButton cancelButton = new JButton("Cancel");
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton, BorderLayout.WEST);
cancelButton.addActionListener((evt) -> { dispose(); });
}
}
}
/**
* @return true if Enter should be used to send a message instead of ctrl+enter
* @since Envoy v0.1-alpha
*/
public static boolean isEnterToSend() { return enterToSend; }
/**
* @param enterToSend <br>
* toggles whether a message should be sent via
* <br>
* buttonpress "enter" or "ctrl"+"enter"
* @since Envoy v0.1-alpha
*/
public static void setEnterToSend(boolean enterForSend) { enterToSend = enterForSend; }
// TODO: Should be changed to private, but later to avoid warnings
}