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 class IngestMessagesToolbar
extends javax.swing.JPanel {
42 private IngestMessagesButton ingestMessagesButton =
new IngestMessagesButton();
43 private static volatile IngestMessagesToolbar instance;
45 private IngestMessagesToolbar() {
47 customizeComponents();
50 public static IngestMessagesToolbar getDefault() {
51 if (instance == null) {
52 synchronized (IngestMessagesToolbar.class) {
53 if (instance == null) {
54 instance =
new IngestMessagesToolbar();
66 @SuppressWarnings(
"unchecked")
68 private
void initComponents() {
70 setToolTipText(
org.openide.util.NbBundle.getMessage(IngestMessagesToolbar.class,
"IngestMessagesToolbar.toolTipText"));
71 setMaximumSize(
new java.awt.Dimension(32767, 25));
72 setPreferredSize(
new java.awt.Dimension(80, 25));
73 setLayout(
new java.awt.BorderLayout());
78 private void customizeButton() {
79 ingestMessagesButton =
new IngestMessagesButton();
81 setMaximumSize(
new java.awt.Dimension(32767, 25));
82 setPreferredSize(
new java.awt.Dimension(80, 25));
84 ingestMessagesButton.setFocusPainted(
false);
85 ingestMessagesButton.setContentAreaFilled(
false);
86 ingestMessagesButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/ingest/eye-bw-25.png")));
87 ingestMessagesButton.setRolloverEnabled(
true);
88 ingestMessagesButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/ingest/eye-bw-25-rollover.png")));
89 ingestMessagesButton.setToolTipText(
90 NbBundle.getMessage(
this.getClass(),
"IngestMessagesToolbar.customizeButton.toolTipText"));
91 ingestMessagesButton.setBorder(null);
92 ingestMessagesButton.setBorderPainted(
false);
93 ingestMessagesButton.setEnabled(
false);
94 ingestMessagesButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
95 ingestMessagesButton.setMargin(
new java.awt.Insets(0, 0, 0, 0));
96 ingestMessagesButton.setMaximumSize(
new java.awt.Dimension(38, 24));
97 ingestMessagesButton.setMinimumSize(
new java.awt.Dimension(38, 24));
98 ingestMessagesButton.setPreferredSize(
new java.awt.Dimension(38, 24));
99 ingestMessagesButton.addActionListener((java.awt.event.ActionEvent evt) -> {
100 EventQueue.invokeLater(this::showIngestMessages);
102 this.add(ingestMessagesButton, BorderLayout.CENTER);
105 private void customizeComponents() {
109 this.setBorder(null);
111 IngestMessagePanel.addPropertyChangeSupportListener(
new PropertyChangeListener() {
112 private int numNewMessages = 0;
115 public void propertyChange(PropertyChangeEvent evt) {
117 String propName = evt.getPropertyName();
118 int newNumNewMessages = numNewMessages;
119 if (propName.equals(IngestMessagePanel.MESSAGES_BOX_CLEARED)
120 || propName.equals(IngestMessagePanel.TOTAL_NUM_NEW_MESSAGES_CHANGED)) {
121 newNumNewMessages = (Integer) evt.getNewValue();
124 if (newNumNewMessages != numNewMessages) {
125 ingestMessagesButton.setMessages(newNumNewMessages);
126 numNewMessages = newNumNewMessages;
127 ingestMessagesButton.repaint();
132 Case.addEventTypeSubscriber(EnumSet.of(Case.Events.CURRENT_CASE), (PropertyChangeEvent evt) -> {
133 if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) {
134 setEnabled(evt.getNewValue() != null && RuntimeProperties.runningWithGUI());
142 void showIngestMessages() {
143 IngestMessageTopComponent tc = IngestMessageTopComponent.findInstance();
145 Mode mode = WindowManager.getDefault().findMode(
"floatingLeftBottom");
149 String something = mode.getName();
156 public void setEnabled(
boolean enabled) {
157 super.setEnabled(enabled);
158 ingestMessagesButton.setEnabled(enabled);
174 Font messagesFont = g.getFont().deriveFont(Font.PLAIN, FONT_SIZE);
175 String messageStr = Integer.toString(messages);
176 final int len = messageStr.length();
177 g.setFont(messagesFont);
179 int dx = len * 5 + 5;
180 int x = getSize().width - dx;
184 g.setColor(Color.GRAY);
186 g.fillRoundRect(x, 1, dx, FONT_SIZE, 2, 2);
187 g.setColor(Color.WHITE);
188 g.drawString(messageStr, x + 2, FONT_SIZE);
191 void setMessages(
int messages) {