Compare commits
10 Commits
9aab34f605
...
8930ba9bf3
| Author | SHA1 | Date |
|---|---|---|
|
|
8930ba9bf3 | |
|
|
42ba2744cb | |
|
|
5d5d87de77 | |
|
|
91fc3d7666 | |
|
|
4793fbdacf | |
|
|
fd16955a34 | |
|
|
69dbb18825 | |
|
|
449795f6e2 | |
|
|
64ca5cca8d | |
|
|
bb436701db |
|
|
@ -1,2 +1,10 @@
|
||||||
# shareMySheet
|
# shareMySheet
|
||||||
ScreenCast System to share your Screen
|
ScreenCast System to share your Screen
|
||||||
|
|
||||||
|
Baixe o jar no endereço:
|
||||||
|
|
||||||
|
https://github.com/flschiavoni/shareMySheet/releases
|
||||||
|
|
||||||
|
Rode ele com java -jar ShareMySheet-20170126.jar
|
||||||
|
|
||||||
|
Seja feliz!
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
<project name="ShareMySheet" default="dist" basedir=".">
|
||||||
|
<description>
|
||||||
|
ScreenCast Build file
|
||||||
|
</description>
|
||||||
|
<!-- set global properties for this build -->
|
||||||
|
<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 -->
|
||||||
|
<tstamp/>
|
||||||
|
<!-- Create the build directory structure used by compile -->
|
||||||
|
<mkdir dir="${build}"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="compile" depends="init" description="compile the source">
|
||||||
|
<!-- Compile the java code from ${src} into ${build} -->
|
||||||
|
<javac srcdir="${src}" destdir="${build}"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="dist" depends="compile"
|
||||||
|
description="generate the distribution">
|
||||||
|
<!-- Create the distribution directory -->
|
||||||
|
<mkdir dir="${dist}/lib"/>
|
||||||
|
|
||||||
|
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
|
||||||
|
<jar destfile="${dist}/lib/ShareMySheet-${DSTAMP}.jar" basedir="${build}">
|
||||||
|
<manifest>
|
||||||
|
<attribute name="Main-Class" value="br.edu.ufsj.sms.Main"/>
|
||||||
|
</manifest>
|
||||||
|
</jar>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="clean"
|
||||||
|
description="clean up">
|
||||||
|
<!-- Delete the ${build} and ${dist} directory trees -->
|
||||||
|
<delete dir="${build}"/>
|
||||||
|
<delete dir="${dist}"/>
|
||||||
|
</target>
|
||||||
|
</project>
|
||||||
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
/*
|
||||||
|
* 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.BorderLayout;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JSpinner;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author flavio
|
||||||
|
*/
|
||||||
|
public final class Login extends JDialog {
|
||||||
|
|
||||||
|
JLabel nameLabel = new JLabel("Name: ");
|
||||||
|
JLabel portLabel = new JLabel("Port: ");
|
||||||
|
|
||||||
|
JTextField nameField = new JTextField();
|
||||||
|
JSpinner portField = new JSpinner();
|
||||||
|
|
||||||
|
JButton okButton = new JButton("OK");
|
||||||
|
JButton cancelButton = new JButton("Cancel");
|
||||||
|
|
||||||
|
public Login() {
|
||||||
|
initComponents();
|
||||||
|
this.setSize(400, 150);
|
||||||
|
this.setModal(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initComponents() {
|
||||||
|
this.setTitle("Login");
|
||||||
|
|
||||||
|
portField.setModel(new javax.swing.SpinnerNumberModel(8000, 8000, 9000, 1));
|
||||||
|
nameField.setText(System.getProperty("user.name"));
|
||||||
|
|
||||||
|
JPanel topPanel = new JPanel(new GridBagLayout());
|
||||||
|
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||||
|
|
||||||
|
buttonPanel.add(okButton);
|
||||||
|
buttonPanel.add(cancelButton);
|
||||||
|
|
||||||
|
GridBagConstraints gbc = new GridBagConstraints();
|
||||||
|
|
||||||
|
gbc.insets = new Insets(4, 4, 4, 4);
|
||||||
|
|
||||||
|
gbc.gridx = 0;
|
||||||
|
gbc.gridy = 0;
|
||||||
|
gbc.weightx = 0;
|
||||||
|
topPanel.add(nameLabel, gbc);
|
||||||
|
|
||||||
|
gbc.gridx = 1;
|
||||||
|
gbc.gridy = 0;
|
||||||
|
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc.weightx = 1;
|
||||||
|
topPanel.add(nameField, gbc);
|
||||||
|
|
||||||
|
gbc.gridx = 0;
|
||||||
|
gbc.gridy = 1;
|
||||||
|
gbc.fill = GridBagConstraints.NONE;
|
||||||
|
gbc.weightx = 0;
|
||||||
|
topPanel.add(portLabel, gbc);
|
||||||
|
|
||||||
|
gbc.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc.gridx = 1;
|
||||||
|
gbc.gridy = 1;
|
||||||
|
gbc.weightx = 1;
|
||||||
|
topPanel.add(portField, gbc);
|
||||||
|
|
||||||
|
this.add(topPanel);
|
||||||
|
this.add(buttonPanel, BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
okButton.addActionListener((ActionEvent e) -> {
|
||||||
|
Login.this.setVisible(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
cancelButton.addActionListener((ActionEvent e) -> {
|
||||||
|
System.exit(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return nameField.getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPort() {
|
||||||
|
return ((Integer) portField.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,182 @@
|
||||||
|
/*
|
||||||
|
* 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 br.edu.ufsj.sms.control.AlarmClock;
|
||||||
|
import br.edu.ufsj.sms.control.ImageTransformation;
|
||||||
|
import br.edu.ufsj.sms.control.ScreenShot;
|
||||||
|
import br.edu.ufsj.sms.net.ChatMessage;
|
||||||
|
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.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;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author flavio
|
||||||
|
*/
|
||||||
|
public class MainWindow extends javax.swing.JFrame {
|
||||||
|
|
||||||
|
private javax.swing.JScrollPane jScrollPane1;
|
||||||
|
private javax.swing.JLabel status;
|
||||||
|
private javax.swing.JPanel statusPanel;
|
||||||
|
private javax.swing.JTabbedPane tabbedPane;
|
||||||
|
private ChatWindow chatWindow;
|
||||||
|
|
||||||
|
private Socket socket;
|
||||||
|
private AlarmClock alarmClock;
|
||||||
|
private Timer timer;
|
||||||
|
public final static int TIME = 1000;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
private float compressRatio;
|
||||||
|
|
||||||
|
public MainWindow(String name, int port) throws UnknownHostException {
|
||||||
|
this.name = name;
|
||||||
|
this.port = port;
|
||||||
|
this.compressRatio = 0.5f;
|
||||||
|
this.initComponents();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initComponents() throws UnknownHostException {
|
||||||
|
this.setJMenuBar(new MenuBar(this));
|
||||||
|
this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
this.setTitle("Share My Sheet");
|
||||||
|
|
||||||
|
jScrollPane1 = new javax.swing.JScrollPane();
|
||||||
|
tabbedPane = new javax.swing.JTabbedPane();
|
||||||
|
statusPanel = new javax.swing.JPanel();
|
||||||
|
status = new javax.swing.JLabel();
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
this.getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
|
||||||
|
this.getContentPane().add(statusPanel, java.awt.BorderLayout.PAGE_END);
|
||||||
|
|
||||||
|
this.pack();
|
||||||
|
|
||||||
|
this.socket = new Socket(this);
|
||||||
|
this.timer = new Timer();
|
||||||
|
this.chatWindow = new ChatWindow(this);
|
||||||
|
|
||||||
|
this.socket.start();
|
||||||
|
this.setSize(new java.awt.Dimension(1024, 768));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showChatWindow() {
|
||||||
|
this.chatWindow.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showAboutWindow() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shareMySheet(boolean status) {
|
||||||
|
if (status) {
|
||||||
|
this.timer = new Timer();
|
||||||
|
this.alarmClock = new AlarmClock(this);
|
||||||
|
this.timer.scheduleAtFixedRate(this.alarmClock, 0, MainWindow.TIME);
|
||||||
|
} else {
|
||||||
|
this.timer.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeCurrentTab() {
|
||||||
|
tabbedPane.remove(tabbedPane.getSelectedIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exit() {
|
||||||
|
this.chatWindow.setVisible(true);
|
||||||
|
this.setVisible(false);
|
||||||
|
this.dispose();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendChatMessage(String text) {
|
||||||
|
ChatMessage message = new ChatMessage(this.name, text);
|
||||||
|
try {
|
||||||
|
this.socket.send(message.toByteArray());
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendScreenCastMessage() {
|
||||||
|
byte[] msg = null;
|
||||||
|
try {
|
||||||
|
BufferedImage image = ScreenShot.takeAShot();
|
||||||
|
BufferedImage rescaled = ImageTransformation.resize(image, 1024, 768);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void receiveScreenCastMessage(ScreenCastMessage message) {
|
||||||
|
ByteArrayInputStream bais = new ByteArrayInputStream(message.getImageByte());
|
||||||
|
BufferedImage image;
|
||||||
|
try {
|
||||||
|
|
||||||
|
image = ImageIO.read(bais);
|
||||||
|
ImageIcon imageIcon = new ImageIcon(image);
|
||||||
|
|
||||||
|
JLabel myShoot = new JLabel(imageIcon);
|
||||||
|
|
||||||
|
for (int i = 0; i < tabbedPane.getTabCount(); i++) {
|
||||||
|
String title = tabbedPane.getTitleAt(i);
|
||||||
|
if (title.equals(message.getName())) {
|
||||||
|
tabbedPane.setComponentAt(i, myShoot);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tabbedPane.addTab(message.getName(), myShoot);
|
||||||
|
} catch (IOException 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();
|
||||||
|
chatWindow.receiveChatMessage(dt.format(date) + " "
|
||||||
|
+ "<b>" + message.getName() + "</b>: "
|
||||||
|
+ message.getText() + "<br>");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the port
|
||||||
|
*/
|
||||||
|
public int getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,100 @@
|
||||||
|
/*
|
||||||
|
* 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 final MainWindow mainWindow;
|
||||||
|
|
||||||
|
public MenuBar(MainWindow mainWindow) {
|
||||||
|
this.mainWindow = mainWindow;
|
||||||
|
this.initComponents();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initComponents() {
|
||||||
|
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");
|
||||||
|
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(this::closeTabMenuActionPerformed);
|
||||||
|
exitMenu.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
|
||||||
|
exitMenu.setText("Exit");
|
||||||
|
exitMenu.addActionListener(this::exitMenuActionPerformed);
|
||||||
|
fileMenu.add(closeTabMenu);
|
||||||
|
fileMenu.add(exitMenu);
|
||||||
|
this.add(fileMenu);
|
||||||
|
|
||||||
|
editMenu.setText("Edit");
|
||||||
|
shareMySheetMenu.setText("Share My Sheet!");
|
||||||
|
shareMySheetMenu.addActionListener(this::shareMySheetMenuActionPerformed);
|
||||||
|
editMenu.add(shareMySheetMenu);
|
||||||
|
this.add(editMenu);
|
||||||
|
|
||||||
|
viewMenu.setText("View");
|
||||||
|
showChatWindowMenu.setText("Chat Window");
|
||||||
|
showChatWindowMenu.addActionListener(this::showChatWindowMenuActionPerformed);
|
||||||
|
viewMenu.add(showChatWindowMenu);
|
||||||
|
this.add(viewMenu);
|
||||||
|
|
||||||
|
helpMenu.setText("Help");
|
||||||
|
aboutMenu.setText("About");
|
||||||
|
aboutMenu.addActionListener(this::aboutMenuActionPerformed);
|
||||||
|
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) {
|
||||||
|
mainWindow.shareMySheet(shareMySheetMenu.isSelected());
|
||||||
|
if (shareMySheetMenu.isSelected()) {
|
||||||
|
shareMySheetMenu.setText("Stop sharing it!");
|
||||||
|
} else {
|
||||||
|
shareMySheetMenu.setText("Share My Sheer!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void closeTabMenuActionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
|
mainWindow.closeCurrentTab();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void exitMenuActionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
|
mainWindow.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import br.edu.ufsj.sms.GUI.Login;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author flavio
|
||||||
|
*/
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param args the command line arguments
|
||||||
|
*/
|
||||||
|
public static void main(String args[]) {
|
||||||
|
/* Set the Nimbus look and feel */
|
||||||
|
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||||
|
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
||||||
|
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||||
|
if ("Nimbus".equals(info.getName())) {
|
||||||
|
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (ClassNotFoundException 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.MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||||
|
} catch (IllegalAccessException 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.MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
//</editor-fold>
|
||||||
|
|
||||||
|
/* Create and display the form */
|
||||||
|
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Login login = new Login();
|
||||||
|
login.setVisible(true);
|
||||||
|
String name = login.getName();
|
||||||
|
int port = login.getPort();
|
||||||
|
login.dispose();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* 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.control;
|
||||||
|
|
||||||
|
import br.edu.ufsj.sms.GUI.MainWindow;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author flavio
|
||||||
|
*/
|
||||||
|
public class AlarmClock extends TimerTask {
|
||||||
|
|
||||||
|
private final MainWindow mainWindow;
|
||||||
|
|
||||||
|
public AlarmClock(MainWindow mainWindow) {
|
||||||
|
this.mainWindow = mainWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
this.mainWindow.sendScreenCastMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* 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.control;
|
||||||
|
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import javax.imageio.IIOImage;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.imageio.ImageWriteParam;
|
||||||
|
import javax.imageio.ImageWriter;
|
||||||
|
import javax.imageio.stream.ImageOutputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author flavio
|
||||||
|
*/
|
||||||
|
public class ImageTransformation {
|
||||||
|
|
||||||
|
public static byte[] toByteArray(BufferedImage image) throws IOException {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
ImageIO.write(image, "jpg", baos);
|
||||||
|
byte[] data = baos.toByteArray();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] compress(BufferedImage image, float scale) throws IOException {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
|
||||||
|
ImageWriter writer = writers.next();
|
||||||
|
ImageWriteParam param = writer.getDefaultWriteParam();
|
||||||
|
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
||||||
|
param.setCompressionQuality(scale);
|
||||||
|
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
|
||||||
|
writer.setOutput(ios);
|
||||||
|
writer.write(null, new IIOImage(image, null, null), param);
|
||||||
|
byte[] data = baos.toByteArray();
|
||||||
|
writer.dispose();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BufferedImage resize(BufferedImage img, int maxWidth, int maxHeight) throws IOException {
|
||||||
|
int scaledWidth = 0;
|
||||||
|
int scaledHeight = 0;
|
||||||
|
|
||||||
|
scaledWidth = maxWidth;
|
||||||
|
scaledHeight = (int) (img.getHeight() * ((double) scaledWidth / img.getWidth()));
|
||||||
|
|
||||||
|
if (scaledHeight > maxHeight) {
|
||||||
|
scaledHeight = maxHeight;
|
||||||
|
scaledWidth = (int) (img.getWidth() * ((double) scaledHeight / img.getHeight()));
|
||||||
|
|
||||||
|
if (scaledWidth > maxWidth) {
|
||||||
|
scaledWidth = maxWidth;
|
||||||
|
scaledHeight = maxHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Image resized = img.getScaledInstance(scaledWidth, scaledHeight, Image.SCALE_SMOOTH);
|
||||||
|
BufferedImage buffered = new BufferedImage(scaledWidth, scaledHeight, Image.SCALE_REPLICATE);
|
||||||
|
buffered.getGraphics().drawImage(resized, 0, 0, null);
|
||||||
|
|
||||||
|
return buffered;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* 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.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.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author flavio
|
||||||
|
*/
|
||||||
|
public class ScreenShot {
|
||||||
|
|
||||||
|
public static BufferedImage takeAShot() throws AWTException, IOException {
|
||||||
|
Robot robot = new Robot();
|
||||||
|
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
|
||||||
|
BufferedImage output = robot.createScreenCapture(screenRect);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author flavio
|
||||||
|
*/
|
||||||
|
public class ChatMessage extends Message{
|
||||||
|
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
public String getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param text the text to set
|
||||||
|
*/
|
||||||
|
public void setText(String text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* 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.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectOutput;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author flavio
|
||||||
|
*/
|
||||||
|
public abstract class Message implements Serializable{
|
||||||
|
|
||||||
|
public byte[] toByteArray() throws IOException {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
ObjectOutput out = new ObjectOutputStream(baos);
|
||||||
|
out.writeObject(this);
|
||||||
|
out.flush();
|
||||||
|
return baos.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author flavio
|
||||||
|
*/
|
||||||
|
public class ScreenCastMessage extends Message {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
* 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 br.edu.ufsj.sms.GUI.MainWindow;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInput;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.net.DatagramPacket;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.MulticastSocket;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author flavio
|
||||||
|
*/
|
||||||
|
public class Socket extends Thread {
|
||||||
|
|
||||||
|
private MulticastSocket multicastSocket;
|
||||||
|
private InetAddress address;
|
||||||
|
private MainWindow main;
|
||||||
|
public final static String INET_ADDR = "224.0.0.3";
|
||||||
|
|
||||||
|
public Socket(MainWindow main) throws UnknownHostException {
|
||||||
|
this.main = main;
|
||||||
|
this.address = InetAddress.getByName(Socket.INET_ADDR);
|
||||||
|
try {
|
||||||
|
multicastSocket = new MulticastSocket(this.main.getPort());
|
||||||
|
multicastSocket.setSendBufferSize(256000);
|
||||||
|
multicastSocket.setReceiveBufferSize(256000);
|
||||||
|
multicastSocket.setReuseAddress(true);
|
||||||
|
multicastSocket.joinGroup(address);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
System.out.println("There is no socket connection. Sorry.");
|
||||||
|
System.out.println(ex.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(byte[] msg) throws IOException {
|
||||||
|
DatagramPacket msgPacket;
|
||||||
|
msgPacket = new DatagramPacket(msg, msg.length, this.address, this.main.getPort());
|
||||||
|
multicastSocket.send(msgPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
Object message;
|
||||||
|
message = in.readObject();
|
||||||
|
if (message instanceof ScreenCastMessage) {
|
||||||
|
this.main.receiveScreenCastMessage((ScreenCastMessage) message);
|
||||||
|
}
|
||||||
|
if (message instanceof ChatMessage) {
|
||||||
|
this.main.receiveChatMessage((ChatMessage) message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
this.receive();
|
||||||
|
} catch (IOException | ClassNotFoundException ex) {
|
||||||
|
Logger.getLogger(Socket.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue