Blame view

BRIC/src/GUI/ProtocolsGUI.java 8.91 KB
eeb5cac08   Madiel de Souza Conserva Filho   first
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
  /*
   * 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.
   Por favor, escreva novamente seu protocolo 
   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
  }