notifications statusbar icons
authorAlexey Pegov <alexey.pegov@jetbrains.com>
Fri, 16 Oct 2009 14:12:20 +0000 (18:12 +0400)
committerAlexey Pegov <alexey.pegov@jetbrains.com>
Fri, 16 Oct 2009 14:12:20 +0000 (18:12 +0400)
platform/icons/src/ide/error_notifications.png [new file with mode: 0644]
platform/icons/src/ide/info_notifications.png [new file with mode: 0644]
platform/icons/src/ide/read_notifications.png
platform/icons/src/ide/unread_notifications.png [deleted file]
platform/icons/src/ide/warning_notifications.png [new file with mode: 0644]
platform/platform-impl/src/com/intellij/notification/impl/NotificationModel.java
platform/platform-impl/src/com/intellij/notification/impl/NotificationsManagerImpl.java
platform/platform-impl/src/com/intellij/notification/impl/ui/NotificationComponent.java

diff --git a/platform/icons/src/ide/error_notifications.png b/platform/icons/src/ide/error_notifications.png
new file mode 100644 (file)
index 0000000..ef68f6a
Binary files /dev/null and b/platform/icons/src/ide/error_notifications.png differ
diff --git a/platform/icons/src/ide/info_notifications.png b/platform/icons/src/ide/info_notifications.png
new file mode 100644 (file)
index 0000000..eab7574
Binary files /dev/null and b/platform/icons/src/ide/info_notifications.png differ
index 2d865bb119f059f215fb1632c523b63ed1fb85b0..77bedbcc15e2303640e18a8060ae1f7482cfc272 100644 (file)
Binary files a/platform/icons/src/ide/read_notifications.png and b/platform/icons/src/ide/read_notifications.png differ
diff --git a/platform/icons/src/ide/unread_notifications.png b/platform/icons/src/ide/unread_notifications.png
deleted file mode 100644 (file)
index 022bb1b..0000000
Binary files a/platform/icons/src/ide/unread_notifications.png and /dev/null differ
diff --git a/platform/icons/src/ide/warning_notifications.png b/platform/icons/src/ide/warning_notifications.png
new file mode 100644 (file)
index 0000000..ac2d621
Binary files /dev/null and b/platform/icons/src/ide/warning_notifications.png differ
index b9e1781c3803d01a4662367a3930f4c285293c5d..a4c3c69429b47159df3ab9213f5b1054e5f249df 100644 (file)
@@ -104,7 +104,8 @@ public class NotificationModel {
 
   private LinkedList<Notification> filterNotifications(@NotNull PairFunction<Notification, Project, Boolean> filter) {
     final LinkedList<Notification> result = new LinkedList<Notification>();
-    final HashSet<Map.Entry<Notification, Pair<Project, Boolean>>> entries = new HashSet<Map.Entry<Notification, Pair<Project, Boolean>>>(myNotifications.entrySet());
+    final HashSet<Map.Entry<Notification, Pair<Project, Boolean>>> entries =
+      new HashSet<Map.Entry<Notification, Pair<Project, Boolean>>>(myNotifications.entrySet());
     for (final Map.Entry<Notification, Pair<Project, Boolean>> entry : entries) {
       if (filter.fun(entry.getKey(), entry.getValue().first)) {
         result.addFirst(entry.getKey());
@@ -183,4 +184,24 @@ public class NotificationModel {
   public boolean hasRead(PairFunction<Notification, Project, Boolean> filter) {
     return getUnreadCount(filter) < myNotifications.size();
   }
+
+  @Nullable
+  public NotificationType getMaximumType(PairFunction<Notification, Project, Boolean> filter) {
+    final LinkedList<Notification> notifications = filterNotifications(filter);
+    NotificationType result = null;
+    for (Notification notification : notifications) {
+      if (NotificationType.ERROR == notification.getType()) {
+        return NotificationType.ERROR;
+      }
+
+      if (NotificationType.WARNING == notification.getType()) {
+        result = NotificationType.WARNING;
+      }
+      else if (result == null && NotificationType.INFORMATION == notification.getType()) {
+        result = NotificationType.INFORMATION;
+      }
+    }
+
+    return result;
+  }
 }
index ac076e5ece210dea1e2597c6fb3afd92f81e293f..5130a80723d72420b334a02acc039a9ac956ff77 100644 (file)
@@ -268,6 +268,11 @@ public class NotificationsManagerImpl extends NotificationsManager implements No
     return myModel.getByType(type, createFilter(project, false));
   }
 
+  @Nullable
+  public NotificationType getMaximumType(@Nullable final Project project) {
+    return myModel.getMaximumType(createFilter(project, false));
+  }
+
   public boolean hasUnread(@Nullable final Project project) {
     return myModel.hasUnread(createFilter(project, false));
   }
index c876faf73e140d5e34ad32046d323155c868e366..29aaf0aadd1e4c11d2e441668052df859a3d0073 100644 (file)
@@ -17,6 +17,7 @@ package com.intellij.notification.impl.ui;
 
 import com.intellij.concurrency.JobScheduler;
 import com.intellij.notification.Notification;
+import com.intellij.notification.NotificationType;
 import com.intellij.notification.impl.*;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.popup.JBPopup;
@@ -39,7 +40,9 @@ import java.util.concurrent.TimeUnit;
 public class NotificationComponent extends JLabel implements NotificationModelListener {
   private static final Icon EMPTY_ICON = IconLoader.getIcon("/ide/notifications.png");
   private static final Icon READ_ICON = IconLoader.getIcon("/ide/read_notifications.png");
-  private static final Icon UNREAD_ICON = IconLoader.getIcon("/ide/unread_notifications.png");
+  private static final Icon ERROR_ICON = IconLoader.getIcon("/ide/error_notifications.png");
+  private static final Icon WARNING_ICON = IconLoader.getIcon("/ide/warning_notifications.png");
+  private static final Icon INFO_ICON = IconLoader.getIcon("/ide/info_notifications.png");
 
   private WeakReference<JBPopup> myPopupRef;
 
@@ -112,11 +115,20 @@ public class NotificationComponent extends JLabel implements NotificationModelLi
     final NotificationsManagerImpl manager = getManager();
 
     Icon icon = EMPTY_ICON;
-    if (manager.hasUnread(getProject())) {
-      icon = UNREAD_ICON;
-    }
-    else if (manager.hasRead(getProject())) {
-      icon = READ_ICON;
+    final NotificationType maximumType = manager.getMaximumType(getProject());
+    if (maximumType != null) {
+      switch (maximumType) {
+        case WARNING:
+          icon = WARNING_ICON;
+          break;
+        case ERROR:
+          icon = ERROR_ICON;
+          break;
+        case INFORMATION:
+        default:
+          icon = INFO_ICON;
+          break;
+      }
     }
 
     myCurrentIcon = new BlinkIconWrapper(icon, false);