Compare commits
9
Commits
d0083e8069
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b45d515ba | ||
|
|
2e50dacee7 | ||
|
|
a628490fcb | ||
|
|
395363e4bd | ||
|
|
12497594e4 | ||
|
|
6a597092fe | ||
|
|
ffd474e7ff | ||
|
|
4d39648ee7 | ||
|
|
095af14463 |
No files matched your search
@@ -8,13 +8,13 @@ package pitiupi.chat.GUI;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import pitiupi.chat.net.ChatMessage;
|
import pitiupi.chat.net.ChatMessage;
|
||||||
import pitiupi.plugin.Pitiupi;
|
import pitiupi.control.ConnectionManager;
|
||||||
import pitiupi.models.Messages.Message;
|
import pitiupi.models.Messages.Message;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tony
|
*
|
||||||
* @author flavio
|
* @author flavio
|
||||||
*/
|
*/
|
||||||
public class ChatWindow extends JDialog {
|
public class ChatWindow extends JDialog {
|
||||||
@@ -28,12 +28,13 @@ public class ChatWindow extends JDialog {
|
|||||||
private JSplitPane jSplitPane1;
|
private JSplitPane jSplitPane1;
|
||||||
private JTextArea jTextArea1;
|
private JTextArea jTextArea1;
|
||||||
|
|
||||||
private final Pitiupi pitiupi;
|
private final ConnectionManager connectionManager;
|
||||||
|
|
||||||
|
public ChatWindow(ConnectionManager connectionManager) {
|
||||||
|
this.connectionManager = connectionManager;
|
||||||
|
initComponents();
|
||||||
|
}
|
||||||
|
|
||||||
public ChatWindow(Pitiupi pitiupi) {
|
|
||||||
this.pitiupi = pitiupi;
|
|
||||||
initComponents();
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* This method is called from within the constructor to initialize the form.
|
* 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
|
* WARNING: Do NOT modify this code. The content of this method is always
|
||||||
@@ -92,13 +93,13 @@ public class ChatWindow extends JDialog {
|
|||||||
if (jTextArea1.getText().trim().isEmpty()) {
|
if (jTextArea1.getText().trim().isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ChatMessage message = new ChatMessage(pitiupi.getUserName(), jTextArea1.getText());
|
ChatMessage message = new ChatMessage(connectionManager.getUserName(), jTextArea1.getText());
|
||||||
this.sendChatMessage(message);
|
this.sendChatMessage(message);
|
||||||
jTextArea1.setText("");
|
jTextArea1.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendChatMessage(Message message) {
|
public void sendChatMessage(Message message) {
|
||||||
pitiupi.sendUdpMulticast(message);
|
connectionManager.sendUdpMulticast(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void receiveChatMessage(ChatMessage message) {
|
public void receiveChatMessage(ChatMessage message) {
|
||||||
|
|||||||
@@ -8,29 +8,29 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import pitiupi.plugin.Pitiupi;
|
|
||||||
import pitiupi.chat.GUI.ChatMenu;
|
import pitiupi.chat.GUI.ChatMenu;
|
||||||
import pitiupi.chat.GUI.ChatWindow;
|
import pitiupi.chat.GUI.ChatWindow;
|
||||||
import pitiupi.chat.net.ChatMessage;
|
import pitiupi.chat.net.ChatMessage;
|
||||||
|
import pitiupi.control.ConnectionManager;
|
||||||
|
import pitiupi.control.GuiManager;
|
||||||
import pitiupi.models.Menus.MenuCategory;
|
import pitiupi.models.Menus.MenuCategory;
|
||||||
import pitiupi.models.Messages.Message;
|
import pitiupi.models.Messages.Message;
|
||||||
import pitiupi.models.Plugin;
|
import pitiupi.models.Plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*@author tony
|
*
|
||||||
* @author flavio
|
* @author flavio
|
||||||
*/
|
*/
|
||||||
public class ChatPlugin extends Plugin {
|
public class ChatPlugin extends Plugin {
|
||||||
|
|
||||||
private ChatWindow chatWindow;
|
private ChatWindow chatWindow;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createPlugin(Pitiupi pitiupi) {
|
public void createPlugin(ConnectionManager connectionManager, GuiManager guiManager) {
|
||||||
this.chatWindow = new ChatWindow(pitiupi);
|
this.chatWindow = new ChatWindow(connectionManager);
|
||||||
pitiupi.createMenu(MenuCategory.Social, new ChatMenu(chatWindow));
|
guiManager.createMenu(MenuCategory.Social, new ChatMenu(chatWindow));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Class<? extends Message>> getMessages() {
|
public List<Class<? extends Message>> getMessages() {
|
||||||
return List.of(ChatMessage.class);
|
return List.of(ChatMessage.class);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package pitiupi.control.plugins;
|
package pitiupi.control.plugins;
|
||||||
|
|
||||||
import pitiupi.plugin.Pitiupi;
|
|
||||||
import pitiupi.Main;
|
import pitiupi.Main;
|
||||||
import pitiupi.control.ConnectionManager;
|
import pitiupi.control.ConnectionManager;
|
||||||
import pitiupi.control.GuiManager;
|
import pitiupi.control.GuiManager;
|
||||||
@@ -93,7 +92,6 @@ public class PluginManager {
|
|||||||
public void loadPlugins(ConnectionManager connectionManager, GuiManager guiManager) {
|
public void loadPlugins(ConnectionManager connectionManager, GuiManager guiManager) {
|
||||||
File pluginDir = new File("plugins");
|
File pluginDir = new File("plugins");
|
||||||
File[] jarFiles = pluginDir.listFiles((dir, name) -> name.endsWith(".jar"));
|
File[] jarFiles = pluginDir.listFiles((dir, name) -> name.endsWith(".jar"));
|
||||||
Pitiupi pitiupi = new Pitiupi(connectionManager, guiManager);
|
|
||||||
|
|
||||||
if (jarFiles == null || jarFiles.length == 0) {
|
if (jarFiles == null || jarFiles.length == 0) {
|
||||||
System.out.println("No plugins found in the " + pluginDir.getAbsolutePath() + " directory.");
|
System.out.println("No plugins found in the " + pluginDir.getAbsolutePath() + " directory.");
|
||||||
@@ -120,7 +118,7 @@ public class PluginManager {
|
|||||||
System.out.println("Loading: " + plugin.getName());
|
System.out.println("Loading: " + plugin.getName());
|
||||||
LoadedPlugin loadedPlugin = new LoadedPlugin(plugin, classLoader);
|
LoadedPlugin loadedPlugin = new LoadedPlugin(plugin, classLoader);
|
||||||
|
|
||||||
plugin.createPlugin(pitiupi);
|
plugin.createPlugin(connectionManager, guiManager);
|
||||||
loadedPlugins.add(loadedPlugin);
|
loadedPlugins.add(loadedPlugin);
|
||||||
loadedJars.add(file.getName());
|
loadedJars.add(file.getName());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template
|
||||||
*/
|
*/
|
||||||
package pitiupi.models;
|
package pitiupi.models;
|
||||||
import pitiupi.plugin.Pitiupi;
|
|
||||||
|
import pitiupi.control.ConnectionManager;
|
||||||
|
import pitiupi.control.GuiManager;
|
||||||
import pitiupi.models.Messages.Message;
|
import pitiupi.models.Messages.Message;
|
||||||
import pitiupi.net.tcp.TcpConnection;
|
import pitiupi.net.tcp.TcpConnection;
|
||||||
|
|
||||||
@@ -31,7 +33,7 @@ public abstract class Plugin {
|
|||||||
* @param connectionManager interface com o sistema de conexões da aplicação.
|
* @param connectionManager interface com o sistema de conexões da aplicação.
|
||||||
* @param guiManager interface com a janela principal da aplicação
|
* @param guiManager interface com a janela principal da aplicação
|
||||||
*/
|
*/
|
||||||
public abstract void createPlugin(Pitiupi pitiupi);
|
public abstract void createPlugin(ConnectionManager connectionManager, GuiManager guiManager);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retorna uma mensagem utilizada pelo plugin.
|
* Retorna uma mensagem utilizada pelo plugin.
|
||||||
@@ -60,4 +62,4 @@ public abstract class Plugin {
|
|||||||
public boolean onSocketClosed(TcpConnection connection) {
|
public boolean onSocketClosed(TcpConnection connection) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
package pitiupi.plugin;
|
|
||||||
|
|
||||||
import pitiupi.control.ConnectionManager;
|
|
||||||
import pitiupi.control.GuiManager;
|
|
||||||
import pitiupi.models.Menus.Menu;
|
|
||||||
import pitiupi.models.Menus.MenuCategory;
|
|
||||||
import pitiupi.models.Messages.Message;
|
|
||||||
import pitiupi.net.tcp.TcpConnection;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
|
|
||||||
public class Pitiupi {
|
|
||||||
|
|
||||||
private final ConnectionManager connectionManager;
|
|
||||||
private final GuiManager guiManager;
|
|
||||||
|
|
||||||
public Pitiupi(ConnectionManager connectionManager, GuiManager guiManager) {
|
|
||||||
this.connectionManager = connectionManager;
|
|
||||||
this.guiManager = guiManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean sendUdpMulticast(Message message) {
|
|
||||||
return connectionManager.sendUdpMulticast(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean sendUdpUnicast(Message message, InetAddress address) {
|
|
||||||
return connectionManager.sendUdpUnicast(message, address);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean sendTcp(Message message, InetAddress address) {
|
|
||||||
return connectionManager.sendTcp(message, address);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TcpConnection connectTcp(InetAddress address, String senderId, String receiverId) {
|
|
||||||
return connectionManager.connectPluginTcp(address, senderId, receiverId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUserName() {
|
|
||||||
return connectionManager.getUserName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPort() {
|
|
||||||
return connectionManager.getPort();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createMenu(MenuCategory category, Menu menu) {
|
|
||||||
guiManager.createMenu(category, menu);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user