Autopsy  4.19.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestRunningLabel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 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.datasourcesummary.uiutils;
20 
21 import java.awt.BorderLayout;
22 import java.beans.PropertyChangeListener;
23 import java.net.URL;
24 import java.util.EnumSet;
25 import java.util.HashSet;
26 import java.util.Set;
27 import javax.swing.ImageIcon;
28 import javax.swing.JLabel;
29 import javax.swing.JPanel;
30 import org.openide.util.NbBundle.Messages;
32 
36 @Messages({
37  "IngestRunningLabel_defaultMessage=Ingest is currently running."
38 })
39 public class IngestRunningLabel extends JPanel {
40 
41  private static final long serialVersionUID = 1L;
42  public static final String DEFAULT_MESSAGE = Bundle.IngestRunningLabel_defaultMessage();
43  private static final URL DEFAULT_ICON = IngestRunningLabel.class.getResource("/org/sleuthkit/autopsy/modules/filetypeid/warning16.png");
44 
45  private static final Set<IngestManager.IngestJobEvent> INGEST_JOB_EVENTS_OF_INTEREST = EnumSet.of(
49  );
50 
51  private static Set<IngestRunningLabel> activeLabels = new HashSet<>();
52  private static PropertyChangeListener classListener = null;
53  private static Object lockObject = new Object();
54 
60  private static void setupListener(IngestRunningLabel label) {
61  synchronized (lockObject) {
62 
63  // if listener is not initialized, initialize it.
64  if (classListener == null) {
65  classListener = (evt) -> {
66  if (evt == null) {
67  return;
68  }
69 
70  if (evt.getPropertyName().equals(IngestManager.IngestJobEvent.STARTED.toString())) {
71  // ingest started
72  notifyListeners(true);
73 
74  } else if (evt.getPropertyName().equals(IngestManager.IngestJobEvent.CANCELLED.toString())
75  || evt.getPropertyName().equals(IngestManager.IngestJobEvent.COMPLETED.toString())) {
76  // ingest cancelled or finished
77  notifyListeners(false);
78 
79  }
80  };
81  IngestManager.getInstance().addIngestJobEventListener(INGEST_JOB_EVENTS_OF_INTEREST, classListener);
82  }
83 
84  // add the item to the set
85  activeLabels.add(label);
86  }
87  }
88 
94  private static void notifyListeners(boolean ingestIsRunning) {
95  synchronized (lockObject) {
96  for (IngestRunningLabel label : activeLabels) {
97  label.refreshState(ingestIsRunning);
98  }
99  }
100  }
101 
107  private static void removeListener(IngestRunningLabel label) {
108  synchronized (lockObject) {
109  activeLabels.remove(label);
110  if (activeLabels.isEmpty() && classListener != null) {
112  classListener = null;
113  }
114  }
115  }
116 
121  this(DEFAULT_MESSAGE, true);
122  }
123 
130  public IngestRunningLabel(String message, boolean showWarningIcon) {
131  JLabel jlabel = new JLabel();
132  jlabel.setText(message);
133 
134  if (showWarningIcon) {
135  jlabel.setIcon(new ImageIcon(DEFAULT_ICON));
136  }
137 
138  setLayout(new BorderLayout());
139  add(jlabel, BorderLayout.NORTH);
140 
141  setupListener(this);
142  refreshState();
143  }
144 
148  protected final void refreshState() {
149  refreshState(IngestManager.getInstance().isIngestRunning());
150  }
151 
157  protected final void refreshState(boolean ingestIsRunning) {
158  setVisible(ingestIsRunning);
159  }
160 
164  public void unregister() {
165  removeListener(this);
166  }
167 }
static synchronized IngestManager getInstance()
void removeIngestJobEventListener(final PropertyChangeListener listener)
void addIngestJobEventListener(final PropertyChangeListener listener)

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