19 package org.sleuthkit.autopsy.corecomponents;
21 import java.awt.Cursor;
22 import java.beans.PropertyChangeEvent;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.List;
26 import java.util.concurrent.ExecutionException;
27 import java.util.logging.Level;
28 import javax.swing.JTabbedPane;
29 import javax.swing.SwingWorker;
30 import javax.swing.event.ChangeEvent;
31 import javax.swing.event.ChangeListener;
32 import org.openide.nodes.Node;
33 import org.openide.util.Lookup;
34 import org.openide.util.NbBundle;
45 @SuppressWarnings(
"PMD.SingularField")
49 private final List<UpdateWrapper> viewers =
new ArrayList<>();
52 private boolean listeningToTabbedPane =
false;
70 Collection<? extends DataContentViewer> dcvs = Lookup.getDefault().lookupAll(
DataContentViewer.class);
80 javax.swing.JScrollPane scrollTab =
new javax.swing.JScrollPane(dcv.
getComponent());
81 scrollTab.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_NEVER);
82 jTabbedPane1.addTab(dcv.
getTitle(), null,
87 int numTabs = jTabbedPane1.getTabCount();
88 for (
int tab = 0; tab < numTabs; ++tab) {
89 jTabbedPane1.setEnabledAt(tab,
false);
112 @SuppressWarnings(
"unchecked")
114 private
void initComponents() {
116 jTabbedPane1 =
new javax.swing.JTabbedPane();
118 setMinimumSize(
new java.awt.Dimension(5, 5));
120 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
121 this.setLayout(layout);
122 layout.setHorizontalGroup(
123 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
124 .addComponent(jTabbedPane1)
126 layout.setVerticalGroup(
127 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
128 .addComponent(jTabbedPane1)
138 if (workerThread != null) {
139 workerThread.cancel(
true);
146 for (
int index = 0; index < jTabbedPane1.getTabCount(); index++) {
147 jTabbedPane1.setEnabledAt(index,
false);
148 String tabTitle = viewers.get(index).getTitle(selectedNode);
149 tabTitle = tabTitle == null ?
"" : tabTitle;
150 if (!tabTitle.equals(jTabbedPane1.getTitleAt(index))) {
151 jTabbedPane1.setTitleAt(index, tabTitle);
154 viewers.get(index).resetComponent();
157 if (selectedNode != null) {
159 workerThread.execute();
171 private void updateTabs(Node selectedNode, List<Integer> supportedIndices,
int preferredIndex) {
174 if (listeningToTabbedPane ==
false) {
175 jTabbedPane1.addChangeListener(
this);
176 listeningToTabbedPane =
true;
179 for (Integer index : supportedIndices) {
180 jTabbedPane1.setEnabledAt(index,
true);
188 if (jTabbedPane1.isEnabledAt(tabIndex) ==
false) {
189 dcv.resetComponent();
191 dcv.setNode(selectedNode);
195 jTabbedPane1.setSelectedIndex(tabIndex);
196 jTabbedPane1.getSelectedComponent().repaint();
205 JTabbedPane pane = (JTabbedPane) evt.getSource();
208 int currentTab = pane.getSelectedIndex();
209 if (currentTab != -1) {
213 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
215 dcv.setNode(currentNode);
217 this.setCursor(null);
229 this.wrapped = wrapped;
230 this.outdated =
true;
233 void setNode(Node selectedNode) {
234 this.wrapped.
setNode(selectedNode);
235 this.outdated =
false;
238 void resetComponent() {
240 this.outdated =
true;
243 boolean isOutdated() {
244 return this.outdated;
247 boolean isSupported(Node node) {
251 int isPreferred(Node node) {
255 String getTitle(Node node) {
259 DataContentViewer getViewer() {
284 List<Integer> supportedViewers =
new ArrayList<>();
285 int preferredViewerIndex = 0;
286 int maxPreferred = 0;
288 for (
int index = 0; index < viewers.size(); index++) {
290 if (dcv.isSupported(node)) {
291 supportedViewers.add(index);
293 int currentPreferred = dcv.isPreferred(node);
294 if (currentPreferred > maxPreferred) {
295 preferredViewerIndex = index;
296 maxPreferred = currentPreferred;
300 if (this.isCancelled()) {
306 return new WorkerResults(node, supportedViewers, preferredViewerIndex);
319 if (results != null) {
320 updateTabs(results.getNode(), results.getSupportedIndices(), results.getPreferredViewerIndex());
323 }
catch (InterruptedException | ExecutionException ex) {
324 logger.log(Level.SEVERE,
"Failed to updated data content panel for node " + node.getName(), ex);
326 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
340 WorkerResults(Node node, List<Integer> supportedViewerIndices,
int preferredViewerIndex) {
342 this.supportedViewerIndices = supportedViewerIndices;
343 this.preferredViewerIndex = preferredViewerIndex;
360 List<Integer> getSupportedIndices() {
361 return supportedViewerIndices;
369 int getPreferredViewerIndex() {
370 return preferredViewerIndex;
boolean isSupported(Node node)
void setNode(Node selectedNode)
void setNode(Node selectedNode)
final List< Integer > supportedViewerIndices
WorkerResults doInBackground()
void stateChanged(ChangeEvent evt)
javax.swing.JTabbedPane jTabbedPane1
static boolean keepPreferredContentViewer()
JTabbedPane getTabPanels()
final DataContentViewer wrapped
final int preferredViewerIndex
static DataContentPanel createInstance()
void updateTabs(Node selectedNode, List< Integer > supportedIndices, int preferredIndex)
DataContentPanelWorker workerThread
void propertyChange(PropertyChangeEvent evt)
synchronized static Logger getLogger(String name)
int isPreferred(Node node)
DataContentViewer createInstance()