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

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