Package client

Class ChatView

java.lang.Object
client.ChatView
All Implemented Interfaces:
ChatModelListener

public class ChatView extends Object implements ChatModelListener
ChatView - The View component of the MVC pattern. Responsible for displaying the UI. Contains no business logic. Implements ChatModelListener(Observer) to receive updates from the Model.
  • Constructor Details

    • ChatView

      public ChatView()
  • Method Details

    • createAndShowUi

      public void createAndShowUi(String inituser)
      Initializes the GUI components, sets up layouts, and displays the main frame.
      Parameters:
      inituser - The initial username to display in the login field.
    • onMessageAdded

      public void onMessageAdded(Chat chat)
      Updates the UI when a message is added to a specific chat. Re-initializes the entire chat message panel.
      Specified by:
      onMessageAdded in interface ChatModelListener
      Parameters:
      chat - The Chat object containing the updated message history.
    • onMessageReceived

      public void onMessageReceived(Message message)
      Updates the current chat view with a single incoming message.
      Specified by:
      onMessageReceived in interface ChatModelListener
      Parameters:
      message - The Message object to append to the view.
    • updateUserList

      public void updateUserList(String chatName, String[] activeUsers, ArrayList<String> inChatUsers)
      Updates the user list in the sidebar when a chat update is received.
      Specified by:
      updateUserList in interface ChatModelListener
      Parameters:
      chatName - The name of the chat room being updated.
      activeUsers - An array of usernames currently active in the chat.
      inChatUsers - An ArrayList of usernames currently in the chat.
    • onChatsLoaded

      public void onChatsLoaded(ArrayList<String> chats, String ActiveChat)
      Populates the sidebar with the list of available chat rooms. Ensures listeners are reapplied to new buttons.
      Specified by:
      onChatsLoaded in interface ChatModelListener
      Parameters:
      chats - An ArrayList of strings representing chat room names.
      ActiveChat - The name of the currently selected chat room.
    • onChatSelected

      public void onChatSelected(Chat chat)
      Updates the display when a user selects a different chat room.
      Specified by:
      onChatSelected in interface ChatModelListener
      Parameters:
      chat - The Chat room data to display.
    • clearAddChatField

      public void clearAddChatField()
      Clears the text in the "Add Chat" input field.
    • getAddChatText

      public String getAddChatText()
      Returns:
      The text currently in the "Add Chat" input field.
    • addChatSelectionListener

      public void addChatSelectionListener(ActionListener listener)
      Registers a listener for selecting chat rooms. The listener is stored to be reapplied when the chat list refreshes.
      Parameters:
      listener - The ActionListener for chat room selection buttons.
    • addChatButtonListener

      public void addChatButtonListener(ActionListener l)
      Registers a listener for the "Add Chat" button.
    • addSendButtonListener

      public void addSendButtonListener(ActionListener l)
      Registers a listener for the "Send" message button.
    • addSendImageButtonListener

      public void addSendImageButtonListener(ActionListener l)
      Registers a listener for the "Send Image" button.
    • addLoginButtonListener

      public void addLoginButtonListener(ActionListener l)
      Registers a listener for the "Login" button.
    • addDisconnectButtonListener

      public void addDisconnectButtonListener(ActionListener l)
      Registers a listener for the "Disconnect" button.
    • addInputFieldListener

      public void addInputFieldListener(ActionListener l)
      Registers a listener for the message input field (e.g., for Enter key).
    • removeChatPanel

      public void removeChatPanel()
      Removes content of chatPanel
    • getLoginText

      public String getLoginText()
      Returns:
      The text currently in the Login input field.
    • getInputText

      public String getInputText()
      Returns:
      The text currently in the message input field.
    • clearInputField

      public void clearInputField()
      Clears the message input field.
    • getFrame

      public JFrame getFrame()
      Returns:
      The main JFrame of the application.