undoManager = new UndoManager(); this.setDragEnabled(true); this.getDocument().addUndoableEditListener(undoManager); Action undo = new AbstractAction() { private static final long serialVersionUID = -8897769620508545403L; escapeKeyStroke = KeyStroke.getKeyStroke("ESCAPE"); getInputMap().put(ctrlbackspaceKeyStroke, "ctrlbackspace"); getInputMap().put(undoKeyStroke, "undo"); getInputMap().put(escapeKeyStroke, "escape"); getInputMap().put(KeyStroke.getKeyStroke("Ctrl W"), "escape"); registerKeyboardAction(undo, KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.CTRL_MASK), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); registerKeyboardAction(ctrlbackspace, KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, KeyEvent.CTRL_MASK), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); registerKeyboardAction(escape, KeyStroke.getKeyStroke("ESCAPE"), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); getDocument().addDocumentListener(this); addMouseListener(this);
@Override public void actionPerformed( ActionEvent e ) { getChatInputEditor().appendText( match.substring( needle.length() ) ); popup.setVisible( false ); } } );
/** * Disables the Chat Editor, rendering it to the system default * color. */ public void showAsDisabled() { this.setEditable(false); this.setEnabled(false); clear(); final Color disabledColor = (Color)UIManager.get("Button.disabled"); this.setBackground(disabledColor); }
/** * Inserts text into the current document at the current caret position. * * @param text the text to insert * @throws BadLocationException if the location is not available for insertion. */ public void insertText(String text) throws BadLocationException { final Document doc = getDocument(); doc.insertString(this.getCaret().getDot(), text, null); } }
/** * Remove dependices when no longer in use. */ public void close() { getDocument().removeDocumentListener(this); getDocument().removeUndoableEditListener(undoManager); removeMouseListener(this); getInputMap().remove(undoKeyStroke); getInputMap().remove(ctrlbackspaceKeyStroke); getInputMap().remove(escapeKeyStroke); getInputMap().remove(KeyStroke.getKeyStroke("Ctrl W")); }
if (getSelectedText() != null && getSelectedText().length() > 0) { ChatInputEditor.this.removeWordInBetween(getSelectionStart(), getSelectionEnd()); } else if (getCaretPosition() < getText().length()) { String preCaret = getText() .substring(0, getCaretPosition()); for (int i = lastSpace; getText().charAt(i) == ' '; --i) { lastSpace--; ChatInputEditor.this.removeWordInBetween(lastSpace, getCaretPosition()); if (lastSpace <= getText().length()) { setCaretPosition(lastSpace); } else { setCaretPosition(getText().length()); } else if (getText().contains(" ")) { int untilhere = getText().lastIndexOf(" "); for (int i = untilhere; getText().charAt(i) == ' '; --i) { untilhere--; ChatInputEditor.this.removeLastWord(getText().substring( untilhere)); } else {
transcriptWindow.setBackground(Color.white); getChatInputEditor().setSelectedTextColor((Color)UIManager.get("ChatInput.SelectedTextColor")); getChatInputEditor().setSelectionColor((Color)UIManager.get("ChatInput.SelectionColor")); getChatInputEditor().getDocument().addDocumentListener(this); getChatInputEditor().addKeyListener(chatEditorKeyListener); getChatInputEditor().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ctrl F4"), "closeTheRoom"); getChatInputEditor().getActionMap().put("closeTheRoom", new AbstractAction("closeTheRoom") { private static final long serialVersionUID = 1L; getChatInputEditor().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ctrl SPACE"), "handleCompletion"); getChatInputEditor().getActionMap().put("handleCompletion", new AbstractAction("handleCompletion") { private static final long serialVersionUID = 1L; getChatInputEditor().setTransferHandler(transferHandler);
/** * Checks to see if enter was pressed and validates room. * * @param e the KeyEvent */ 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); SparkManager.getWorkspace().getTranscriptPlugin().persistChatRoom(this); } 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) { Log.error("Error when checking for enter:", badLoc); } } }
/** * Adds a message that is to be sent to the transcript window. * * @param message The message to be displayed. */ private void displaySendMessage( Message message ) { lastActivity = System.currentTimeMillis(); try { getTranscriptWindow().insertMessage( getNickname(), message, ChatManager.TO_COLOR); getChatInputEditor().selectAll(); getTranscriptWindow().validate(); getTranscriptWindow().repaint(); getChatInputEditor().clear(); } catch (Exception ex) { Log.error( "Error sending message", ex); } // Notify users that message has been sent fireMessageSent(message); addToTranscript(message, false); getChatInputEditor().setCaretPosition(0); getChatInputEditor().requestFocusInWindow(); scrollToBottom(); }
/** * Close the ChatRoom. */ public void closeChatRoom() { fireClosingListeners(); setChatState(ChatState.gone); if (typingTimerTask != null) { TaskEngine.getInstance().cancelScheduledTask(typingTimerTask); typingTimerTask = null; } getTranscriptWindow().removeContextMenuListener(this); getTranscriptWindow().removeMouseListener(transcriptWindowMouseListener); getChatInputEditor().removeKeyListener(chatEditorKeyListener); this.removeAll(); textScroller.getViewport().remove(transcriptWindow); // Remove Connection Listener SparkManager.getConnection().removeConnectionListener(this); getTranscriptWindow().setTransferHandler(null); getChatInputEditor().setTransferHandler(null); transferHandler = null; packetIDList.clear(); messageListeners.clear(); fileDropListeners.clear(); getChatInputEditor().close(); getChatInputEditor().getActionMap().remove("closeTheRoom"); chatAreaButton.getButton().removeActionListener(this); bottomPanel.remove(chatAreaButton); _chatFrame.removeWindowToFrontListener(this); }
/** * Requests valid focus to the SendField. */ public void positionCursor() { getChatInputEditor().setCaretPosition(getChatInputEditor().getCaretPosition()); chatAreaButton.getChatInputArea().requestFocusInWindow(); }
final String text = getChatInputEditor().getText(); if ( text == null || text.isEmpty() ) getChatInputEditor().appendText( matches.iterator().next().substring( needle.length() ) ); getChatInputEditor().getCaret().getMagicCaretPosition().x, SparkManager.getChatManager().getChatContainer().getHeight() - 20 );
getChatInputEditor().clear(); getTranscriptWindow().validate(); getTranscriptWindow().repaint(); getChatInputEditor().setCaretPosition( 0 ); getChatInputEditor().requestFocusInWindow(); scrollToBottom();
/** * Creates a new IconTextField with Icon. * * @param text the text to use on the button. */ public ChatAreaSendField(String text) { setLayout(new GridBagLayout()); setBackground((Color)UIManager.get("TextPane.background")); textField = new ChatInputEditor(); textField.setBorder(null); setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.lightGray)); button = new JButton(); if (Spark.isMac()) { button.setContentAreaFilled(false); } ResourceUtils.resButton(button, text); add(button, new GridBagConstraints(1, 0, 1, 1, 0.0, 1.0, GridBagConstraints.EAST, GridBagConstraints.VERTICAL, new Insets(2, 2, 2, 2), 0, 0)); button.setVisible(false); final JScrollPane pane = new JScrollPane(textField); pane.setBorder(null); add(pane, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(2, 2, 2, 2), 0, 0)); button.setEnabled(false); }
public ChatRoomTransferDecorator(final ChatRoom chatRoom) { this.chatRoom = chatRoom; chatRoom.addFileDropListener(this); chatRoom.getChatInputEditor().addKeyListener(this); chatRoom.addClosingListener(this); sendFileButton = UIComponentRegistry.getButtonFactory().createSendFileButton(); sendFileButton.setToolTipText(Res.getString("message.send.file.to.user")); chatRoom.addChatRoomButton(sendFileButton); sendFileButton.addActionListener(this); sendScreenShotButton = UIComponentRegistry.getButtonFactory().createScreenshotButton(); sendScreenShotButton.setToolTipText(Res.getString("message.send.picture")); chatRoom.addChatRoomButton(sendScreenShotButton); sendScreenShotButton.addActionListener(this); }
public void actionPerformed(ActionEvent e) { sendMessage(); // Clear send field and disable send button getChatInputEditor().clear(); chatAreaButton.getButton().setEnabled(false); }
messageBox = new ChatInputEditor(); normalMessageButton = new JRadioButton(Res.getString("message.normal")); JRadioButton alertMessageButton = new JRadioButton(Res.getString("message.alert.notify"));
room.getChatInputEditor().addKeyListener(this);