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

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.