package jnet.client.gui.dialog;

import jnet.client.Client;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import jnet.lib.LogFile;
import jnet.lib.object.OnlineClients;

public class OnlineClientsDialog extends JDialog {

    public OnlineClientsDialog() {
        setTitle("Online klienti");
        setLocationRelativeTo(null);
        setAlwaysOnTop(true);

        setLayout(new FlowLayout(FlowLayout.CENTER));

        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
        panel.setBorder(new EmptyBorder(10, 25, 10, 25));

        panel.add(Box.createRigidArea(new Dimension(5, 10)));
        for (OnlineClients oc : Client.onlineClients) {
            try {
                JLabel line = new JLabel("      " + oc.getUsername() + "      (" + oc.getIp() + ")");
                switch (oc.getPlatform()) {
                    case OnlineClients.PLATFORM_MOBILE:
                        line.setIcon(new ImageIcon(ImageIO.read(new File("img/platform_android.png"))));
                        break;
                    case OnlineClients.PLATFORM_PC:
                        line.setIcon(new ImageIcon(ImageIO.read(new File("img/platform_pc.png"))));
                        break;
                }
                panel.add(line);
                panel.add(Box.createRigidArea(new Dimension(5, 10)));
            } catch (IOException ex) {
                LogFile.printErr("Online Clients dialog exception: " + ex.getMessage());
            }

            panel.add(Box.createRigidArea(new Dimension(5, 20)));
        }

        add(panel);
        pack();

        setVisible(true);
    }

}
