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

Copyright © 2012-2016 Basis Technology. Generated on: Tue Oct 25 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.