aboutsummaryrefslogtreecommitdiff
path: root/src/UI/Components/LoginPanel.java
blob: 9950706d91d6b20d9ed4d7de8a2619c62bb06cab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package UI.Components;

import UI.MainWindow;
import UI.SettingsPopupWindow;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;

public class LoginPanel extends JPanel {
    public JButton loginButton;
    public JButton signUpButton;
    public JLabel statusLabel;
    private SettingsPopupWindow settingsPopupWindow;

    public InputBox usernameInput;
    public InputBox passwordInput;

    public LoginPanel() {
        statusLabel = new JLabel();

        usernameInput = new InputBox("Username:");
        usernameInput.setBorder(new EmptyBorder(140, 100, 0, 100));
        this.add(usernameInput);

        passwordInput = new InputBox("Password:");
        passwordInput.setBorder(new EmptyBorder(10, 100, 10, 100));
        this.add(passwordInput);

        JPanel buttonPanel = new JPanel();

        JButton settingsButton = new JButton("Settings");
        settingsButton.addActionListener(_ -> {
            if (settingsPopupWindow == null) {
                settingsPopupWindow = new SettingsPopupWindow();
                settingsPopupWindow.saveButton.addActionListener(_ -> {
                    MainWindow.url = settingsPopupWindow.hostnameInput.getValue();
                    settingsPopupWindow.setVisible(false);
                });
            }

            settingsPopupWindow.hostnameInput.setValue(MainWindow.url);

            settingsPopupWindow.setVisible(true);
        });
        buttonPanel.add(settingsButton);

        buttonPanel.add(Box.createRigidArea(new Dimension(90, 0)));

        signUpButton = new JButton("Sign Up");
        buttonPanel.add(signUpButton);

        buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));

        loginButton = new JButton("Login");
        buttonPanel.add(loginButton);

        buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
        this.add(buttonPanel);

        this.add(Box.createRigidArea(new Dimension(600, 0)));
        this.add(statusLabel);

        this.setMaximumSize(new Dimension(350, 200));
    }
}