New version of everything

This commit is contained in:
fls committed 2026-07-16 15:28:00 -03:00
1 parent c13dd4282b
commit 24b0db40ed
79 files changed
+7278

No files matched your search

@@ -0,0 +1 @@
pitiupi.screenCast.plugin.ScreenCastPlugin
@@ -0,0 +1,31 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package pitiupi.screenCast.GUI;
import java.awt.event.ActionEvent;
import javax.swing.JMenu;
/**
*
* @author flavio
*/
public class ScreenCastMenu extends JMenu {
private final ScreenCastWindow screenCastWindow;
private final javax.swing.JMenuItem menuItem;
public ScreenCastMenu(ScreenCastWindow screenCastWindow) {
this.screenCastWindow = screenCastWindow;
this.setText("Screen Cast");
menuItem = new javax.swing.JMenuItem();
menuItem.setText("ScreenCast Window");
menuItem.addActionListener(this::chatMenuActionPerformed);
this.add(menuItem);
}
private void chatMenuActionPerformed(ActionEvent ae) {
this.screenCastWindow.setVisible(true);
}
}
@@ -0,0 +1,135 @@
/*
* 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 pitiupi.screenCast.GUI;
import pitiupi.screenCast.control.AlarmClock;
import pitiupi.screenCast.control.ImageTransformation;
import pitiupi.screenCast.control.ScreenShot;
import pitiupi.screenCast.net.ScreenCastMessage;
import java.awt.AWTException;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
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;
import pitiupi.GUI.MainWindow;
import pitiupi.net.Message;
/**
*
* @author flavio
*/
public class ScreenCastWindow extends javax.swing.JFrame {
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTabbedPane tabbedPane;
private javax.swing.JCheckBox onlineButton;
private AlarmClock alarmClock;
private Timer timer;
public final static int TIME = 1000;
private float compressRatio;
private final MainWindow mainWindow;
public ScreenCastWindow(MainWindow mainWindow) {
this.mainWindow = mainWindow;
this.compressRatio = 0.5f;
this.initComponents();
}
private void initComponents() {
this.setTitle("screen cast");
onlineButton = new javax.swing.JCheckBox("Sharing?");
onlineButton.setSelected(false);
onlineButton.addActionListener(this::onlineButtonActionPerformed);
this.getContentPane().add(onlineButton, java.awt.BorderLayout.NORTH);
jScrollPane1 = new javax.swing.JScrollPane();
tabbedPane = new javax.swing.JTabbedPane();
jScrollPane1.setViewportView(tabbedPane);
this.getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
this.pack();
this.timer = new Timer();
this.setSize(new java.awt.Dimension(1024, 768));
}
public void shareMySheet(boolean status) {
if (status) {
this.timer = new Timer();
this.alarmClock = new AlarmClock(this);
this.timer.scheduleAtFixedRate(this.alarmClock, 0, ScreenCastWindow.TIME);
} else {
this.timer.cancel();
}
}
public void closeCurrentTab() {
if (tabbedPane.getSelectedIndex() > 0) {
tabbedPane.remove(tabbedPane.getSelectedIndex());
}
}
public void exit() {
this.shareMySheet(false);
}
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.mainWindow.getUserName(), byteImage);
msg = message.toByteArray();
} catch (AWTException | IOException ex) {
Logger.getLogger(AlarmClock.class.getName()).log(Level.SEVERE, null, ex);
}
if (msg != null) {
try {
this.mainWindow.getSocket().send(msg);
} catch (IOException ex) {
System.out.println(ex.toString());
this.compressRatio -= 0.1f;
}
}
}
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(ScreenCastWindow.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void onlineButtonActionPerformed(ActionEvent ae) {
this.shareMySheet(this.onlineButton.isSelected());
}
}
@@ -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 pitiupi.screenCast.control;
import java.util.TimerTask;
import pitiupi.screenCast.GUI.ScreenCastWindow;
/**
*
* @author flavio
*/
public class AlarmClock extends TimerTask {
private final ScreenCastWindow screenCastWindow;
public AlarmClock(ScreenCastWindow mainWindow) {
this.screenCastWindow = mainWindow;
}
@Override
public void run() {
this.screenCastWindow.sendScreenCastMessage();
}
}
@@ -0,0 +1,67 @@
/*
* 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 pitiupi.screenCast.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 = maxWidth;
int 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 pitiupi.screenCast.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,55 @@
/*
* 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 pitiupi.screenCast.net;
import pitiupi.net.Message;
/**
*
* @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,69 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package pitiupi.screenCast.plugin;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import pitiupi.GUI.MainWindow;
import pitiupi.net.Message;
import pitiupi.plugin.Plugin;
import pitiupi.screenCast.GUI.ScreenCastMenu;
import pitiupi.screenCast.GUI.ScreenCastWindow;
import pitiupi.screenCast.net.ScreenCastMessage;
/**
*
* @author flavio
*/
public class ScreenCastPlugin implements Plugin {
private ScreenCastWindow screenCastWindow;
private MainWindow mainWindow;
@Override
public String getName() {
return "ScreenCast";
}
@Override
public String getAuthor() {
return "Flávio Schiavoni";
}
@Override
public String getVersion() {
return "0.0";
}
@Override
public void createPlugin(MainWindow mainWindow) {
this.mainWindow = mainWindow;
this.screenCastWindow = new ScreenCastWindow(mainWindow);
this.mainWindow.addMenu(new ScreenCastMenu(screenCastWindow));
}
@Override
public void receiveMessage(byte[] message) {
ByteArrayInputStream bis = new ByteArrayInputStream(message);
ObjectInputStream ois;
try {
ois = new ObjectInputStream(bis);
if (ois.readObject() instanceof ScreenCastMessage msg) {
this.screenCastWindow.receiveScreenCastMessage(msg);
}
} catch (IOException ex) {
System.out.println(ex.toString());
} catch (ClassNotFoundException ex) {
System.out.println(ex.toString());
}
}
@Override
public Message getMessage() {
return new ScreenCastMessage();
}
}