/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* SendMessageDialog.java
*
* Created on Nov 5, 2009, 3:56:37 PM
*/
package com.client.gui;
import com.bean.MessageBean;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
/**
*
* @author Administrator
*/
public class SendMessageDialog extends javax.swing.JFrame {
/** Creates new form SendMessageDialog */
ClientMain clientMain = null;
public SendMessageDialog(ClientMain clientMain) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);
initComponents();
this.clientMain = clientMain;
ipAddressLabel.setText(InetAddress.getLocalHost().getHostAddress());
} catch (UnknownHostException ex) {
Logger.getLogger(SendMessageDialog.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(SendMessageDialog.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(SendMessageDialog.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(SendMessageDialog.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(SendMessageDialog.class.getName()).log(Level.SEVERE, null, ex);
}
}
/** 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() {
messagePopupMenu = new javax.swing.JPopupMenu();
cutMenuItem = new javax.swing.JMenuItem();
copyMenuItem = new javax.swing.JMenuItem();
pasteMenuItem = new javax.swing.JMenuItem();
clearMenuItem = new javax.swing.JMenuItem();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
ipAddressLabel = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
subjectTextField = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
messageTextArea = new javax.swing.JTextArea();
closeButton = new javax.swing.JButton();
sendMessageButton = new javax.swing.JButton();
clearButton = new javax.swing.JButton();
cutMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/client/icons/cut.PNG"))); // NOI18N
cutMenuItem.setText("Cut");
messagePopupMenu.add(cutMenuItem);
copyMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/client/icons/copy.PNG"))); // NOI18N
copyMenuItem.setText("Copy");
messagePopupMenu.add(copyMenuItem);
pasteMenuItem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/client/icons/paste.png"))); // NOI18N
pasteMenuItem.setText("Paste");
messagePopupMenu.add(pasteMenuItem);
clearMenuItem.setText("Clear Message");
messagePopupMenu.add(clearMenuItem);
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Send Message To Server");
jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jLabel1.setText("IP Address:");
ipAddressLabel.setText("000.000.000.000");
jLabel2.setText("Subject:");
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.TRAILING)
.addComponent(jLabel2)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(ipAddressLabel)
.addComponent(subjectTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 533, Short.MAX_VALUE))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(ipAddressLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(subjectTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
messageTextArea.setColumns(20);
messageTextArea.setRows(5);
messageTextArea.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
messageTextAreaMouseClicked(evt);
}
});
jScrollPane1.setViewportView(messageTextArea);
closeButton.setText("Close");
closeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
closeButtonActionPerformed(evt);
}
});
sendMessageButton.setText("Send");
sendMessageButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sendMessageButtonActionPerformed(evt);
}
});
clearButton.setText("Clear");
clearButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 619, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(clearButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(sendMessageButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(closeButton)))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {clearButton, closeButton, sendMessageButton});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(closeButton)
.addComponent(sendMessageButton)
.addComponent(clearButton))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void messageTextAreaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_messageTextAreaMouseClicked
// TODO add your handling code here:
if (evt.isMetaDown()) {
messagePopupMenu.show(messageTextArea, evt.getX(), evt.getY());
}
}//GEN-LAST:event_messageTextAreaMouseClicked
private void sendMessageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendMessageButtonActionPerformed
if (subjectTextField.getText().equals("")) {
JOptionPane.showMessageDialog(this,
"Please enter the message subject.", "Send Message",
JOptionPane.WARNING_MESSAGE);
} else if (messageTextArea.getText().equals("")) {
JOptionPane.showMessageDialog(this,
"Please enter the message content.", "Send Message",
JOptionPane.WARNING_MESSAGE);
} else {
try {
MessageBean messageBean = new MessageBean();
messageBean.setSubject(subjectTextField.getText());
messageBean.setMessage(messageTextArea.getText());
clientMain.connectionManager.sendDataToServer(messageBean);
JOptionPane.showMessageDialog(this, "The message successfully send.", "Send Message", JOptionPane.WARNING_MESSAGE);
subjectTextField.setText("");
messageTextArea.setText("");
} catch (IOException ex) {
Logger.getLogger(SendMessageDialog.class.getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_sendMessageButtonActionPerformed
private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButtonActionPerformed
subjectTextField.setText("");
messageTextArea.setText("");
}//GEN-LAST:event_clearButtonActionPerformed
private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
// TODO add your handling code here:
this.dispose();
}//GEN-LAST:event_closeButtonActionPerformed
/**
* @param args the command line arguments
*/
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton clearButton;
private javax.swing.JMenuItem clearMenuItem;
private javax.swing.JButton closeButton;
private javax.swing.JMenuItem copyMenuItem;
private javax.swing.JMenuItem cutMenuItem;
private javax.swing.JLabel ipAddressLabel;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JPopupMenu messagePopupMenu;
private javax.swing.JTextArea messageTextArea;
private javax.swing.JMenuItem pasteMenuItem;
private javax.swing.JButton sendMessageButton;
private javax.swing.JTextField subjectTextField;
// End of variables declaration//GEN-END:variables
}