Search in sources :

Example 1 with SwingTimerTask

use of org.jivesoftware.spark.util.SwingTimerTask in project Spark by igniterealtime.

the class BuzzPlugin method initialize.

public void initialize() {
    ProviderManager.addExtensionProvider(ELEMENTNAME, NAMESPACE, new BuzzPacket.Provider());
    ProviderManager.addExtensionProvider(ELEMENTNAME_OLD, NAMESPACE_OLD, new BuzzPacket.Provider());
    SparkManager.getConnection().addAsyncStanzaListener(stanza -> {
        if (stanza instanceof Message) {
            final Message message = (Message) stanza;
            boolean buzz = message.getExtension(ELEMENTNAME_OLD, NAMESPACE_OLD) != null || message.getExtension(ELEMENTNAME, NAMESPACE) != null;
            if (buzz) {
                SwingUtilities.invokeLater(() -> shakeWindow(message));
            }
        }
    }, new StanzaTypeFilter(Message.class));
    SparkManager.getChatManager().addChatRoomListener(new ChatRoomListener() {

        public void chatRoomOpened(final ChatRoom room) {
            TimerTask task = new SwingTimerTask() {

                public void doRun() {
                    addBuzzFeatureToChatRoom(room);
                }
            };
            TaskEngine.getInstance().schedule(task, 100);
        }

        public void chatRoomLeft(ChatRoom room) {
        }

        public void chatRoomClosed(ChatRoom room) {
        }

        public void chatRoomActivated(ChatRoom room) {
        }

        public void userHasJoined(ChatRoom room, String userid) {
        }

        public void userHasLeft(ChatRoom room, String userid) {
        }
    });
}
Also used : StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) Message(org.jivesoftware.smack.packet.Message) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) TimerTask(java.util.TimerTask) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomListener(org.jivesoftware.spark.ui.ChatRoomListener)

Example 2 with SwingTimerTask

use of org.jivesoftware.spark.util.SwingTimerTask in project Spark by igniterealtime.

the class ChatContainer method addChatRoom.

/**
 * Adds a new ChatRoom to Spark.
 *
 * @param room the ChatRoom to add.
 */
public synchronized void addChatRoom(final ChatRoom room) {
    createFrameIfNeeded();
    room.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY));
    AndFilter presenceFilter = new AndFilter(new StanzaTypeFilter(Presence.class), FromMatchesFilter.createBare(room.getRoomname()));
    // Next, create a packet listener. We use an anonymous inner class for brevity.
    StanzaListener myListener = stanza -> SwingUtilities.invokeLater(() -> handleRoomPresence((Presence) stanza));
    room.registeredToFrame(chatFrame);
    SparkManager.getConnection().addAsyncStanzaListener(myListener, presenceFilter);
    // Add to PresenceMap
    presenceMap.put(room.getRoomname(), myListener);
    String tooltip;
    if (room instanceof ChatRoomImpl) {
        tooltip = ((ChatRoomImpl) room).getParticipantJID();
        String nickname = SparkManager.getUserManager().getUserNicknameFromJID(((ChatRoomImpl) room).getParticipantJID());
        tooltip = "<html><body><b>Contact:&nbsp;</b>" + nickname + "<br><b>JID:&nbsp;</b>" + tooltip;
    } else {
        tooltip = room.getRoomname();
    }
    // Create ChatRoom UI and dock
    SparkTab tab = addTab(room.getTabTitle(), room.getTabIcon(), room, tooltip);
    tab.addMouseListener(new MouseAdapter() {

        public void mouseReleased(MouseEvent e) {
            checkTabPopup(e);
        }

        public void mousePressed(MouseEvent e) {
            checkTabPopup(e);
        }
    });
    room.addMessageListener(this);
    // Remove brand panel
    final String title = getTabAt(0).getActualText();
    if (title.equals(WELCOME_TITLE)) {
        chatFrame.setTitle(room.getRoomTitle());
    }
    final TimerTask visibleTask = new SwingTimerTask() {

        public void doRun() {
            checkVisibility(room);
        }
    };
    TaskEngine.getInstance().schedule(visibleTask, 100);
    // Add to ChatRoomList
    chatRoomList.add(room);
    // Notify users that the chat room has been opened.
    fireChatRoomOpened(room);
    // Focus Chat
    focusChat();
    // Add Room listeners to override issue with input maps and keybinding on the mac.
    if (Spark.isMac()) {
        room.getChatInputEditor().addKeyListener(this);
    }
}
Also used : java.util(java.util) SparkTabbedPaneListener(org.jivesoftware.spark.component.tabbedPane.SparkTabbedPaneListener) SettingsManager(org.jivesoftware.sparkimpl.settings.local.SettingsManager) Res(org.jivesoftware.resource.Res) Log(org.jivesoftware.spark.util.log.Log) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl) MainWindow(org.jivesoftware.MainWindow) SparkToaster(org.jivesoftware.sparkimpl.plugin.alerts.SparkToaster) ChangeListener(javax.swing.event.ChangeListener) GroupChatRoomListener(org.jivesoftware.spark.ui.conferences.GroupChatRoomListener) AndFilter(org.jivesoftware.smack.filter.AndFilter) TaskEngine(org.jivesoftware.spark.util.TaskEngine) ChangeEvent(javax.swing.event.ChangeEvent) FromMatchesFilter(org.jivesoftware.smack.filter.FromMatchesFilter) Presence(org.jivesoftware.smack.packet.Presence) ChatManager(org.jivesoftware.spark.ChatManager) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) SparkRes(org.jivesoftware.resource.SparkRes) SwingWorker(org.jivesoftware.spark.util.SwingWorker) SparkTabbedPane(org.jivesoftware.spark.component.tabbedPane.SparkTabbedPane) SparkTab(org.jivesoftware.spark.component.tabbedPane.SparkTab) GroupChatRoom(org.jivesoftware.spark.ui.rooms.GroupChatRoom) XmppStringUtils(org.jxmpp.util.XmppStringUtils) Spark(org.jivesoftware.Spark) java.awt(java.awt) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) List(java.util.List) SparkManager(org.jivesoftware.spark.SparkManager) java.awt.event(java.awt.event) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) Message(org.jivesoftware.smack.packet.Message) Pattern(java.util.regex.Pattern) StanzaListener(org.jivesoftware.smack.StanzaListener) javax.swing(javax.swing) AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) SparkTab(org.jivesoftware.spark.component.tabbedPane.SparkTab) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) Presence(org.jivesoftware.smack.packet.Presence) StanzaListener(org.jivesoftware.smack.StanzaListener) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 3 with SwingTimerTask

