diff --git a/src/br/edu/ufsj/sms/GUI/Login.java b/src/br/edu/ufsj/sms/GUI/Login.java index 2f45ee2..429329c 100644 --- a/src/br/edu/ufsj/sms/GUI/Login.java +++ b/src/br/edu/ufsj/sms/GUI/Login.java @@ -11,7 +11,6 @@ import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JDialog; diff --git a/src/br/edu/ufsj/sms/GUI/MainWindow.form b/src/br/edu/ufsj/sms/GUI/MainWindow.form deleted file mode 100644 index b70a321..0000000 --- a/src/br/edu/ufsj/sms/GUI/MainWindow.form +++ /dev/null @@ -1,162 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/src/br/edu/ufsj/sms/GUI/MainWindow.java b/src/br/edu/ufsj/sms/GUI/MainWindow.java index 141e1d1..befb9eb 100644 --- a/src/br/edu/ufsj/sms/GUI/MainWindow.java +++ b/src/br/edu/ufsj/sms/GUI/MainWindow.java @@ -43,165 +43,68 @@ public class MainWindow extends javax.swing.JFrame { private ChatWindow chatWindow; 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); - this.chatWindow = new ChatWindow(this); + this.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. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { + private void initComponents() throws UnknownHostException { + + this.setSize(new java.awt.Dimension(1024, 768)); + this.setJMenuBar(new MenuBar(this)); + this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + this.setTitle("Share My Sheet"); - jMenu4 = new javax.swing.JMenu(); jScrollPane1 = new javax.swing.JScrollPane(); - jTabbedPane1 = new javax.swing.JTabbedPane(); - jPanel1 = new javax.swing.JPanel(); - 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(); + tabbedPane = new javax.swing.JTabbedPane(); + statusPanel = new javax.swing.JPanel(); + status = new javax.swing.JLabel(); - 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); - setTitle("Share My Sheet"); + this.getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER); + 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"); - jPanel1.add(jLabel1); + this.socket.start(); - 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); - - 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(); - }// //GEN-END:initComponents - - private void showChatWindowMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showChatWindowMenuActionPerformed + public void showChatWindow() { 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 + public void showAboutWindow() { - 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.alarmClock = new AlarmClock(this.name, this.socket); this.timer.scheduleAtFixedRate(this.alarmClock, 0, MainWindow.TIME); - shareMySheetMenu.setText("Stop sharing it!"); } else { this.timer.cancel(); - shareMySheetMenu.setText("Share My Sheet!"); } - }//GEN-LAST:event_shareMySheetMenuActionPerformed + } - private void closeTabMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeTabMenuActionPerformed - jTabbedPane1.remove(jTabbedPane1.getSelectedIndex()); - }//GEN-LAST:event_closeTabMenuActionPerformed + public void closeCurrentTab() { + tabbedPane.remove(tabbedPane.getSelectedIndex()); + } - private void quitMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitMenuActionPerformed + public void exit() { this.setVisible(false); this.dispose(); System.exit(0); - }//GEN-LAST:event_quitMenuActionPerformed + } public void sendChatMessage(String 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()); BufferedImage image; try { - for (int i = 0; i < jTabbedPane1.getTabCount(); i++) { - String name = jTabbedPane1.getTitleAt(i); - if (name.equals(message.getName())) { + for (int i = 0; i < tabbedPane.getTabCount(); i++) { + String title = tabbedPane.getTitleAt(i); + if (title.equals(message.getName())) { image = ImageIO.read(bais); JLabel myShoot = new JLabel(new ImageIcon(image)); - jTabbedPane1.setComponentAt(i, myShoot); + tabbedPane.setComponentAt(i, myShoot); return; } } - image = ImageIO.read(bais); JLabel myShoot = new JLabel(new ImageIcon(image)); - jTabbedPane1.addTab(message.getName(), myShoot); + tabbedPane.addTab(message.getName(), myShoot); } catch (IOException 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) { SimpleDateFormat dt = new SimpleDateFormat("dd/MM/yyyyy hh:mm:ss"); Date date = new Date(); - chatWindow.receiveChatMessage(dt.format(date) + " | " + chatWindow.receiveChatMessage(dt.format(date) + " " + "" + message.getName() + ": " + message.getText() + "
"); } // 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.JTabbedPane jTabbedPane1; - private javax.swing.JMenuItem quitMenu; - private javax.swing.JCheckBoxMenuItem shareMySheetMenu; - private javax.swing.JMenuItem showChatWindowMenu; - private javax.swing.JMenu viewMenu; + private javax.swing.JLabel status; + private javax.swing.JPanel statusPanel; + private javax.swing.JTabbedPane tabbedPane; // End of variables declaration//GEN-END:variables /** diff --git a/src/br/edu/ufsj/sms/GUI/MenuBar.java b/src/br/edu/ufsj/sms/GUI/MenuBar.java new file mode 100644 index 0000000..e0a7d57 --- /dev/null +++ b/src/br/edu/ufsj/sms/GUI/MenuBar.java @@ -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(); + } + +} diff --git a/src/br/edu/ufsj/sms/control/AlarmClock.java b/src/br/edu/ufsj/sms/control/AlarmClock.java index e3065b0..e5f7922 100644 --- a/src/br/edu/ufsj/sms/control/AlarmClock.java +++ b/src/br/edu/ufsj/sms/control/AlarmClock.java @@ -5,7 +5,6 @@ */ 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.Socket; import java.awt.AWTException; @@ -21,10 +20,10 @@ import java.util.logging.Logger; */ public class AlarmClock extends TimerTask { - ScreenShot ss; - String name; - Socket socket; - float compressRatio; + private final ScreenShot ss; + private final String name; + private final Socket socket; + private float compressRatio; public AlarmClock(String name, Socket socket) { ss = new ScreenShot(); @@ -39,7 +38,15 @@ public class AlarmClock extends TimerTask { try { BufferedImage image = ss.takeAShot(); 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); + for (int i = 0 ; i < size ; i++){ + + } ScreenCastMessage message = new ScreenCastMessage(this.name, byteImage); msg = message.toByteArray(); } catch (AWTException | IOException ex) { diff --git a/src/br/edu/ufsj/sms/GUI/ScreenShot.java b/src/br/edu/ufsj/sms/control/ScreenShot.java similarity index 87% rename from src/br/edu/ufsj/sms/GUI/ScreenShot.java rename to src/br/edu/ufsj/sms/control/ScreenShot.java index 6c4a706..df72f33 100644 --- a/src/br/edu/ufsj/sms/GUI/ScreenShot.java +++ b/src/br/edu/ufsj/sms/control/ScreenShot.java @@ -3,16 +3,14 @@ * To change this template file, choose Tools | Templates * 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.Rectangle; import java.awt.Robot; import java.awt.Toolkit; import java.awt.image.BufferedImage; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import javax.imageio.ImageIO; /** * @@ -26,4 +24,4 @@ public class ScreenShot { BufferedImage output = robot.createScreenCapture(screenRect); return output; } -} +} \ No newline at end of file diff --git a/src/br/edu/ufsj/sms/net/ChatMessage.java b/src/br/edu/ufsj/sms/net/ChatMessage.java index 6766f8f..50e94fa 100644 --- a/src/br/edu/ufsj/sms/net/ChatMessage.java +++ b/src/br/edu/ufsj/sms/net/ChatMessage.java @@ -5,13 +5,11 @@ */ package br.edu.ufsj.sms.net; -import java.io.Serializable; - /** * * @author flavio */ -public class ChatMessage extends Message implements Serializable{ +public class ChatMessage extends Message{ private String text; private String name; diff --git a/src/br/edu/ufsj/sms/net/Message.java b/src/br/edu/ufsj/sms/net/Message.java index 1d726c7..d09a5d6 100644 --- a/src/br/edu/ufsj/sms/net/Message.java +++ b/src/br/edu/ufsj/sms/net/Message.java @@ -9,12 +9,13 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutput; import java.io.ObjectOutputStream; +import java.io.Serializable; /** * * @author flavio */ -public abstract class Message { +public abstract class Message implements Serializable{ public byte[] toByteArray() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -23,4 +24,4 @@ public abstract class Message { out.flush(); return baos.toByteArray(); } -} +} \ No newline at end of file diff --git a/src/br/edu/ufsj/sms/net/ScreenCastMessage.java b/src/br/edu/ufsj/sms/net/ScreenCastMessage.java index b071e32..d00e8f3 100644 --- a/src/br/edu/ufsj/sms/net/ScreenCastMessage.java +++ b/src/br/edu/ufsj/sms/net/ScreenCastMessage.java @@ -5,19 +5,17 @@ */ package br.edu.ufsj.sms.net; -import java.io.Serializable; - /** * * @author flavio */ -public class ScreenCastMessage extends Message implements Serializable { +public class ScreenCastMessage extends Message { - private byte[] imageByte; private String name; + private int y; + private byte[] imageByte; public ScreenCastMessage() { - } public ScreenCastMessage(String name, byte[] imageByte) { diff --git a/src/br/edu/ufsj/sms/net/Socket.java b/src/br/edu/ufsj/sms/net/Socket.java index 39624f8..f6ca0e1 100644 --- a/src/br/edu/ufsj/sms/net/Socket.java +++ b/src/br/edu/ufsj/sms/net/Socket.java @@ -7,18 +7,13 @@ package br.edu.ufsj.sms.net; import br.edu.ufsj.sms.GUI.MainWindow; import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; -import java.io.ObjectOutput; -import java.io.ObjectOutputStream; import java.net.DatagramPacket; import java.net.InetAddress; -import java.net.InetSocketAddress; import java.net.MulticastSocket; import java.net.UnknownHostException; -import java.nio.ByteBuffer; import java.util.logging.Level; import java.util.logging.Logger;