/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package GUI;
import CSP_ANALYSE.AnalyseProtocol;
import CSP_ANALYSE.ResultVerification;
import LOGIC.Channel;
import LOGIC.ObjectList;
import LOGIC.Protocols;
import java.util.LinkedList;
import javax.swing.JOptionPane;
/**
*
* @author sarah
*/
public class ProtocolsGUI extends javax.swing.JFrame {
/**
* Creates new form ProtocolsGUI
*/
public ProtocolsGUI(LinkedList<Protocols> protocols, ObjectList listas, int prot) {
initComponents();
//this.canal = canal;
this.listas = listas;
//protocol.setText(canal.getName());
this.protocols = protocols;
this.prot = prot;
protocol.setText(protocols.get(prot).getProtocol());
dualProtocol.setText(protocols.get(prot).getDualProtocol());
}
//private Channel canal;
ObjectList listas;
private Protocols protocolo = new Protocols();
LinkedList<Protocols> protocols = new LinkedList();
//int local;
//int lugar;
int prot;
/**
* 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() {
jTextField1 = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
protocol = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
dualProtocol = new javax.swing.JTextArea();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jTextField1.setText("jTextField1");
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
protocol.setColumns(20);
protocol.setRows(5);
jScrollPane1.setViewportView(protocol);
dualProtocol.setColumns(20);
dualProtocol.setRows(5);
jScrollPane2.setViewportView(dualProtocol);
jLabel1.setText("Protocol:");
jLabel2.setText("Dual-Protocol:");
jButton1.setText("concluir");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("cancelar");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 314, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(14, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
this.dispose(); // TODO add your handling code here:
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
if(!protocol.getText().equals("")&&!dualProtocol.getText().equals("")){
AnalyseProtocol analyse = new AnalyseProtocol(listas, protocol.getText(), dualProtocol.getText());
ResultVerification r = new ResultVerification();
r = analyse.takeResultProtocol();
if(r.getResultado() == false){
JOptionPane.showMessageDialog(null, "Protocolo não corresponde a nenhum processo.\n Por favor, escreva novamente seu protocolo \n ou volte e defina um novo processo auxiliar. ");
}
else{
protocols.get(prot).setDualProtocol(dualProtocol.getText());
protocols.get(prot).setProtocol(protocol.getText());
// protocolo.setCanal(canal);
// protocolo.setProtocol(protocol.getText());
// protocolo.setDualProtocol(dualProtocol.getText());
// lugar = takeLugar(canal);
// if(lugar>-1){
//
// protocols.remove(lugar);
// protocols.add(protocolo);
// }
// else{
// protocols.add(protocolo);
//}
this.dispose();
}
}
if((!protocol.getText().equals("")&&dualProtocol.getText().equals(""))||protocol.getText().equals("")&&!dualProtocol.getText().equals("")){
JOptionPane.showMessageDialog(null, "escreva os dois protocolos (protocol e dual-protocol) ou cancele a operação. Ao apagar os dois você estará excluindo-os");
}
// if(protocol.getText().equals("")&&dualProtocol.getText().equals("")){
// if(prot != -1){
// protocols.remove(takeLugar(canal));
// }
// this.dispose();
// }
// Dalay, estou tentando verificar através do checker o comportamento dos protocolos
//preciso receber de vc, os tipos, canais, processos auxiliares e protocolos
// verificar se protocolos foram definidos corretamente
}//GEN-LAST:event_jButton1ActionPerformed
/* public void checalista(){
for(int i = 0; i<protocols.size(); i++){
if(canal == protocols.get(i).getCanal()){
local = i;
break;
}
}
}*/
public int takeLugar(Channel c){
for (int i = 0; i<protocols.size(); i++){
if(c==protocols.get(i).getCanal()){
return i;
}
}
return -1;
}
/**
* @param args the command line arguments
*/
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextArea dualProtocol;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextArea protocol;
// End of variables declaration//GEN-END:variables
}