use of org.jivesoftware.spark.util.SwingTimerTask in project Spark by igniterealtime.

the class BookmarkPlugin method initialize.

@Override
public void initialize() {
    final SwingWorker bookmarkThreadWorker = new SwingWorker() {

        @Override
        public Object construct() {
            return this;
        }

        /**
         * Installing menu into spark menu and adding events to bookmarks
         */
        @Override
        public void finished() {
            try {
                initialize();
            } catch (Exception e) {
                Log.error(e);
            }
        }

        /**
         */
        public void initialize() {
            final JMenu bookmarkMenu = new JMenu(Res.getString("menuitem.bookmarks"));
            createMenu(bookmarkMenu);
            if (bookmarkMenu.getMenuComponentCount() > 0) {
                SparkManager.getMainWindow().getMenu().add(bookmarkMenu, 3);
            }
            BookmarksUI bookmarksUi = ConferenceServices.getBookmarkedConferences();
            bookmarksUi.addBookmarksListener(new BookmarksListener() {

                @Override
                public void bookmarkAdded(String roomJID) {
                    rescan(bookmarkMenu);
                }

                @Override
                public void bookmarkRemoved(String roomJID) {
                    rescan(bookmarkMenu);
                }
            });
        }

        /**
         * Rescaning our bookmarks and remaking menu items
         *
         * @param bookmarkMenu menu Jmenu
         */
        public void rescan(JMenu bookmarkMenu) {
            // removing old menus
            bookmarkMenu.removeAll();
            try {
                // making new
                setBookmarks(bookmarkMenu);
                int onPanel = SparkManager.getMainWindow().getMenu().getComponentIndex(bookmarkMenu);
                if (onPanel < 0) {
                    if (bookmarkMenu.getMenuComponentCount() > 0) {
                        int menuCount = SparkManager.getMainWindow().getMenu().getMenuCount();
                        SparkManager.getMainWindow().getMenu().add(bookmarkMenu, menuCount - 2);
                    }
                }
                if (onPanel >= 0) {
                    if (bookmarkMenu.getMenuComponentCount() <= 0) {
                        SparkManager.getMainWindow().getMenu().remove(bookmarkMenu);
                    }
                }
                SparkManager.getMainWindow().getMenu().invalidate();
                SparkManager.getMainWindow().getMenu().validate();
                SparkManager.getMainWindow().getMenu().repaint();
            } catch (XMPPException | SmackException ex) {
                Log.error(ex);
            }
        }

        /**
         * Updating statusbar and generating menu items
         *
         * @param bookmarkMenu menu Jmenu
         */
        public void createMenu(JMenu bookmarkMenu) {
            try {
                setBookmarks(bookmarkMenu);
            } catch (XMPPException | SmackException ex) {
                Log.error(ex);
            }
        }

        /**
         * loading menu items and setting bookmarks listeners
         *
         * @param bookmarkMenu menu Jmenu
         */
        public void setBookmarks(JMenu bookmarkMenu) throws XMPPException, SmackException {
            BookmarkManager manager = BookmarkManager.getBookmarkManager(SparkManager.getConnection());
            if (manager != null) {
                Collection<BookmarkedConference> bookmarkedConferences = manager.getBookmarkedConferences();
                final Collection<BookmarkedURL> bookmarkedLinks = manager.getBookmarkedURLs();
                for (Object bookmarkedLink : bookmarkedLinks) {
                    final BookmarkedURL link = (BookmarkedURL) bookmarkedLink;
                    Action urlAction = new AbstractAction() {

                        private static final long serialVersionUID = 4246574779205966917L;

                        @Override
                        public void actionPerformed(ActionEvent actionEvent) {
                            try {
                                BrowserLauncher.openURL(link.getURL());
                            } catch (Exception e) {
                                Log.error(e);
                            }
                        }
                    };
                    urlAction.putValue(Action.NAME, link.getName());
                    urlAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.LINK_16x16));
                    bookmarkMenu.add(urlAction);
                }
                for (Object bookmarkedConference : bookmarkedConferences) {
                    final BookmarkedConference conferences = (BookmarkedConference) bookmarkedConference;
                    Action conferenceAction = new AbstractAction() {

                        private static final long serialVersionUID = 5964584172262968704L;

                        @Override
                        public void actionPerformed(ActionEvent actionEvent) {
                            final TimerTask task = new SwingTimerTask() {

                                @Override
                                public void doRun() {
                                    ConferenceUtils.joinConferenceOnSeperateThread(conferences.getName(), conferences.getJid(), conferences.getPassword());
                                }
                            };
                            TaskEngine.getInstance().schedule(task, 10);
                        }
                    };
                    conferenceAction.putValue(Action.NAME, conferences.getName());
                    conferenceAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.CONFERENCE_IMAGE_16x16));
                    bookmarkMenu.add(conferenceAction);
                }
            }
        }
    };
    bookmarkThreadWorker.start();
}
Also used : BookmarkedURL(org.jivesoftware.smackx.bookmarks.BookmarkedURL) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) ActionEvent(java.awt.event.ActionEvent) SmackException(org.jivesoftware.smack.SmackException) BookmarksListener(org.jivesoftware.spark.ui.conferences.BookmarksListener) BookmarkedConference(org.jivesoftware.smackx.bookmarks.BookmarkedConference) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException) BookmarksUI(org.jivesoftware.spark.ui.conferences.BookmarksUI) BookmarkManager(org.jivesoftware.smackx.bookmarks.BookmarkManager) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) TimerTask(java.util.TimerTask) SwingWorker(org.jivesoftware.spark.util.SwingWorker) XMPPException(org.jivesoftware.smack.XMPPException) AbstractAction(javax.swing.AbstractAction) JMenu(javax.swing.JMenu)

