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

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