/*
* ClienteView.java
*
* Created on 30 de Outubro de 2008, 12:16
*/
package view;
import model.Cliente;
import controller.GerenciadorOperacional;
import controller.Strings;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import thread.ClienteRunMensagem;
import view.componentes.JLabelButton;
/**
*
* @author Consult
*/
public class ClienteView extends javax.swing.JFrame {
private static Cliente cliente;
public static String status;
public static String usuario;
/** Creates new form ClienteView */
public ClienteView() {
initComponents();
jLRelease.setText(Strings.release);
}
public static boolean desconectar() {
try {
cliente.getOut().println("/sair");
cliente.getSocket().close();
status = "desconectado";
ClienteMensagem.jLabelStatus.setText("Desconectado");
jBDesconectar.setEnabled(false);
jBConversa.setEnabled(false);
jBConectar.setEnabled(true);
jTFUsuario.setEnabled(true);
return true;
} catch (IOException ex) {
Logger.getLogger(ClienteMensagem.class.getName()).log(Level.SEVERE, null, ex);
return false;
}
}
public static boolean conectar() {
usuario = jTFUsuario.getText();
cliente = new Cliente(usuario);
cliente.getOut().println(usuario);
new ClienteRunMensagem(cliente).start();
jBConectar.setEnabled(false);
jBDesconectar.setEnabled(true);
jBConversa.setEnabled(true);
jTFUsuario.setText("");
jTFUsuario.setEnabled(false);
status = "conectado";
return true;
}
/** 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();
jLabel1 = new javax.swing.JLabel();
jBConectar = new javax.swing.JButton();
jBDesconectar = new javax.swing.JButton();
jTFUsuario = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jBConversa = new javax.swing.JButton();
jLRelease = new JLabelButton(Strings.release);
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem2 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
setTitle("Messenger");
setBackground(new java.awt.Color(255, 255, 255));
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
jPanel1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jPanel1MouseClicked(evt);
}
});
jPanel1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseDragged(java.awt.event.MouseEvent evt) {
jPanel1MouseDragged(evt);
}
});
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/images/fagoc.PNG"))); // NOI18N
jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jBConectar.setText("Entrar");
jBConectar.setFocusable(false);
jBConectar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jBConectar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jBConectar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBConectarActionPerformed(evt);
}
});
jBDesconectar.setText("Sair");
jBDesconectar.setFocusable(false);
jBDesconectar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jBDesconectar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jBDesconectar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBDesconectarActionPerformed(evt);
}
});
jTFUsuario.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTFUsuarioActionPerformed(evt);
}
});
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel2.setText("Usuário:");
jLabel2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jBConversa.setText("Conversa");
jBConversa.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jBConversaActionPerformed(evt);
}
});
jLRelease.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLRelease.setText("Release");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLRelease, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jBConectar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jBDesconectar)
.addGap(18, 18, 18)
.addComponent(jBConversa))
.addComponent(jTFUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE))
.addGap(18, 18, 18))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 53, Short.MAX_VALUE)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTFUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jBConversa)
.addComponent(jBConectar)
.addComponent(jBDesconectar))
.addGap(18, 18, 18)
.addComponent(jLRelease, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jMenu1.setText("Arquivo");
jMenuItem2.setText("Sair");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem2);
jMenuBar1.add(jMenu1);
jMenu2.setText("Ajuda");
jMenuItem1.setText("Sobre");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem1);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
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.Alignment.TRAILING, 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-263)/2, (screenSize.height-282)/2, 263, 282);
}// </editor-fold>//GEN-END:initComponents
private void jBConectarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBConectarActionPerformed
// TODO add your handling code here:
conectar();
}//GEN-LAST:event_jBConectarActionPerformed
private void jBDesconectarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBDesconectarActionPerformed
// TODO add your handling code here:
desconectar();
}//GEN-LAST:event_jBDesconectarActionPerformed
private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
// TODO add your handling code here:
jBDesconectar.setEnabled(false);
jBConversa.setEnabled(false);
}//GEN-LAST:event_formWindowOpened
private void jBConversaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBConversaActionPerformed
// TODO add your handling code here:
new ClienteMensagem(cliente).setVisible(true);
}//GEN-LAST:event_jBConversaActionPerformed
private void jTFUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTFUsuarioActionPerformed
// TODO add your handling code here:
conectar();
}//GEN-LAST:event_jTFUsuarioActionPerformed
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
// TODO add your handling code here:
GerenciadorOperacional.setVisibleMessenger(false);
}//GEN-LAST:event_formWindowClosing
private void jPanel1MouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel1MouseDragged
// TODO add your handling code here:
//System.out.println("evt - " + evt.getXOnScreen() + ", " + evt.getYOnScreen());
//System.out.println("form - " + getX() + ", " + getY());
int x = getX();
int i = evt.getXOnScreen();
int a = x + (i - x);
int y = getY();
int j = evt.getYOnScreen();
int b = y + (j - y);
setLocation(a, b);
}//GEN-LAST:event_jPanel1MouseDragged
private void jPanel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel1MouseClicked
// TODO add your handling code here:
System.out.println(evt.getXOnScreen() + ", " + evt.getYOnScreen());
System.out.println(getX() + ", " + getY());
}//GEN-LAST:event_jPanel1MouseClicked
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
// TODO add your handling code here:
new FormSobre().setVisible(true);
}//GEN-LAST:event_jMenuItem1ActionPerformed
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
// TODO add your handling code here:
System.exit(0);
}//GEN-LAST:event_jMenuItem2ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ClienteView().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
public static javax.swing.JButton jBConectar;
public static javax.swing.JButton jBConversa;
public static javax.swing.JButton jBDesconectar;
private javax.swing.JLabel jLRelease;
private javax.swing.JLabel jLabel1;
public static javax.swing.JLabel jLabel2;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JPanel jPanel1;
public static javax.swing.JTextField jTFUsuario;
// End of variables declaration//GEN-END:variables
}