/*
 *  Panel for examination of connection data details
 *
 *  2004 - 2011 Frantisek Zboril jr.
 *  Faculty of Information Technology
 *  zborilf@fit.vutbr.cz
 *  http://www.fit.vutbr.cz/~zborilf
 *
 * (C) Brno University of Technology
 * Freeware licence VUT v Brně
 * https://wis.fit.vutbr.cz/FIT/db/dir.php/dr/VZ2007/externiInformace/softwareNaWebu/Priloha2_rozh23.pdf

 */

package jTGUI;

import jTMass.core.jTMassModel.TModelConnection;
import jTMass.core.jTMassModel.jModelData.TModelData;
import jTMass.core.jTMassModel.jModelData.TSpeechAct;
import java.util.LinkedList;
import javax.swing.DefaultListModel;
import javax.swing.JTabbedPane;


public class TDataInspectionPanel extends javax.swing.JPanel {

    LinkedList<TModelData> PDataList;
    TModelConnection PConnection;

    public void initDataList(){
        PDataList=new LinkedList<TModelData>();
    }

    void setComboItems(){
        DefaultListModel listModel=new DefaultListModel();
        for(TModelData data:PDataList)
            listModel.addElement(data.getContentEx());
        TDataList.setModel(listModel);
    }

    void setSpeechAct(TSpeechAct act){
        if(act==null){
            PESpeechAct.setText("no act");
            PELanguage.setText("");
            PESender.setText("");
            PEReceiver.setText("");
            PEContent.setText("");
            PEReplyWith.setText("");
            PEInReplyTo.setText("");
            return;
         }
            PESpeechAct.setText(TSpeechAct.getSAText(act.getAct()));
            PELanguage.setText(TSpeechAct.getCLText(act.getLanguage()));
            PESender.setText(act.getSender());
            PEReceiver.setText(act.getReceiver());
            PEContent.setText(act.getContentS());
            PEReplyWith.setText(act.getReplyWith());
            PEInReplyTo.setText(act.getInReplyTo());
    }

    public boolean isConnection(TModelConnection con){
        return(con==PConnection);
    }

    public void setData(){
        initDataList();
        for (TModelData ndata:PConnection.getDataList()){
            PDataList.add(ndata);
        }
        setComboItems();
        TModelData data=PConnection.getData();
        if((data instanceof TSpeechAct)||(data==null))
            setSpeechAct((TSpeechAct)PConnection.getData());
    }

    public TDataInspectionPanel(TModelConnection con) {
        PConnection=con;
        initComponents();
        setData();
    }

