Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
UpdateRecentCases.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 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.casemodule;
20 
21 import javax.swing.JComponent;
22 import javax.swing.JMenuItem;
23 import javax.swing.JSeparator;
24 import org.openide.awt.DynamicMenuContent;
25 import org.openide.util.NbBundle;
26 import org.openide.util.actions.SystemAction;
27 
31 class UpdateRecentCases extends JMenuItem implements DynamicMenuContent {
32 
33  private static final long serialVersionUID = 1L;
34  private static int NUM_CASES_TO_DISPLAY;
35  private static boolean hasRecentCase = false;
36 
40  UpdateRecentCases() {
41  // display last 5 cases.
42  NUM_CASES_TO_DISPLAY = 5;
43  }
44 
45  static void setHasRecentCase(boolean value) {
46  hasRecentCase = value;
47  }
48 
57  @Override
58  public JComponent[] getMenuPresenters() {
59  String[] caseName = RecentCases.getInstance().getRecentCaseNames();
60  String[] casePath = RecentCases.getInstance().getRecentCasePaths();
61  JComponent[] comps = new JComponent[NUM_CASES_TO_DISPLAY + 2]; // + 2 for separator and clear menu
62 
63  // if it has the recent menus, add them to the component list
64  for (int i = 0; i < NUM_CASES_TO_DISPLAY; i++) {
65  if ((!caseName[i].equals(""))) {
66  JMenuItem menuItem = new JMenuItem(caseName[i]);
67  menuItem.setActionCommand(caseName[i].toUpperCase());
68  menuItem.addActionListener(new RecentItems(caseName[i], casePath[i]));
69  comps[i] = menuItem;
70  hasRecentCase = true;
71  }
72  }
73 
74  // if it has recent case, create clear menu
75  if (hasRecentCase) {
76  comps[NUM_CASES_TO_DISPLAY] = new JSeparator();
77  JMenuItem clearMenu = new JMenuItem(
78  NbBundle.getMessage(UpdateRecentCases.class, "UpdateRecentCases.menuItem.clearRecentCases.text"));
79  clearMenu.addActionListener(SystemAction.get(RecentCases.class));
80  comps[NUM_CASES_TO_DISPLAY + 1] = clearMenu;
81  } // otherwise, just create a disabled empty menu
82  else {
83  comps = new JComponent[1];
84  JMenuItem emptyMenu = new JMenuItem(NbBundle.getMessage(UpdateRecentCases.class, "UpdateRecentCases.menuItem.empty"));
85  emptyMenu.addActionListener(new RecentItems("", ""));
86  comps[0] = emptyMenu;
87  comps[0].setEnabled(false);
88  }
89  return comps;
90  }
91 
100  @Override
101  public JComponent[] synchMenuPresenters(JComponent[] menuItems) {
102  return getMenuPresenters();
103  }
104 }

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.