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 javax.swing.JButton;
29 import org.openide.util.NbBundle;
30 import org.openide.windows.Mode;
31 import org.openide.windows.WindowManager;
39 class IngestMessagesToolbar
extends javax.swing.JPanel {
41 private IngestMessagesButton ingestMessagesButton =
new IngestMessagesButton();
42 private static volatile IngestMessagesToolbar instance;
44 private IngestMessagesToolbar() {
46 customizeComponents();
49 public static IngestMessagesToolbar getDefault() {
50 if (instance == null) {
51 synchronized (IngestMessagesToolbar.class) {
52 if (instance == null) {
53 instance =
new IngestMessagesToolbar();
65 @SuppressWarnings(
"unchecked")
67 private
void initComponents() {
69 setToolTipText(
org.openide.util.NbBundle.getMessage(IngestMessagesToolbar.class,
"IngestMessagesToolbar.toolTipText"));
70 setMaximumSize(
new java.awt.Dimension(32767, 25));
71 setPreferredSize(
new java.awt.Dimension(80, 25));
72 setLayout(
new java.awt.BorderLayout());
77 private void customizeButton() {
78 ingestMessagesButton =
new IngestMessagesButton();
80 setMaximumSize(
new java.awt.Dimension(32767, 25));
81 setPreferredSize(
new java.awt.Dimension(80, 25));
83 ingestMessagesButton.setFocusPainted(
false);
84 ingestMessagesButton.setContentAreaFilled(
false);
85 ingestMessagesButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/ingest/eye-bw-25.png")));
86 ingestMessagesButton.setRolloverEnabled(
true);
87 ingestMessagesButton.setRolloverIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/ingest/eye-bw-25-rollover.png")));
88 ingestMessagesButton.setToolTipText(
89 NbBundle.getMessage(
this.getClass(),
"IngestMessagesToolbar.customizeButton.toolTipText"));
90 ingestMessagesButton.setBorder(null);
91 ingestMessagesButton.setBorderPainted(
false);
92 ingestMessagesButton.setEnabled(
false);
93 ingestMessagesButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
94 ingestMessagesButton.setMargin(
new java.awt.Insets(0, 0, 0, 0));
95 ingestMessagesButton.setMaximumSize(
new java.awt.Dimension(38, 24));
96 ingestMessagesButton.setMinimumSize(
new java.awt.Dimension(38, 24));
97 ingestMessagesButton.setPreferredSize(
new java.awt.Dimension(38, 24));
98 ingestMessagesButton.addActionListener((java.awt.event.ActionEvent evt) -> {
99 EventQueue.invokeLater(this::showIngestMessages);
101 this.add(ingestMessagesButton, BorderLayout.CENTER);
104 private void customizeComponents() {
108 this.setBorder(null);
110 IngestMessagePanel.addPropertyChangeSupportListener(
new PropertyChangeListener() {
111 private int numNewMessages = 0;
114 public void propertyChange(PropertyChangeEvent evt) {
116 String propName = evt.getPropertyName();
117 int newNumNewMessages = numNewMessages;
118 if (propName.equals(IngestMessagePanel.MESSAGES_BOX_CLEARED)
119 || propName.equals(IngestMessagePanel.TOTAL_NUM_NEW_MESSAGES_CHANGED)) {
120 newNumNewMessages = (Integer) evt.getNewValue();
123 if (newNumNewMessages != numNewMessages) {
124 ingestMessagesButton.setMessages(newNumNewMessages);
125 numNewMessages = newNumNewMessages;
126 ingestMessagesButton.repaint();
131 Case.addPropertyChangeListener((PropertyChangeEvent evt) -> {
132 if (evt.getPropertyName().equals(Case.Events.CURRENT_CASE.toString())) {
133 setEnabled(evt.getNewValue() != null && RuntimeProperties.runningWithGUI());
141 void showIngestMessages() {
142 IngestMessageTopComponent tc = IngestMessageTopComponent.findInstance();
144 Mode mode = WindowManager.getDefault().findMode(
"floatingLeftBottom");
148 String something = mode.getName();
155 public void setEnabled(
boolean enabled) {
156 super.setEnabled(enabled);
157 ingestMessagesButton.setEnabled(enabled);
173 Font messagesFont = g.getFont().deriveFont(Font.PLAIN, FONT_SIZE);
174 String messageStr = Integer.toString(messages);
175 final int len = messageStr.length();
176 g.setFont(messagesFont);
178 int dx = len * 5 + 5;
179 int x = getSize().width - dx;
183 g.setColor(Color.GRAY);
185 g.fillRoundRect(x, 1, dx, FONT_SIZE, 2, 2);
186 g.setColor(Color.WHITE);
187 g.drawString(messageStr, x + 2, FONT_SIZE);
190 void setMessages(
int messages) {