- Added Chat messages
- Changed login port form field from text to spin - Created an abstract class to message serialization
This commit is contained in:
parent
69dbb18825
commit
fd16955a34
|
|
@ -6,6 +6,8 @@
|
|||
<property name="src" location="src"/>
|
||||
<property name="build" location="build"/>
|
||||
<property name="dist" location="dist"/>
|
||||
<property name="ant.build.javac.source" value="1.7"/>
|
||||
<property name="ant.build.javac.target" value="1.7"/>
|
||||
|
||||
<target name="init">
|
||||
<!-- Create the time stamp -->
|
||||
|
|
@ -14,8 +16,7 @@
|
|||
<mkdir dir="${build}"/>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="init"
|
||||
description="compile the source">
|
||||
<target name="compile" depends="init" description="compile the source">
|
||||
<!-- Compile the java code from ${src} into ${build} -->
|
||||
<javac srcdir="${src}" destdir="${build}"/>
|
||||
</target>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.2" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.DialogFormInfo">
|
||||
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.DialogFormInfo">
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
|
|
@ -18,6 +18,7 @@
|
|||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">
|
||||
|
|
@ -82,9 +83,11 @@
|
|||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="jTextField2">
|
||||
<Component class="javax.swing.JSpinner" name="jSpinner1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="8888"/>
|
||||
<Property name="model" type="javax.swing.SpinnerModel" editor="org.netbeans.modules.form.editors2.SpinnerModelEditor">
|
||||
<SpinnerModel initial="8000" maximum="9000" minimum="8000" numberType="java.lang.Integer" stepSize="1" type="number"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Container class="javax.swing.JPanel" name="jPanel10">
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ public class Login extends java.awt.Dialog {
|
|||
public Login(java.awt.Frame parent, boolean modal) {
|
||||
super(parent, modal);
|
||||
initComponents();
|
||||
jTextField1.setText(System.getProperty("user.name"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -33,7 +34,7 @@ public class Login extends java.awt.Dialog {
|
|||
jPanel5 = new javax.swing.JPanel();
|
||||
jPanel7 = new javax.swing.JPanel();
|
||||
jLabel2 = new javax.swing.JLabel();
|
||||
jTextField2 = new javax.swing.JTextField();
|
||||
jSpinner1 = new javax.swing.JSpinner();
|
||||
jPanel10 = new javax.swing.JPanel();
|
||||
jPanel6 = new javax.swing.JPanel();
|
||||
jButton1 = new javax.swing.JButton();
|
||||
|
|
@ -66,8 +67,8 @@ public class Login extends java.awt.Dialog {
|
|||
jLabel2.setPreferredSize(new java.awt.Dimension(200, 18));
|
||||
jPanel5.add(jLabel2);
|
||||
|
||||
jTextField2.setText("8888");
|
||||
jPanel5.add(jTextField2);
|
||||
jSpinner1.setModel(new javax.swing.SpinnerNumberModel(8000, 8000, 9000, 1));
|
||||
jPanel5.add(jSpinner1);
|
||||
jPanel5.add(jPanel10);
|
||||
|
||||
add(jPanel5);
|
||||
|
|
@ -101,7 +102,7 @@ public class Login extends java.awt.Dialog {
|
|||
}
|
||||
|
||||
public int getPort() {
|
||||
return Integer.parseInt(jTextField2.getText());
|
||||
return ((Integer) jSpinner1.getValue()).intValue();
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
|
|
@ -116,7 +117,7 @@ public class Login extends java.awt.Dialog {
|
|||
private javax.swing.JPanel jPanel7;
|
||||
private javax.swing.JPanel jPanel8;
|
||||
private javax.swing.JPanel jPanel9;
|
||||
private javax.swing.JSpinner jSpinner1;
|
||||
private javax.swing.JTextField jTextField1;
|
||||
private javax.swing.JTextField jTextField2;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,74 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
<Property name="title" type="java.lang.String" value="Share My Sheet"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="jToolBar1" alignment="0" pref="400" max="32767" attributes="0"/>
|
||||
<Component id="jScrollPane1" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="jToolBar1" min="-2" pref="63" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane1" pref="231" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<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="actionCommand" 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">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Container class="javax.swing.JTabbedPane" name="jTabbedPane1">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JTabbedPaneSupportLayout"/>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
|
@ -0,0 +1,171 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
||||
<Property name="title" type="java.lang.String" value="Share My Sheet"/>
|
||||
</Properties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="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="jScrollPane1" alignment="1" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="jToolBar1" min="-2" pref="63" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jScrollPane1" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jPanel1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<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">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Container class="javax.swing.JTabbedPane" name="jTabbedPane1">
|
||||
|
||||
<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>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JPanel" name="jPanel1">
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<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>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="jLabel1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="jLabel1"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
|
@ -6,13 +6,15 @@
|
|||
package br.edu.ufsj.sms.GUI;
|
||||
|
||||
import br.edu.ufsj.sms.control.AlarmClock;
|
||||
import br.edu.ufsj.sms.net.Message;
|
||||
import br.edu.ufsj.sms.net.ChatMessage;
|
||||
import br.edu.ufsj.sms.net.ScreenCastMessage;
|
||||
import br.edu.ufsj.sms.net.Socket;
|
||||
import java.awt.Component;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Timer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
|
@ -24,10 +26,10 @@ import javax.swing.JLabel;
|
|||
*
|
||||
* @author flavio
|
||||
*/
|
||||
public class Main extends javax.swing.JFrame {
|
||||
public class MainWindow extends javax.swing.JFrame {
|
||||
|
||||
/**
|
||||
* Creates new form Main
|
||||
* Creates new form MainWindow
|
||||
*/
|
||||
private Socket socket;
|
||||
private AlarmClock alarmClock;
|
||||
|
|
@ -38,13 +40,14 @@ public class Main extends javax.swing.JFrame {
|
|||
private String name;
|
||||
private int port;
|
||||
|
||||
public Main(String name, int port) throws UnknownHostException {
|
||||
public MainWindow(String name, int port) throws UnknownHostException {
|
||||
initComponents();
|
||||
this.name = name;
|
||||
this.port = port;
|
||||
this.socket = new Socket(this);
|
||||
this.socket.start();
|
||||
this.timer = new Timer();
|
||||
jLabel1.setText("Connected on port " + this.port + " name " + this.name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -60,6 +63,15 @@ public class Main extends javax.swing.JFrame {
|
|||
shareButton = new javax.swing.JToggleButton();
|
||||
jScrollPane1 = new javax.swing.JScrollPane();
|
||||
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();
|
||||
jLabel1 = new javax.swing.JLabel();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
setTitle("Share My Sheet");
|
||||
|
|
@ -67,7 +79,6 @@ public class Main extends javax.swing.JFrame {
|
|||
jToolBar1.setRollover(true);
|
||||
|
||||
shareButton.setText("Share My Sheet!");
|
||||
shareButton.setActionCommand("Share My Sheet!");
|
||||
shareButton.setFocusable(false);
|
||||
shareButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
|
||||
shareButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
|
||||
|
|
@ -78,33 +89,81 @@ public class Main extends javax.swing.JFrame {
|
|||
});
|
||||
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);
|
||||
|
||||
jLabel1.setText("jLabel1");
|
||||
|
||||
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()
|
||||
.addComponent(jLabel1)
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
jPanel1Layout.setVerticalGroup(
|
||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jLabel1)
|
||||
);
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
|
||||
.addComponent(jScrollPane1)
|
||||
.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(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE))
|
||||
.addComponent(jScrollPane1)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void shareButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shareButtonActionPerformed
|
||||
// TODO add your handling code here:
|
||||
System.out.println("" + shareButton.isSelected());
|
||||
if (shareButton.isSelected()) {
|
||||
this.timer = new Timer();
|
||||
this.alarmClock = new AlarmClock(this.name, this.socket);
|
||||
this.timer.scheduleAtFixedRate(this.alarmClock, 0, Main.TIME);
|
||||
this.timer.scheduleAtFixedRate(this.alarmClock, 0, MainWindow.TIME);
|
||||
shareButton.setText("Stop sharing it!");
|
||||
} else {
|
||||
this.timer.cancel();
|
||||
|
|
@ -112,11 +171,25 @@ public class Main extends javax.swing.JFrame {
|
|||
}
|
||||
}//GEN-LAST:event_shareButtonActionPerformed
|
||||
|
||||
public void receiveMessage(Message message) {
|
||||
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
|
||||
if (jTextArea2.getText().trim().length() == 0) {
|
||||
return;
|
||||
}
|
||||
ChatMessage message = new ChatMessage();
|
||||
message.setText(jTextArea2.getText());
|
||||
message.setName(this.name);
|
||||
try {
|
||||
this.socket.send(message.toByteArray());
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
jTextArea2.setText("");
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
|
||||
public void receiveScreenCastMessage(ScreenCastMessage message) {
|
||||
// Verificar se a aba existe, se existir, atualizo.
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(message.getImageByte());
|
||||
BufferedImage image;
|
||||
Component tab = null;
|
||||
try {
|
||||
for (int i = 0; i < jTabbedPane1.getTabCount(); i++) {
|
||||
String name = jTabbedPane1.getTitleAt(i);
|
||||
|
|
@ -132,13 +205,31 @@ public class Main extends javax.swing.JFrame {
|
|||
JLabel myShoot = new JLabel(new ImageIcon(image));
|
||||
jTabbedPane1.addTab(message.getName(), myShoot);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
||||
Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void receiveChatMessage(ChatMessage message) {
|
||||
SimpleDateFormat dt = new SimpleDateFormat("dd/MM/yyyyy hh:mm:ss");
|
||||
Date date = new Date();
|
||||
chatBoard.setText(dt.format(date) + " | " +
|
||||
"<b>" + message.getName() + "</b>: "+
|
||||
message.getText() + "<br>" +
|
||||
chatBoard.getText()
|
||||
);
|
||||
}
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JEditorPane chatBoard;
|
||||
private javax.swing.JButton jButton1;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
private javax.swing.JPanel jPanel1;
|
||||
private javax.swing.JPanel jPanel2;
|
||||
private javax.swing.JPanel jPanel3;
|
||||
private javax.swing.JScrollPane jScrollPane1;
|
||||
private javax.swing.JScrollPane jScrollPane3;
|
||||
private javax.swing.JSplitPane jSplitPane1;
|
||||
private javax.swing.JTabbedPane jTabbedPane1;
|
||||
private javax.swing.JTextArea jTextArea2;
|
||||
private javax.swing.JToolBar jToolBar1;
|
||||
private javax.swing.JToggleButton shareButton;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
|
@ -20,14 +20,10 @@ import javax.imageio.ImageIO;
|
|||
*/
|
||||
public class ScreenShot {
|
||||
|
||||
public ScreenShot() {
|
||||
}
|
||||
|
||||
public BufferedImage takeAShot() throws AWTException, IOException {
|
||||
Robot robot = new Robot();
|
||||
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
|
||||
BufferedImage output = robot.createScreenCapture(screenRect);
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,13 +33,13 @@ public class Main {
|
|||
}
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
java.util.logging.Logger.getLogger(br.edu.ufsj.sms.GUI.Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
java.util.logging.Logger.getLogger(br.edu.ufsj.sms.GUI.MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (InstantiationException ex) {
|
||||
java.util.logging.Logger.getLogger(br.edu.ufsj.sms.GUI.Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
java.util.logging.Logger.getLogger(br.edu.ufsj.sms.GUI.MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
java.util.logging.Logger.getLogger(br.edu.ufsj.sms.GUI.Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
java.util.logging.Logger.getLogger(br.edu.ufsj.sms.GUI.MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
java.util.logging.Logger.getLogger(br.edu.ufsj.sms.GUI.Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
java.util.logging.Logger.getLogger(br.edu.ufsj.sms.GUI.MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
|
|
@ -50,10 +50,15 @@ public class Main {
|
|||
Login login = new Login(null, true);
|
||||
login.setVisible(true);
|
||||
String name = login.getName();
|
||||
if (name.equals("Chat")) {
|
||||
System.out.println("Invalid name");
|
||||
login.dispose();
|
||||
return;
|
||||
}
|
||||
int port = login.getPort();
|
||||
login.dispose();
|
||||
br.edu.ufsj.sms.GUI.Main main;
|
||||
main = new br.edu.ufsj.sms.GUI.Main(name, port);
|
||||
br.edu.ufsj.sms.GUI.MainWindow main;
|
||||
main = new br.edu.ufsj.sms.GUI.MainWindow(name, port);
|
||||
main.setVisible(true);
|
||||
} catch (UnknownHostException ex) {
|
||||
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
||||
|
|
|
|||
|
|
@ -6,21 +6,14 @@
|
|||
package br.edu.ufsj.sms.control;
|
||||
|
||||
import br.edu.ufsj.sms.GUI.ScreenShot;
|
||||
import br.edu.ufsj.sms.net.Message;
|
||||
import br.edu.ufsj.sms.net.ScreenCastMessage;
|
||||
import br.edu.ufsj.sms.net.Socket;
|
||||
import java.awt.AWTException;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.TimerTask;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -31,27 +24,34 @@ public class AlarmClock extends TimerTask {
|
|||
ScreenShot ss;
|
||||
String name;
|
||||
Socket socket;
|
||||
float compressRatio;
|
||||
|
||||
public AlarmClock(String name, Socket socket) {
|
||||
ss = new ScreenShot();
|
||||
this.name = name;
|
||||
this.socket = socket;
|
||||
this.compressRatio = 0.5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
byte[] msg = null;
|
||||
try {
|
||||
BufferedImage image = ss.takeAShot();
|
||||
BufferedImage rescaled = ImageTransformation.resize(image, 1024, 768);
|
||||
byte[] data = ImageTransformation.compress(rescaled, 0.45f);
|
||||
Message message = new Message(this.name, data);
|
||||
this.socket.send(message);
|
||||
} catch (AWTException ex) {
|
||||
byte[] byteImage = ImageTransformation.compress(rescaled, compressRatio);
|
||||
ScreenCastMessage message = new ScreenCastMessage(this.name, byteImage);
|
||||
msg = message.toByteArray();
|
||||
} catch (AWTException | IOException ex) {
|
||||
Logger.getLogger(AlarmClock.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
if (msg != null) {
|
||||
try {
|
||||
this.socket.send(msg);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(AlarmClock.class.getName()).log(Level.SEVERE, null, ex);
|
||||
this.compressRatio -= 0.05f;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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.net;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author flavio
|
||||
*/
|
||||
public class ChatMessage extends Message implements Serializable{
|
||||
private String name;
|
||||
private String text;
|
||||
|
||||
/**
|
||||
* @return the text
|
||||
*/
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param text the text to set
|
||||
*/
|
||||
public void setText(String 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,49 +5,22 @@
|
|||
*/
|
||||
package br.edu.ufsj.sms.net;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.Serializable;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author flavio
|
||||
*/
|
||||
public class Message implements Serializable {
|
||||
public abstract class Message {
|
||||
|
||||
private String name;
|
||||
private byte[] imageByte;
|
||||
|
||||
public Message(String name, byte[] imageByte) {
|
||||
this.name = name;
|
||||
this.imageByte = imageByte;
|
||||
public byte[] toByteArray() throws IOException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutput out = new ObjectOutputStream(baos);
|
||||
out.writeObject(this);
|
||||
out.flush();
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the imageByte
|
||||
*/
|
||||
public byte[] getImageByte() {
|
||||
return imageByte;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param imageByte the image to set
|
||||
*/
|
||||
public void setImageByte(byte[] imageByte) {
|
||||
this.imageByte = imageByte;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* 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.net;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author flavio
|
||||
*/
|
||||
public class ScreenCastMessage extends Message implements Serializable {
|
||||
|
||||
private String name;
|
||||
private byte[] imageByte;
|
||||
|
||||
public ScreenCastMessage(){
|
||||
|
||||
}
|
||||
|
||||
public ScreenCastMessage(String name, byte[] imageByte) {
|
||||
this.name = name;
|
||||
this.imageByte = imageByte;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the imageByte
|
||||
*/
|
||||
public byte[] getImageByte() {
|
||||
return imageByte;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param imageByte the image to set
|
||||
*/
|
||||
public void setImageByte(byte[] imageByte) {
|
||||
this.imageByte = imageByte;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
package br.edu.ufsj.sms.net;
|
||||
|
||||
import br.edu.ufsj.sms.GUI.Main;
|
||||
import br.edu.ufsj.sms.GUI.MainWindow;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
|
@ -30,11 +30,11 @@ public class Socket extends Thread {
|
|||
|
||||
private MulticastSocket multicastSocket;
|
||||
private InetAddress address;
|
||||
private Main main;
|
||||
private MainWindow main;
|
||||
|
||||
public Socket(Main main) throws UnknownHostException {
|
||||
public Socket(MainWindow main) throws UnknownHostException {
|
||||
this.main = main;
|
||||
this.address = InetAddress.getByName(Main.INET_ADDR);
|
||||
this.address = InetAddress.getByName(MainWindow.INET_ADDR);
|
||||
try {
|
||||
multicastSocket = new MulticastSocket(this.main.getPort());
|
||||
multicastSocket.setSendBufferSize(256000);
|
||||
|
|
@ -48,27 +48,25 @@ public class Socket extends Thread {
|
|||
}
|
||||
|
||||
public void receive() throws UnknownHostException, IOException, ClassNotFoundException {
|
||||
|
||||
byte[] buf = new byte[256000];
|
||||
|
||||
while (true) {
|
||||
// Receive the information and print it.
|
||||
DatagramPacket msgPacket = new DatagramPacket(buf, buf.length);
|
||||
multicastSocket.receive(msgPacket);
|
||||
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(msgPacket.getData());
|
||||
ObjectInput in = new ObjectInputStream(bis);
|
||||
Message message = (Message) in.readObject();
|
||||
this.main.receiveMessage(message);
|
||||
Object message;
|
||||
message = in.readObject();
|
||||
if (message instanceof ScreenCastMessage) {
|
||||
this.main.receiveScreenCastMessage((ScreenCastMessage) message);
|
||||
}
|
||||
if (message instanceof ChatMessage) {
|
||||
this.main.receiveChatMessage((ChatMessage) message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void send(Message message) throws IOException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutput out = new ObjectOutputStream(baos);
|
||||
out.writeObject(message);
|
||||
out.flush();
|
||||
byte[] msg = baos.toByteArray();
|
||||
public void send(byte[] msg) throws IOException {
|
||||
DatagramPacket msgPacket;
|
||||
msgPacket = new DatagramPacket(msg, msg.length, this.address, this.main.getPort());
|
||||
multicastSocket.send(msgPacket);
|
||||
|
|
@ -78,9 +76,7 @@ public class Socket extends Thread {
|
|||
public void run() {
|
||||
try {
|
||||
this.receive();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(Socket.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
} catch (IOException | ClassNotFoundException ex) {
|
||||
Logger.getLogger(Socket.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue