/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package GUI; import LOGIC.BoolType; import LOGIC.Channel; import LOGIC.Contract; import LOGIC.Datatype; import LOGIC.EventChannel; import LOGIC.Internacional; import LOGIC.IntervalType; import LOGIC.ObjectList; import LOGIC.Protocols; import java.awt.AWTException; import java.awt.Robot; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; import javax.swing.table.DefaultTableModel; /** * * @author sarah */ public class InsertEventGUI extends javax.swing.JFrame { /** * Creates new form InsertEventGUI */ public InsertEventGUI(Internacional inter, Channel c, Contract contrato, ObjectList listas, String tipo) { this.c = c; this.inter = inter; tipos = new String[c.getType().size() + 1]; nome = c.getName() + "."; for (int i = 0; i < c.getType().size(); i++) { if (i == c.getType().size() - 1) { nome = nome + c.getType().get(i).getNome(); } else { nome = nome + c.getType().get(i).getNome() + "."; } } tipos[0] = c.getName(); for (int i = 1; i < c.getType().size() + 1; i++) { tipos[i] = c.getType().get(i - 1).getNome(); // System.out.println(c.getType().get(i - 1).getNome()); } tTipo = new DefaultTableModel(null, tipos); if (c.getType().isEmpty()) { } else { String[] linha = new String[]{null}; tTipo.addRow(linha); for (int j = -1; j < c.getType().size(); j++) { //if (VerificaI(c.getType().get(j).getEvento())){ tTipo.addColumn(linha); } tTipo.setValueAt(c.getName(), 0, 0); } initComponents(); tTipo.setColumnCount(tipos.length); channel.setText(nome); this.listas = listas; this.contrato = contrato; this.tipo = tipo; bundleButtons(); } Channel c; String[] tipos; String nome = ""; DefaultTableModel tTipo; ObjectList listas; Contract contrato; String tipo; Internacional inter; /** * 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() { finish = new javax.swing.JButton(); cancel = new javax.swing.JButton(); defina = new javax.swing.JLabel(); channel = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); tabela = new javax.swing.JTable(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setMinimumSize(new java.awt.Dimension(308, 160)); finish.setText("Concluir"); finish.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { finishActionPerformed(evt); } }); cancel.setText("Cancelar"); cancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelActionPerformed(evt); } }); defina.setText("Defina os valores para o canal:"); channel.setText("canal"); tabela.setModel(tTipo); tabela.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { tabelaMouseClicked(evt); } }); jScrollPane1.setViewportView(tabela); 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() .addGap(12, 12, 12) .addComponent(channel) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(cancel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(finish)) .addGroup(layout.createSequentialGroup() .addComponent(defina) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(defina) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(channel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(finish) .addComponent(cancel)) .addContainerGap()) ); pack(); }// //GEN-END:initComponents private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed ContractGUI.aberto = false; this.dispose(); // TODO add your handling code here: }//GEN-LAST:event_cancelActionPerformed private void finishActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_finishActionPerformed tabela.selectAll(); String aux = (String) tabela.getValueAt(0, 0); String aux2 = (String) tabela.getValueAt(0, 1); //if (aux2 == null) { // JOptionPane.showMessageDialog(null, "coloque pelo menos um tipo para que seja um evento..."); // } else { if (aux.equals(c.getName())) { if (checaTipos()) { String evento; evento = criaEvento(); System.out.println(evento); EventChannel e = new EventChannel(); e.criaEvento(c, evento); //System.out.println("olha o sufixo aquiiii .... "+evento); contrato.getEvents().add(e); //System.out.println("sufixoooooooo... "+e.getSufixo()); if (tipo.equals("in")) { contrato.getIn().add(e); if(verificaC()){ c.setFlag("in"); contrato.getChannel().add(c); } } if (tipo.equals("out")) { contrato.getOut().add(e); if(verificaC()){ c.setFlag("out"); contrato.getChannel().add(c); } } if (tipo.equals("cc")){ if(verificaP(c.getName()+evento)){ Protocols p = new Protocols(); p.setCanal(c); p.setDualProtocol(""); p.setProtocol(""); p.setCc(c.getName()+evento); contrato.getProtocolos().add(p); if(verificaC()){ c.setFlag("cc"); contrato.getChannel().add(c); } } else{ JOptionPane.showMessageDialog(null, "Esse canal de comunicação já existe"); } } this.dispose(); } else { } } else { JOptionPane.showMessageDialog(null, "O canal não é mais o mesmo..."); } // } // TODO add your handling code here: }//GEN-LAST:event_finishActionPerformed private void tabelaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaMouseClicked // TODO add your handling code here: }//GEN-LAST:event_tabelaMouseClicked public boolean verificaP(String c){ for(int i = 0; i= inter.getMim()) { // System.out.println("inter true " + s); return true; } else { // System.out.println("inter false " + s + " min: " + inter.getMim() + " max: " + inter.getMax()); } } if (t instanceof BoolType) { if (s.equals("true") || s.equals("false")) { // System.out.println("bool true " + s); return true; } else { System.out.println("bool false " + s); } } return false; } public String criaEvento() { String e; String aux2 = (String) tabela.getValueAt(0, 1); if (aux2 == null) { e = ""; } else { e = "."; } for (int i = 1; i < tabela.getColumnCount(); i++) { String aux = (String) tabela.getValueAt(0, i); String aux1 = "uhu"; if (i < tabela.getColumnCount() - 1) { aux1 = (String) tabela.getValueAt(0, i + 1); } if (aux == null) { break; } if (i == tabela.getColumnCount() - 1 || aux1 == null) { e = e + aux; } else { e = e + aux + "."; } } return e; } public boolean verificaC(){ for(int i = 0; i