/*
* ServidorView.java
*
* Created on 28 de Outubro de 2008, 00:07
*/
package view;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.Servidor;
import thread.ServidorRunConexao;
import thread.ServidorRunMensagem;
/**
*
* @author Consult
*/
public class ServidorView extends javax.swing.JFrame {
private Servidor servidor;
private Thread thread;
private int porta = 8080;
/** Creates new form ServidorView */
public ServidorView() {
initComponents();
jBConectar.setEnabled(true);
jBDesconectar.setEnabled(false);
}
/** 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() {
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextAreaReceptor = new javax.swing.JTextArea();
jSeparator1 = new javax.swing.JSeparator();
jBConectar = new javax.swing.JButton();
jBDesconectar = new javax.swing.JButton();
jLbStatus = new javax.swing.JLabel();
jSeparator2 = new javax.swing.JSeparator();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Servidor");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
jTextAreaReceptor.setColumns(20);
jTextAreaReceptor.setEditable(false);
jTextAreaReceptor.setFont(new java.awt.Font("Arial", 0, 13));
jTextAreaReceptor.setRows(5);
jScrollPane1.setViewportView(jTextAreaReceptor);
jBConectar.setText("Conectar");
jBConectar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBConectarActionPerformed(evt);
}
});
jBDesconectar.setText("Desconectar");
jBDesconectar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBDesconectarActionPerformed(evt);
}
});
jLbStatus.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLbStatus.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/images/loading.gif"))); // NOI18N
jLbStatus.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
.addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(jLbStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jBConectar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jBDesconectar)))))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jBConectar)
.addComponent(jBDesconectar)))
.addComponent(jLbStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE)
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-293)/2, (screenSize.height-368)/2, 293, 368);
}// </editor-fold>//GEN-END:initComponents
private void jBConectarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBConectarActionPerformed
// TODO add your handling code here:
servidor = new Servidor(porta);
thread = new ServidorRunConexao(servidor);
thread.start();
jBConectar.setEnabled(false);
jBDesconectar.setEnabled(true);
}//GEN-LAST:event_jBConectarActionPerformed
private void jBDesconectarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBDesconectarActionPerformed
// TODO add your handling code here:
try {
ServidorRunConexao.loop = false;
ServidorRunMensagem.loop = false;
thread.interrupt();
jBConectar.setEnabled(true);
jBDesconectar.setEnabled(false);
jTextAreaReceptor.append("\nÚltimas mensagens de cada cliente...\n\n");
} catch (Exception ex) {
Logger.getLogger(ServidorView.class.getName()).log(Level.SEVERE, null, ex);//GEN-LAST:event_jBDesconectarActionPerformed
}
ServidorView.jLbStatus.setVisible(false);
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
// TODO add your handling code here:
jLbStatus.setVisible(false);
}//GEN-LAST:event_formWindowOpened
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jBConectar;
private javax.swing.JButton jBDesconectar;
public static javax.swing.JLabel jLbStatus;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JSeparator jSeparator2;
public static javax.swing.JTextArea jTextAreaReceptor;
// End of variables declaration//GEN-END:variables
}