package jnet.client.gui;

import jnet.client.gui.dialog.OnlineClientsDialog;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import jnet.lib.LogFile;

public class StatusBar extends JPanel {
    
    private JLabel message;
    private JLabel online;
    private JButton btnOnline;

    public StatusBar() {
        super();
        super.setPreferredSize(new Dimension(100, 35));
        
        setLayout(null);
        
        online = new JLabel("Odpojeno");
        online.setBounds(10, 0, 100, 30);
        add(online);
        
        message = new JLabel("");
        message.setBounds(250, 0, 100, 30);
        add(message);
        
        // tlacitko zobrazujici klienty
        try {
            BufferedImage buttonIcon = ImageIO.read(getClass().getResourceAsStream("/img/online_clients.png"));
            btnOnline = new JButton(new ImageIcon(buttonIcon));
            btnOnline.setFocusPainted(false);
            btnOnline.setContentAreaFilled(false);
            btnOnline.setBorderPainted(false);
            btnOnline.setToolTipText("Online uživatelé");
            btnOnline.addActionListener(new ActionListener(){  
                @Override
                public void actionPerformed(ActionEvent e) {
                    // TODO jeli offlice vypnout tlačítko
                    new OnlineClientsDialog();
                }
            }); 
            btnOnline.setBounds(200, 0, 32, 32);
            add(btnOnline);
        } catch (IOException ex) {
            LogFile.printErr("File not found: image online_clinets.png");
        }
                
    }

    public void setMessage(String text) {
        message.setText(text);        
    }        
    
    public void setConectionStatus(String state){
        online.setText(state);
    }
}
