diff --git a/src/br/edu/ufsj/sms/GUI/ChatWindow.java b/src/br/edu/ufsj/sms/GUI/ChatWindow.java new file mode 100644 index 0000000..a57579d --- /dev/null +++ b/src/br/edu/ufsj/sms/GUI/ChatWindow.java @@ -0,0 +1,97 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package br.edu.ufsj.sms.GUI; + +import java.awt.event.KeyEvent; + +/** + * + * @author flavio + */ +public class ChatWindow extends javax.swing.JDialog { + + private javax.swing.JButton jButton1; + private javax.swing.JEditorPane jEditorPane1; + private javax.swing.JPanel jPanel1; + private javax.swing.JPanel jPanel2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JSplitPane jSplitPane1; + private javax.swing.JTextArea jTextArea1; + + private MainWindow mainWindow; + + public ChatWindow(MainWindow mainWindow) { + this.mainWindow = mainWindow; + initComponents(); + } + + /** + * 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. + */ + private void initComponents() { + + this.setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE); + this.setTitle("Chat Window"); + this.setBounds(new java.awt.Rectangle(0, 0, 800, 600)); + this.getContentPane().setLayout(new java.awt.BorderLayout(5, 5)); + this.setPreferredSize(new java.awt.Dimension(800, 600)); + + jSplitPane1 = new javax.swing.JSplitPane(); + jScrollPane1 = new javax.swing.JScrollPane(); + jEditorPane1 = new javax.swing.JEditorPane(); + jPanel1 = new javax.swing.JPanel(); + jScrollPane2 = new javax.swing.JScrollPane(); + jTextArea1 = new javax.swing.JTextArea(); + jPanel2 = new javax.swing.JPanel(); + jButton1 = new javax.swing.JButton(); + + jSplitPane1.setDividerLocation(500); + jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); + jEditorPane1.setContentType("text/html"); + jPanel1.setLayout(new java.awt.BorderLayout()); + jTextArea1.setColumns(20); + jTextArea1.setRows(5); + jTextArea1.addKeyListener(new java.awt.event.KeyAdapter() { + @Override + public void keyTyped(java.awt.event.KeyEvent evt) { + if (evt.getKeyChar() == '\n') { + sendMessage(); + } + } + }); + jButton1.setText("Send"); + + jScrollPane1.setViewportView(jEditorPane1); + jScrollPane2.setViewportView(jTextArea1); + jSplitPane1.setTopComponent(jScrollPane1); + + jPanel1.add(jScrollPane2, java.awt.BorderLayout.CENTER); + jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT)); + jButton1.addActionListener((java.awt.event.ActionEvent evt) -> { + sendMessage(); + }); + jPanel2.add(jButton1); + jPanel1.add(jPanel2, java.awt.BorderLayout.PAGE_END); + jSplitPane1.setRightComponent(jPanel1); + getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER); + pack(); + } + + private void sendMessage() { + if (jTextArea1.getText().trim().length() == 0) { + return; + } + mainWindow.sendChatMessage(jTextArea1.getText()); + jTextArea1.setText(""); + } + + public void receiveChatMessage(String message) { + jEditorPane1.setText(message + jEditorPane1.getText()); + } +} diff --git a/src/br/edu/ufsj/sms/GUI/MainWindow.form b/src/br/edu/ufsj/sms/GUI/MainWindow.form index 132d096..b70a321 100644 --- a/src/br/edu/ufsj/sms/GUI/MainWindow.form +++ b/src/br/edu/ufsj/sms/GUI/MainWindow.form @@ -1,11 +1,102 @@