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