Autopsy 4.22.1
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 */
19package org.sleuthkit.autopsy.datasourcesummary.uiutils;
20
21import java.awt.BorderLayout;
22import java.beans.PropertyChangeListener;
23import java.net.URL;
24import java.util.EnumSet;
25import java.util.HashSet;
26import java.util.Set;
27import javax.swing.ImageIcon;
28import javax.swing.JLabel;
29import javax.swing.JPanel;
30import org.openide.util.NbBundle.Messages;
31import org.sleuthkit.autopsy.ingest.IngestManager;
32
36@Messages({
37 "IngestRunningLabel_defaultMessage=Ingest is currently running."
38})
39public 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 };
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() {
150 }
151
157 protected final void refreshState(boolean ingestIsRunning) {
158 setVisible(ingestIsRunning);
159 }
160
164 public void unregister() {
165 removeListener(this);
166 }
167}
static final Set< IngestManager.IngestJobEvent > INGEST_JOB_EVENTS_OF_INTEREST
static synchronized IngestManager getInstance()
void removeIngestJobEventListener(final PropertyChangeListener listener)
void addIngestJobEventListener(final PropertyChangeListener listener)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.