/*
 * SmsView.java
 */

package sms;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.bluetooth.*;
import javax.swing.DefaultComboBoxModel;

/**
 * Hlavne okno aplikacie
 * @author Richard Scepko
 */
public class SmsView extends FrameView {

    public SmsView(SingleFrameApplication app) throws BluetoothStateException {
        super(app);

        initComponents();

        this.deviceDiscovery = new DeviceDiscovery();
        this.servicesSearch = new ServicesSearch(deviceDiscovery);
        this.client = new Client(this.servicesSearch, this);
        this.addUser = new AddUser(this);
        this.addUser.hide();
        loadUsers();
        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = SmsApp.getApplication().getMainFrame();
            aboutBox = new SmsAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        SmsApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jButton3 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel6 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox2 = new javax.swing.JComboBox();
        jComboBox3 = new javax.swing.JComboBox();
        jComboBox4 = new javax.swing.JComboBox();
        jComboBox5 = new javax.swing.JComboBox();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jComboBox6 = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jComboBox7 = new javax.swing.JComboBox();
        jComboBox8 = new javax.swing.JComboBox();
        jComboBox9 = new javax.swing.JComboBox();
        jComboBox10 = new javax.swing.JComboBox();
        jComboBox11 = new javax.swing.JComboBox();
        jComboBox12 = new javax.swing.JComboBox();
        jComboBox13 = new javax.swing.JComboBox();
        jComboBox14 = new javax.swing.JComboBox();
        jComboBox15 = new javax.swing.JComboBox();
        jComboBox16 = new javax.swing.JComboBox();
        jComboBox17 = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();

        mainPanel.setName("mainPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sms.SmsApp.class).getContext().getResourceMap(SmsView.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jList1.setName("jList1"); // NOI18N
        jScrollPane1.setViewportView(jList1);

        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTextArea1.setColumns(20);
        jTextArea1.setFont(resourceMap.getFont("jTextArea1.font")); // NOI18N
        jTextArea1.setRows(5);
        jTextArea1.setTabSize(12);
        jTextArea1.setName("jTextArea1"); // NOI18N
        jScrollPane2.setViewportView(jTextArea1);

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jComboBox1.setName("jComboBox1"); // NOI18N

        jComboBox2.setName("jComboBox2"); // NOI18N

        jComboBox3.setName("jComboBox3"); // NOI18N

        jComboBox4.setName("jComboBox4"); // NOI18N

        jComboBox5.setName("jComboBox5"); // NOI18N

        jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
        jButton4.setName("jButton4"); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
        jButton5.setName("jButton5"); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jComboBox6.setName("jComboBox6"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jComboBox7.setName("jComboBox7"); // NOI18N

        jComboBox8.setName("jComboBox8"); // NOI18N

        jComboBox9.setName("jComboBox9"); // NOI18N

        jComboBox10.setName("jComboBox10"); // NOI18N

        jComboBox11.setName("jComboBox11"); // NOI18N

        jComboBox12.setName("jComboBox12"); // NOI18N

        jComboBox13.setName("jComboBox13"); // NOI18N

        jComboBox14.setName("jComboBox14"); // NOI18N

        jComboBox15.setName("jComboBox15"); // NOI18N

        jComboBox16.setName("jComboBox16"); // NOI18N

        jComboBox17.setName("jComboBox17"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                        .add(jButton3, 0, 0, Short.MAX_VALUE)
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE))
                    .add(jLabel6))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 291, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, mainPanelLayout.createSequentialGroup()
                            .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                            .add(jButton4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .add(org.jdesktop.layout.GroupLayout.LEADING, mainPanelLayout.createSequentialGroup()
                            .add(jLabel8)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                            .add(jComboBox6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 106, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                            .add(jButton5)))
                    .add(jLabel1))
                .add(34, 34, 34)
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(mainPanelLayout.createSequentialGroup()
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jComboBox12, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jComboBox5, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jComboBox4, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jComboBox3, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jComboBox2, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jComboBox1, 0, 149, Short.MAX_VALUE)
                            .add(jComboBox13, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jComboBox14, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 14, Short.MAX_VALUE)
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(jComboBox17, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jComboBox16, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jComboBox15, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jComboBox11, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jComboBox10, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jComboBox9, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jComboBox8, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jComboBox7, 0, 142, Short.MAX_VALUE)))
                    .add(jLabel2))
                .add(56, 56, 56))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mainPanelLayout.createSequentialGroup()
                .add(36, 36, 36)
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel6)
                    .add(jLabel1)
                    .add(jLabel2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(mainPanelLayout.createSequentialGroup()
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jComboBox7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jComboBox8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jComboBox3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jComboBox9, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jComboBox4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jComboBox10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jComboBox5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jComboBox11, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jComboBox12, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jComboBox15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jComboBox13, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jComboBox16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jComboBox14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jComboBox17, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(41, 41, 41))
                    .add(mainPanelLayout.createSequentialGroup()
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jButton3)
                            .add(jButton2)
                            .add(jButton1)
                            .add(jButton4))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel8)
                            .add(jComboBox6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jButton5))
                        .add(35, 35, 35))))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(sms.SmsApp.class).getContext().getActionMap(SmsView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setComponent(mainPanel);
        setMenuBar(menuBar);
    }// </editor-fold>//GEN-END:initComponents

    public JTextArea getjTextArea1() {
        return jTextArea1;
    }

    public void setjTextArea1(JTextArea jTextArea1) {
        this.jTextArea1 = jTextArea1;
    }

    public JComboBox getjComboBox1() {
        return jComboBox1;
    }

    public void setjComboBox1(JComboBox jComboBox1) {
        this.jComboBox1 = jComboBox1;
    }

    public JComboBox getjComboBox2() {
        return jComboBox2;
    }

    public void setjComboBox2(JComboBox jComboBox2) {
        this.jComboBox2 = jComboBox2;
    }

    public JComboBox getjComboBox3() {
        return jComboBox3;
    }

    public void setjComboBox3(JComboBox jComboBox3) {
        this.jComboBox3 = jComboBox3;
    }

    public JComboBox getjComboBox4() {
        return jComboBox4;
    }

    public void setjComboBox4(JComboBox jComboBox4) {
        this.jComboBox4 = jComboBox4;
    }

    public JComboBox getjComboBox5() {
        return jComboBox5;
    }

    public void setjComboBox5(JComboBox jComboBox5) {
        this.jComboBox5 = jComboBox5;
    }

    public JComboBox getjComboBox10() {
        return jComboBox10;
    }

    public void setjComboBox10(JComboBox jComboBox10) {
        this.jComboBox10 = jComboBox10;
    }

    public JComboBox getjComboBox11() {
        return jComboBox11;
    }

    public void setjComboBox11(JComboBox jComboBox11) {
        this.jComboBox11 = jComboBox11;
    }

    public JComboBox getjComboBox6() {
        return jComboBox6;
    }

    public void setjComboBox6(JComboBox jComboBox6) {
        this.jComboBox6 = jComboBox6;
    }

    public JComboBox getjComboBox7() {
        return jComboBox7;
    }

    public void setjComboBox7(JComboBox jComboBox7) {
        this.jComboBox7 = jComboBox7;
    }

    public JComboBox getjComboBox8() {
        return jComboBox8;
    }

    public void setjComboBox8(JComboBox jComboBox8) {
        this.jComboBox8 = jComboBox8;
    }

    public JComboBox getjComboBox9() {
        return jComboBox9;
    }

    public JComboBox getjComboBox12() {
        return jComboBox12;
    }

    public void setjComboBox12(JComboBox jComboBox12) {
        this.jComboBox12 = jComboBox12;
    }

    public JComboBox getjComboBox13() {
        return jComboBox13;
    }

    public void setjComboBox13(JComboBox jComboBox13) {
        this.jComboBox13 = jComboBox13;
    }

    public JComboBox getjComboBox14() {
        return jComboBox14;
    }

    public void setjComboBox14(JComboBox jComboBox14) {
        this.jComboBox14 = jComboBox14;
    }

    public JComboBox getjComboBox15() {
        return jComboBox15;
    }

    public void setjComboBox15(JComboBox jComboBox15) {
        this.jComboBox15 = jComboBox15;
    }

    public JComboBox getjComboBox16() {
        return jComboBox16;
    }

    public void setjComboBox16(JComboBox jComboBox16) {
        this.jComboBox16 = jComboBox16;
    }

    public JComboBox getjComboBox17() {
        return jComboBox17;
    }

    public void setjComboBox17(JComboBox jComboBox17) {
        this.jComboBox17 = jComboBox17;
    }

    public void setjComboBox9(JComboBox jComboBox9) {
        this.jComboBox9 = jComboBox9;
    }

    public DefaultComboBoxModel getCbm1() {
        return cbm1;
    }

    public void setCbm1(DefaultComboBoxModel cbm1) {
        this.cbm1 = cbm1;
    }

    public DefaultComboBoxModel getCbm2() {
        return cbm2;
    }

    public void setCbm2(DefaultComboBoxModel cbm2) {
        this.cbm2 = cbm2;
    }

    public DefaultComboBoxModel getCbm3() {
        return cbm3;
    }

    public void setCbm3(DefaultComboBoxModel cbm3) {
        this.cbm3 = cbm3;
    }

    public DefaultComboBoxModel getCbm4() {
        return cbm4;
    }

    public void setCbm4(DefaultComboBoxModel cbm4) {
        this.cbm4 = cbm4;
    }

    public DefaultComboBoxModel getCbm5() {
        return cbm5;
    }

    public void setCbm5(DefaultComboBoxModel cbm5) {
        this.cbm5 = cbm5;
    }

    public DefaultComboBoxModel getCbm10() {
        return cbm10;
    }

    public void setCbm10(DefaultComboBoxModel cbm10) {
        this.cbm10 = cbm10;
    }

    public DefaultComboBoxModel getCbm11() {
        return cbm11;
    }

    public void setCbm11(DefaultComboBoxModel cbm11) {
        this.cbm11 = cbm11;
    }

    public DefaultComboBoxModel getCbm6() {
        return cbm6;
    }

    public void setCbm6(DefaultComboBoxModel cbm6) {
        this.cbm6 = cbm6;
    }

    public DefaultComboBoxModel getCbm7() {
        return cbm7;
    }

    public void setCbm7(DefaultComboBoxModel cbm7) {
        this.cbm7 = cbm7;
    }

    public DefaultComboBoxModel getCbm8() {
        return cbm8;
    }

    public void setCbm8(DefaultComboBoxModel cbm8) {
        this.cbm8 = cbm8;
    }

    public DefaultComboBoxModel getCbm9() {
        return cbm9;
    }

    public void setCbm9(DefaultComboBoxModel cbm9) {
        this.cbm9 = cbm9;
    }
    
    
    /**
     * ActionEvent metoda vyvolana pre najdenie zariadeni
     * @param evt
     */
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        try {
            this.deviceDiscovery.run();
        } catch (IOException ex) {
            Logger.getLogger(SmsView.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InterruptedException ex) {
            Logger.getLogger(SmsView.class.getName()).log(Level.SEVERE, null, ex);
        }
        DefaultListModel listModel = new DefaultListModel();
        for(int i = 0; i < this.deviceDiscovery.devicesDiscovered.size(); i++){
            try {
                listModel.addElement(((RemoteDevice) this.deviceDiscovery.devicesDiscovered.get(i)).getFriendlyName(false));
            } catch (IOException cantGetDeviceName) {
            }
        }
        jList1.setModel(listModel);
    }//GEN-LAST:event_jButton3ActionPerformed

    /**
     * ActionEvent metoda pre poslanie spravy na server
     * @param evt
     */
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        try {
            String[] searchArgs = null;
            searchArgs = new String[] { "11111111111111111111111111111123" };
            this.servicesSearch.run(searchArgs, this.jList1.getSelectedIndex()+1);
            this.client.run(null);
        } catch (IOException ex) {
            Logger.getLogger(SmsView.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InterruptedException ex) {
            Logger.getLogger(SmsView.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jButton2ActionPerformed
    /**
     * ActionEvent metoda pre zobrazenie okienka s pridanim uzivatela
     * @param evt
     */
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        this.addUser.show();
    }//GEN-LAST:event_jButton4ActionPerformed

    /**
     * ActionEvent metoda pre zmazanie uzivatela
     * @param evt
     */
    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        String content = "";
        try{
            FileInputStream fstream = new FileInputStream("users");
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String strLine;
            while ((strLine = br.readLine()) != null){
                if(!strLine.equals(((User)this.jComboBox6.getSelectedItem()).getName() + "#" + ((User)this.jComboBox6.getSelectedItem()).getNumber()))
                    content += strLine + "\n";
            }
            in.close();
        }catch (Exception e){//Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }
        PrintWriter pwr;
        try {
            pwr = new PrintWriter(new FileWriter("users"));
            pwr.print(content);
            pwr.close();
        } catch (IOException ex) {
            Logger.getLogger(AddUser.class.getName()).log(Level.SEVERE, null, ex);
        }
        loadUsers();
    }//GEN-LAST:event_jButton5ActionPerformed

    /**
     * ActionEvent metoda pre resetovanie
     * @param evt
     */
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.jTextArea1.setText("");
        loadUsers();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * Nacita uzivatelov do comboboxov
     */
    public void loadUsers(){
        this.cbm1 = new DefaultComboBoxModel();
        this.cbm2 = new DefaultComboBoxModel();
        this.cbm3 = new DefaultComboBoxModel();
        this.cbm4 = new DefaultComboBoxModel();
        this.cbm5 = new DefaultComboBoxModel();
        this.cbm6 = new DefaultComboBoxModel();
        this.cbm7 = new DefaultComboBoxModel();
        this.cbm8 = new DefaultComboBoxModel();
        this.cbm9 = new DefaultComboBoxModel();
        this.cbm10 = new DefaultComboBoxModel();
        this.cbm11 = new DefaultComboBoxModel();
        this.cbm12 = new DefaultComboBoxModel();
        this.cbm13 = new DefaultComboBoxModel();
        this.cbm14 = new DefaultComboBoxModel();
        this.cbm15 = new DefaultComboBoxModel();
        this.cbm16 = new DefaultComboBoxModel();
        this.cbm17 = new DefaultComboBoxModel();
        this.users = new ArrayList();
        cbm1.addElement(new User("...",""));
        cbm2.addElement(new User("...",""));
        cbm3.addElement(new User("...",""));
        cbm4.addElement(new User("...",""));
        cbm5.addElement(new User("...",""));
        cbm7.addElement(new User("...",""));
        cbm8.addElement(new User("...",""));
        cbm9.addElement(new User("...",""));
        cbm10.addElement(new User("...",""));
        cbm11.addElement(new User("...",""));
        cbm12.addElement(new User("...",""));
        cbm13.addElement(new User("...",""));
        cbm14.addElement(new User("...",""));
        cbm15.addElement(new User("...",""));
        cbm16.addElement(new User("...",""));
        cbm17.addElement(new User("...",""));
        try{
        FileInputStream fstream = new FileInputStream("users");
        DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;
        while ((strLine = br.readLine()) != null){
            User temp = new User(strLine.substring(0, strLine.indexOf("#")), strLine.substring(strLine.indexOf("#") + 1));
            this.users.add(temp);
            this.cbm1.addElement(temp);
            this.cbm2.addElement(temp);
            this.cbm3.addElement(temp);
            this.cbm4.addElement(temp);
            this.cbm5.addElement(temp);
            this.cbm6.addElement(temp);
            this.cbm7.addElement(temp);
            this.cbm8.addElement(temp);
            this.cbm9.addElement(temp);
            this.cbm10.addElement(temp);
            this.cbm11.addElement(temp);
            this.cbm12.addElement(temp);
            this.cbm13.addElement(temp);
            this.cbm14.addElement(temp);
            this.cbm15.addElement(temp);
            this.cbm16.addElement(temp);
            this.cbm17.addElement(temp);
        }
        in.close();
        }catch (Exception e){//Catch exception if any
          System.err.println("Error: " + e.getMessage());
        }
        this.jComboBox1.setModel(cbm1);
        this.jComboBox2.setModel(cbm2);
        this.jComboBox3.setModel(cbm3);
        this.jComboBox4.setModel(cbm4);
        this.jComboBox5.setModel(cbm5);
        this.jComboBox6.setModel(cbm6);
        this.jComboBox7.setModel(cbm7);
        this.jComboBox8.setModel(cbm8);
        this.jComboBox9.setModel(cbm9);
        this.jComboBox10.setModel(cbm10);
        this.jComboBox11.setModel(cbm11);
        this.jComboBox12.setModel(cbm12);
        this.jComboBox13.setModel(cbm13);
        this.jComboBox14.setModel(cbm14);
        this.jComboBox15.setModel(cbm15);
        this.jComboBox16.setModel(cbm16);
        this.jComboBox17.setModel(cbm17);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox10;
    private javax.swing.JComboBox jComboBox11;
    private javax.swing.JComboBox jComboBox12;
    private javax.swing.JComboBox jComboBox13;
    private javax.swing.JComboBox jComboBox14;
    private javax.swing.JComboBox jComboBox15;
    private javax.swing.JComboBox jComboBox16;
    private javax.swing.JComboBox jComboBox17;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JComboBox jComboBox5;
    private javax.swing.JComboBox jComboBox6;
    private javax.swing.JComboBox jComboBox7;
    private javax.swing.JComboBox jComboBox8;
    private javax.swing.JComboBox jComboBox9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    // End of variables declaration//GEN-END:variables
    private DeviceDiscovery deviceDiscovery;
    private ServicesSearch servicesSearch;
    private Client client;
    private DefaultComboBoxModel cbm1;
    private DefaultComboBoxModel cbm2;
    private DefaultComboBoxModel cbm3;
    private DefaultComboBoxModel cbm4;
    private DefaultComboBoxModel cbm5;
    private DefaultComboBoxModel cbm6;
    private DefaultComboBoxModel cbm7;
    private DefaultComboBoxModel cbm8;
    private DefaultComboBoxModel cbm9;
    private DefaultComboBoxModel cbm10;
    private DefaultComboBoxModel cbm11;
    private DefaultComboBoxModel cbm12;
    private DefaultComboBoxModel cbm13;
    private DefaultComboBoxModel cbm14;
    private DefaultComboBoxModel cbm15;
    private DefaultComboBoxModel cbm16;
    private DefaultComboBoxModel cbm17;
    private List<User> users;
    private AddUser addUser;

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
}
