Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
MessageNotifyUtil.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.coreutils;
20 
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
26 import java.util.logging.Level;
27 import javax.swing.Icon;
28 import javax.swing.ImageIcon;
29 import org.openide.DialogDisplayer;
30 import org.openide.NotifyDescriptor;
31 import org.openide.awt.Notification;
32 import org.openide.awt.NotificationDisplayer;
33 import org.openide.util.ImageUtilities;
34 
45 public class MessageNotifyUtil {
46 
47  private MessageNotifyUtil() {
48  }
49 
50  public enum MessageType {
51 
52  INFO(NotifyDescriptor.INFORMATION_MESSAGE, "info-icon-16.png"), //NON-NLS
53  ERROR(NotifyDescriptor.ERROR_MESSAGE, "error-icon-16.png"), //NON-NLS
54  WARNING(NotifyDescriptor.WARNING_MESSAGE, "warning-icon-16.png"); //NON-NLS
55  private int notifyDescriptorType;
56  private Icon icon;
57 
58  private MessageType(int notifyDescriptorType, String resourceName) {
59  this.notifyDescriptorType = notifyDescriptorType;
60  if (resourceName == null) {
61  icon = new ImageIcon();
62  } else {
63  icon = loadIcon(resourceName);
64  }
65  }
66 
67  private static Icon loadIcon(String resourceName) {
68  Icon icon = ImageUtilities.loadImageIcon("org/sleuthkit/autopsy/images/" + resourceName, false); //NON-NLS
69  if (icon == null) {
71  logger.log(Level.SEVERE, "Failed to load icon resource: " + resourceName + ". Using blank image."); //NON-NLS NON-NLS
72  icon = new ImageIcon();
73  }
74  return icon;
75  }
76 
78  return notifyDescriptorType;
79  }
80 
81  Icon getIcon() {
82  return icon;
83  }
84  }
85 
89  public static class Message {
90 
91  private Message() {
92  }
93 
97  public static DialogDisplayer getDialogDisplayer() {
98  return DialogDisplayer.getDefault();
99  }
100 
107  public static void show(String message, MessageType messageType) {
108  getDialogDisplayer().notify(new NotifyDescriptor.Message(message,
109  messageType.getNotifyDescriptorType()));
110  }
111 
117  public static void info(String message) {
118  show(message, MessageType.INFO);
119  }
120 
126  public static void error(String message) {
127  show(message, MessageType.ERROR);
128  }
129 
135  public static void warn(String message) {
136  show(message, MessageType.WARNING);
137  }
138  }
139 
143  public static class Notify {
144 
145  //notifications to keep track of and to reset when case is closed
146  private static final List<Notification> notifications = Collections.synchronizedList(new ArrayList<Notification>());
147 
148  private Notify() {
149  }
150 
155  public static void clear() {
156  for (Notification n : notifications) {
157  n.clear();
158  }
159  notifications.clear();
160  }
161 
165  public static void show(String title, String message, MessageType type, ActionListener actionListener) {
166  Notification newNotification =
167  NotificationDisplayer.getDefault().notify(title, type.getIcon(), message, actionListener);
168  notifications.add(newNotification);
169  }
170 
180  public static void show(String title, final String message, final MessageType type) {
181  ActionListener actionListener = new ActionListener() {
182  @Override
183  public void actionPerformed(ActionEvent e) {
184  MessageNotifyUtil.Message.show(message, type);
185  }
186  };
187 
188  show(title, message, type, actionListener);
189  }
190 
197  public static void info(String title, String message) {
198  show(title, message, MessageType.INFO);
199  }
200 
207  public static void error(String title, String message) {
208  show(title, message, MessageType.ERROR);
209  }
210 
217  public static void warn(String title, String message) {
218  show(title, message, MessageType.WARNING);
219  }
220  }
221 }
MessageType(int notifyDescriptorType, String resourceName)
static void show(String message, MessageType messageType)
static void show(String title, String message, MessageType type, ActionListener actionListener)
static void show(String title, final String message, final MessageType type)
static Logger getLogger(String name)
Definition: Logger.java:131

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.