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

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