- Added a MenuBar

- Chat Window is now a separated Modal Window
This commit is contained in:
Flávio Luiz Schiavoni 2017-01-23 11:38:19 -02:00
parent fd16955a34
commit 4793fbdacf
5 changed files with 345 additions and 225 deletions

View File

@ -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());
}
}

View File

@ -1,11 +1,102 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> <Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
<NonVisualComponents>
<Container class="javax.swing.JMenu" name="jMenu4">
<Properties>
<Property name="text" type="java.lang.String" value="jMenu4"/>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<Property name="useNullLayout" type="boolean" value="true"/>
</Layout>
</Container>
<Menu class="javax.swing.JMenuBar" name="jMenuBar1">
<SubComponents>
<Menu class="javax.swing.JMenu" name="fileMenu">
<Properties>
<Property name="text" type="java.lang.String" value="File"/>
<Property name="toolTipText" type="java.lang.String" value=""/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="closeTabMenu">
<Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
<KeyStroke key="Ctrl+W"/>
</Property>
<Property name="text" type="java.lang.String" value="Close Current Tab"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="closeTabMenuActionPerformed"/>
</Events>
</MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="quitMenu">
<Properties>
<Property name="accelerator" type="javax.swing.KeyStroke" editor="org.netbeans.modules.form.editors.KeyStrokeEditor">
<KeyStroke key="Alt+F4"/>
</Property>
<Property name="text" type="java.lang.String" value="Quit"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="quitMenuActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
<Menu class="javax.swing.JMenu" name="editMenu">
<Properties>
<Property name="text" type="java.lang.String" value="Edit"/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JCheckBoxMenuItem" name="shareMySheetMenu">
<Properties>
<Property name="text" type="java.lang.String" value="Share My Sheet!"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="shareMySheetMenuActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
<Menu class="javax.swing.JMenu" name="viewMenu">
<Properties>
<Property name="text" type="java.lang.String" value="View"/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="showChatWindowMenu">
<Properties>
<Property name="text" type="java.lang.String" value="Chat Window"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="showChatWindowMenuActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
<Menu class="javax.swing.JMenu" name="helpMenu">
<Properties>
<Property name="text" type="java.lang.String" value="Help"/>
</Properties>
<SubComponents>
<MenuItem class="javax.swing.JMenuItem" name="aboutMenu">
<Properties>
<Property name="text" type="java.lang.String" value="About"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="aboutMenuActionPerformed"/>
</Events>
</MenuItem>
</SubComponents>
</Menu>
</SubComponents>
</Menu>
</NonVisualComponents>
<Properties> <Properties>
<Property name="defaultCloseOperation" type="int" value="3"/> <Property name="defaultCloseOperation" type="int" value="3"/>
<Property name="title" type="java.lang.String" value="Share My Sheet"/> <Property name="title" type="java.lang.String" value="Share My Sheet"/>
</Properties> </Properties>
<SyntheticProperties> <SyntheticProperties>
<SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/> <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/> <SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties> </SyntheticProperties>
@ -24,17 +115,18 @@
<Layout> <Layout>
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="jToolBar1" alignment="0" max="32767" attributes="0"/>
<Component id="jPanel1" alignment="0" max="32767" attributes="0"/> <Component id="jPanel1" alignment="0" max="32767" attributes="0"/>
<Component id="jScrollPane1" alignment="1" max="32767" attributes="0"/> <Group type="102" alignment="0" attributes="0">
<Component id="jScrollPane1" min="-2" pref="846" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
<DimensionLayout dim="1"> <DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<Component id="jToolBar1" min="-2" pref="63" max="-2" attributes="0"/> <EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <Component id="jScrollPane1" pref="463" max="32767" attributes="0"/>
<Component id="jScrollPane1" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="jPanel1" min="-2" max="-2" attributes="0"/> <Component id="jPanel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
@ -43,26 +135,6 @@
</DimensionLayout> </DimensionLayout>
</Layout> </Layout>
<SubComponents> <SubComponents>
<Container class="javax.swing.JToolBar" name="jToolBar1">
<Properties>
<Property name="rollover" type="boolean" value="true"/>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
<SubComponents>
<Component class="javax.swing.JToggleButton" name="shareButton">
<Properties>
<Property name="text" type="java.lang.String" value="Share My Sheet!"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="shareButtonActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JScrollPane" name="jScrollPane1"> <Container class="javax.swing.JScrollPane" name="jScrollPane1">
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/> <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
@ -70,94 +142,13 @@
<Container class="javax.swing.JTabbedPane" name="jTabbedPane1"> <Container class="javax.swing.JTabbedPane" name="jTabbedPane1">
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/> <Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/>
<SubComponents>
<Container class="javax.swing.JPanel" name="jPanel2">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout$JTabbedPaneConstraintsDescription">
<JTabbedPaneConstraints tabName="Chat">
<Property name="tabTitle" type="java.lang.String" value="Chat"/>
</JTabbedPaneConstraints>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
<SubComponents>
<Container class="javax.swing.JSplitPane" name="jSplitPane1">
<Properties>
<Property name="dividerLocation" type="int" value="400"/>
<Property name="orientation" type="int" value="0"/>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="jScrollPane3">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="left"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JEditorPane" name="chatBoard">
<Properties>
<Property name="contentType" type="java.lang.String" value="text/html" noResource="true"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel3">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
<JSplitPaneConstraints position="bottom"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
<Property name="alignment" type="int" value="0"/>
</Layout>
<SubComponents>
<Component class="javax.swing.JTextArea" name="jTextArea2">
<Properties>
<Property name="columns" type="int" value="20"/>
<Property name="rows" type="int" value="5"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="jButton1">
<Properties>
<Property name="text" type="java.lang.String" value="Send"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Container> </Container>
</SubComponents> </SubComponents>
</Container> </Container>
<Container class="javax.swing.JPanel" name="jPanel1"> <Container class="javax.swing.JPanel" name="jPanel1">
<Layout> <Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
<DimensionLayout dim="0"> <Property name="alignment" type="int" value="2"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
</Group>
</DimensionLayout>
</Layout> </Layout>
<SubComponents> <SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1"> <Component class="javax.swing.JLabel" name="jLabel1">

