Package net.hearthstats.osx

Source Code of net.hearthstats.osx.OsxNotificationQueue

package net.hearthstats.osx;

import net.hearthstats.osx.jna.NSUserNotification;
import net.hearthstats.osx.jna.NSUserNotificationCenter;
import net.hearthstats.ui.notification.NotificationQueue;
import org.rococoa.cocoa.foundation.NSAutoreleasePool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class OsxNotificationQueue implements NotificationQueue {

  private final static Logger debugLog = LoggerFactory.getLogger(OsxNotificationQueue.class);


  @Override
  public void add(String header, String message, boolean allowFocus) {
    debugLog.debug("    Showing OS X notification \"{}\", \"{}\"", header, message);

    final NSAutoreleasePool pool = NSAutoreleasePool.new_();
    try {
      NSUserNotification nsUserNotification = NSUserNotification.CLASS.alloc();

      nsUserNotification.setTitle(header);
      nsUserNotification.setSubtitle(message);

      NSUserNotificationCenter defaultNotificationCenter = NSUserNotificationCenter.CLASS.defaultUserNotificationCenter();
      defaultNotificationCenter.setDelegate(defaultNotificationCenter);
      defaultNotificationCenter.deliverNotification(nsUserNotification);
    } finally {
      pool.drain();
    }

  }


  @Override
  public void clearAllNotifications() {
    debugLog.debug("    Clearing all notifications");

    final NSAutoreleasePool pool = NSAutoreleasePool.new_();
    try {
      NSUserNotificationCenter defaultNotificationCenter = NSUserNotificationCenter.CLASS.defaultUserNotificationCenter();
      defaultNotificationCenter.removeAllDeliveredNotifications();
    } finally {
      pool.drain();
    }

  }
}
TOP

Related Classes of net.hearthstats.osx.OsxNotificationQueue

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.