Example #1
0
  public void closeChatRoom() {
    fireClosingListeners();
    getTranscriptWindow().removeContextMenuListener(this);
    getTranscriptWindow().removeMouseListener(transcriptWindowMouseListener);
    getChatInputEditor().removeKeyListener(chatEditorKeyListener);
    textScroller.getViewport().remove(transcriptWindow);
    ChatsyManager.getConnection().removeConnectionListener(this);

    packetIDList.clear();
    messageListeners.clear();
    getChatInputEditor().close();

    getChatInputEditor().getActionMap().remove("closeTheRoom");
    chatAreaButton.getButton().removeActionListener(this);
    bottomPanel.remove(chatAreaButton);
  }
Example #2
0
 private void checkForEnter(KeyEvent e) {
   final KeyStroke keyStroke = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers());
   if (!keyStroke.equals(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK))
       && e.getKeyChar() == KeyEvent.VK_ENTER) {
     e.consume();
     sendMessage();
     getChatInputEditor().setText("");
     getChatInputEditor().setCaretPosition(0);
   } else if (keyStroke.equals(
       KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK))) {
     final Document document = getChatInputEditor().getDocument();
     try {
       document.insertString(getChatInputEditor().getCaretPosition(), "\n", null);
       getChatInputEditor().requestFocusInWindow();
       chatAreaButton.getButton().setEnabled(true);
     } catch (BadLocationException badLoc) {
     }
   }
 }
Example #3
0
 public JButton getSendButton() {
   return chatAreaButton.getButton();
 }
Example #4
0
 public ChatInputEditor getChatInputEditor() {
   return chatAreaButton.getChatInputArea();
 }
Example #5
0
 public void positionCursor() {
   getChatInputEditor().setCaretPosition(getChatInputEditor().getCaretPosition());
   chatAreaButton.getChatInputArea().requestFocusInWindow();
 }
Example #6
0
 protected void checkForText(DocumentEvent e) {
   final int length = e.getDocument().getLength();
   if (length > 0) chatAreaButton.getButton().setEnabled(true);
   else chatAreaButton.getButton().setEnabled(false);
 }
Example #7
0
 public void actionPerformed(ActionEvent e) {
   sendMessage();
   getChatInputEditor().clear();
   chatAreaButton.getButton().setEnabled(false);
 }
Example #8
0
  private void init() {
    setLayout(new GridBagLayout());
    setBackground(Color.white);

    splitPane.setBorder(BorderFactory.createEmptyBorder());
    splitPane.setOneTouchExpandable(false);

    verticalSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    add(
        verticalSplit,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    verticalSplit.setBorder(BorderFactory.createEmptyBorder());
    verticalSplit.setOneTouchExpandable(false);
    verticalSplit.setTopComponent(splitPane);
    textScroller.setAutoscrolls(true);
    textScroller.getVerticalScrollBar().setBlockIncrement(50);
    textScroller.getVerticalScrollBar().setUnitIncrement(20);

    chatWindowPanel = new JPanel();
    chatWindowPanel.setLayout(new GridBagLayout());
    chatWindowPanel.add(
        textScroller,
        new GridBagConstraints(
            0,
            10,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(0, 0, 0, 0),
            0,
            0));
    chatWindowPanel.setOpaque(false);

    chatPanel.add(
        chatWindowPanel,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(0, 5, 0, 5),
            0,
            0));
    splitPane.setLeftComponent(chatPanel);

    editorBar.setOpaque(false);
    chatPanel.setOpaque(false);

    bottomPanel.setOpaque(false);
    splitPane.setOpaque(false);
    bottomPanel.setLayout(new GridBagLayout());
    bottomPanel.add(
        chatAreaButton,
        new GridBagConstraints(
            0,
            1,
            5,
            1,
            1.0,
            1.0,
            GridBagConstraints.WEST,
            GridBagConstraints.BOTH,
            new Insets(0, 5, 5, 5),
            0,
            15));
    bottomPanel.add(
        editorBar,
        new GridBagConstraints(
            0,
            0,
            5,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 5, 0, 5),
            0,
            0));

    bottomPanel.setBorder(BorderFactory.createEmptyBorder());
    verticalSplit.setOpaque(false);

    verticalSplit.setBottomComponent(bottomPanel);
    verticalSplit.setResizeWeight(1.0);
    verticalSplit.setDividerSize(2);

    chatAreaButton.getButton().addActionListener(this);
    getChatInputEditor().getDocument().addDocumentListener(this);
    chatEditorKeyListener =
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            checkForEnter(e);
          }
        };
    getChatInputEditor().addKeyListener(chatEditorKeyListener);
    getChatInputEditor()
        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put(KeyStroke.getKeyStroke("ctrl F4"), "closeTheRoom");
    getChatInputEditor()
        .getActionMap()
        .put(
            "closeTheRoom",
            new AbstractAction("closeTheRoom") {
              public void actionPerformed(ActionEvent evt) {
                closeChatRoom();
              }
            });
  }