    /** 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() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jScrollPane4 = new javax.swing.JScrollPane();
        PEContent = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        TDataList = new javax.swing.JList();
        TActDetailsPanel = new javax.swing.JPanel();
        TLSender = new javax.swing.JLabel();
        TLSpeechAct = new javax.swing.JLabel();
        TLLanguage = new javax.swing.JLabel();
        TLReceiver = new javax.swing.JLabel();
        PESpeechAct = new javax.swing.JTextField();
        PESender = new javax.swing.JTextField();
        PELanguage = new javax.swing.JTextField();
        PEReceiver = new javax.swing.JTextField();
        TLReplyWith = new javax.swing.JLabel();
        TLInReplyTo = new javax.swing.JLabel();
        PEReplyWith = new javax.swing.JTextField();
        PEInReplyTo = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();

        jScrollPane1.setViewportView(jTextPane1);

        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane3.setViewportView(jList1);

        addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                onFocusLost(evt);
            }
        });

        PEContent.setColumns(20);
        PEContent.setRows(5);
        PEContent.setToolTipText("Message Content");
        jScrollPane4.setViewportView(PEContent);

        TDataList.setFont(new java.awt.Font("Tahoma", 0, 10));
        TDataList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        TDataList.setToolTipText("Message");
        TDataList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                TDataListValueChanged(evt);
            }
        });
        TDataList.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                TDataListCaretPositionChanged(evt);
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
            }
        });
        jScrollPane2.setViewportView(TDataList);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 345, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
        );

        TActDetailsPanel.setBackground(new java.awt.Color(255, 255, 255));
        TActDetailsPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        TLSender.setFont(new java.awt.Font("Arial", 0, 11));
        TLSender.setForeground(new java.awt.Color(0, 51, 51));
        TLSender.setText("Sender:");

        TLSpeechAct.setFont(new java.awt.Font("Arial", 0, 11));
        TLSpeechAct.setForeground(new java.awt.Color(0, 51, 51));
        TLSpeechAct.setText("Speech Act: ");

        TLLanguage.setFont(new java.awt.Font("Arial", 0, 11));
        TLLanguage.setForeground(new java.awt.Color(0, 51, 51));
        TLLanguage.setText("Language:");

        TLReceiver.setFont(new java.awt.Font("Arial", 0, 11));
        TLReceiver.setForeground(new java.awt.Color(0, 51, 51));
        TLReceiver.setText("Receiver:");

        PESpeechAct.setBackground(new java.awt.Color(204, 204, 255));
        PESpeechAct.setEditable(false);
        PESpeechAct.setText("no act");
        PESpeechAct.setDisabledTextColor(new java.awt.Color(0, 51, 51));
        PESpeechAct.setEnabled(false);
        PESpeechAct.setHighlighter(null);

        PESender.setBackground(new java.awt.Color(204, 204, 255));
        PESender.setEditable(false);
        PESender.setText(" ");
        PESender.setToolTipText("Message Sender");
        PESender.setDisabledTextColor(new java.awt.Color(0, 51, 51));
        PESender.setEnabled(false);
        PESender.setHighlighter(null);

        PELanguage.setBackground(new java.awt.Color(204, 204, 255));
        PELanguage.setEditable(false);
        PELanguage.setText(" ");
        PELanguage.setDisabledTextColor(new java.awt.Color(0, 51, 51));
        PELanguage.setEnabled(false);
        PELanguage.setHighlighter(null);

        PEReceiver.setBackground(new java.awt.Color(204, 204, 255));
        PEReceiver.setEditable(false);
        PEReceiver.setText(" ");
        PEReceiver.setToolTipText("Message Reciever");
        PEReceiver.setDisabledTextColor(new java.awt.Color(0, 51, 51));
        PEReceiver.setEnabled(false);
        PEReceiver.setHighlighter(null);
        PEReceiver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PEReceiverActionPerformed(evt);
            }
        });

        TLReplyWith.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        TLReplyWith.setText("Reply with:");

        TLInReplyTo.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        TLInReplyTo.setText("In reply to:");

        PEReplyWith.setBackground(new java.awt.Color(204, 204, 255));
        PEReplyWith.setText(" ");
        PEReplyWith.setToolTipText("Conversation Identifier");

        PEInReplyTo.setBackground(new java.awt.Color(204, 204, 255));
        PEInReplyTo.setText(" ");
        PEInReplyTo.setToolTipText("Reply Identifier");

        javax.swing.GroupLayout TActDetailsPanelLayout = new javax.swing.GroupLayout(TActDetailsPanel);
        TActDetailsPanel.setLayout(TActDetailsPanelLayout);
        TActDetailsPanelLayout.setHorizontalGroup(
            TActDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(TActDetailsPanelLayout.createSequentialGroup()
                .addGroup(TActDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(TLSender)
                    .addComponent(TLSpeechAct)
                    .addComponent(TLReplyWith))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(TActDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(PEReplyWith, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
                    .addComponent(PESender, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
                    .addComponent(PESpeechAct, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(TActDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(TActDetailsPanelLayout.createSequentialGroup()
                        .addComponent(TLLanguage)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(PELanguage, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE))
                    .addGroup(TActDetailsPanelLayout.createSequentialGroup()
                        .addGroup(TActDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(TLReceiver)
                            .addComponent(TLInReplyTo))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(TActDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(PEInReplyTo, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(PEReceiver, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))))
                .addContainerGap())
        );
        TActDetailsPanelLayout.setVerticalGroup(
            TActDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(TActDetailsPanelLayout.createSequentialGroup()
                .addGroup(TActDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, TActDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(TLLanguage)
                        .addComponent(PELanguage, javax.swing.GroupLayout.DEFAULT_SIZE, 21, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, TActDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(TLSpeechAct)
                        .addComponent(PESpeechAct)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(TActDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(TLSender)
                    .addComponent(PESender, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(TLReceiver)
                    .addComponent(PEReceiver, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(TActDetailsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TLReplyWith)
                    .addComponent(TLInReplyTo)
                    .addComponent(PEReplyWith, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(PEInReplyTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 12));
        jButton1.setMnemonic('C');
        jButton1.setText("CLOSE");
        jButton1.setToolTipText("Close window");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 429, Short.MAX_VALUE)
            .addComponent(TActDetailsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 48, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(5, 5, 5)
                .addComponent(TActDetailsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void onFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_onFocusLost
        this.setVisible(false);
    }//GEN-LAST:event_onFocusLost

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.getParent().remove(((JTabbedPane)this.getParent()).getSelectedIndex());
    }//GEN-LAST:event_jButton1ActionPerformed

    private void PEReceiverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PEReceiverActionPerformed

    }//GEN-LAST:event_PEReceiverActionPerformed

    private void TDataListCaretPositionChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_TDataListCaretPositionChanged

    }//GEN-LAST:event_TDataListCaretPositionChanged

    private void TDataListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_TDataListValueChanged
        setSpeechAct((TSpeechAct)PDataList.get(TDataList.getSelectedIndex()));
    }//GEN-LAST:event_TDataListValueChanged


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea PEContent;
    private javax.swing.JTextField PEInReplyTo;
    private javax.swing.JTextField PELanguage;
    private javax.swing.JTextField PEReceiver;
    private javax.swing.JTextField PEReplyWith;
    private javax.swing.JTextField PESender;
    private javax.swing.JTextField PESpeechAct;
    private javax.swing.JPanel TActDetailsPanel;
    private javax.swing.JList TDataList;
    private javax.swing.JLabel TLInReplyTo;
    private javax.swing.JLabel TLLanguage;
    private javax.swing.JLabel TLReceiver;
    private javax.swing.JLabel TLReplyWith;
    private javax.swing.JLabel TLSender;
    private javax.swing.JLabel TLSpeechAct;
    private javax.swing.JButton jButton1;
    private javax.swing.JList jList1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration//GEN-END:variables

}
