package com.github.noxan.aves.demo.chat;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.UIManager;

import layout.TableLayout;

public class ChatClientGUI {
    private JFrame frame;
    private JPanel cards;

    public ChatClientGUI(ChatClient client) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch(Exception e) {
        }

        frame = new JFrame();
        frame.setTitle("aves - chatclient");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        cards = new JPanel(new CardLayout());
        cards.add(new ConnectPanel(client), "connect");

        frame.add(cards, BorderLayout.CENTER);

        frame.setSize(320, 680);
        frame.setLocationByPlatform(true);
        frame.setVisible(true);
    }

    private class ConnectPanel extends JPanel {
        private static final long serialVersionUID = -8154588851543816456L;

        private ChatClient client;

        private JButton connectButton;

        public ConnectPanel(ChatClient client) {
            this.client = client;
            setLayout(new TableLayout(new double[][] { { TableLayout.FILL, 0.5f, TableLayout.FILL }, { TableLayout.FILL, TableLayout.PREFERRED, 5, TableLayout.PREFERRED, TableLayout.FILL } }));
            initComponents();
        }

        private void initComponents() {
            JLabel offlineLabel = new JLabel("Server currently offline.");
            offlineLabel.setHorizontalAlignment(SwingConstants.CENTER);
            add(offlineLabel, "1,1");

            connectButton = new JButton("Try reconnect");
            connectButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    client.connect();
                }
            });
            add(connectButton, "1,3");
        }
    }
}

@@ -272,24 +272,90 @@
 ing.JPanel;%0A
+import javax.swing.JPasswordField;%0Aimport javax.swing.JTextField;%0A
 import javax
@@ -377,16 +377,16 @@
 stants;%0A
-
 import j
@@ -940,16 +940,68 @@
 nnect%22);
+%0A        cards.add(new LoginPanel(client), %22login%22);
 %0A%0A      
@@ -2186,16 +2186,16 @@
     %7D);%0A
-
         
@@ -2240,11 +2240,1621 @@
  %7D%0A    %7D
+%0A%0A    private class LoginPanel extends JPanel implements ActionListener %7B%0A        private static final long serialVersionUID = 4260715489603841434L;%0A%0A        private ChatClient client;%0A%0A        private JTextField usernameField;%0A        private JPasswordField passwordField;%0A        private JButton loginButton;%0A%0A        public LoginPanel(ChatClient client) %7B%0A            this.client = client;%0A            setLayout(new TableLayout(new double%5B%5D%5B%5D %7B %7B TableLayout.FILL, 0.5f, TableLayout.FILL %7D,%0A                    %7B TableLayout.FILL, TableLayout.PREFERRED, 5, TableLayout.PREFERRED, 5, TableLayout.PREFERRED, 5, TableLayout.PREFERRED, 5, TableLayout.PREFERRED, TableLayout.FILL %7D %7D));%0A%0A            initComponents();%0A        %7D%0A%0A        @Override%0A        public void actionPerformed(ActionEvent e) %7B%0A            client.login(usernameField.getText(), new String(passwordField.getPassword()));%0A        %7D%0A%0A        private void initComponents() %7B%0A            JLabel usernameLabel = new JLabel(%22Username%22);%0A            usernameLabel.setHorizontalAlignment(SwingConstants.CENTER);%0A            add(usernameLabel, %221,1%22);%0A%0A            usernameField = new JTextField();%0A            add(usernameField, %221,3%22);%0A%0A            JLabel passwordLabel = new JLabel(%22Password%22);%0A            passwordLabel.setHorizontalAlignment(SwingConstants.CENTER);%0A            add(passwordLabel, %221,5%22);%0A%0A            passwordField = new JPasswordField();%0A            add(passwordField, %221,7%22);%0A%0A            loginButton = new JButton(%22Login%22);%0A            loginButton.addActionListener(this);%0A            add(loginButton, %221,9%22);%0A        %7D%0A    %7D
 %0A%7D%0A

implement login panel and add it to chat gui