- MainWindow is a class without a Netbeans form
- Menu is a separated Class - Login is a class without a NetBeans form - Messages are using heritage to be serializable
This commit is contained in:
parent
91fc3d7666
commit
5d5d87de77
|
|
@ -11,7 +11,6 @@ import java.awt.GridBagConstraints;
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
|
|
|
||||||
|
|
@ -1,162 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
|
|
||||||
<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>
|
|
||||||
<Property name="defaultCloseOperation" type="int" value="3"/>
|
|
||||||
<Property name="title" type="java.lang.String" value="Share My Sheet"/>
|
|
||||||
</Properties>
|
|
||||||
<SyntheticProperties>
|
|
||||||
<SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/>
|
|
||||||
<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="jPanel1" alignment="0" 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>
|
|
||||||
</DimensionLayout>
|
|
||||||
<DimensionLayout dim="1">
|
|
||||||
<Group type="103" groupAlignment="0" attributes="0">
|
|
||||||
<Group type="102" alignment="0" attributes="0">
|
|
||||||
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
|
|
||||||
<Component id="jScrollPane1" pref="463" 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.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>
|
|
||||||
<Container class="javax.swing.JPanel" name="jPanel1">
|
|
||||||
|
|
||||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout">
|
|
||||||
<Property name="alignment" type="int" value="2"/>
|
|
||||||
</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>
|
|
||||||
|
|
@ -43,165 +43,68 @@ public class MainWindow extends javax.swing.JFrame {
|
||||||
private ChatWindow chatWindow;
|
private ChatWindow chatWindow;
|
||||||
|
|
||||||
public MainWindow(String name, int port) throws UnknownHostException {
|
public MainWindow(String name, int port) throws UnknownHostException {
|
||||||
initComponents();
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.socket = new Socket(this);
|
this.initComponents();
|
||||||
this.socket.start();
|
|
||||||
this.timer = new Timer();
|
|
||||||
jLabel1.setText("Connected on port " + this.port + " name " + this.name);
|
|
||||||
this.chatWindow = new ChatWindow(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void initComponents() throws UnknownHostException {
|
||||||
* 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
|
this.setSize(new java.awt.Dimension(1024, 768));
|
||||||
* regenerated by the Form Editor.
|
this.setJMenuBar(new MenuBar(this));
|
||||||
*/
|
this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||||
@SuppressWarnings("unchecked")
|
this.setTitle("Share My Sheet");
|
||||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
|
||||||
private void initComponents() {
|
|
||||||
|
|
||||||
jMenu4 = new javax.swing.JMenu();
|
|
||||||
jScrollPane1 = new javax.swing.JScrollPane();
|
jScrollPane1 = new javax.swing.JScrollPane();
|
||||||
jTabbedPane1 = new javax.swing.JTabbedPane();
|
tabbedPane = new javax.swing.JTabbedPane();
|
||||||
jPanel1 = new javax.swing.JPanel();
|
statusPanel = new javax.swing.JPanel();
|
||||||
jLabel1 = new javax.swing.JLabel();
|
status = 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");
|
jScrollPane1.setViewportView(tabbedPane);
|
||||||
|
statusPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
|
||||||
|
status.setText("Connected on port " + this.port + " name " + this.name);
|
||||||
|
statusPanel.add(status);
|
||||||
|
|
||||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
this.getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
|
||||||
setTitle("Share My Sheet");
|
this.getContentPane().add(statusPanel, java.awt.BorderLayout.PAGE_END);
|
||||||
|
|
||||||
jScrollPane1.setViewportView(jTabbedPane1);
|
this.pack();
|
||||||
|
|
||||||
jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
|
this.socket = new Socket(this);
|
||||||
|
this.timer = new Timer();
|
||||||
|
this.chatWindow = new ChatWindow(this);
|
||||||
|
|
||||||
jLabel1.setText("jLabel1");
|
this.socket.start();
|
||||||
jPanel1.add(jLabel1);
|
|
||||||
|
|
||||||
fileMenu.setText("File");
|
}
|
||||||
fileMenu.setToolTipText("");
|
|
||||||
|
|
||||||
closeTabMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));
|
public void showChatWindow() {
|
||||||
closeTabMenu.setText("Close Current Tab");
|
|
||||||
closeTabMenu.addActionListener(new java.awt.event.ActionListener() {
|
|
||||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
||||||
closeTabMenuActionPerformed(evt);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
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());
|
|
||||||
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)
|
|
||||||
.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.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
||||||
.addGroup(layout.createSequentialGroup()
|
|
||||||
.addGap(0, 0, 0)
|
|
||||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE)
|
|
||||||
.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 showChatWindowMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showChatWindowMenuActionPerformed
|
|
||||||
this.chatWindow.setVisible(true);
|
this.chatWindow.setVisible(true);
|
||||||
}//GEN-LAST:event_showChatWindowMenuActionPerformed
|
}
|
||||||
|
|
||||||
private void aboutMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuActionPerformed
|
public void showAboutWindow() {
|
||||||
// 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()) {
|
|
||||||
|
public void shareMySheet(boolean status) {
|
||||||
|
if (status) {
|
||||||
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);
|
||||||
shareMySheetMenu.setText("Stop sharing it!");
|
|
||||||
} else {
|
} else {
|
||||||
this.timer.cancel();
|
this.timer.cancel();
|
||||||
shareMySheetMenu.setText("Share My Sheet!");
|
|
||||||
}
|
}
|
||||||
}//GEN-LAST:event_shareMySheetMenuActionPerformed
|
}
|
||||||
|
|
||||||
private void closeTabMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeTabMenuActionPerformed
|
public void closeCurrentTab() {
|
||||||
jTabbedPane1.remove(jTabbedPane1.getSelectedIndex());
|
tabbedPane.remove(tabbedPane.getSelectedIndex());
|
||||||
}//GEN-LAST:event_closeTabMenuActionPerformed
|
}
|
||||||
|
|
||||||
private void quitMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitMenuActionPerformed
|
public void exit() {
|
||||||
this.setVisible(false);
|
this.setVisible(false);
|
||||||
this.dispose();
|
this.dispose();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}//GEN-LAST:event_quitMenuActionPerformed
|
}
|
||||||
|
|
||||||
public void sendChatMessage(String text) {
|
public void sendChatMessage(String text) {
|
||||||
ChatMessage message = new ChatMessage(this.name, text);
|
ChatMessage message = new ChatMessage(this.name, text);
|
||||||
|
|
@ -217,19 +120,18 @@ public class MainWindow extends javax.swing.JFrame {
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(message.getImageByte());
|
ByteArrayInputStream bais = new ByteArrayInputStream(message.getImageByte());
|
||||||
BufferedImage image;
|
BufferedImage image;
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < jTabbedPane1.getTabCount(); i++) {
|
for (int i = 0; i < tabbedPane.getTabCount(); i++) {
|
||||||
String name = jTabbedPane1.getTitleAt(i);
|
String title = tabbedPane.getTitleAt(i);
|
||||||
if (name.equals(message.getName())) {
|
if (title.equals(message.getName())) {
|
||||||
image = ImageIO.read(bais);
|
image = ImageIO.read(bais);
|
||||||
JLabel myShoot = new JLabel(new ImageIcon(image));
|
JLabel myShoot = new JLabel(new ImageIcon(image));
|
||||||
jTabbedPane1.setComponentAt(i, myShoot);
|
tabbedPane.setComponentAt(i, myShoot);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
image = ImageIO.read(bais);
|
image = ImageIO.read(bais);
|
||||||
JLabel myShoot = new JLabel(new ImageIcon(image));
|
JLabel myShoot = new JLabel(new ImageIcon(image));
|
||||||
jTabbedPane1.addTab(message.getName(), myShoot);
|
tabbedPane.addTab(message.getName(), myShoot);
|
||||||
} 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);
|
||||||
}
|
}
|
||||||
|
|
@ -238,27 +140,16 @@ 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();
|
||||||
chatWindow.receiveChatMessage(dt.format(date) + " | "
|
chatWindow.receiveChatMessage(dt.format(date) + " "
|
||||||
+ "<b>" + message.getName() + "</b>: "
|
+ "<b>" + message.getName() + "</b>: "
|
||||||
+ message.getText() + "<br>");
|
+ message.getText() + "<br>");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
private javax.swing.JMenuItem aboutMenu;
|
|
||||||
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.JMenu jMenu4;
|
|
||||||
private javax.swing.JMenuBar jMenuBar1;
|
|
||||||
private javax.swing.JPanel jPanel1;
|
|
||||||
private javax.swing.JScrollPane jScrollPane1;
|
private javax.swing.JScrollPane jScrollPane1;
|
||||||
private javax.swing.JTabbedPane jTabbedPane1;
|
private javax.swing.JLabel status;
|
||||||
private javax.swing.JMenuItem quitMenu;
|
private javax.swing.JPanel statusPanel;
|
||||||
private javax.swing.JCheckBoxMenuItem shareMySheetMenu;
|
private javax.swing.JTabbedPane tabbedPane;
|
||||||
private javax.swing.JMenuItem showChatWindowMenu;
|
|
||||||
private javax.swing.JMenu viewMenu;
|
|
||||||
// End of variables declaration//GEN-END:variables
|
// End of variables declaration//GEN-END:variables
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,129 @@
|
||||||
|
/*
|
||||||
|
* 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 javax.swing.JMenuBar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author flavio
|
||||||
|
*/
|
||||||
|
public class MenuBar extends JMenuBar {
|
||||||
|
|
||||||
|
private javax.swing.JMenuItem aboutMenu;
|
||||||
|
private javax.swing.JMenuItem closeTabMenu;
|
||||||
|
private javax.swing.JMenu editMenu;
|
||||||
|
private javax.swing.JMenu fileMenu;
|
||||||
|
private javax.swing.JMenu helpMenu;
|
||||||
|
|
||||||
|
private javax.swing.JMenuItem exitMenu;
|
||||||
|
private javax.swing.JCheckBoxMenuItem shareMySheetMenu;
|
||||||
|
private javax.swing.JMenuItem showChatWindowMenu;
|
||||||
|
private javax.swing.JMenu viewMenu;
|
||||||
|
|
||||||
|
private MainWindow mainWindow;
|
||||||
|
|
||||||
|
public MenuBar(MainWindow mainWindow) {
|
||||||
|
this.mainWindow = mainWindow;
|
||||||
|
|
||||||
|
fileMenu = new javax.swing.JMenu();
|
||||||
|
closeTabMenu = new javax.swing.JMenuItem();
|
||||||
|
exitMenu = 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();
|
||||||
|
|
||||||
|
fileMenu.setText("File");
|
||||||
|
fileMenu.setToolTipText("");
|
||||||
|
|
||||||
|
closeTabMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_MASK));
|
||||||
|
closeTabMenu.setText("Close Current Tab");
|
||||||
|
closeTabMenu.addActionListener(new java.awt.event.ActionListener() {
|
||||||
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
|
closeTabMenuActionPerformed(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fileMenu.add(closeTabMenu);
|
||||||
|
|
||||||
|
exitMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
|
||||||
|
exitMenu.setText("Exit");
|
||||||
|
exitMenu.addActionListener(new java.awt.event.ActionListener() {
|
||||||
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
|
exitMenuActionPerformed(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fileMenu.add(exitMenu);
|
||||||
|
|
||||||
|
this.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);
|
||||||
|
|
||||||
|
this.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);
|
||||||
|
|
||||||
|
this.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);
|
||||||
|
|
||||||
|
this.add(helpMenu);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showChatWindowMenuActionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
|
mainWindow.showChatWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void aboutMenuActionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
|
mainWindow.showAboutWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void shareMySheetMenuActionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
|
if (shareMySheetMenu.isSelected()) {
|
||||||
|
shareMySheetMenu.setText("Stop sharing it!");
|
||||||
|
} else {
|
||||||
|
shareMySheetMenu.setText("Share My Sheer!");
|
||||||
|
}
|
||||||
|
|
||||||
|
mainWindow.shareMySheet(shareMySheetMenu.isSelected());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void closeTabMenuActionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
|
mainWindow.closeCurrentTab();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void exitMenuActionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
|
mainWindow.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,6 @@
|
||||||
*/
|
*/
|
||||||
package br.edu.ufsj.sms.control;
|
package br.edu.ufsj.sms.control;
|
||||||
|
|
||||||
import br.edu.ufsj.sms.GUI.ScreenShot;
|
|
||||||
import br.edu.ufsj.sms.net.ScreenCastMessage;
|
import br.edu.ufsj.sms.net.ScreenCastMessage;
|
||||||
import br.edu.ufsj.sms.net.Socket;
|
import br.edu.ufsj.sms.net.Socket;
|
||||||
import java.awt.AWTException;
|
import java.awt.AWTException;
|
||||||
|
|
@ -21,10 +20,10 @@ import java.util.logging.Logger;
|
||||||
*/
|
*/
|
||||||
public class AlarmClock extends TimerTask {
|
public class AlarmClock extends TimerTask {
|
||||||
|
|
||||||
ScreenShot ss;
|
private final ScreenShot ss;
|
||||||
String name;
|
private final String name;
|
||||||
Socket socket;
|
private final Socket socket;
|
||||||
float compressRatio;
|
private float compressRatio;
|
||||||
|
|
||||||
public AlarmClock(String name, Socket socket) {
|
public AlarmClock(String name, Socket socket) {
|
||||||
ss = new ScreenShot();
|
ss = new ScreenShot();
|
||||||
|
|
@ -39,7 +38,15 @@ public class AlarmClock extends TimerTask {
|
||||||
try {
|
try {
|
||||||
BufferedImage image = ss.takeAShot();
|
BufferedImage image = ss.takeAShot();
|
||||||
BufferedImage rescaled = ImageTransformation.resize(image, 1024, 768);
|
BufferedImage rescaled = ImageTransformation.resize(image, 1024, 768);
|
||||||
|
|
||||||
|
int size = ImageTransformation.toByteArray(rescaled).length / 65000;
|
||||||
|
size++;
|
||||||
|
int number_of_cuts = rescaled.getWidth() / size;
|
||||||
|
|
||||||
byte[] byteImage = ImageTransformation.compress(rescaled, compressRatio);
|
byte[] byteImage = ImageTransformation.compress(rescaled, compressRatio);
|
||||||
|
for (int i = 0 ; i < size ; i++){
|
||||||
|
|
||||||
|
}
|
||||||
ScreenCastMessage message = new ScreenCastMessage(this.name, byteImage);
|
ScreenCastMessage message = new ScreenCastMessage(this.name, byteImage);
|
||||||
msg = message.toByteArray();
|
msg = message.toByteArray();
|
||||||
} catch (AWTException | IOException ex) {
|
} catch (AWTException | IOException ex) {
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,14 @@
|
||||||
* To change this template file, choose Tools | Templates
|
* To change this template file, choose Tools | Templates
|
||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
package br.edu.ufsj.sms.GUI;
|
package br.edu.ufsj.sms.control;
|
||||||
|
|
||||||
import java.awt.AWTException;
|
import java.awt.AWTException;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.Robot;
|
import java.awt.Robot;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -5,13 +5,11 @@
|
||||||
*/
|
*/
|
||||||
package br.edu.ufsj.sms.net;
|
package br.edu.ufsj.sms.net;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author flavio
|
* @author flavio
|
||||||
*/
|
*/
|
||||||
public class ChatMessage extends Message implements Serializable{
|
public class ChatMessage extends Message{
|
||||||
|
|
||||||
private String text;
|
private String text;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,13 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectOutput;
|
import java.io.ObjectOutput;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author flavio
|
* @author flavio
|
||||||
*/
|
*/
|
||||||
public abstract class Message {
|
public abstract class Message implements Serializable{
|
||||||
|
|
||||||
public byte[] toByteArray() throws IOException {
|
public byte[] toByteArray() throws IOException {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
|
|
||||||
|
|
@ -5,19 +5,17 @@
|
||||||
*/
|
*/
|
||||||
package br.edu.ufsj.sms.net;
|
package br.edu.ufsj.sms.net;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author flavio
|
* @author flavio
|
||||||
*/
|
*/
|
||||||
public class ScreenCastMessage extends Message implements Serializable {
|
public class ScreenCastMessage extends Message {
|
||||||
|
|
||||||
private byte[] imageByte;
|
|
||||||
private String name;
|
private String name;
|
||||||
|
private int y;
|
||||||
|
private byte[] imageByte;
|
||||||
|
|
||||||
public ScreenCastMessage() {
|
public ScreenCastMessage() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScreenCastMessage(String name, byte[] imageByte) {
|
public ScreenCastMessage(String name, byte[] imageByte) {
|
||||||
|
|
|
||||||
|
|
@ -7,18 +7,13 @@ package br.edu.ufsj.sms.net;
|
||||||
|
|
||||||
import br.edu.ufsj.sms.GUI.MainWindow;
|
import br.edu.ufsj.sms.GUI.MainWindow;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInput;
|
import java.io.ObjectInput;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutput;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.net.DatagramPacket;
|
import java.net.DatagramPacket;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.MulticastSocket;
|
import java.net.MulticastSocket;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue