示例#1
0
  public void scrollToBottom() {
    if (mousePressed) return;

    int lengthOfChat = transcriptWindow.getDocument().getLength();
    transcriptWindow.setCaretPosition(lengthOfChat);

    try {
      JScrollBar scrollBar = textScroller.getVerticalScrollBar();
      scrollBar.setValue(scrollBar.getMaximum());
    } catch (Exception e) {
    }
  }
示例#2
0
 public void addToTranscript(Message message, boolean updateDate) {
   final Message newMessage = new Message();
   newMessage.setTo(message.getTo());
   newMessage.setFrom(message.getFrom());
   newMessage.setBody(message.getBody());
   newMessage.setProperty("date", new Date());
   transcript.add(newMessage);
   if (updateDate && transcriptWindow.getLastUpdated() != null)
     notificationLabel.setText(
         "las msg received at "
             + ChatsyManager.DATE_SECOND_FORMATTER.format(transcriptWindow.getLastUpdated()));
   scrollToBottom();
 }
示例#3
0
  protected ChatRoom() {
    chatPanel = new JPanel(new GridBagLayout());
    transcriptWindow = new TranscriptWindow();
    splitPane = new JSplitPane();
    packetIDList = new ArrayList<String>();
    notificationLabel = new JLabel();
    toolbar = new ChatToolBar();
    bottomPanel = new JPanel();

    messageListeners = new ArrayList<MessageListener>();
    transcript = new ArrayList<Message>();
    editorBar = new JPanel(new FlowLayout(FlowLayout.LEFT, 1, 1));

    transcriptWindowMouseListener =
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            getChatInputEditor().requestFocus();
          }

          public void mouseReleased(MouseEvent e) {
            mousePressed = false;
            if (transcriptWindow.getSelectedText() == null) getChatInputEditor().requestFocus();
          }

          public void mousePressed(MouseEvent e) {
            mousePressed = true;
          }
        };
    transcriptWindow.addMouseListener(transcriptWindowMouseListener);
    transcriptWindow.setBackground(Color.white);
    chatAreaButton = new ChatAreaSendField("Send");

    textScroller = new JScrollPane(transcriptWindow);
    textScroller.setBackground(transcriptWindow.getBackground());
    textScroller.getViewport().setBackground(Color.white);
    textScroller.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.lightGray));

    getChatInputEditor().setSelectedTextColor(Color.decode("0xffffff"));
    getChatInputEditor().setSelectionColor(Color.decode("0x336699"));
    init();
    getSplitPane().setRightComponent(null);
    getTranscriptWindow().addContextMenuListener(this);

    ChatsyManager.getConnection().addConnectionListener(this);
    addFocusListener(this);
  }