diff --git a/pitiupi.chat/build.xml b/pitiupi.chat/build.xml new file mode 100644 index 0000000..fdd5503 --- /dev/null +++ b/pitiupi.chat/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project pitiupi.chat. + + + diff --git a/pitiupi.chat/build/built-jar.properties b/pitiupi.chat/build/built-jar.properties new file mode 100644 index 0000000..499f65e --- /dev/null +++ b/pitiupi.chat/build/built-jar.properties @@ -0,0 +1,6 @@ +#Thu, 16 Jul 2026 15:21:36 -0300 + + +/home/flavio/NetBeansProjects/pitiupi.chat= + +/home/flavio/NetBeansProjects/pitiupi= diff --git a/pitiupi.chat/build/classes/META-INF/services/pitiupi.plugin.Plugin b/pitiupi.chat/build/classes/META-INF/services/pitiupi.plugin.Plugin new file mode 100644 index 0000000..eea07c1 --- /dev/null +++ b/pitiupi.chat/build/classes/META-INF/services/pitiupi.plugin.Plugin @@ -0,0 +1 @@ +pitiupi.chat.plugin.ChatPlugin diff --git a/pitiupi.chat/build/classes/pitiupi/chat/GUI/ChatMenu.class b/pitiupi.chat/build/classes/pitiupi/chat/GUI/ChatMenu.class new file mode 100644 index 0000000..e78acc9 Binary files /dev/null and b/pitiupi.chat/build/classes/pitiupi/chat/GUI/ChatMenu.class differ diff --git a/pitiupi.chat/build/classes/pitiupi/chat/GUI/ChatWindow$1.class b/pitiupi.chat/build/classes/pitiupi/chat/GUI/ChatWindow$1.class new file mode 100644 index 0000000..254570a Binary files /dev/null and b/pitiupi.chat/build/classes/pitiupi/chat/GUI/ChatWindow$1.class differ diff --git a/pitiupi.chat/build/classes/pitiupi/chat/GUI/ChatWindow.class b/pitiupi.chat/build/classes/pitiupi/chat/GUI/ChatWindow.class new file mode 100644 index 0000000..4d4bde2 Binary files /dev/null and b/pitiupi.chat/build/classes/pitiupi/chat/GUI/ChatWindow.class differ diff --git a/pitiupi.chat/build/classes/pitiupi/chat/net/ChatMessage.class b/pitiupi.chat/build/classes/pitiupi/chat/net/ChatMessage.class new file mode 100644 index 0000000..de14b13 Binary files /dev/null and b/pitiupi.chat/build/classes/pitiupi/chat/net/ChatMessage.class differ diff --git a/pitiupi.chat/build/classes/pitiupi/chat/plugin/ChatPlugin.class b/pitiupi.chat/build/classes/pitiupi/chat/plugin/ChatPlugin.class new file mode 100644 index 0000000..b5d0c5d Binary files /dev/null and b/pitiupi.chat/build/classes/pitiupi/chat/plugin/ChatPlugin.class differ diff --git a/pitiupi.chat/dist/pitiupi.chat.jar b/pitiupi.chat/dist/pitiupi.chat.jar new file mode 100644 index 0000000..78438b7 Binary files /dev/null and b/pitiupi.chat/dist/pitiupi.chat.jar differ diff --git a/pitiupi.chat/nbproject/build-impl.xml b/pitiupi.chat/nbproject/build-impl.xml new file mode 100644 index 0000000..9ea09d4 --- /dev/null +++ b/pitiupi.chat/nbproject/build-impl.xml @@ -0,0 +1,1789 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pitiupi.chat/nbproject/genfiles.properties b/pitiupi.chat/nbproject/genfiles.properties new file mode 100644 index 0000000..42ba841 --- /dev/null +++ b/pitiupi.chat/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=3f66efc2 +build.xml.script.CRC32=3953f1a4 +build.xml.stylesheet.CRC32=f85dc8f2@1.119.0.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=3f66efc2 +nbproject/build-impl.xml.script.CRC32=a4594806 +nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.119.0.48 diff --git a/pitiupi.chat/nbproject/private/config.properties b/pitiupi.chat/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/pitiupi.chat/nbproject/private/private.properties b/pitiupi.chat/nbproject/private/private.properties new file mode 100644 index 0000000..2a5dca8 --- /dev/null +++ b/pitiupi.chat/nbproject/private/private.properties @@ -0,0 +1,8 @@ +compile.on.save=true +do.depend=false +do.jar=true +do.jlink=false +javac.debug=true +javadoc.preview=true +jlink.strip=false +user.properties.file=/home/flavio/snap/netbeans/145/build.properties diff --git a/pitiupi.chat/nbproject/project.properties b/pitiupi.chat/nbproject/project.properties new file mode 100644 index 0000000..b87aa66 --- /dev/null +++ b/pitiupi.chat/nbproject/project.properties @@ -0,0 +1,98 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=pitiupi.chat +application.vendor=flavio +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/pitiupi.chat.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/pitiupi.chat +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath=\ + ${reference.pitiupi.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=25 +javac.target=25 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# The jlink additional root modules to resolve +jlink.additionalmodules= +# The jlink additional command line parameters +jlink.additionalparam= +jlink.launcher=true +jlink.launcher.name=pitiupi.chat +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=true +platform.active=default_platform +project.pitiupi=../pitiupi +reference.pitiupi.jar=${project.pitiupi}/dist/pitiupi.jar +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/pitiupi.chat/nbproject/project.xml b/pitiupi.chat/nbproject/project.xml new file mode 100644 index 0000000..4b42f84 --- /dev/null +++ b/pitiupi.chat/nbproject/project.xml @@ -0,0 +1,25 @@ + + + org.netbeans.modules.java.j2seproject + + + pitiupi.chat + + + + + + + + + + pitiupi + jar + + jar + clean + jar + + + + diff --git a/pitiupi.chat/src/META-INF/services/pitiupi.plugin.Plugin b/pitiupi.chat/src/META-INF/services/pitiupi.plugin.Plugin new file mode 100644 index 0000000..eea07c1 --- /dev/null +++ b/pitiupi.chat/src/META-INF/services/pitiupi.plugin.Plugin @@ -0,0 +1 @@ +pitiupi.chat.plugin.ChatPlugin diff --git a/pitiupi.chat/src/pitiupi/chat/GUI/ChatMenu.java b/pitiupi.chat/src/pitiupi/chat/GUI/ChatMenu.java new file mode 100644 index 0000000..8406b59 --- /dev/null +++ b/pitiupi.chat/src/pitiupi/chat/GUI/ChatMenu.java @@ -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.chat.GUI; + +import java.awt.event.ActionEvent; +import javax.swing.JMenu; + +/** + * + * @author flavio + */ +public class ChatMenu extends JMenu { + + private final ChatWindow chatWindow; + private javax.swing.JMenuItem menuItem; + + public ChatMenu(ChatWindow chatWindow) { + this.chatWindow = chatWindow; + this.setText("Chat"); + menuItem = new javax.swing.JMenuItem(); + menuItem.setText("Show Chat Window"); + menuItem.addActionListener(this::chatMenuActionPerformed); + this.add(menuItem); + } + + private void chatMenuActionPerformed(ActionEvent ae) { + this.chatWindow.setVisible(true); + } +} diff --git a/pitiupi.chat/src/pitiupi/chat/GUI/ChatWindow.java b/pitiupi.chat/src/pitiupi/chat/GUI/ChatWindow.java new file mode 100644 index 0000000..f894a65 --- /dev/null +++ b/pitiupi.chat/src/pitiupi/chat/GUI/ChatWindow.java @@ -0,0 +1,121 @@ +/* + * 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.chat.GUI; + +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.logging.Level; +import java.util.logging.Logger; +import pitiupi.chat.net.ChatMessage; +import pitiupi.GUI.MainWindow; +import pitiupi.net.Message; + +/** + * + * @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 final 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; + } + ChatMessage message = new ChatMessage(mainWindow.getName(), jTextArea1.getText()); + this.sendChatMessage(message); + jTextArea1.setText(""); + } + + public void sendChatMessage(Message message) { + try { + mainWindow.getSocket().send(message.toByteArray()); + } 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(); + this.receiveChatMessage(dt.format(date) + " " + + "" + message.getName() + ": " + + message.getText() + "
"); + } + + public void receiveChatMessage(String message) { + jEditorPane1.setText(message + jEditorPane1.getText()); + } +} diff --git a/pitiupi.chat/src/pitiupi/chat/net/ChatMessage.java b/pitiupi.chat/src/pitiupi/chat/net/ChatMessage.java new file mode 100644 index 0000000..e194a2b --- /dev/null +++ b/pitiupi.chat/src/pitiupi/chat/net/ChatMessage.java @@ -0,0 +1,57 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package pitiupi.chat.net; + +import pitiupi.net.Message; +import pitiupi.net.Message; + +/** + * + * @author flavio + */ +public class ChatMessage extends Message{ + + private String text; + private String name; + + + public ChatMessage(){ + + } + + 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; + } + +} diff --git a/pitiupi.chat/src/pitiupi/chat/plugin/ChatPlugin.java b/pitiupi.chat/src/pitiupi/chat/plugin/ChatPlugin.java new file mode 100644 index 0000000..44f3911 --- /dev/null +++ b/pitiupi.chat/src/pitiupi/chat/plugin/ChatPlugin.java @@ -0,0 +1,71 @@ +/* + * 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.chat.plugin; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import pitiupi.GUI.MainWindow; +import pitiupi.chat.GUI.ChatMenu; +import pitiupi.chat.GUI.ChatWindow; +import pitiupi.chat.net.ChatMessage; +import pitiupi.net.Message; +import pitiupi.plugin.Plugin; + +/** + * + * @author flavio + */ +public class ChatPlugin implements Plugin { + + private ChatWindow chatWindow; + private MainWindow mainWindow; + + public ChatPlugin() { + } + + @Override + public void createPlugin(MainWindow mainWindow) { + this.mainWindow = mainWindow; + this.chatWindow = new ChatWindow(mainWindow); + this.mainWindow.addMenu(new ChatMenu(chatWindow)); + } + + @Override + public void receiveMessage(byte[] message) { + ByteArrayInputStream bis = new ByteArrayInputStream(message); + ObjectInputStream ois; + try { + ois = new ObjectInputStream(bis); + if (ois.readObject() instanceof ChatMessage msg) { + this.chatWindow.receiveChatMessage(msg); + } + } catch (IOException ex) { + System.out.println(ex.toString()); + } catch (ClassNotFoundException ex) { + System.out.println(ex.toString()); + } + } + + @Override + public String getName() { + return "Chat"; + } + + @Override + public String getAuthor() { + return "Flávio Schiavoni"; + } + + @Override + public String getVersion() { + return "0"; + } + + @Override + public Message getMessage() { + return new ChatMessage(); + } +} diff --git a/pitiupi.screenCast/build.xml b/pitiupi.screenCast/build.xml new file mode 100644 index 0000000..659019b --- /dev/null +++ b/pitiupi.screenCast/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project pitiupi.screenCast. + + + diff --git a/pitiupi.screenCast/build/built-jar.properties b/pitiupi.screenCast/build/built-jar.properties new file mode 100644 index 0000000..6898243 --- /dev/null +++ b/pitiupi.screenCast/build/built-jar.properties @@ -0,0 +1,6 @@ +#Thu, 16 Jul 2026 15:21:39 -0300 + + +/home/flavio/NetBeansProjects/pitiupi.screenCast= + +/home/flavio/NetBeansProjects/pitiupi= diff --git a/pitiupi.screenCast/build/classes/META-INF/services/pitiupi.plugin.Plugin b/pitiupi.screenCast/build/classes/META-INF/services/pitiupi.plugin.Plugin new file mode 100644 index 0000000..d11a8fc --- /dev/null +++ b/pitiupi.screenCast/build/classes/META-INF/services/pitiupi.plugin.Plugin @@ -0,0 +1 @@ +pitiupi.screenCast.plugin.ScreenCastPlugin diff --git a/pitiupi.screenCast/build/classes/pitiupi/screenCast/GUI/ScreenCastMenu.class b/pitiupi.screenCast/build/classes/pitiupi/screenCast/GUI/ScreenCastMenu.class new file mode 100644 index 0000000..4c002f1 Binary files /dev/null and b/pitiupi.screenCast/build/classes/pitiupi/screenCast/GUI/ScreenCastMenu.class differ diff --git a/pitiupi.screenCast/build/classes/pitiupi/screenCast/GUI/ScreenCastWindow.class b/pitiupi.screenCast/build/classes/pitiupi/screenCast/GUI/ScreenCastWindow.class new file mode 100644 index 0000000..490ff3f Binary files /dev/null and b/pitiupi.screenCast/build/classes/pitiupi/screenCast/GUI/ScreenCastWindow.class differ diff --git a/pitiupi.screenCast/build/classes/pitiupi/screenCast/control/AlarmClock.class b/pitiupi.screenCast/build/classes/pitiupi/screenCast/control/AlarmClock.class new file mode 100644 index 0000000..40e9f43 Binary files /dev/null and b/pitiupi.screenCast/build/classes/pitiupi/screenCast/control/AlarmClock.class differ diff --git a/pitiupi.screenCast/build/classes/pitiupi/screenCast/control/ImageTransformation.class b/pitiupi.screenCast/build/classes/pitiupi/screenCast/control/ImageTransformation.class new file mode 100644 index 0000000..b4c1d43 Binary files /dev/null and b/pitiupi.screenCast/build/classes/pitiupi/screenCast/control/ImageTransformation.class differ diff --git a/pitiupi.screenCast/build/classes/pitiupi/screenCast/control/ScreenShot.class b/pitiupi.screenCast/build/classes/pitiupi/screenCast/control/ScreenShot.class new file mode 100644 index 0000000..3cde756 Binary files /dev/null and b/pitiupi.screenCast/build/classes/pitiupi/screenCast/control/ScreenShot.class differ diff --git a/pitiupi.screenCast/build/classes/pitiupi/screenCast/net/ScreenCastMessage.class b/pitiupi.screenCast/build/classes/pitiupi/screenCast/net/ScreenCastMessage.class new file mode 100644 index 0000000..dc8a7ea Binary files /dev/null and b/pitiupi.screenCast/build/classes/pitiupi/screenCast/net/ScreenCastMessage.class differ diff --git a/pitiupi.screenCast/build/classes/pitiupi/screenCast/plugin/ScreenCastPlugin.class b/pitiupi.screenCast/build/classes/pitiupi/screenCast/plugin/ScreenCastPlugin.class new file mode 100644 index 0000000..77a7e76 Binary files /dev/null and b/pitiupi.screenCast/build/classes/pitiupi/screenCast/plugin/ScreenCastPlugin.class differ diff --git a/pitiupi.screenCast/dist/README.TXT b/pitiupi.screenCast/dist/README.TXT new file mode 100644 index 0000000..28b99c7 --- /dev/null +++ b/pitiupi.screenCast/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "pitiupi.screenCast.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/pitiupi.screenCast/dist/lib/pitiupi.jar b/pitiupi.screenCast/dist/lib/pitiupi.jar new file mode 100644 index 0000000..85ec1b8 Binary files /dev/null and b/pitiupi.screenCast/dist/lib/pitiupi.jar differ diff --git a/pitiupi.screenCast/dist/pitiupi.screenCast.jar b/pitiupi.screenCast/dist/pitiupi.screenCast.jar new file mode 100644 index 0000000..06682ea Binary files /dev/null and b/pitiupi.screenCast/dist/pitiupi.screenCast.jar differ diff --git a/pitiupi.screenCast/manifest.mf b/pitiupi.screenCast/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/pitiupi.screenCast/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/pitiupi.screenCast/nbproject/build-impl.xml b/pitiupi.screenCast/nbproject/build-impl.xml new file mode 100644 index 0000000..6895ddc --- /dev/null +++ b/pitiupi.screenCast/nbproject/build-impl.xml @@ -0,0 +1,1789 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pitiupi.screenCast/nbproject/genfiles.properties b/pitiupi.screenCast/nbproject/genfiles.properties new file mode 100644 index 0000000..78bc088 --- /dev/null +++ b/pitiupi.screenCast/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=96758119 +build.xml.script.CRC32=70726a23 +build.xml.stylesheet.CRC32=f85dc8f2@1.119.0.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=96758119 +nbproject/build-impl.xml.script.CRC32=0f906282 +nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.119.0.48 diff --git a/pitiupi.screenCast/nbproject/private/private.properties b/pitiupi.screenCast/nbproject/private/private.properties new file mode 100644 index 0000000..5e86d43 --- /dev/null +++ b/pitiupi.screenCast/nbproject/private/private.properties @@ -0,0 +1,2 @@ +compile.on.save=true +user.properties.file=/home/flavio/snap/netbeans/145/build.properties diff --git a/pitiupi.screenCast/nbproject/project.properties b/pitiupi.screenCast/nbproject/project.properties new file mode 100644 index 0000000..59c1b5f --- /dev/null +++ b/pitiupi.screenCast/nbproject/project.properties @@ -0,0 +1,98 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/pitiupi.screenCast.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/pitiupi.screenCast +excludes= +includes=** +jar.compress=false +javac.classpath=\ + ${reference.pitiupi.jar} +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=25 +javac.target=25 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# The jlink additional root modules to resolve +jlink.additionalmodules= +# The jlink additional command line parameters +jlink.additionalparam= +jlink.launcher=true +jlink.launcher.name=pitiupi.screenCast +main.class= +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +project.pitiupi=../pitiupi +reference.pitiupi.jar=${project.pitiupi}/dist/pitiupi.jar +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/pitiupi.screenCast/nbproject/project.xml b/pitiupi.screenCast/nbproject/project.xml new file mode 100644 index 0000000..1c77854 --- /dev/null +++ b/pitiupi.screenCast/nbproject/project.xml @@ -0,0 +1,25 @@ + + + org.netbeans.modules.java.j2seproject + + + pitiupi.screenCast + + + + + + + + + + pitiupi + jar + + jar + clean + jar + + + + diff --git a/pitiupi.screenCast/src/META-INF/services/pitiupi.plugin.Plugin b/pitiupi.screenCast/src/META-INF/services/pitiupi.plugin.Plugin new file mode 100644 index 0000000..d11a8fc --- /dev/null +++ b/pitiupi.screenCast/src/META-INF/services/pitiupi.plugin.Plugin @@ -0,0 +1 @@ +pitiupi.screenCast.plugin.ScreenCastPlugin diff --git a/pitiupi.screenCast/src/pitiupi/screenCast/GUI/ScreenCastMenu.java b/pitiupi.screenCast/src/pitiupi/screenCast/GUI/ScreenCastMenu.java new file mode 100644 index 0000000..93abd86 --- /dev/null +++ b/pitiupi.screenCast/src/pitiupi/screenCast/GUI/ScreenCastMenu.java @@ -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); + } +} diff --git a/pitiupi.screenCast/src/pitiupi/screenCast/GUI/ScreenCastWindow.java b/pitiupi.screenCast/src/pitiupi/screenCast/GUI/ScreenCastWindow.java new file mode 100644 index 0000000..f3ae1ca --- /dev/null +++ b/pitiupi.screenCast/src/pitiupi/screenCast/GUI/ScreenCastWindow.java @@ -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()); + } +} diff --git a/pitiupi.screenCast/src/pitiupi/screenCast/control/AlarmClock.java b/pitiupi.screenCast/src/pitiupi/screenCast/control/AlarmClock.java new file mode 100644 index 0000000..c3d1e79 --- /dev/null +++ b/pitiupi.screenCast/src/pitiupi/screenCast/control/AlarmClock.java @@ -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(); + } +} diff --git a/pitiupi.screenCast/src/pitiupi/screenCast/control/ImageTransformation.java b/pitiupi.screenCast/src/pitiupi/screenCast/control/ImageTransformation.java new file mode 100644 index 0000000..1dcda37 --- /dev/null +++ b/pitiupi.screenCast/src/pitiupi/screenCast/control/ImageTransformation.java @@ -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 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; + } +} diff --git a/pitiupi.screenCast/src/pitiupi/screenCast/control/ScreenShot.java b/pitiupi.screenCast/src/pitiupi/screenCast/control/ScreenShot.java new file mode 100644 index 0000000..6d256ed --- /dev/null +++ b/pitiupi.screenCast/src/pitiupi/screenCast/control/ScreenShot.java @@ -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; + } +} diff --git a/pitiupi.screenCast/src/pitiupi/screenCast/net/ScreenCastMessage.java b/pitiupi.screenCast/src/pitiupi/screenCast/net/ScreenCastMessage.java new file mode 100644 index 0000000..99b4ae1 --- /dev/null +++ b/pitiupi.screenCast/src/pitiupi/screenCast/net/ScreenCastMessage.java @@ -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; + } + +} diff --git a/pitiupi.screenCast/src/pitiupi/screenCast/plugin/ScreenCastPlugin.java b/pitiupi.screenCast/src/pitiupi/screenCast/plugin/ScreenCastPlugin.java new file mode 100644 index 0000000..b8d593a --- /dev/null +++ b/pitiupi.screenCast/src/pitiupi/screenCast/plugin/ScreenCastPlugin.java @@ -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(); + } + +} diff --git a/pitiupi/build.xml b/pitiupi/build.xml new file mode 100644 index 0000000..8d808a2 --- /dev/null +++ b/pitiupi/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project pitiupi. + + + diff --git a/pitiupi/build/classes/.netbeans_automatic_build b/pitiupi/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/pitiupi/build/classes/.netbeans_update_resources b/pitiupi/build/classes/.netbeans_update_resources new file mode 100644 index 0000000..e69de29 diff --git a/pitiupi/build/classes/pitiupi/GUI/Login.class b/pitiupi/build/classes/pitiupi/GUI/Login.class new file mode 100644 index 0000000..b5380ba Binary files /dev/null and b/pitiupi/build/classes/pitiupi/GUI/Login.class differ diff --git a/pitiupi/build/classes/pitiupi/GUI/MainWindow.class b/pitiupi/build/classes/pitiupi/GUI/MainWindow.class new file mode 100644 index 0000000..e7780db Binary files /dev/null and b/pitiupi/build/classes/pitiupi/GUI/MainWindow.class differ diff --git a/pitiupi/build/classes/pitiupi/GUI/MenuBar.class b/pitiupi/build/classes/pitiupi/GUI/MenuBar.class new file mode 100644 index 0000000..71aaa0d Binary files /dev/null and b/pitiupi/build/classes/pitiupi/GUI/MenuBar.class differ diff --git a/pitiupi/build/classes/pitiupi/Main$1.class b/pitiupi/build/classes/pitiupi/Main$1.class new file mode 100644 index 0000000..ab626d0 Binary files /dev/null and b/pitiupi/build/classes/pitiupi/Main$1.class differ diff --git a/pitiupi/build/classes/pitiupi/Main.class b/pitiupi/build/classes/pitiupi/Main.class new file mode 100644 index 0000000..c1bcbbd Binary files /dev/null and b/pitiupi/build/classes/pitiupi/Main.class differ diff --git a/pitiupi/build/classes/pitiupi/control/PluginLoader.class b/pitiupi/build/classes/pitiupi/control/PluginLoader.class new file mode 100644 index 0000000..97ef0bc Binary files /dev/null and b/pitiupi/build/classes/pitiupi/control/PluginLoader.class differ diff --git a/pitiupi/build/classes/pitiupi/net/Message.class b/pitiupi/build/classes/pitiupi/net/Message.class new file mode 100644 index 0000000..4033d96 Binary files /dev/null and b/pitiupi/build/classes/pitiupi/net/Message.class differ diff --git a/pitiupi/build/classes/pitiupi/net/Socket.class b/pitiupi/build/classes/pitiupi/net/Socket.class new file mode 100644 index 0000000..d182b43 Binary files /dev/null and b/pitiupi/build/classes/pitiupi/net/Socket.class differ diff --git a/pitiupi/build/classes/pitiupi/plugin/Plugin.class b/pitiupi/build/classes/pitiupi/plugin/Plugin.class new file mode 100644 index 0000000..13963a8 Binary files /dev/null and b/pitiupi/build/classes/pitiupi/plugin/Plugin.class differ diff --git a/pitiupi/dist/README.TXT b/pitiupi/dist/README.TXT new file mode 100644 index 0000000..c336b53 --- /dev/null +++ b/pitiupi/dist/README.TXT @@ -0,0 +1,32 @@ +======================== +BUILD OUTPUT DESCRIPTION +======================== + +When you build an Java application project that has a main class, the IDE +automatically copies all of the JAR +files on the projects classpath to your projects dist/lib folder. The IDE +also adds each of the JAR files to the Class-Path element in the application +JAR files manifest file (MANIFEST.MF). + +To run the project from the command line, go to the dist folder and +type the following: + +java -jar "pitiupi.jar" + +To distribute this project, zip up the dist folder (including the lib folder) +and distribute the ZIP file. + +Notes: + +* If two JAR files on the project classpath have the same name, only the first +JAR file is copied to the lib folder. +* Only JAR files are copied to the lib folder. +If the classpath contains other types of files or folders, these files (folders) +are not copied. +* If a library on the projects classpath also has a Class-Path element +specified in the manifest,the content of the Class-Path element has to be on +the projects runtime path. +* To set a main class in a standard Java project, right-click the project node +in the Projects window and choose Properties. Then click Run and enter the +class name in the Main Class field. Alternatively, you can manually type the +class name in the manifest Main-Class element. diff --git a/pitiupi/dist/pitiupi.jar b/pitiupi/dist/pitiupi.jar new file mode 100644 index 0000000..85ec1b8 Binary files /dev/null and b/pitiupi/dist/pitiupi.jar differ diff --git a/pitiupi/manifest.mf b/pitiupi/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/pitiupi/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/pitiupi/nbproject/build-impl.xml b/pitiupi/nbproject/build-impl.xml new file mode 100644 index 0000000..adb5cae --- /dev/null +++ b/pitiupi/nbproject/build-impl.xml @@ -0,0 +1,1771 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pitiupi/nbproject/genfiles.properties b/pitiupi/nbproject/genfiles.properties new file mode 100644 index 0000000..f517d26 --- /dev/null +++ b/pitiupi/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=f8465dc7 +build.xml.script.CRC32=9e28b0e5 +build.xml.stylesheet.CRC32=f85dc8f2@1.119.0.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=f8465dc7 +nbproject/build-impl.xml.script.CRC32=bd3b876a +nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.119.0.48 diff --git a/pitiupi/nbproject/private/config.properties b/pitiupi/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/pitiupi/nbproject/private/private.properties b/pitiupi/nbproject/private/private.properties new file mode 100644 index 0000000..2a5dca8 --- /dev/null +++ b/pitiupi/nbproject/private/private.properties @@ -0,0 +1,8 @@ +compile.on.save=true +do.depend=false +do.jar=true +do.jlink=false +javac.debug=true +javadoc.preview=true +jlink.strip=false +user.properties.file=/home/flavio/snap/netbeans/145/build.properties diff --git a/pitiupi/nbproject/private/private.xml b/pitiupi/nbproject/private/private.xml new file mode 100644 index 0000000..b64f1b3 --- /dev/null +++ b/pitiupi/nbproject/private/private.xml @@ -0,0 +1,10 @@ + + + + + + file:/home/flavio/NetBeansProjects/pitiupi/src/pitiupi/control/PluginManager.java + file:/home/flavio/NetBeansProjects/pitiupi/src/pitiupi/control/ImageTransformation.java + + + diff --git a/pitiupi/nbproject/project.properties b/pitiupi/nbproject/project.properties new file mode 100644 index 0000000..19c843c --- /dev/null +++ b/pitiupi/nbproject/project.properties @@ -0,0 +1,97 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=pitiupi +application.vendor=flavio +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.modulepath=\ + ${run.modulepath} +debug.test.classpath=\ + ${run.test.classpath} +debug.test.modulepath=\ + ${run.test.modulepath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/pitiupi.jar +dist.javadoc.dir=${dist.dir}/javadoc +dist.jlink.dir=${dist.dir}/jlink +dist.jlink.output=${dist.jlink.dir}/pitiupi +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.external.vm=true +javac.modulepath= +javac.processormodulepath= +javac.processorpath=\ + ${javac.classpath} +javac.source=25 +javac.target=25 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.modulepath=\ + ${javac.modulepath} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.html5=false +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +# The jlink additional root modules to resolve +jlink.additionalmodules= +# The jlink additional command line parameters +jlink.additionalparam= +jlink.launcher=true +jlink.launcher.name=pitiupi +main.class=pitiupi.Main +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.modulepath=\ + ${javac.modulepath} +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +run.test.modulepath=\ + ${javac.test.modulepath} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/pitiupi/nbproject/project.xml b/pitiupi/nbproject/project.xml new file mode 100644 index 0000000..f89d919 --- /dev/null +++ b/pitiupi/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + pitiupi + + + + + + + + + diff --git a/pitiupi/plugins/pitiupi.chat.jar b/pitiupi/plugins/pitiupi.chat.jar new file mode 120000 index 0000000..b2c6a32 --- /dev/null +++ b/pitiupi/plugins/pitiupi.chat.jar @@ -0,0 +1 @@ +../../pitiupi.chat/dist/pitiupi.chat.jar \ No newline at end of file diff --git a/pitiupi/plugins/pitiupi.screenCast.jar b/pitiupi/plugins/pitiupi.screenCast.jar new file mode 120000 index 0000000..e6a0dc7 --- /dev/null +++ b/pitiupi/plugins/pitiupi.screenCast.jar @@ -0,0 +1 @@ +../../pitiupi.screenCast/dist/pitiupi.screenCast.jar \ No newline at end of file diff --git a/pitiupi/src/pitiupi/GUI/Login.java b/pitiupi/src/pitiupi/GUI/Login.java new file mode 100644 index 0000000..4c9c61c --- /dev/null +++ b/pitiupi/src/pitiupi/GUI/Login.java @@ -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 pitiupi.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()); + } +} diff --git a/pitiupi/src/pitiupi/GUI/MainWindow.java b/pitiupi/src/pitiupi/GUI/MainWindow.java new file mode 100644 index 0000000..bcd03fe --- /dev/null +++ b/pitiupi/src/pitiupi/GUI/MainWindow.java @@ -0,0 +1,98 @@ +/* + * 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.GUI; + +import pitiupi.net.Socket; +import java.util.ArrayList; +import java.util.List; +import javax.swing.JMenu; +import pitiupi.control.PluginLoader; +import pitiupi.plugin.Plugin; + +/** + * + * @author flavio + */ +public class MainWindow extends javax.swing.JFrame { + + private final MenuBar menuBar; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JLabel status; + private javax.swing.JPanel statusPanel; + private javax.swing.JTabbedPane tabbedPane; + + private Socket socket; + + private final String userName; + private final int port; + + private PluginLoader pluginManager; + private final List plugins; + + + public MainWindow(String userName, int port) { + this.userName = userName; + this.port = port; + this.menuBar = new MenuBar(this); + this.plugins = new ArrayList<>(); + this.initComponents(); + } + + private void initComponents() { + this.setJMenuBar(menuBar); + 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.userName); + 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.socket.start(); + + this.setSize(new java.awt.Dimension(1024, 768)); + this.pluginManager = new PluginLoader(this); + this.pluginManager.loadPlugins(); + } + + + public void exit() { + this.setVisible(false); + this.dispose(); + System.exit(0); + } + + public String getUserName(){ + return this.userName; + } + + public void addMenu(JMenu menu) { + this.menuBar.addPlugin(menu); + } + + public int getPort() { + return this.port; + } + + public Socket getSocket() { + return this.socket; + } + + public List getPlugins() { + return plugins; + } +} diff --git a/pitiupi/src/pitiupi/GUI/MenuBar.java b/pitiupi/src/pitiupi/GUI/MenuBar.java new file mode 100644 index 0000000..2a7e1b1 --- /dev/null +++ b/pitiupi/src/pitiupi/GUI/MenuBar.java @@ -0,0 +1,68 @@ +/* + * 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.GUI; + +import javax.swing.JMenu; +import javax.swing.JMenuBar; + +/** + * + * @author flavio + */ +public class MenuBar extends JMenuBar { + + private javax.swing.JMenuItem setupMenu; + private javax.swing.JMenu fileMenu; + private javax.swing.JMenu helpMenu; + private javax.swing.JMenu pluginMenu; + private javax.swing.JMenuItem exitMenu; + private final MainWindow mainWindow; + + public MenuBar(MainWindow mainWindow) { + this.mainWindow = mainWindow; + this.initComponents(); + } + + private void initComponents() { + fileMenu = new javax.swing.JMenu(); + exitMenu = new javax.swing.JMenuItem(); + helpMenu = new javax.swing.JMenu(); + pluginMenu = new javax.swing.JMenu(); + setupMenu = new javax.swing.JMenuItem(); + + fileMenu.setText("File"); + 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(exitMenu); + this.add(fileMenu); + + pluginMenu.setText("Plugin"); + this.add(pluginMenu); + + helpMenu.setText("Help"); + setupMenu.setText("Preferences"); + setupMenu.addActionListener(this::setupMenuActionPerformed); + helpMenu.add(setupMenu); + this.add(helpMenu); + } + + + + private void exitMenuActionPerformed(java.awt.event.ActionEvent evt) { + mainWindow.exit(); + } + + private void setupMenuActionPerformed(java.awt.event.ActionEvent evt) { + Login login = new Login(); + login.setVisible(true); + login.dispose(); + } + + public void addPlugin(JMenu menu){ + this.pluginMenu.add(menu); + } +} diff --git a/pitiupi/src/pitiupi/Main.java b/pitiupi/src/pitiupi/Main.java new file mode 100644 index 0000000..297b61a --- /dev/null +++ b/pitiupi/src/pitiupi/Main.java @@ -0,0 +1,56 @@ +/* + * 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; + +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 */ + // + /* 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(pitiupi.GUI.MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (InstantiationException ex) { + java.util.logging.Logger.getLogger(pitiupi.GUI.MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (IllegalAccessException ex) { + java.util.logging.Logger.getLogger(pitiupi.GUI.MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } catch (javax.swing.UnsupportedLookAndFeelException ex) { + java.util.logging.Logger.getLogger(pitiupi.GUI.MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); + } + // + + /* Create and display the form */ + java.awt.EventQueue.invokeLater(new Runnable() { + @Override + public void run() { + pitiupi.GUI.MainWindow main; + main = new pitiupi.GUI.MainWindow(System.getProperty("user.name"), 8000); + main.setVisible(true); + } + }); + } + +} diff --git a/pitiupi/src/pitiupi/control/PluginLoader.java b/pitiupi/src/pitiupi/control/PluginLoader.java new file mode 100644 index 0000000..386724a --- /dev/null +++ b/pitiupi/src/pitiupi/control/PluginLoader.java @@ -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.control; + +import java.awt.List; +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.ServiceLoader; +import java.util.Vector; +import pitiupi.GUI.MainWindow; +import pitiupi.Main; +import pitiupi.plugin.Plugin; + +/** + * + * @author flavio + */ +public class PluginLoader { + + private final pitiupi.GUI.MainWindow mainWindow; + + public PluginLoader(MainWindow main) { + this.mainWindow = main; + } + + public void loadPlugins() { + File pluginDir = new File("plugins"); + File[] jarFiles = pluginDir.listFiles((dir, name) -> name.endsWith(".jar")); + + if (jarFiles == null || jarFiles.length == 0) { + System.out.println("No plugins found in the " + pluginDir.getAbsolutePath() + " directory."); + return; + } + + try { + // 2. Convert jar file paths into URLs + ArrayList urls = new ArrayList(); + for (File file : jarFiles) { + urls.add(file.toURI().toURL()); + System.out.println("Discovered plugin package: " + file.getName()); + } + + // 3. Create a class loader isolated from the application's default loader + URLClassLoader pluginClassLoader = new URLClassLoader( + (URL[])urls.toArray(new URL[0]), + Main.class.getClassLoader() + ); + System.out.println(pluginClassLoader); + + // 4. Locate and instantiate all classes implementing the Plugin interface + ServiceLoader serviceLoader = ServiceLoader.load(Plugin.class, pluginClassLoader); + + System.out.println("\n--- Executing Discovered Plugins ---" + serviceLoader.findFirst()); + for (Plugin plugin : serviceLoader) { + System.out.println("Loading: " + plugin.getName()); + plugin.createPlugin(this.mainWindow); + this.mainWindow.getPlugins().add(plugin); + } + + } catch (MalformedURLException e) { + System.out.println(e.toString()); + } + } +} diff --git a/pitiupi/src/pitiupi/net/Message.java b/pitiupi/src/pitiupi/net/Message.java new file mode 100644 index 0000000..3b5966b --- /dev/null +++ b/pitiupi/src/pitiupi/net/Message.java @@ -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.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(); + } +} diff --git a/pitiupi/src/pitiupi/net/Socket.java b/pitiupi/src/pitiupi/net/Socket.java new file mode 100644 index 0000000..8710697 --- /dev/null +++ b/pitiupi/src/pitiupi/net/Socket.java @@ -0,0 +1,78 @@ +/* + * 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.net; + +import pitiupi.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; +import pitiupi.plugin.Plugin; + +/** + * + * @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) { + this.main = main; + try { + this.address = InetAddress.getByName(Socket.INET_ADDR); + } catch (UnknownHostException ex) { + System.getLogger(Socket.class.getName()).log(System.Logger.Level.ERROR, (String) null, ex); + } + 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); + for (Plugin plugin : main.getPlugins()) { + System.out.println(msgPacket.getAddress().toString()); + plugin.receiveMessage(msgPacket.getData()); + } + } + } + + @Override + public void run() { + try { + this.receive(); + } catch (IOException | ClassNotFoundException ex) { + Logger.getLogger(Socket.class.getName()).log(Level.SEVERE, null, ex); + } + } +} diff --git a/pitiupi/src/pitiupi/plugin/Plugin.java b/pitiupi/src/pitiupi/plugin/Plugin.java new file mode 100644 index 0000000..7a6b711 --- /dev/null +++ b/pitiupi/src/pitiupi/plugin/Plugin.java @@ -0,0 +1,23 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template + */ +package pitiupi.plugin; + +import javax.swing.JMenu; +import pitiupi.GUI.MainWindow; +import pitiupi.net.Message; + +/** + * + * @author flavio + */ +public interface Plugin { + + public String getName(); + public String getAuthor(); + public String getVersion(); + public void createPlugin(MainWindow window); + public Message getMessage(); + public void receiveMessage(byte[] message); +} \ No newline at end of file