Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataContentDynamicMenu.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2021 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.menuactions;
20 
21 import java.util.List;
22 import javax.swing.JComponent;
23 import javax.swing.JMenu;
24 import javax.swing.JMenuItem;
25 import org.openide.awt.DynamicMenuContent;
26 import org.openide.util.NbBundle;
27 import org.openide.windows.TopComponent;
31 
36 class DataContentDynamicMenu extends JMenuItem implements DynamicMenuContent {
37 
38  private static final long serialVersionUID = 1L;
39 
40  @NbBundle.Messages({"DataContentDynamicMenu.mainContentViewer.name=Main",
41  "DataContentDynamicMenu.contentViewers.text=Content Viewers"})
42  @Override
43  public JComponent[] getMenuPresenters() {
44  JMenu submenu = new JMenu(Bundle.DataContentDynamicMenu_contentViewers_text());
45  if (Case.isCaseOpen()) {
46 
47  List<DataContentTopComponent> newWindowLists = DataContentTopComponent.getNewWindowList();
48 
49  TopComponent contentWin = DataContentTopComponent.findInstance();
50  JMenuItem defaultItem = new JMenuItem(Bundle.DataContentDynamicMenu_mainContentViewer_name()); // set the main name
51  defaultItem.addActionListener(new OpenTopComponentAction(contentWin));
52  try {
53  Case currentCase = Case.getCurrentCaseThrows();
54  defaultItem.setEnabled(currentCase.hasData());
55  } catch (NoCurrentCaseException ex) {
56  defaultItem.setEnabled(false); // disable the menu when no case is opened
57  }
58  submenu.add(defaultItem);
59  // add the submenu
60  if (!newWindowLists.isEmpty()) {
61  for (int i = 0; i < newWindowLists.size(); i++) {
62  DataContentTopComponent dctc = newWindowLists.get(i);
63  JMenuItem item = new JMenuItem(dctc.getName());
64  item.addActionListener(new OpenTopComponentAction(dctc));
65  submenu.add(item);
66  }
67  }
68 
69  }
70  submenu.setEnabled(submenu.getItemCount() > 0);
71  JComponent[] comps = new JComponent[1];
72  comps[0] = submenu;
73  return comps;
74  }
75 
76  @Override
77  public JComponent[] synchMenuPresenters(JComponent[] jcs) {
78  return getMenuPresenters();
79  }
80 
81  @Override
82  public boolean isEnabled() {
83  return Case.isCaseOpen();
84  }
85 }
static synchronized DataContentTopComponent findInstance()

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.