Search in sources :

Example 1 with ChatInputEditor

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));
    }
}
Also used : ChatManager(org.jivesoftware.spark.ChatManager) Collection(java.util.Collection) JPopupMenu(javax.swing.JPopupMenu) SettingsManager(org.jivesoftware.sparkimpl.settings.local.SettingsManager) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) UIComponentRegistry(org.jivesoftware.spark.util.UIComponentRegistry) BadLocationException(javax.swing.text.BadLocationException) Log(org.jivesoftware.spark.util.log.Log) Plugin(org.jivesoftware.spark.plugin.Plugin) MouseEvent(java.awt.event.MouseEvent) ThemePreference(org.jivesoftware.spark.ui.themes.ThemePreference) SparkManager(org.jivesoftware.spark.SparkManager) MouseAdapter(java.awt.event.MouseAdapter) ChatInputEditor(org.jivesoftware.spark.ui.ChatInputEditor) RolloverButton(org.jivesoftware.spark.component.RolloverButton) ChatRoomListener(org.jivesoftware.spark.ui.ChatRoomListener) ChatInputEditor(org.jivesoftware.spark.ui.ChatInputEditor) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) RolloverButton(org.jivesoftware.spark.component.RolloverButton) JPopupMenu(javax.swing.JPopupMenu) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 Collection (java.util.Collection)1 JPopupMenu (javax.swing.JPopupMenu)1 BadLocationException (javax.swing.text.BadLocationException)1 ChatManager (org.jivesoftware.spark.ChatManager)1 SparkManager (org.jivesoftware.spark.SparkManager)1 RolloverButton (org.jivesoftware.spark.component.RolloverButton)1 Plugin (org.jivesoftware.spark.plugin.Plugin)1 ChatInputEditor (org.jivesoftware.spark.ui.ChatInputEditor)1 ChatRoom (org.jivesoftware.spark.ui.ChatRoom)1 ChatRoomListener (org.jivesoftware.spark.ui.ChatRoomListener)1 ThemePreference (org.jivesoftware.spark.ui.themes.ThemePreference)1 UIComponentRegistry (org.jivesoftware.spark.util.UIComponentRegistry)1 Log (org.jivesoftware.spark.util.log.Log)1 SettingsManager (org.jivesoftware.sparkimpl.settings.local.SettingsManager)1