Autopsy  4.21.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-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.corecomponents;
20 
21 import java.awt.Font;
22 import java.awt.GraphicsEnvironment;
23 import java.awt.Insets;
24 import java.beans.PropertyChangeEvent;
25 import java.beans.PropertyChangeListener;
26 import java.util.Collection;
27 import java.util.Enumeration;
28 import java.util.Iterator;
29 import java.util.Map;
30 import java.util.TreeMap;
31 import java.util.logging.Level;
32 import java.util.stream.Stream;
33 import javax.swing.BorderFactory;
34 import javax.swing.ImageIcon;
35 import javax.swing.SwingUtilities;
36 import javax.swing.UIManager;
37 import javax.swing.UIManager.LookAndFeelInfo;
38 import javax.swing.UnsupportedLookAndFeelException;
39 import javax.swing.plaf.FontUIResource;
40 import org.netbeans.spi.sendopts.OptionProcessor;
41 import org.netbeans.swing.tabcontrol.plaf.DefaultTabbedContainerUI;
42 import org.openide.modules.ModuleInstall;
43 import org.openide.util.Lookup;
44 import org.openide.windows.WindowManager;
52 
56 public class Installer extends ModuleInstall {
57 
58  private static final long serialVersionUID = 1L;
59  private static final Logger logger = Logger.getLogger(Installer.class.getName());
60  private static Installer instance;
61 
62  public synchronized static Installer getDefault() {
63  if (null == instance) {
64  instance = new Installer();
65  }
66  return instance;
67  }
68 
69  private Installer() {
70  super();
71  }
72 
73  @Override
74  public void restored() {
75  super.restored();
76  Collection<? extends CommandLineOptionProcessor> optionProcessors = Lookup.getDefault().lookupAll(CommandLineOptionProcessor.class);
77  CommandLineOptionProcessor processor = null;
78  if(!optionProcessors.isEmpty()) {
79  Iterator<? extends CommandLineOptionProcessor> iter = optionProcessors.iterator();
80  while (iter.hasNext() || processor == null) {
81  processor = iter.next();
82  }
83  }
84 
85 
86  if (!GraphicsEnvironment.isHeadless()) {
87  SwingUtilities.invokeLater(() -> {
89  });
90 
91  UIManager.put("ViewTabDisplayerUI", "org.sleuthkit.autopsy.corecomponents.NoTabsTabDisplayerUI");
92  UIManager.put(DefaultTabbedContainerUI.KEY_VIEW_CONTENT_BORDER, BorderFactory.createEmptyBorder());
93  UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0));
94  }
95 
96  final CommandLineOptionProcessor finalprocessor = processor;
97 
103  final boolean crFirstTimeSetup = CRDefaultSetupAction.getInstance().setupDefaultCentralRepository();
104 
105  // When the --nogui flag is supplied invokeWhenUIReady happens a lot sooner
106  // than it would when running wiht the gui. Makes sense. That means that
107  // the starupWindowprovider may get kicked off before the command line
108  // options have been processed. To solve this issue, check to see if
109  // the command line options have been processed if they haven't, wait for them.
110  // Why || instead of &&. If the main window is visible assume that the -nogui
111  // switch was not supplied and that things are running normally.
112  // Why not just listen to the command processor instead of using the invokeWhen?
113  // If there were no command line options supplied then the process method will never
114  // be called.
115  if (GraphicsEnvironment.isHeadless()) {
116  if (finalprocessor.getState() == CommandLineOptionProcessor.ProcessState.COMPLETED) {
118  } else {
119  finalprocessor.addPropertyChangeListener(new PropertyChangeListener() {
120  @Override
121  public void propertyChange(PropertyChangeEvent evt) {
122  if (evt.getPropertyName().equals(CommandLineOptionProcessor.PROCESSING_COMPLETED)) {
124  }
125  }
126  });
127  }
128  } else {
129  WindowManager.getDefault().invokeWhenUIReady(() -> {
130  if(WindowManager.getDefault().getMainWindow().isVisible() || finalprocessor == null || finalprocessor.getState() == CommandLineOptionProcessor.ProcessState.COMPLETED) {
131  showStartupWindows(crFirstTimeSetup);
132  } else {
133  finalprocessor.addPropertyChangeListener(new PropertyChangeListener(){
134  @Override
135  public void propertyChange(PropertyChangeEvent evt) {
136  if(evt.getPropertyName().equals(CommandLineOptionProcessor.PROCESSING_COMPLETED)) {
137  showStartupWindows(crFirstTimeSetup);
138  }
139  }
140  });
141  }
142  });
143  }
144  }
145 
150  private void showStartupWindows(boolean crFirstTimeSetup) {
151  if (crFirstTimeSetup && CentralRepositoryNotificationDialog.shouldDisplay()) {
153  }
154 
156  }
157 
158  @Override
159  public void uninstalled() {
160  super.uninstalled();
161  }
162 
163  private void setLookAndFeel() {
164 
165  ImageIcon questionIcon = new ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/question_32.png"));
166  ImageIcon warningIcon = new ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/warning_32.png"));
167  ImageIcon informationIcon = new ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/information_32.png"));
168  ImageIcon errorIcon = new ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/error_32.png"));
169  UIManager.put("OptionPane.errorIcon", errorIcon);
170  UIManager.put("OptionPane.warningIcon", warningIcon);
171  UIManager.put("OptionPane.questionIcon", questionIcon);
172  UIManager.put("OptionPane.informationIcon", informationIcon);
173 
174  if (System.getProperty("os.name").toLowerCase().contains("mac")) { //NON-NLS
176  setModuleSettings("false");
177  }else if (System.getProperty("os.name").toLowerCase().contains("nux")){
179  }
180  }
181 
187  private void setOSXLookAndFeel() {
188  try {
189  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
190  } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
191  logger.log(Level.WARNING, "Error setting OS-X look-and-feel", ex); //NON-NLS
192  }
193 
194 
195  // Store the keys that deal with menu items
196  final String[] UI_MENU_ITEM_KEYS = new String[]{"MenuBarUI",}; //NON-NLS
197  Map<Object, Object> uiEntries = new TreeMap<>();
198  for (String key : UI_MENU_ITEM_KEYS) {
199  uiEntries.put(key, UIManager.get(key));
200  }
201 
202  // Use Metal if available.
203  for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
204  if ("Nimbus".equals(info.getName())) { //NON-NLS
205  try {
206  UIManager.setLookAndFeel(info.getClassName());
207  } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
208  logger.log(Level.WARNING, "Error setting OS-X look-and-feel", ex); //NON-NLS
209  }
210  break;
211  }
212  }
213 
214  // Overwrite the Metal menu item keys to use the Aqua versions.
215  uiEntries.entrySet().stream().forEach((entry) -> {
216  UIManager.put(entry.getKey(), entry.getValue());
217  });
218  }
219 
220  private static void setUIFont (javax.swing.plaf.FontUIResource f){
221  java.util.Enumeration<Object> keys = UIManager.getDefaults().keys();
222  while (keys.hasMoreElements()) {
223  Object key = keys.nextElement();
224  Object value = UIManager.getDefaults().get(key);
225  if (value instanceof javax.swing.plaf.FontUIResource)
226  UIManager.put(key, f);
227  }
228  }
229 
230  private void setModuleSettings(String value) {
231  if (ModuleSettings.configExists("timeline")) {
232  ModuleSettings.setConfigSetting("timeline", "enable_timeline", value);
233  } else {
234  ModuleSettings.makeConfigFile("timeline");
235  ModuleSettings.setConfigSetting("timeline", "enable_timeline", value);
236  }
237  }
238 
239  private void setUnixLookAndFeel(){
240  try {
241  UIManager.put("swing.boldMetal", Boolean.FALSE);
242  UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
243  setUIFont (new javax.swing.plaf.FontUIResource("DejaVu Sans Condensed", Font.PLAIN, 11));
244  setModuleSettings("true");
245  } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
246  logger.log(Level.WARNING, "Error setting crossplatform look-and-feel, setting default look-and-feel",ex);
247  setModuleSettings("false");
248  }
249  }
250 }
static synchronized boolean makeConfigFile(String moduleName)
void showStartupWindows(boolean crFirstTimeSetup)
Definition: Installer.java:150
static synchronized Installer getDefault()
Definition: Installer.java:62
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static synchronized boolean configExists(String moduleName)
static void setUIFont(javax.swing.plaf.FontUIResource f)
Definition: Installer.java:220
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2024 Sleuth Kit Labs. Generated on: Mon Mar 17 2025
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.