use of org.jivesoftware.sparkimpl.plugin.alerts.SparkToaster in project Spark by igniterealtime.
the class PresenceChangePlugin method initialize.
public void initialize() {
// Listen for right-clicks on ContactItem
final ContactList contactList = SparkManager.getWorkspace().getContactList();
final Action listenAction = new AbstractAction() {
private static final long serialVersionUID = 7705539667621148816L;
public void actionPerformed(ActionEvent e) {
for (ContactItem item : contactList.getSelectedUsers()) {
String bareAddress = XmppStringUtils.parseBareJid(item.getJID());
sparkContacts.add(bareAddress);
}
}
};
listenAction.putValue(Action.NAME, Res.getString("menuitem.alert.when.online"));
listenAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_ALARM_CLOCK));
final Action removeAction = new AbstractAction() {
private static final long serialVersionUID = -8726129089417116105L;
public void actionPerformed(ActionEvent e) {
for (ContactItem item : contactList.getSelectedUsers()) {
String bareAddress = XmppStringUtils.parseBareJid(item.getJID());
sparkContacts.remove(bareAddress);
}
}
};
removeAction.putValue(Action.NAME, Res.getString("menuitem.remove.alert.when.online"));
removeAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_DELETE));
contactList.addContextMenuListener(new ContextMenuListener() {
public void poppingUp(Object object, JPopupMenu popup) {
if (object instanceof ContactItem) {
ContactItem item = (ContactItem) object;
String bareAddress = XmppStringUtils.parseBareJid(item.getJID());
if (!item.getPresence().isAvailable() || item.getPresence().isAway()) {
if (sparkContacts.contains(bareAddress)) {
popup.add(removeAction);
} else {
popup.add(listenAction);
}
}
}
}
public void poppingDown(JPopupMenu popup) {
}
public boolean handleDefaultAction(MouseEvent e) {
return false;
}
});
// Check presence changes
SparkManager.getConnection().addAsyncStanzaListener(stanza -> {
try {
Presence presence = (Presence) stanza;
if (!presence.isAvailable() || presence.isAway()) {
return;
}
String from = presence.getFrom();
ArrayList<String> removelater = new ArrayList<>();
for (final String jid : sparkContacts) {
if (jid.equals(XmppStringUtils.parseBareJid(from))) {
removelater.add(jid);
// sparkContacts.remove(jid);
String nickname = SparkManager.getUserManager().getUserNicknameFromJID(jid);
String time = SparkManager.DATE_SECOND_FORMATTER.format(new Date());
String infoText = Res.getString("message.user.now.available.to.chat", nickname, time);
if (localPref.getShowToasterPopup()) {
EventQueue.invokeLater(() -> {
SparkToaster toaster = new SparkToaster();
toaster.setDisplayTime(5000);
toaster.setBorder(BorderFactory.createBevelBorder(0));
toaster.setToasterHeight(150);
toaster.setToasterWidth(200);
toaster.setTitle(nickname);
toaster.showToaster(null, infoText);
toaster.setCustomAction(new AbstractAction() {
private static final long serialVersionUID = 4827542713848133369L;
@Override
public void actionPerformed(ActionEvent e) {
SparkManager.getChatManager().getChatRoom(jid);
}
});
});
}
ChatRoom room = SparkManager.getChatManager().getChatRoom(jid);
if (localPref.getWindowTakesFocus()) {
EventQueue.invokeLater(() -> SparkManager.getChatManager().activateChat(jid, nickname));
}
EventQueue.invokeLater(() -> room.getTranscriptWindow().insertNotificationMessage(infoText, ChatManager.NOTIFICATION_COLOR));
}
}
for (String s : removelater) {
sparkContacts.remove(s);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}, new StanzaTypeFilter(Presence.class));
}
use of org.jivesoftware.sparkimpl.plugin.alerts.SparkToaster in project Spark by igniterealtime.
the class TaskNotification method notifyUser.
private void notifyUser() {
TimerTask newTask = new TimerTask() {
@Override
public void run() {
EventQueue.invokeLater(() -> {
final JPanel mainPanel = new JPanel();
mainPanel.setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, false));
mainPanel.setBackground(Color.white);
long now = System.currentTimeMillis();
Tasks tasks = Tasks.getTaskList(SparkManager.getConnection());
Iterator<Task> taskIter = tasks.getTasks().iterator();
final JPanel titlePanel = new JPanel(new BorderLayout()) {
private static final long serialVersionUID = -8871487137643685431L;
public void paintComponent(Graphics g) {
Color startColor = Color.white;
Color endColor = new Color(198, 211, 247);
Graphics2D g2 = (Graphics2D) g;
int w = getWidth();
int h = getHeight();
GradientPaint gradient = new GradientPaint(0, 0, startColor, w, h, endColor, true);
g2.setPaint(gradient);
g2.fillRect(0, 0, w, h);
}
};
final JLabel taskLabel = new JLabel("Due ");
taskLabel.setFont(taskLabel.getFont().deriveFont(Font.BOLD));
titlePanel.add(taskLabel, BorderLayout.EAST);
mainPanel.add(titlePanel);
boolean hasItems = false;
while (taskIter.hasNext()) {
Task task = taskIter.next();
if (task.isCompleted()) {
continue;
}
long dueDate = task.getDueDate();
if (dueDate != -1) {
if (now > dueDate) {
final JPanel item = new JPanel(new BorderLayout());
item.setOpaque(false);
JLabel label = new JLabel(task.getTitle());
item.add(label, BorderLayout.CENTER);
JLabel dueItem = new JLabel(formatter.format(new Date(task.getDueDate())));
item.add(dueItem, BorderLayout.EAST);
mainPanel.add(item);
hasItems = true;
}
}
}
if (hasItems) {
SparkToaster toaster = new SparkToaster();
toaster.setDisplayTime(30000);
toaster.setToasterHeight(175);
toaster.setToasterWidth(300);
toaster.setBorder(BorderFactory.createBevelBorder(0));
JScrollPane pane = new JScrollPane(mainPanel);
pane.getViewport().setBackground(Color.white);
toaster.showToaster(Res.getString("title.task.notification"), pane);
}
});
}
};
TaskEngine.getInstance().schedule(newTask, 500);
}
use of org.jivesoftware.sparkimpl.plugin.alerts.SparkToaster in project Spark by igniterealtime.
the class NotificationPlugin method notifyUserOffline.
/**
* Notify client that a user has gone offline.
*
* @param jid the jid of the user who has gone offline.
* @param presence of the offline user.
*/
private void notifyUserOffline(final String jid, final Presence presence) {
try {
EventQueue.invokeAndWait(() -> {
SparkToaster toaster = new SparkToaster();
toaster.setCustomAction(new ChatAction(jid));
toaster.setDisplayTime(preferences.getNotificationsDisplayTime());
toaster.setBorder(BorderFactory.createBevelBorder(0));
NotificationAlertUI alertUI = new NotificationAlertUI(jid, false, presence);
toaster.setToasterHeight((int) alertUI.getPreferredSize().getHeight() + 40);
int width = (int) alertUI.getPreferredSize().getWidth() + 40;
if (width < 300) {
width = 300;
}
toaster.setToasterWidth(width);
toaster.showToaster(alertUI.topLabel.getText(), alertUI);
toaster.setTitleAlert(new Font("Dialog", Font.BOLD, 13), presence);
});
} catch (Exception ex) {
Log.error(ex);
}
}
use of org.jivesoftware.sparkimpl.plugin.alerts.SparkToaster in project Spark by igniterealtime.
the class IncomingCall method showIncomingCall.
/**
* Notifies user of an incoming call. The UI allows for users to either accept or reject
* the incoming session.
*
* @param request the JingleSession.
*/
private void showIncomingCall(final JingleSessionRequest request) {
toasterManager = new SparkToaster();
toasterManager.setHidable(false);
final IncomingCallUI incomingCall = new IncomingCallUI(request.getFrom());
toasterManager.setToasterHeight(175);
toasterManager.setToasterWidth(300);
toasterManager.setDisplayTime(500000000);
toasterManager.showToaster("Incoming Voice Chat", incomingCall);
toasterManager.hideTitle();
incomingCall.getAcceptButton().addActionListener(e -> acceptSession(request));
incomingCall.getRejectButton().addActionListener(e -> rejectIncomingCall());
// Start the ringing.
final Runnable ringer = () -> ringing.loop();
TaskEngine.getInstance().submit(ringer);
// End after 30 seconds max.
TimerTask endTask = new SwingTimerTask() {
public void doRun() {
if (!session.isFullyEstablished()) {
rejectIncomingCall();
}
}
};
TaskEngine.getInstance().schedule(endTask, 30000);
}
use of org.jivesoftware.sparkimpl.plugin.alerts.SparkToaster in project Spark by igniterealtime.
the class MissedCalls method addMissedCall.
/**
* Called whenever the user misses a call. The information will be displayed in the Spark Toaster until the user
* explicitly closes the window.
*
* @param callerID the callerID
* @param number the number the user dialed from.
*/
public void addMissedCall(String callerID, final String number) {
callID = callerID;
VCard vcard = SparkManager.getVCardManager().searchPhoneNumber(number);
if (vcard != null) {
String firstName = vcard.getFirstName();
String lastName = vcard.getLastName();
if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
callID = firstName + " " + lastName;
} else if (ModelUtil.hasLength(firstName)) {
callID = firstName;
}
}
try {
EventQueue.invokeAndWait(new Runnable() {
public void run() {
final MissedCall missedCall = new MissedCall(callID, new Date(), number);
model.insertElementAt(missedCall, 0);
if (toaster == null || !list.isShowing()) {
toaster = new SparkToaster();
toaster.setToasterHeight(230);
toaster.setToasterWidth(300);
toaster.setDisplayTime(500000000);
toaster.showToaster(PhoneRes.getIString("phone.missedcalls"), gui);
}
}
});
} catch (Exception e) {
Log.error(e);
}
}
Aggregations