Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0083e8069 | ||
|
|
dda324228f | ||
|
|
840183ee9f | ||
|
|
eb3ce132cd | ||
|
|
d1dc427185 |
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.control.ConnectionManager;
|
import pitiupi.plugin.Pitiupi;
|
||||||
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,13 +28,12 @@ public class ChatWindow extends JDialog {
|
|||||||
private JSplitPane jSplitPane1;
|
private JSplitPane jSplitPane1;
|
||||||
private JTextArea jTextArea1;
|
private JTextArea jTextArea1;
|
||||||
|
|
||||||
private final ConnectionManager connectionManager;
|
private final Pitiupi pitiupi;
|
||||||
|
|
||||||
public ChatWindow(ConnectionManager connectionManager) {
|
public ChatWindow(Pitiupi pitiupi) {
|
||||||
this.connectionManager = connectionManager;
|
this.pitiupi = pitiupi;
|
||||||
initComponents();
|
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
|
||||||
@@ -93,13 +92,13 @@ public class ChatWindow extends JDialog {
|
|||||||
if (jTextArea1.getText().trim().isEmpty()) {
|
if (jTextArea1.getText().trim().isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ChatMessage message = new ChatMessage(connectionManager.getUserName(), jTextArea1.getText());
|
ChatMessage message = new ChatMessage(pitiupi.getUserName(), jTextArea1.getText());
|
||||||
this.sendChatMessage(message);
|
this.sendChatMessage(message);
|
||||||
jTextArea1.setText("");
|
jTextArea1.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendChatMessage(Message message) {
|
public void sendChatMessage(Message message) {
|
||||||
connectionManager.sendUdpMulticast(message);
|
pitiupi.sendUdpMulticast(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void receiveChatMessage(ChatMessage message) {
|
public void receiveChatMessage(ChatMessage message) {
|
||||||
|
|||||||
@@ -8,17 +8,16 @@ 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 {
|
||||||
@@ -26,11 +25,12 @@ public class ChatPlugin extends Plugin {
|
|||||||
private ChatWindow chatWindow;
|
private ChatWindow chatWindow;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createPlugin(ConnectionManager connectionManager, GuiManager guiManager) {
|
public void createPlugin(Pitiupi pitiupi) {
|
||||||
this.chatWindow = new ChatWindow(connectionManager);
|
this.chatWindow = new ChatWindow(pitiupi);
|
||||||
guiManager.createMenu(MenuCategory.Social, new ChatMenu(chatWindow));
|
pitiupi.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,5 +1,6 @@
|
|||||||
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;
|
||||||
@@ -92,6 +93,7 @@ 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.");
|
||||||
@@ -118,7 +120,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(connectionManager, guiManager);
|
plugin.createPlugin(pitiupi);
|
||||||
loadedPlugins.add(loadedPlugin);
|
loadedPlugins.add(loadedPlugin);
|
||||||
loadedJars.add(file.getName());
|
loadedJars.add(file.getName());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,7 @@
|
|||||||
* 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;
|
||||||
|
|
||||||
@@ -33,7 +31,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(ConnectionManager connectionManager, GuiManager guiManager);
|
public abstract void createPlugin(Pitiupi pitiupi);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retorna uma mensagem utilizada pelo plugin.
|
* Retorna uma mensagem utilizada pelo plugin.
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
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