/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package GUI; import CSP_ANALYSE.CSPVerificationRules; import CSP_ANALYSE.FDRResult; import CSP_CREATOR.CreatorNewComponent; import LOGIC.Channel; import LOGIC.Instance; import LOGIC.Internacional; import LOGIC.ObjectList; import LOGIC.Protocols; import java.util.ArrayList; import java.util.LinkedList; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JComboBox; import javax.swing.JOptionPane; /** * * @author Dalay */ public class SystemCompositionSimplesGUI extends javax.swing.JFrame { public SystemCompositionSimplesGUI(Internacional inter, ObjectList listas) { initComponents(); this.inter = inter; combo1.removeAllItems(); combo2.removeAllItems(); combo3.removeAllItems(); combo4.removeAllItems(); combo5.removeAllItems(); combo1.addItem(inter.retornarMensagem("COD0013")); combo2.addItem(inter.retornarMensagem("COD0012")); combo3.addItem(inter.retornarMensagem("COD0013")); combo4.addItem(inter.retornarMensagem("COD0012")); combo5.addItem(inter.retornarMensagem("COD0014")); this.listas = listas; criarListas(); listar(); compor.setText(inter.retornarMensagem("COD0011")); } LinkedList listaInstances = new LinkedList(); LinkedList listaProtocols = new LinkedList(); ObjectList listas; Internacional inter; CreatorNewComponent newComp; LinkedList instancias = new LinkedList(); LinkedList canais; public void criarListas() { for (int i = 0; i < listas.getInstanceList().size(); i++) { if (listas.getInstanceList().get(i).getFlag()) { instancias.add(listas.getInstanceList().get(i)); } } } public void listarRegra() { if (combo1.getSelectedItem().equals(inter.retornarMensagem("COD0013")) || combo3.getSelectedItem().equals(inter.retornarMensagem("COD0013"))) { combo5.removeAllItems(); combo5.addItem(inter.retornarMensagem("COD0014")); } else { if (combo2.getSelectedItem().equals(inter.retornarMensagem("COD0012")) && combo4.getSelectedItem().equals(inter.retornarMensagem("COD0012"))) { combo5.removeAllItems(); combo5.addItem(inter.retornarMensagem("COD0014")); combo5.addItem("Interleaving"); } else { if (!combo2.getSelectedItem().equals(inter.retornarMensagem("COD0012")) && !combo4.getSelectedItem().equals(inter.retornarMensagem("COD0012"))) { if (combo1.getSelectedItem().equals(combo3.getSelectedItem())) { combo5.removeAllItems(); combo5.addItem(inter.retornarMensagem("COD0014")); combo5.addItem("Feedback"); combo5.addItem("Reflexive"); } else { combo5.removeAllItems(); combo5.addItem(inter.retornarMensagem("COD0014")); combo5.addItem("Interleaving"); combo5.addItem("Communication"); } } } } } private void listar() { // System.out.println(listas.getInstanceList()); for (int i = 0; i < instancias.size(); i++) { combo1.addItem(instancias.get(i).getName()); } for (int i = 0; i < instancias.size(); i++) { combo3.addItem(instancias.get(i).getName()); } } public void compor() throws InterruptedException { new Thread() { public void run() { if (combo5.getSelectedItem().equals(inter.retornarMensagem("COD0014"))) { JOptionPane.showMessageDialog(null, "Selecione um modo de composição e os componentes..."); } if (combo5.getSelectedItem().equals("Interleaving")) { listaInstances.add(instancias.get(combo1.getSelectedIndex() - 1)); listaInstances.add(instancias.get(combo3.getSelectedIndex() - 1)); CSPVerificationRules r = new CSPVerificationRules(listaInstances, listaProtocols, listas); ArrayList result = new ArrayList(); result = r.RuleInterleaveIsDeadlockFree(); CreatorNewComponent newComp = new CreatorNewComponent(listaInstances, listaProtocols); excluiPais(listaInstances.get(0), listaInstances.get(1)); listas.getInstanceList().add(newComp.creatorNewComponentIterleave()); new ShowResultIOProcessGUI(inter, result, "composition").setVisible(true); } if (combo5.getSelectedItem().equals("Communication")) { listaInstances.add(instancias.get(combo1.getSelectedIndex() - 1)); listaInstances.add(instancias.get(combo3.getSelectedIndex() - 1)); listaProtocols.add(instancias.get(combo1.getSelectedIndex() - 1).getProtocolos().get(combo2.getSelectedIndex() - 1)); listaProtocols.add(instancias.get(combo3.getSelectedIndex() - 1).getProtocolos().get(combo4.getSelectedIndex() - 1)); CSPVerificationRules r = new CSPVerificationRules(listaInstances, listaProtocols, listas); ArrayList result = new ArrayList(); try { result = r.RuleCommunicationIsDeadlockFree(); } catch (InterruptedException ex) { Logger.getLogger(SystemCompositionSimplesGUI.class.getName()).log(Level.SEVERE, null, ex); } CreatorNewComponent newComp = new CreatorNewComponent(listaInstances, listaProtocols); excluiPais(listaInstances.get(0), listaInstances.get(1)); listas.getInstanceList().add(newComp.creatorNewComponentComunication()); new ShowResultIOProcessGUI(inter, result, "composition").setVisible(true); } if (combo5.getSelectedItem().equals("Feedback")) { listaInstances.add(instancias.get(combo1.getSelectedIndex() - 1)); listaInstances.add(instancias.get(combo3.getSelectedIndex() - 1)); listaProtocols.add(instancias.get(combo1.getSelectedIndex() - 1).getProtocolos().get(combo2.getSelectedIndex() - 1)); listaProtocols.add(instancias.get(combo3.getSelectedIndex() - 1).getProtocolos().get(combo4.getSelectedIndex() - 1)); CSPVerificationRules r = new CSPVerificationRules(listaInstances, listaProtocols, listas); ArrayList result = new ArrayList(); try { result = r.RuleFeedbackIsDeadlockFree(); } catch (InterruptedException ex) { Logger.getLogger(SystemCompositionSimplesGUI.class.getName()).log(Level.SEVERE, null, ex); } CreatorNewComponent newComp = new CreatorNewComponent(listaInstances, listaProtocols); excluiPais(listaInstances.get(0), listaInstances.get(1)); listas.getInstanceList().add(newComp.creatorNewComponentFeedBack()); new ShowResultIOProcessGUI(inter, result, "composition").setVisible(true); } if (combo5.getSelectedItem().equals("Reflexive")) { listaInstances.add(instancias.get(combo1.getSelectedIndex() - 1)); listaInstances.add(instancias.get(combo3.getSelectedIndex() - 1)); listaProtocols.add(instancias.get(combo1.getSelectedIndex() - 1).getProtocolos().get(combo2.getSelectedIndex() - 1)); listaProtocols.add(instancias.get(combo3.getSelectedIndex() - 1).getProtocolos().get(combo4.getSelectedIndex() - 1)); CSPVerificationRules r = new CSPVerificationRules(listaInstances, listaProtocols, listas); ArrayList result = new ArrayList(); try { result = r.RuleReflexiveIsDeadlockFree(); //trocar essa linha } catch (InterruptedException ex) { Logger.getLogger(SystemCompositionSimplesGUI.class.getName()).log(Level.SEVERE, null, ex); } CreatorNewComponent newComp = new CreatorNewComponent(listaInstances, listaProtocols); excluiPais(listaInstances.get(0), listaInstances.get(1)); listas.getInstanceList().add(newComp.creatorNewComponentReflexive()); new ShowResultIOProcessGUI(inter, result, "composition").setVisible(true); ; } } }.start(); this.dispose(); } public void excluiPais(Instance instancia1, Instance instancia2) { if (listas.getInstanceList().contains(instancia1)) { listas.getInstanceList().remove(instancia1); } if (listas.getInstanceList().contains(instancia2)) { listas.getInstanceList().remove(instancia2); } } private void listarCanais1() { if (!combo1.getSelectedItem().equals(inter.retornarMensagem("COD0013"))) { combo2.removeAllItems(); combo2.addItem(inter.retornarMensagem("COD0012")); //System.out.println("hvjhgvfjbvkjhvb " + instancias.get(combo1.getSelectedIndex() - 1).getProtocolos()); for (int i = 0; i < instancias.get(combo1.getSelectedIndex() - 1).getProtocolos().size(); i++) { if (!instancias.get(combo1.getSelectedIndex() - 1).getProtocolos().get(i).getProtocol().equals("") && !instancias.get(combo1.getSelectedIndex() - 1).getProtocolos().get(i).getDualProtocol().equals("")) { combo2.addItem(instancias.get(combo1.getSelectedIndex() - 1).getProtocolos().get(i).getCc()); System.out.println("COISASS " + instancias.get(combo1.getSelectedIndex() - 1).getProtocolos().get(i).getCanal().getName()); } } } else { combo2.removeAllItems(); combo2.addItem(inter.retornarMensagem("COD0012")); } } private void listarCanais2() { if (!combo3.getSelectedItem().equals(inter.retornarMensagem("COD0013"))) { combo4.removeAllItems(); combo4.addItem(inter.retornarMensagem("COD0012")); for (int i = 0; i < instancias.get(combo3.getSelectedIndex() - 1).getProtocolos().size(); i++) { if (!instancias.get(combo3.getSelectedIndex() - 1).getProtocolos().get(i).getProtocol().equals("") && !instancias.get(combo3.getSelectedIndex() - 1).getProtocolos().get(i).getDualProtocol().equals("")) { combo4.addItem(instancias.get(combo3.getSelectedIndex() - 1).getProtocolos().get(i).getCc()); } } } else { combo4.removeAllItems(); combo4.addItem(inter.retornarMensagem("COD0012")); } } /** * 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") // //GEN-BEGIN:initComponents private void initComponents() { combo1 = new javax.swing.JComboBox(); combo2 = new javax.swing.JComboBox(); combo3 = new javax.swing.JComboBox(); combo4 = new javax.swing.JComboBox(); combo5 = new javax.swing.JComboBox(); compor = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setMinimumSize(new java.awt.Dimension(358, 100)); combo1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); combo1.setMaximumSize(new java.awt.Dimension(190, 27)); combo1.setMinimumSize(new java.awt.Dimension(190, 27)); combo1.setPreferredSize(new java.awt.Dimension(190, 27)); combo1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { combo1ActionPerformed(evt); } }); combo2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); combo2.setMaximumSize(new java.awt.Dimension(190, 27)); combo2.setMinimumSize(new java.awt.Dimension(190, 27)); combo2.setPreferredSize(new java.awt.Dimension(190, 27)); combo2.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseEntered(java.awt.event.MouseEvent evt) { combo2MouseEntered(evt); } }); combo2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { combo2ActionPerformed(evt); } }); combo3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); combo3.setMaximumSize(new java.awt.Dimension(190, 27)); combo3.setMinimumSize(new java.awt.Dimension(190, 27)); combo3.setPreferredSize(new java.awt.Dimension(190, 27)); combo4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); combo4.setMaximumSize(new java.awt.Dimension(190, 27)); combo4.setMinimumSize(new java.awt.Dimension(190, 27)); combo4.setPreferredSize(new java.awt.Dimension(190, 27)); combo4.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseEntered(java.awt.event.MouseEvent evt) { combo4MouseEntered(evt); } }); combo4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { combo4ActionPerformed(evt); } }); combo5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); combo5.setMaximumSize(new java.awt.Dimension(190, 27)); combo5.setMinimumSize(new java.awt.Dimension(190, 27)); combo5.setPreferredSize(new java.awt.Dimension(190, 27)); combo5.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseEntered(java.awt.event.MouseEvent evt) { combo5MouseEntered(evt); } }); compor.setText("compor"); compor.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { comporActionPerformed(evt); } }); jLabel1.setText("Componente 1:"); jLabel2.setText("Canal:"); jLabel3.setText("Componente 2:"); jLabel4.setText("Canal:"); jLabel5.setText("Regra:"); 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) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel1) .addComponent(jLabel3) .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(combo1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(combo2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(combo3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(combo4, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(combo5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createSequentialGroup() .addGap(146, 146, 146) .addComponent(compor))) .addContainerGap(34, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(combo1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(combo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2)) .addGap(19, 19, 19) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel3) .addComponent(combo3, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(combo4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4)) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(combo5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5)) .addGap(18, 18, 18) .addComponent(compor) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// //GEN-END:initComponents private void comporActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comporActionPerformed try { /*CSPVerificationRules r = new CSPVerificationRules(listaInstances, listas); ArrayList result = new ArrayList(); result = r.RuleIsDeadlockFree(); CreatorNewComponent newComp = new CreatorNewComponent(listaInstances); listas.getInstanceList().add(newComp); new ShowResultIOProcessGUI(inter, result, "composition").setVisible(true);*/ compor(); } catch (InterruptedException ex) { Logger.getLogger(SystemCompositionSimplesGUI.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_comporActionPerformed private void combo5MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_combo5MouseEntered listarRegra(); // TODO add your handling code here: }//GEN-LAST:event_combo5MouseEntered private void combo2MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_combo2MouseEntered listarCanais1(); // TODO add your handling code here: }//GEN-LAST:event_combo2MouseEntered private void combo4MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_combo4MouseEntered listarCanais2(); // TODO add your handling code here: }//GEN-LAST:event_combo4MouseEntered private void combo2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_combo2ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_combo2ActionPerformed private void combo4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_combo4ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_combo4ActionPerformed private void combo1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_combo1ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_combo1ActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox combo1; private javax.swing.JComboBox combo2; private javax.swing.JComboBox combo3; private javax.swing.JComboBox combo4; private javax.swing.JComboBox combo5; private javax.swing.JButton compor; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; // End of variables declaration//GEN-END:variables }