View File

@ -40,6 +40,8 @@ public class MainWindow extends javax.swing.JFrame {
private String name; private String name;
private int port; private int port;
private ChatWindow chatWindow;
public MainWindow(String name, int port) throws UnknownHostException { public MainWindow(String name, int port) throws UnknownHostException {
initComponents(); initComponents();
this.name = name; this.name = name;
@ -48,6 +50,7 @@ public class MainWindow extends javax.swing.JFrame {
this.socket.start(); this.socket.start();
this.timer = new Timer(); this.timer = new Timer();
jLabel1.setText("Connected on port " + this.port + " name " + this.name); jLabel1.setText("Connected on port " + this.port + " name " + this.name);
this.chatWindow = new ChatWindow(this);
} }
/** /**
@ -59,98 +62,109 @@ public class MainWindow extends javax.swing.JFrame {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() { private void initComponents() {
jToolBar1 = new javax.swing.JToolBar(); jMenu4 = new javax.swing.JMenu();
shareButton = new javax.swing.JToggleButton();
jScrollPane1 = new javax.swing.JScrollPane(); jScrollPane1 = new javax.swing.JScrollPane();
jTabbedPane1 = new javax.swing.JTabbedPane(); jTabbedPane1 = new javax.swing.JTabbedPane();
jPanel2 = new javax.swing.JPanel();
jSplitPane1 = new javax.swing.JSplitPane();
jScrollPane3 = new javax.swing.JScrollPane();
chatBoard = new javax.swing.JEditorPane();
jPanel3 = new javax.swing.JPanel();
jTextArea2 = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel(); jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
closeTabMenu = new javax.swing.JMenuItem();
quitMenu = new javax.swing.JMenuItem();
editMenu = new javax.swing.JMenu();
shareMySheetMenu = new javax.swing.JCheckBoxMenuItem();
viewMenu = new javax.swing.JMenu();
showChatWindowMenu = new javax.swing.JMenuItem();
helpMenu = new javax.swing.JMenu();
aboutMenu = new javax.swing.JMenuItem();
jMenu4.setText("jMenu4");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Share My Sheet"); setTitle("Share My Sheet");
jToolBar1.setRollover(true);
shareButton.setText("Share My Sheet!");
shareButton.setFocusable(false);
shareButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
shareButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
shareButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
shareButtonActionPerformed(evt);
}
});
jToolBar1.add(shareButton);
jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.LINE_AXIS));
jSplitPane1.setDividerLocation(400);
jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
chatBoard.setContentType("text/html"); // NOI18N
jScrollPane3.setViewportView(chatBoard);
jSplitPane1.setLeftComponent(jScrollPane3);
jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
jTextArea2.setColumns(20);
jTextArea2.setRows(5);
jPanel3.add(jTextArea2);
jButton1.setText("Send");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel3.add(jButton1);
jSplitPane1.setBottomComponent(jPanel3);
jPanel2.add(jSplitPane1);
jTabbedPane1.addTab("Chat", jPanel2);
jScrollPane1.setViewportView(jTabbedPane1); jScrollPane1.setViewportView(jTabbedPane1);
jLabel1.setText("jLabel1"); jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jLabel1.setText("jLabel1");
jPanel1.setLayout(jPanel1Layout); jPanel1.add(jLabel1);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) fileMenu.setText("File");
.addGroup(jPanel1Layout.createSequentialGroup() fileMenu.setToolTipText("");
.addContainerGap()
.addComponent(jLabel1) closeTabMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) closeTabMenu.setText("Close Current Tab");
); closeTabMenu.addActionListener(new java.awt.event.ActionListener() {
jPanel1Layout.setVerticalGroup( public void actionPerformed(java.awt.event.ActionEvent evt) {
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) closeTabMenuActionPerformed(evt);
.addComponent(jLabel1) }
); });
fileMenu.add(closeTabMenu);
quitMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
quitMenu.setText("Quit");
quitMenu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
quitMenuActionPerformed(evt);
}
});
fileMenu.add(quitMenu);
jMenuBar1.add(fileMenu);
editMenu.setText("Edit");
shareMySheetMenu.setText("Share My Sheet!");
shareMySheetMenu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
shareMySheetMenuActionPerformed(evt);
}
});
editMenu.add(shareMySheetMenu);
jMenuBar1.add(editMenu);
viewMenu.setText("View");
showChatWindowMenu.setText("Chat Window");
showChatWindowMenu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
showChatWindowMenuActionPerformed(evt);
}
});
viewMenu.add(showChatWindowMenu);
jMenuBar1.add(viewMenu);
helpMenu.setText("Help");
aboutMenu.setText("About");
aboutMenu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
aboutMenuActionPerformed(evt);
}
});
helpMenu.add(aboutMenu);
jMenuBar1.add(helpMenu);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout); getContentPane().setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 846, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, 0)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE)
.addComponent(jScrollPane1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap()) .addContainerGap())
@ -159,32 +173,44 @@ public class MainWindow extends javax.swing.JFrame {
pack(); pack();
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents
private void shareButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shareButtonActionPerformed private void showChatWindowMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showChatWindowMenuActionPerformed
if (shareButton.isSelected()) { this.chatWindow.setVisible(true);
}//GEN-LAST:event_showChatWindowMenuActionPerformed
private void aboutMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_aboutMenuActionPerformed
private void shareMySheetMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shareMySheetMenuActionPerformed
if (shareMySheetMenu.isSelected()) {
this.timer = new Timer(); this.timer = new Timer();
this.alarmClock = new AlarmClock(this.name, this.socket); this.alarmClock = new AlarmClock(this.name, this.socket);
this.timer.scheduleAtFixedRate(this.alarmClock, 0, MainWindow.TIME); this.timer.scheduleAtFixedRate(this.alarmClock, 0, MainWindow.TIME);
shareButton.setText("Stop sharing it!"); shareMySheetMenu.setText("Stop sharing it!");
} else { } else {
this.timer.cancel(); this.timer.cancel();
shareButton.setText("Share My Sheet!"); shareMySheetMenu.setText("Share My Sheet!");
} }
}//GEN-LAST:event_shareButtonActionPerformed }//GEN-LAST:event_shareMySheetMenuActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed private void closeTabMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeTabMenuActionPerformed
if (jTextArea2.getText().trim().length() == 0) { jTabbedPane1.remove(jTabbedPane1.getSelectedIndex());
return; }//GEN-LAST:event_closeTabMenuActionPerformed
}
ChatMessage message = new ChatMessage(); private void quitMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitMenuActionPerformed
message.setText(jTextArea2.getText()); this.setVisible(false);
message.setName(this.name); this.dispose();
System.exit(0);
}//GEN-LAST:event_quitMenuActionPerformed
public void sendChatMessage(String text) {
ChatMessage message = new ChatMessage(this.name, text);
try { try {
this.socket.send(message.toByteArray()); this.socket.send(message.toByteArray());
} catch (IOException ex) { } catch (IOException ex) {
Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
} }
jTextArea2.setText(""); }
}//GEN-LAST:event_jButton1ActionPerformed
public void receiveScreenCastMessage(ScreenCastMessage message) { public void receiveScreenCastMessage(ScreenCastMessage message) {
// Verificar se a aba existe, se existir, atualizo. // Verificar se a aba existe, se existir, atualizo.
@ -212,26 +238,27 @@ public class MainWindow extends javax.swing.JFrame {
public void receiveChatMessage(ChatMessage message) { public void receiveChatMessage(ChatMessage message) {
SimpleDateFormat dt = new SimpleDateFormat("dd/MM/yyyyy hh:mm:ss"); SimpleDateFormat dt = new SimpleDateFormat("dd/MM/yyyyy hh:mm:ss");
Date date = new Date(); Date date = new Date();
chatBoard.setText(dt.format(date) + " | " + chatWindow.receiveChatMessage(dt.format(date) + " | "
"<b>" + message.getName() + "</b>: "+ + "<b>" + message.getName() + "</b>: "
message.getText() + "<br>" + + message.getText() + "<br>");
chatBoard.getText()
);
} }
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JEditorPane chatBoard; private javax.swing.JMenuItem aboutMenu;
private javax.swing.JButton jButton1; private javax.swing.JMenuItem closeTabMenu;
private javax.swing.JMenu editMenu;
private javax.swing.JMenu fileMenu;
private javax.swing.JMenu helpMenu;
private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel1;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JTabbedPane jTabbedPane1; private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JTextArea jTextArea2; private javax.swing.JMenuItem quitMenu;
private javax.swing.JToolBar jToolBar1; private javax.swing.JCheckBoxMenuItem shareMySheetMenu;
private javax.swing.JToggleButton shareButton; private javax.swing.JMenuItem showChatWindowMenu;
private javax.swing.JMenu viewMenu;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
/** /**

View File

@ -12,8 +12,27 @@ import java.io.Serializable;
* @author flavio * @author flavio
*/ */
public class ChatMessage extends Message implements Serializable{ public class ChatMessage extends Message implements Serializable{
private String name;
private String text; private String text;
private String name;
public ChatMessage(String name, String text){
this.name = name;
this.text = text;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/** /**
* @return the text * @return the text
@ -29,17 +48,4 @@ public class ChatMessage extends Message implements Serializable{
this.text = text; this.text = text;
} }
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
} }

View File

@ -13,8 +13,8 @@ import java.io.Serializable;
*/ */
public class ScreenCastMessage extends Message implements Serializable { public class ScreenCastMessage extends Message implements Serializable {
private String name;
private byte[] imageByte; private byte[] imageByte;
private String name;
public ScreenCastMessage() { public ScreenCastMessage() {
@ -53,5 +53,4 @@ public class ScreenCastMessage extends Message implements Serializable {
this.imageByte = imageByte; this.imageByte = imageByte;
} }
} }