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) {
}
});
}
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: </b>" + nickname + "<br><b>JID: </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);
}
}
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();
}
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);
}
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);
}
Aggregations