WIP bugfix
This commit is contained in:
1 parent
cac549f1ee
commit
96b8faca5b
11 files changed
+31
-26
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -2,6 +2,7 @@ package GUI;
|
||||
|
||||
import net.TestChatMessage;
|
||||
import pitiupi.GUI.MainWindow;
|
||||
import pitiupi.control.ConnectionManager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -10,13 +11,13 @@ import java.net.UnknownHostException;
|
||||
|
||||
public abstract class ChatWindow extends JFrame {
|
||||
|
||||
protected final MainWindow mainWindow;
|
||||
protected final ConnectionManager connectionManager;
|
||||
|
||||
private JTextArea receivedMessagesArea;
|
||||
protected JTextField messageField;
|
||||
|
||||
public ChatWindow(MainWindow mainWindow) {
|
||||
this.mainWindow = mainWindow;
|
||||
public ChatWindow(ConnectionManager connectionManager) {
|
||||
this.connectionManager = connectionManager;
|
||||
initComponents();
|
||||
}
|
||||
|
||||
@@ -65,7 +66,7 @@ public abstract class ChatWindow extends JFrame {
|
||||
|
||||
protected TestChatMessage createMessage(String tipoMensagem) {
|
||||
try {
|
||||
String nome = mainWindow.getUserName();
|
||||
String nome = connectionManager.getUserName();
|
||||
String ip = InetAddress.getLocalHost().getHostAddress();
|
||||
String message = messageField.getText();
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package GUI;
|
||||
|
||||
import net.TestChatMessage;
|
||||
import pitiupi.GUI.MainWindow;
|
||||
import pitiupi.control.ConnectionManager;
|
||||
import pitiupi.net.tcp.TcpConnection;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -13,10 +14,10 @@ public class PrivateChatWindow extends ChatWindow {
|
||||
|
||||
private final TcpConnection connection;
|
||||
|
||||
public PrivateChatWindow(MainWindow mainWindow, TcpConnection connection) {
|
||||
public PrivateChatWindow(ConnectionManager ConnectionManager, TcpConnection connection) {
|
||||
this.connection = connection;
|
||||
|
||||
super(mainWindow);
|
||||
super(ConnectionManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,9 +39,7 @@ public class PrivateChatWindow extends ChatWindow {
|
||||
connection.send(msg.toByteArray());
|
||||
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(
|
||||
PrivateChatWindow.class.getName()
|
||||
).log(Level.SEVERE, null, ex);
|
||||
Logger.getLogger(PrivateChatWindow.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package GUI;
|
||||
|
||||
import net.TestChatMessage;
|
||||
import pitiupi.GUI.MainWindow;
|
||||
import pitiupi.control.ConnectionManager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -13,8 +14,8 @@ public class PublicChatWindow extends ChatWindow {
|
||||
|
||||
private JTextField ipField;
|
||||
|
||||
public PublicChatWindow(MainWindow mainWindow) {
|
||||
super(mainWindow);
|
||||
public PublicChatWindow(ConnectionManager connectionManager) {
|
||||
super(connectionManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,7 +61,7 @@ public class PublicChatWindow extends ChatWindow {
|
||||
|
||||
InetAddress ip = InetAddress.getByName(ipField.getText());
|
||||
|
||||
mainWindow.getSocketTCP().send(msg, ip);
|
||||
connectionManager.sendTcp(msg, ip);
|
||||
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(PublicChatWindow.class.getName()).log(Level.SEVERE, null, ex);
|
||||
@@ -73,7 +74,7 @@ public class PublicChatWindow extends ChatWindow {
|
||||
|
||||
InetAddress ip = InetAddress.getByName(ipField.getText());
|
||||
|
||||
mainWindow.getSocketUDP().sendUnicast(msg, ip);
|
||||
connectionManager.sendUdpUnicast(msg, ip);
|
||||
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(PublicChatWindow.class.getName()).log(Level.SEVERE, null, ex);
|
||||
@@ -84,7 +85,7 @@ public class PublicChatWindow extends ChatWindow {
|
||||
try {
|
||||
TestChatMessage msg = createMessage("UDP Multicast");
|
||||
|
||||
mainWindow.getSocketUDP().sendMulticast(msg);
|
||||
connectionManager.sendUdpMulticast(msg);
|
||||
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(PublicChatWindow.class.getName()).log(Level.SEVERE, null, ex);
|
||||
|
||||
@@ -6,13 +6,14 @@ import GUI.PrivateChatWindow;
|
||||
import GUI.PublicChatWindow;
|
||||
import net.TestChatMessage;
|
||||
import pitiupi.GUI.MainWindow;
|
||||
import pitiupi.control.ConnectionManager;
|
||||
import pitiupi.net.tcp.TcpConnection;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ChatController {
|
||||
MainWindow mainWindow;
|
||||
ConnectionManager connectionManager;
|
||||
ChatMenu chatMenu;
|
||||
|
||||
PublicChatWindow publicChatWindow;
|
||||
@@ -20,9 +21,9 @@ public class ChatController {
|
||||
private final HashMap<TcpConnection, JMenuItem> chatMenus;
|
||||
private final HashMap<TcpConnection, ChatWindow> chatWindows;
|
||||
|
||||
public ChatController(MainWindow mainWindow, ChatMenu chatMenu) {
|
||||
this.mainWindow = mainWindow;
|
||||
publicChatWindow = new PublicChatWindow(mainWindow);
|
||||
public ChatController(ConnectionManager connectionManager, ChatMenu chatMenu) {
|
||||
this.connectionManager = connectionManager;
|
||||
publicChatWindow = new PublicChatWindow(connectionManager);
|
||||
|
||||
chatMenus = new HashMap<>();
|
||||
chatWindows = new HashMap<>();
|
||||
@@ -35,7 +36,7 @@ public class ChatController {
|
||||
public void addChatWindow(TcpConnection tcpConnection) {
|
||||
if (chatWindows.containsKey(tcpConnection)) return;
|
||||
|
||||
PrivateChatWindow newChat = new PrivateChatWindow(mainWindow, tcpConnection);
|
||||
PrivateChatWindow newChat = new PrivateChatWindow(connectionManager, tcpConnection);
|
||||
chatWindows.put(tcpConnection, newChat);
|
||||
JMenuItem newMenuItem = new JMenuItem();
|
||||
chatMenus.put(tcpConnection, newMenuItem);
|
||||
|
||||
@@ -3,7 +3,8 @@ package plugin;
|
||||
import GUI.ChatMenu;
|
||||
import control.ChatController;
|
||||
import net.TestChatMessage;
|
||||
import pitiupi.GUI.MainWindow;
|
||||
import pitiupi.control.ConnectionManager;
|
||||
import pitiupi.control.GuiManager;
|
||||
import pitiupi.net.Message;
|
||||
import pitiupi.net.tcp.TcpConnection;
|
||||
import pitiupi.plugin.PrivateConnectionPlugin;
|
||||
@@ -16,7 +17,8 @@ import java.net.InetAddress;
|
||||
|
||||
public class TestChat implements PrivateConnectionPlugin{
|
||||
ChatController chatController;
|
||||
MainWindow mainWindow;
|
||||
ConnectionManager connectionManager;
|
||||
GuiManager guiManager;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
@@ -39,12 +41,13 @@ public class TestChat implements PrivateConnectionPlugin{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPlugin(MainWindow mainWindow) {
|
||||
this.mainWindow = mainWindow;
|
||||
public void createPlugin(ConnectionManager connectionManager, GuiManager guiManager) {
|
||||
this.connectionManager = connectionManager;
|
||||
this.guiManager = guiManager;
|
||||
|
||||
ChatMenu chatMenu = new ChatMenu(this);
|
||||
chatController = new ChatController(mainWindow, chatMenu);
|
||||
mainWindow.addMenu(chatMenu);
|
||||
chatController = new ChatController(connectionManager, chatMenu);
|
||||
guiManager.addMenu(chatMenu);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,7 +82,7 @@ public class TestChat implements PrivateConnectionPlugin{
|
||||
|
||||
public boolean openConnection(String ip) {
|
||||
try {
|
||||
mainWindow.getSocketTCP().createPrivateConnection(InetAddress.getByName(ip), getIdentifier(), getIdentifier());
|
||||
connectionManager.connectPluginTcp(InetAddress.getByName(ip), getIdentifier(), getIdentifier());
|
||||
return true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
Reference in new issue
Block a user