/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interfaz;

import estaticas.estaticas;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;


/**
 *
 * @author Jose
 */
public class MainPanelWifi extends JPanel {

    public MainPanelWifi() {
        setLayout(new GridBagLayout());
        init();
    }

    private void init() {
        defaultListModel = new DefaultListModel();
        

        list = new JList(defaultListModel);
        list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
        list.setSelectedIndex(1);
        list.setCellRenderer(new MyCellRendererWifi());

        //button1 = new JButton("Guardar Log");

        /*button1.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                try {
                    //Date date = new Date();
                    File file = new File("log/logaso.txt");
                    boolean success = file.createNewFile();
                    if(success)
                    ;
                    else
                        System.out.println("no se pudo crear");

                    estaticas.saveTextFile(textArea.getText(), new File("log/logaso.txt"));
                } catch (IOException ex) {
                    Logger.getLogger(MainPanelWifi.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });*/

        textArea = new JTextArea();
        textArea.setEnabled(false);
        textArea.setBackground(Color.BLACK);

        add(new JLabel("Lista de equipos :"), estaticas.createConstraints(0, 0, 1, 1, 0.0, 0.0,
                GridBagConstraints.ABOVE_BASELINE_TRAILING, GridBagConstraints.BOTH));
        //add(button1, estaticas.createConstraints(2, 0, 1, 1, 1.0, 0.0,
        //        GridBagConstraints.ABOVE_BASELINE_TRAILING, GridBagConstraints.NONE));
        add(new JScrollPane(list), estaticas.createConstraints(0, 1, 4, 1, 1.0, 1.0,
                GridBagConstraints.ABOVE_BASELINE, GridBagConstraints.BOTH));
        add(new JScrollPane(textArea), estaticas.createConstraints(4, 0, 1, 2, 1.0, 1.0,
                GridBagConstraints.ABOVE_BASELINE, GridBagConstraints.BOTH));

    }

    JList list;
    public DefaultListModel defaultListModel;
    JButton button1;
    public JTextArea textArea;
}
class MyCellRendererWifi extends JLabel implements ListCellRenderer {

    final static ImageIcon Icon = new ImageIcon("wifi icon.jpg");

    public MyCellRendererWifi() {
        setOpaque(true);
    }

    public Component getListCellRendererComponent(
            JList list,
            Object value,
            int index,
            boolean isSelected,
            boolean cellHasFocus) {
        setText(value.toString());
        setIcon(Icon);
        setBackground(isSelected ? Color.LIGHT_GRAY : Color.white);
        setForeground(isSelected ? Color.white : Color.black);
        return this;
    }
}
