WIP: atualizar o mpChat para os novos menus
This commit is contained in:
1 parent
d551324e8b
commit
88b75ad75f
19 files changed
+8
-176
No files matched your search
@@ -1,40 +0,0 @@
|
||||
package GUI;
|
||||
|
||||
import pitiupi.models.Menus.MenuCategory;
|
||||
import pitiupi.models.Menus.MulticastMenus.MulticastSubMenu;
|
||||
import plugin.MultiProtocolChat;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class ChatMenu extends MulticastSubMenu {
|
||||
private final MultiProtocolChat multiProtocolChat;
|
||||
|
||||
public ChatMenu(MultiProtocolChat multiProtocolChat) {
|
||||
this.multiProtocolChat = multiProtocolChat;
|
||||
this.setText("MP-Chat");
|
||||
|
||||
JMenuItem startPrivateChat = new JMenuItem("start Private Chat");
|
||||
startPrivateChat.addActionListener(e -> showPrivateChatDialog());
|
||||
this.add(startPrivateChat);
|
||||
}
|
||||
|
||||
public void newMenuItem(JMenuItem newMenuItem, ChatWindow chatWindow) {
|
||||
newMenuItem.addActionListener(e -> chatWindow.setVisible(true));
|
||||
|
||||
this.add(newMenuItem);
|
||||
}
|
||||
|
||||
public void removeMenuItem(JMenuItem removeMenuItem) {
|
||||
this.remove(removeMenuItem);
|
||||
}
|
||||
|
||||
private void showPrivateChatDialog() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return "MP-Chat";
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
package GUI;
|
||||
|
||||
import net.MpChatMessage;
|
||||
import pitiupi.control.ConnectionManager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
public abstract class ChatWindow extends JFrame {
|
||||
|
||||
protected final ConnectionManager connectionManager;
|
||||
|
||||
private JTextArea receivedMessagesArea;
|
||||
protected JTextField messageField;
|
||||
|
||||
public ChatWindow(ConnectionManager connectionManager) {
|
||||
this.connectionManager = connectionManager;
|
||||
initComponents();
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
setTitle("Socket Test");
|
||||
setSize(700, 500);
|
||||
setLocationRelativeTo(null);
|
||||
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
|
||||
|
||||
JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
|
||||
|
||||
mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
|
||||
initReceivedMessagesPanel(mainPanel);
|
||||
initBottomPanel(mainPanel);
|
||||
|
||||
setContentPane(mainPanel);
|
||||
}
|
||||
|
||||
private void initReceivedMessagesPanel(JPanel mainPanel) {
|
||||
receivedMessagesArea = new JTextArea();
|
||||
receivedMessagesArea.setEditable(false);
|
||||
receivedMessagesArea.setLineWrap(true);
|
||||
receivedMessagesArea.setWrapStyleWord(true);
|
||||
|
||||
JScrollPane messagesScrollPane = new JScrollPane(receivedMessagesArea);
|
||||
|
||||
messagesScrollPane.setBorder(BorderFactory.createTitledBorder("Mensagens recebidas"));
|
||||
|
||||
mainPanel.add(messagesScrollPane, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
private void initBottomPanel(JPanel mainPanel) {
|
||||
messageField = new JTextField();
|
||||
|
||||
JPanel bottomPanel = new JPanel(new BorderLayout(10, 10));
|
||||
|
||||
bottomPanel.add(messageField, BorderLayout.CENTER);
|
||||
|
||||
initButtons(bottomPanel);
|
||||
|
||||
mainPanel.add(bottomPanel, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
protected abstract void initButtons(JPanel bottomPanel);
|
||||
|
||||
protected MpChatMessage createMessage(String tipoMensagem) {
|
||||
try {
|
||||
String nome = connectionManager.getUserName();
|
||||
String ip = InetAddress.getLocalHost().getHostAddress();
|
||||
String message = messageField.getText();
|
||||
|
||||
return new MpChatMessage(nome, ip, tipoMensagem, message);
|
||||
|
||||
} catch (UnknownHostException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void receiveMessage(MpChatMessage msg) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
String mensagem = String.format(
|
||||
"[%s] %s (%s): %s%n",
|
||||
msg.getTipoMensagem(),
|
||||
msg.getNome(),
|
||||
msg.getIp(),
|
||||
msg.getMessage()
|
||||
);
|
||||
|
||||
receivedMessagesArea.append(mensagem);
|
||||
|
||||
receivedMessagesArea.setCaretPosition(receivedMessagesArea.getDocument().getLength());
|
||||
});
|
||||
}
|
||||
}
|
||||
+4
-3
@@ -2,10 +2,10 @@ package GUI;
|
||||
|
||||
import pitiupi.models.Menus.MulticastMenus.MulticastActionMenu;
|
||||
|
||||
public class PublicChatMenu extends MulticastActionMenu {
|
||||
public class MulticastMpChatMenu extends MulticastActionMenu {
|
||||
PublicChatWindow publicChatWindow;
|
||||
|
||||
PublicChatMenu(PublicChatWindow publicChatWindow) {
|
||||
public MulticastMpChatMenu(PublicChatWindow publicChatWindow) {
|
||||
this.publicChatWindow = publicChatWindow;
|
||||
}
|
||||
|
||||
@@ -14,8 +14,9 @@ public class PublicChatMenu extends MulticastActionMenu {
|
||||
publicChatWindow.setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return "";
|
||||
return "MP-Chat";
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package GUI;
|
||||
|
||||
import control.ChatController;
|
||||
import pitiupi.models.Menus.UnicastMenus.UnicastActionMenu;
|
||||
import pitiupi.models.User;
|
||||
import plugin.MultiProtocolChat;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.net.InetAddress;
|
||||
|
||||
public class PrivateChatMenu extends UnicastActionMenu {
|
||||
PrivateChatWindow privateChatWindow;
|
||||
private final MultiProtocolChat multiProtocolChat;
|
||||
private final ChatController chatController;
|
||||
|
||||
public PrivateChatMenu(PrivateChatWindow PrivateChatWindow, MultiProtocolChat multiProtocolChat, ChatController chatController) {
|
||||
this.privateChatWindow = PrivateChatWindow;
|
||||
this.multiProtocolChat = multiProtocolChat;
|
||||
this.chatController = chatController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(User user) {
|
||||
if (multiProtocolChat.openConnection(user.getAddress())
|
||||
else errorLabel.setVisible(true);
|
||||
|
||||
dialog.setContentPane(contentPanel);
|
||||
dialog.pack();
|
||||
dialog.setLocationRelativeTo(SwingUtilities.getWindowAncestor(privateChatWindow));
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return "start Private Chat";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package GUI;
|
||||
|
||||
public class UnicastMpChatMenu {
|
||||
}
|
||||
Reference in new issue
Block a user