137 lines
4.7 KiB
Java
137 lines
4.7 KiB
Java
package envoy.client.ui;
|
|
|
|
import java.awt.BorderLayout;
|
|
import java.awt.FlowLayout;
|
|
import java.awt.GridBagConstraints;
|
|
import java.awt.GridBagLayout;
|
|
import java.awt.Insets;
|
|
|
|
import javax.swing.JButton;
|
|
import javax.swing.JDialog;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.border.EmptyBorder;
|
|
|
|
import envoy.client.Settings;
|
|
|
|
/**
|
|
* This class provides the GUI to change the user specific settings.
|
|
*
|
|
* 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();
|
|
private JPanel buttonPane = new JPanel();
|
|
private JButton okButton = new JButton("Save");
|
|
private JButton cancelButton = new JButton("Cancel");
|
|
private static int space = 5;
|
|
private static SettingsScreen settingsScreen;
|
|
|
|
// 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)
|
|
|
|
/**
|
|
* Opens the settings screen.<br>
|
|
*
|
|
* @since Envoy v0.1-alpha
|
|
*/
|
|
public static void open() {
|
|
|
|
UIColors.getInstance(Settings.getInstance().isDarkMode());
|
|
settingsScreen = new SettingsScreen();
|
|
settingsScreen.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
|
settingsScreen.setModal(true);
|
|
settingsScreen.setVisible(true);
|
|
}
|
|
|
|
/**
|
|
* Builds the settings screen.<br>
|
|
*
|
|
* @since Envoy v0.1-alpha
|
|
*/
|
|
private SettingsScreen() {
|
|
|
|
setBounds(100, 100, 450, 300);
|
|
getContentPane().setLayout(new BorderLayout());
|
|
contentPanel.setLayout(new FlowLayout());
|
|
contentPanel.setBorder(new EmptyBorder(space, space, space, space));
|
|
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
|
{
|
|
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
|
GridBagLayout gbl_buttonPane = new GridBagLayout();
|
|
gbl_buttonPane.columnWidths = new int[] { 100, 250, 100, 0 };
|
|
gbl_buttonPane.rowHeights = new int[] { 25, 0 };
|
|
gbl_buttonPane.columnWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE };
|
|
gbl_buttonPane.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
|
|
buttonPane.setLayout(gbl_buttonPane);
|
|
{
|
|
cancelButton.setActionCommand("Cancel");
|
|
GridBagConstraints gbc_cancelButton = new GridBagConstraints();
|
|
gbc_cancelButton.anchor = GridBagConstraints.NORTHWEST;
|
|
gbc_cancelButton.insets = new Insets(space, space, space, space);
|
|
gbc_cancelButton.gridx = 0;
|
|
gbc_cancelButton.gridy = 0;
|
|
buttonPane.add(cancelButton, gbc_cancelButton);
|
|
|
|
cancelButton.addActionListener((evt) -> { dispose(); });
|
|
}
|
|
{
|
|
okButton.setActionCommand("OK");
|
|
GridBagConstraints gbc_okButton = new GridBagConstraints();
|
|
gbc_okButton.anchor = GridBagConstraints.NORTHEAST;
|
|
gbc_okButton.fill = GridBagConstraints.EAST;
|
|
gbc_okButton.insets = new Insets(space, space, space, space);
|
|
gbc_okButton.gridx = 2;
|
|
gbc_okButton.gridy = 0;
|
|
buttonPane.add(okButton, gbc_okButton);
|
|
getRootPane().setDefaultButton(okButton);
|
|
okButton.addActionListener((evt) -> {
|
|
try {
|
|
Settings.getInstance().setUsername(Settings.getInstance().getUsername());// still temporary
|
|
// value
|
|
Settings.getInstance().setEmail(Settings.getInstance().getEmail());// still temporary value
|
|
Settings.getInstance().setDarkMode(!Settings.getInstance().isDarkMode());// TODO temporary
|
|
// values while no
|
|
// UI is implemented
|
|
Settings.getInstance().setEnterToSend(Settings.getInstance().isEnterToSend());// still temporary
|
|
// value
|
|
Settings.getInstance().save();
|
|
UIColors.getUIColors().setDisplayMode(Settings.getInstance().isDarkMode());
|
|
changeSettingsScreenColors();
|
|
revalidate();
|
|
repaint();
|
|
} catch (Exception e) {
|
|
System.err.println("Something went wrong when changing the setting");
|
|
settingsScreen.dispose();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
changeSettingsScreenColors();
|
|
}
|
|
|
|
private void changeSettingsScreenColors() {
|
|
// whole JDialog
|
|
setBackground(UIColors.getUIColors().getBackgroundColor());
|
|
// contentPanel
|
|
contentPanel.setBackground(UIColors.getUIColors().getBackgroundColor());
|
|
// buttonPane
|
|
buttonPane.setBackground(UIColors.getUIColors().getBackgroundColor());
|
|
// cancelButton
|
|
cancelButton.setBackground(UIColors.getUIColors().getSpecialUseColor());
|
|
cancelButton.setForeground(UIColors.getUIColors().getTextColor());
|
|
// okButton
|
|
okButton.setBackground(UIColors.getUIColors().getSpecialUseColor());
|
|
okButton.setForeground(UIColors.getUIColors().getTextColor());
|
|
|
|
}
|
|
|
|
}
|