use of org.jivesoftware.spark.ui.ChatInputEditor in project Spark by igniterealtime.
the class EmoticonPlugin method chatRoomOpened.
public void chatRoomOpened(final ChatRoom room) {
// Check to see if emoticons are enabled.
if (!SettingsManager.getLocalPreferences().areEmoticonsEnabled()) {
return;
}
// final String activeEmoticonSetName =
// emoticonManager.getActiveEmoticonSetName();
emoticonManager = EmoticonManager.getInstance();
Collection<String> emoticonPacks;
emoticonPacks = emoticonManager.getEmoticonPacks();
if (emoticonPacks != null) {
// Add Emoticon button
final RolloverButton emoticonPicker = UIComponentRegistry.getButtonFactory().createEmoticonButton();
room.addEditorComponent(emoticonPicker);
emoticonPicker.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
// Show popup
final JPopupMenu popup = new JPopupMenu();
EmoticonUI emoticonUI = new EmoticonUI();
emoticonUI.setEmoticonPickListener(emoticon -> {
try {
popup.setVisible(false);
final ChatInputEditor editor = room.getChatInputEditor();
String currentText = editor.getText();
if (currentText.length() == 0 || currentText.endsWith(" ")) {
room.getChatInputEditor().insertText(emoticon + " ");
} else {
room.getChatInputEditor().insertText(" " + emoticon + " ");
}
room.getChatInputEditor().requestFocus();
} catch (BadLocationException e1) {
Log.error(e1);
}
});
popup.add(emoticonUI);
popup.show(emoticonPicker, e.getX(), e.getY());
}
});
room.addClosingListener(() -> room.removeEditorComponent(emoticonPicker));
}
}
Aggregations