Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestMessagesToolbar.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 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.ingest;
20 
21 import java.awt.BorderLayout;
22 import java.awt.Color;
23 import java.awt.EventQueue;
24 import java.awt.Font;
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;
35 
40 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
41 class IngestMessagesToolbar extends javax.swing.JPanel {
42 
43  private IngestMessagesButton ingestMessagesButton = new IngestMessagesButton();
44  private static volatile IngestMessagesToolbar instance;
45 
46  private IngestMessagesToolbar() {
47  initComponents();
48  customizeComponents();
49  }
50 
51  public static IngestMessagesToolbar getDefault() {
52  if (instance == null) {
53  synchronized (IngestMessagesToolbar.class) {
54  if (instance == null) {
55  instance = new IngestMessagesToolbar();
56  }
57  }
58  }
59  return instance;
60  }
61 
67  @SuppressWarnings("unchecked")
68  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
69  private void initComponents() {
70 
71  setToolTipText(org.openide.util.NbBundle.getMessage(IngestMessagesToolbar.class, "IngestMessagesToolbar.toolTipText")); // NOI18N
72  setMaximumSize(new java.awt.Dimension(32767, 25));
73  setPreferredSize(new java.awt.Dimension(80, 25));
74  setLayout(new java.awt.BorderLayout());
75  }// </editor-fold>//GEN-END:initComponents
76 
77  // Variables declaration - do not modify//GEN-BEGIN:variables
78  // End of variables declaration//GEN-END:variables
79  private void customizeButton() {
80  ingestMessagesButton = new IngestMessagesButton();
81 
82  setMaximumSize(new java.awt.Dimension(32767, 25));
83  setPreferredSize(new java.awt.Dimension(80, 25));
84 
85  ingestMessagesButton.setFocusPainted(false);
86  ingestMessagesButton.setContentAreaFilled(false);
87  ingestMessagesButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/ingest/mail24.png"))); //NON-NLS
88  ingestMessagesButton.setRolloverEnabled(true);
89  ingestMessagesButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/ingest/mail24-rollover.png"))); //NON-NLS
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);
102  });
103  this.add(ingestMessagesButton, BorderLayout.CENTER);
104  }
105 
106  private void customizeComponents() {
107 
108  customizeButton();
109 
110  this.setBorder(null);
111 
112  IngestMessagePanel.addPropertyChangeSupportListener(new PropertyChangeListener() {
113  private int numNewMessages = 0;
114 
115  @Override
116  public void propertyChange(PropertyChangeEvent evt) {
117 
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();
123  }
124 
125  if (newNumNewMessages != numNewMessages) {
126  ingestMessagesButton.setMessages(newNumNewMessages);
127  numNewMessages = newNumNewMessages;
128  ingestMessagesButton.repaint();
129  }
130  }
131  });
132 
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());
136  }
137  });
138  }
139 
143  void showIngestMessages() {
144  IngestMessageTopComponent tc = IngestMessageTopComponent.findInstance();
145 
146  Mode mode = WindowManager.getDefault().findMode("floatingLeftBottom"); //NON-NLS
147  if (mode != null) {
148  //TopComponent[] tcs = mode.getTopComponents();
149  mode.dockInto(tc);
150  String something = mode.getName();
151  tc.open();
152  //tc.requestActive();
153  }
154  }
155 
156  @Override
157  public void setEnabled(boolean enabled) {
158  super.setEnabled(enabled);
159  ingestMessagesButton.setEnabled(enabled);
160  }
161 
162  private static class IngestMessagesButton extends JButton {
163 
164  private static final int FONT_SIZE = 9;
165  private int messages = 0;
166 
167  @Override
168  public void paint(Graphics g) {
169  super.paint(g);
170 
171  if (messages == 0) {
172  return;
173  }
174  //paint text
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);
179 
180  int dx = len * 5 + 5;
181  int x = getSize().width - dx;
182  if (x < 0) {
183  x = 0;
184  }
185  g.setColor(Color.GRAY);
186  //g.fillRect(x, 1, dx, fontSize);
187  g.fillRoundRect(x, 1, dx, FONT_SIZE, 2, 2);
188  g.setColor(Color.WHITE);
189  g.drawString(messageStr, x + 2, FONT_SIZE);
190  }
191 
192  void setMessages(int messages) {
193  this.messages = messages;
194  }
195  }
196 }

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