19 package org.sleuthkit.autopsy.ingest;
21 import java.awt.BorderLayout;
22 import java.awt.Color;
23 import java.awt.EventQueue;
25 import java.awt.Graphics;
26 import java.beans.PropertyChangeEvent;
27 import java.beans.PropertyChangeListener;
28 import java.util.EnumSet;
29 import javax.swing.JButton;
30 import org.openide.util.NbBundle;
31 import org.openide.windows.Mode;
32 import org.openide.windows.WindowManager;
40 @SuppressWarnings(
"PMD.SingularField")
41 class IngestMessagesToolbar extends javax.swing.JPanel {
43 private IngestMessagesButton ingestMessagesButton =
new IngestMessagesButton();
44 private static volatile IngestMessagesToolbar instance;
46 private IngestMessagesToolbar() {
48 customizeComponents();
51 public static IngestMessagesToolbar getDefault() {
52 if (instance == null) {
53 synchronized (IngestMessagesToolbar.class) {
54 if (instance == null) {
55 instance =
new IngestMessagesToolbar();
67 @SuppressWarnings(
"unchecked")
69 private
void initComponents() {
71 setToolTipText(
org.openide.util.NbBundle.getMessage(IngestMessagesToolbar.class,
"IngestMessagesToolbar.toolTipText"));
72 setMaximumSize(
new java.awt.Dimension(32767, 25));
73 setPreferredSize(
new java.awt.Dimension(80, 25));
74 setLayout(
new java.awt.BorderLayout());
79 private void customizeButton() {
80 ingestMessagesButton =
new IngestMessagesButton();
82 setMaximumSize(
new java.awt.Dimension(32767, 25));
83 setPreferredSize(
new java.awt.Dimension(80, 25));
85 ingestMessagesButton.setFocusPainted(
false);
86 ingestMessagesButton.setContentAreaFilled(
false);
87 ingestMessagesButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/ingest/mail24.png")));
88 ingestMessagesButton.setRolloverEnabled(
true);
89 ingestMessagesButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/ingest/mail24-rollover.png")));
90 ingestMessagesButton.setToolTipText(
91 NbBundle.getMessage(
this.getClass(),
"IngestMessagesToolbar.customizeButton.toolTipText"));
92 ingestMessagesButton.setBorder(null);
93 ingestMessagesButton.setBorderPainted(
false);
94 ingestMessagesButton.setEnabled(
false);
95 ingestMessagesButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
96 ingestMessagesButton.setMargin(
new java.awt.Insets(0, 0, 0, 0));
97 ingestMessagesButton.setMaximumSize(
new java.awt.Dimension(52, 24));
98 ingestMessagesButton.setMinimumSize(
new java.awt.Dimension(52, 24));
99 ingestMessagesButton.setPreferredSize(
new java.awt.Dimension(52, 24));
100 ingestMessagesButton.addActionListener((java.awt.event.ActionEvent evt) -> {
101 EventQueue.invokeLater(this::showIngestMessages);
103 this.add(ingestMessagesButton, BorderLayout.CENTER);
106 private void customizeComponents() {
110 this.setBorder(null);
112 IngestMessagePanel.addPropertyChangeSupportListener(
new PropertyChangeListener() {
113 private int numNewMessages = 0;
116 public void propertyChange(PropertyChangeEvent evt) {
118 String propName = evt.getPropertyName();
119 int newNumNewMessages = numNewMessages;
120 if (propName.equals(IngestMessagePanel.MESSAGES_BOX_CLEARED)
121 || propName.equals(IngestMessagePanel.TOTAL_NUM_NEW_MESSAGES_CHANGED)) {
122 newNumNewMessages = (Integer) evt.getNewValue();
125 if (newNumNewMessages != numNewMessages) {
126 ingestMessagesButton.setMessages(newNumNewMessages);
127 numNewMessages = newNumNewMessages;
128 ingestMessagesButton.repaint();
133 Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), (PropertyChangeEvent evt) -> {
134 if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) {
135 setEnabled(evt.getNewValue() != null && RuntimeProperties.runningWithGUI());
143 void showIngestMessages() {
144 IngestMessageTopComponent tc = IngestMessageTopComponent.findInstance();
146 Mode mode = WindowManager.getDefault().findMode(
"floatingLeftBottom");
150 String something = mode.getName();
157 public void setEnabled(
boolean enabled) {
158 super.setEnabled(enabled);
159 ingestMessagesButton.setEnabled(enabled);
164 private static final int FONT_SIZE = 9;
165 private int messages = 0;
175 Font messagesFont = g.getFont().deriveFont(Font.PLAIN, FONT_SIZE);
176 String messageStr = Integer.toString(messages);
177 final int len = messageStr.length();
178 g.setFont(messagesFont);
180 int dx = len * 5 + 5;
181 int x = getSize().width - dx;
185 g.setColor(Color.GRAY);
187 g.fillRoundRect(x, 1, dx, FONT_SIZE, 2, 2);
188 g.setColor(Color.WHITE);
189 g.drawString(messageStr, x + 2, FONT_SIZE);
192 void setMessages(
int messages) {
193 this.messages = messages;