Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
Installer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2016 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.corecomponents;
20 
21 import java.awt.Insets;
22 import java.io.File;
23 import java.util.Collection;
24 import java.util.Map;
25 import java.util.TreeMap;
26 import java.util.logging.Level;
27 import javax.swing.BorderFactory;
28 import javax.swing.UIManager;
29 import javax.swing.UIManager.LookAndFeelInfo;
30 import javax.swing.UnsupportedLookAndFeelException;
31 import org.netbeans.spi.sendopts.OptionProcessor;
32 import org.netbeans.swing.tabcontrol.plaf.DefaultTabbedContainerUI;
33 import org.openide.modules.ModuleInstall;
34 import org.openide.util.Lookup;
35 import org.openide.windows.WindowManager;
40 
44 public class Installer extends ModuleInstall {
45 
46  private static final long serialVersionUID = 1L;
47  private static final Logger logger = Logger.getLogger(Installer.class.getName());
48  private static Installer instance;
49 
50  public synchronized static Installer getDefault() {
51  if (instance == null) {
52  instance = new Installer();
53  }
54  return instance;
55  }
56 
57  private Installer() {
58  super();
59  }
60 
61  @Override
62  public void restored() {
63  super.restored();
64 
66  UIManager.put("ViewTabDisplayerUI", "org.sleuthkit.autopsy.corecomponents.NoTabsTabDisplayerUI");
67  UIManager.put(DefaultTabbedContainerUI.KEY_VIEW_CONTENT_BORDER, BorderFactory.createEmptyBorder());
68  UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0));
69 
70  /*
71  * Open the case if a case metadata file was double-clicked. This only
72  * works if the user has associated files with ".aut" extensions with
73  * Autopsy.
74  */
75  WindowManager.getDefault().invokeWhenUIReady(() -> {
76  Collection<? extends OptionProcessor> processors = Lookup.getDefault().lookupAll(OptionProcessor.class);
77  for (OptionProcessor processor : processors) {
78  if (processor instanceof OpenFromArguments) {
79  OpenFromArguments argsProcessor = (OpenFromArguments) processor;
80  final String caseFile = argsProcessor.getDefaultArg();
81  if (caseFile != null && !caseFile.equals("") && caseFile.endsWith(".aut") && new File(caseFile).exists()) { //NON-NLS
82  new Thread(() -> {
83  try {
84  Case.open(caseFile);
85  } catch (Exception ex) {
86  logger.log(Level.SEVERE, String.format("Error opening case with metadata file path %s", caseFile), ex); //NON-NLS
87  }
88  }).start();
89  return;
90  }
91  }
92  }
94  });
95 
96  }
97 
98  @Override
99  public void uninstalled() {
100  super.uninstalled();
101  }
102 
103  @Override
104  public void close() {
105  new Thread(() -> {
106  String caseDirName = null;
107  try {
108  if (Case.isCaseOpen()) {
109  Case currentCase = Case.getCurrentCase();
110  caseDirName = currentCase.getCaseDirectory();
111  currentCase.closeCase();
112  }
113  } catch (CaseActionException ex) {
114  logger.log(Level.SEVERE, String.format("Error closing case with case directory %s", (null != caseDirName ? caseDirName : "?")), ex); //NON-NLS
115  } catch (IllegalStateException ignored) {
116  /*
117  * No current case. Case.isCaseOpen is not reliable.
118  */
119  }
120  }).start();
121  }
122 
123  private void setLookAndFeel() {
124  if (System.getProperty("os.name").toLowerCase().contains("mac")) { //NON-NLS
126  }
127  }
128 
134  private void setOSXLookAndFeel() {
135  try {
136  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
137  } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
138  logger.log(Level.WARNING, "Error setting OS-X look-and-feel", ex); //NON-NLS
139  }
140 
141  // Store the keys that deal with menu items
142  final String[] UI_MENU_ITEM_KEYS = new String[]{"MenuBarUI",}; //NON-NLS
143  Map<Object, Object> uiEntries = new TreeMap<>();
144  for (String key : UI_MENU_ITEM_KEYS) {
145  uiEntries.put(key, UIManager.get(key));
146  }
147 
148  // Use Metal if available.
149  for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
150  if ("Nimbus".equals(info.getName())) { //NON-NLS
151  try {
152  UIManager.setLookAndFeel(info.getClassName());
153  } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
154  logger.log(Level.WARNING, "Error setting OS-X look-and-feel", ex); //NON-NLS
155  }
156  break;
157  }
158  }
159 
160  // Overwrite the Metal menu item keys to use the Aqua versions.
161  uiEntries.entrySet().stream().forEach((entry) -> {
162  UIManager.put(entry.getKey(), entry.getValue());
163  });
164  }
165 }
static synchronized Installer getDefault()
Definition: Installer.java:50
static void open(String caseMetadataFilePath)
Definition: Case.java:595
synchronized static Logger getLogger(String name)
Definition: Logger.java:166

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.