package GUI;
import LOGIC.Channel;
import LOGIC.Internacional;
import LOGIC.ObjectList;
import java.util.LinkedList;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableModel;
public class ChannelGUI extends javax.swing.JFrame {
public ChannelGUI(Internacional inter, ObjectList listas, boolean edicao, int local) { //inicialização sa tela...
this.setTitle("Channels"); //seta o titulo da tela...
this.edicao = edicao;
this.local = local;
TelaInicial.aberto = true;
this.listas = listas;
this.inter = inter;
//colunas das tabelas...
name = inter.retornarMensagem("COD0012");
descricao = inter.retornarMensagem("COD0013");
tipo = inter.retornarMensagem("COD0015");
canal = inter.retornarMensagem("COD0003");
//tabelas...
tmTipo = new DefaultTableModel(null, new String[]{name, descricao});
tmTipo2 = new DefaultTableModel(null, new String[]{tipo});
initComponents();
mostrar();
mostrar2();
//botões...
bundleButtons();
verificaEdicao();
}
//variáveis que auxiliam na cração das tabelas...
Internacional inter;
String name;
String descricao;
String canal;
String tipo;
ObjectList listas = new ObjectList();
Channel c = new Channel();
int local;
boolean edicao;
//criação das tabelas...
DefaultTableModel tmTipo = new DefaultTableModel(null, new String[]{"Nome", "Descrição"}) {
public boolean isCellEditable(int rowIndex, int mColIndex) {
return false;
}
};
DefaultTableModel tmTipo2 = new DefaultTableModel(null, new String[]{"tipo"}) {
public boolean isCellEditable(int rowIndex, int mColIndex) {
return false;
}
};
ListSelectionModel listS;
//TelaInicial i = new TelaInicial();
LinkedList<LOGIC.Type> listaTipos = new LinkedList<LOGIC.Type>();
//Lingua lingua = new Lingua();
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
nameChannel = new javax.swing.JLabel();
nome = new javax.swing.JTextField();
typeChannel = new javax.swing.JLabel();
inserir = new javax.swing.JButton();
remover = new javax.swing.JButton();
concluir = new javax.swing.JButton();
jScrollPane3 = new javax.swing.JScrollPane();
tabTipos = new javax.swing.JTable();
jScrollPane4 = new javax.swing.JScrollPane();
tabCanais = new javax.swing.JTable();
cancelar = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setMinimumSize(new java.awt.Dimension(492, 344));
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosed(java.awt.event.WindowEvent evt) {
formWindowClosed(evt);
}
});
nameChannel.setText("Nome:");
typeChannel.setText("Tipos:");
inserir.setText("Inserir");
inserir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
inserirActionPerformed(evt);
}
});
remover.setText("Remover");
remover.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
removerActionPerformed(evt);
}
});
concluir.setText("Concluir");
concluir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
concluirActionPerformed(evt);
}
});
tabTipos.setModel(tmTipo);
tabTipos.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tabTiposMouseClicked(evt);
}
});
jScrollPane3.setViewportView(tabTipos);
tabCanais.setModel(tmTipo2);
jScrollPane4.setViewportView(tabCanais);
cancelar.setText("Cancelar");
cancelar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelarActionPerformed(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(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(nameChannel)
.addComponent(typeChannel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(nome, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(inserir)
.addComponent(remover))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(49, 49, 49))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(cancelar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(concluir)
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(nameChannel)
.addComponent(nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(36, 36, 36)
.addComponent(inserir)
.addGap(18, 18, 18)
.addComponent(remover)
.addGap(34, 179, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(typeChannel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(concluir)
.addComponent(cancelar))
.addContainerGap())))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void concluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_concluirActionPerformed
int lugar;
if (edicao == true) {
lugar = local;
} else {
lugar = (listas.getChannelList().size());
listas.getChannelList().add(new Channel());
}
if (verificaN()) {
if (listaTipos.size() > 0) {
c.setName(nome.getText());
c.setType(listaTipos);
listas.getChannelList().set(lugar, c);
TelaInicial.aberto = false;
this.dispose();
} else {
JOptionPane.showMessageDialog(null, "selecione um ou mais tipos para o canal...");
}
} else {
JOptionPane.showMessageDialog(null, "nome de canal ja existe...");
}
}//GEN-LAST:event_concluirActionPerformed
private void inserirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inserirActionPerformed
//inserção de um canal definitivamente...
if (tabTipos.getSelectedRow() == -1) {
//JOptionPane.showMessageDialog(null, inter.retornarMensagem("COD0025"));
} else {
listaTipos.add(listas.getTypeList().get(tabTipos.getSelectedRow()));
mostrar2();
}
}//GEN-LAST:event_inserirActionPerformed
private void removerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removerActionPerformed
excLinha(); //função responsável pela remoção de um item da lista de canais definitivos...
mostrar2(); //modifica a tabela
}//GEN-LAST:event_removerActionPerformed
private void tabTiposMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabTiposMouseClicked
}//GEN-LAST:event_tabTiposMouseClicked
private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
TelaInicial.aberto = false;
}//GEN-LAST:event_formWindowClosed
private void cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarActionPerformed
TelaInicial.aberto = false;
ChannelGUI.this.setVisible(false);
}//GEN-LAST:event_cancelarActionPerformed
public boolean verificaN() {
for (int j = 0; j < listas.getChannelList().size(); j++) {
if ((nome.getText().equals(listas.getChannelList().get(j).getName())) && local != j) {
return false;
}
}
return true;
}
public void excLinha() {
if (tabCanais.getSelectedRow() > -1) {
listaTipos.remove(tabCanais.getSelectedRow());
} else {
}
/*listaTipos.remove(tabCanais.getSelectedRow());
table.repaint();*/
}
public void mostrar() {
while (tabTipos.getRowCount() > 0) {
tmTipo.removeRow(0);
}
if (listas.getTypeList().isEmpty()) {
//JOptionPane.showMessageDialog(null, inter.retornarMensagem("COD0032"));
} else {
String[] linha = new String[]{null, null};
for (int j = 0; j < listas.getTypeList().size(); j++) {
tmTipo.addRow(linha);
tmTipo.setValueAt(listas.getTypeList().get(j).getNome(), j, 0);
tmTipo.setValueAt(listas.getTypeList().get(j).getTipo(), j, 1);
}
}
}
public void mostrar2() {
while (tabCanais.getRowCount() > 0) {
tmTipo2.removeRow(0);
}
if (listaTipos.isEmpty()) {
} else {
String[] linha = new String[]{null, null};
for (int j = 0; j < listaTipos.size(); j++) {
tmTipo2.addRow(linha);
tmTipo2.setValueAt(listaTipos.get(j).getNome(), j, 0);
}
}
}
private void verificaEdicao() {
if (edicao == true) {
nome.setText(listas.getChannelList().get(local).getName());
listaTipos = (LinkedList<LOGIC.Type>) listas.getChannelList().get(local).getType();
mostrar2();
}
}
public void bundleButtons() {
nameChannel.setText(inter.retornarMensagem("COD0032") + ":");
typeChannel.setText(inter.retornarMensagem("COD0001") + ":");
inserir.setText(inter.retornarMensagem("COD0031"));
remover.setText(inter.retornarMensagem("COD0021"));
concluir.setText(inter.retornarMensagem("COD0025"));
cancelar.setText(inter.retornarMensagem("COD0026"));
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelar;
private javax.swing.JButton concluir;
private javax.swing.JButton inserir;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JLabel nameChannel;
private javax.swing.JTextField nome;
private javax.swing.JButton remover;
private javax.swing.JTable tabCanais;
private javax.swing.JTable tabTipos;
private javax.swing.JLabel typeChannel;
// End of variables declaration//GEN-END:variables
}