Example 4 with SwingTimerTask

use of org.jivesoftware.spark.util.SwingTimerTask in project Spark by igniterealtime.

the class GroupChatInvitationUI method acceptInvitation.

/**
 * Action taking when a user clicks on the accept button.
 */
private void acceptInvitation() {
    setVisible(false);
    String name = XmppStringUtils.parseLocalpart(room);
    ConferenceUtils.enterRoomOnSameThread(name, room, password);
    final TimerTask removeUITask = new SwingTimerTask() {

        public void doRun() {
            removeUI();
        }
    };
    TaskEngine.getInstance().schedule(removeUITask, 2000);
}
Also used : SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) TimerTask(java.util.TimerTask) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask)

Example 5 with SwingTimerTask

use of org.jivesoftware.spark.util.SwingTimerTask in project Spark by igniterealtime.

the class FastpathPlugin method reconnectionSuccessful.

public void reconnectionSuccessful() {
    // Rejoin the workgroup after 15 seconds.
    final TimerTask rejoinTask = new SwingTimerTask() {

        public void doRun() {
            if (wasConnected) {
                joinWorkgroup();
            }
        }
    };
    TaskEngine.getInstance().schedule(rejoinTask, 15000);
}
Also used : SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) TimerTask(java.util.TimerTask) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask)

Aggregations

SwingTimerTask (org.jivesoftware.spark.util.SwingTimerTask)12 TimerTask (java.util.TimerTask)8 Message (org.jivesoftware.smack.packet.Message)3 SmackException (org.jivesoftware.smack.SmackException)2 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)2 SwingWorker (org.jivesoftware.spark.util.SwingWorker)2 java.awt (java.awt)1 BorderLayout (java.awt.BorderLayout)1 Component (java.awt.Component)1 Font (java.awt.Font)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 java.awt.event (java.awt.event)1 ActionEvent (java.awt.event.ActionEvent)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 WindowAdapter (java.awt.event.WindowAdapter)1