Package chat

Source Code of chat.ChatForm

package chat;


import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.BevelBorder;

import ui.misc.feeder.FeederField;
import ui.misc.feeder.FeederFieldListener;


public class ChatForm
{
  private JLabel titleLabel;
  private JTextArea logWindow;

  private JLabel label;
  private FeederField messageField;

  private JButton sendButton;

  public ChatForm(JPanel container, FeederFieldListener feedListener, String title)
  {
    super();

    BorderLayout formLayout = new BorderLayout();
    formLayout.setHgap(4);
    formLayout.setVgap(4);
    container.setLayout(formLayout);

    titleLabel = new JLabel(title);
    container.add(titleLabel, BorderLayout.NORTH);

    logWindow = new JTextArea();
    logWindow.setEditable(false);
    logWindow.setBorder(new BevelBorder(BevelBorder.LOWERED));

    logWindow.setLineWrap(true);
    logWindow.setWrapStyleWord(true);

    container.add(new JScrollPane(logWindow), BorderLayout.CENTER);

    JPanel bottomArea = new JPanel();

    BorderLayout bottomLayout = new BorderLayout();
    bottomLayout.setHgap(4);
    bottomLayout.setVgap(4);
    bottomArea.setLayout(bottomLayout);

    label = new JLabel("Enter text below:");
    label.setEnabled(false);
    bottomArea.add(label, BorderLayout.PAGE_START);

    sendButton = new JButton("Send");
    messageField = new FeederField(2, 0, sendButton, feedListener);
    messageField.setEnabled(false);

    bottomArea.add(messageField, BorderLayout.CENTER);
    bottomArea.add(sendButton, BorderLayout.LINE_END);

    container.add(bottomArea, BorderLayout.PAGE_END);
  }

  public void setTitle(String title)
  {
    titleLabel.setText(title);
  }

  public void logMessage(String sender, String message)
  {
    logWindow.append(sender + "> " + message + "\r\n");
  }

  public void enable()
  {
    label.setEnabled(true);
    messageField.setEnabled(true);
    sendButton.setEnabled(!messageField.getText().equals(""));
  }

  public void disable()
  {
    label.setEnabled(false);
    messageField.setEnabled(false);
    sendButton.setEnabled(false);
  }

}
TOP

Related Classes of chat.ChatForm

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.