Autopsy  4.19.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.util.Map;
24 import java.util.TreeMap;
25 import java.util.logging.Level;
26 import javax.swing.BorderFactory;
27 import javax.swing.ImageIcon;
28 import javax.swing.SwingUtilities;
29 import javax.swing.UIManager;
30 import javax.swing.UIManager.LookAndFeelInfo;
31 import javax.swing.UnsupportedLookAndFeelException;
32 import org.netbeans.swing.tabcontrol.plaf.DefaultTabbedContainerUI;
33 import org.openide.modules.ModuleInstall;
34 import org.openide.windows.WindowManager;
38 
42 public class Installer extends ModuleInstall {
43 
44  private static final long serialVersionUID = 1L;
45  private static final Logger logger = Logger.getLogger(Installer.class.getName());
46  private static Installer instance;
47 
48  public synchronized static Installer getDefault() {
49  if (null == instance) {
50  instance = new Installer();
51  }
52  return instance;
53  }
54 
55  private Installer() {
56  super();
57  }
58 
59  @Override
60  public void restored() {
61  super.restored();
62  SwingUtilities.invokeLater(() -> {
63  setLookAndFeel();
64  });
65  UIManager.put("ViewTabDisplayerUI", "org.sleuthkit.autopsy.corecomponents.NoTabsTabDisplayerUI");
66  UIManager.put(DefaultTabbedContainerUI.KEY_VIEW_CONTENT_BORDER, BorderFactory.createEmptyBorder());
67  UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0));
68  WindowManager.getDefault().invokeWhenUIReady(() -> {
70  });
71  }
72 
73  @Override
74  public void uninstalled() {
75  super.uninstalled();
76  }
77 
78  private void setLookAndFeel() {
79 
80  ImageIcon questionIcon = new ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/question_32.png"));
81  ImageIcon warningIcon = new ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/warning_32.png"));
82  ImageIcon informationIcon = new ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/information_32.png"));
83  ImageIcon errorIcon = new ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/error_32.png"));
84  UIManager.put("OptionPane.errorIcon", errorIcon);
85  UIManager.put("OptionPane.warningIcon", warningIcon);
86  UIManager.put("OptionPane.questionIcon", questionIcon);
87  UIManager.put("OptionPane.informationIcon", informationIcon);
88 
89  if (System.getProperty("os.name").toLowerCase().contains("mac")) { //NON-NLS
91  setModuleSettings("false");
92  }else if (System.getProperty("os.name").toLowerCase().contains("nux")){
94  }
95  }
96 
102  private void setOSXLookAndFeel() {
103  try {
104  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
105  } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
106  logger.log(Level.WARNING, "Error setting OS-X look-and-feel", ex); //NON-NLS
107  }
108 
109 
110  // Store the keys that deal with menu items
111  final String[] UI_MENU_ITEM_KEYS = new String[]{"MenuBarUI",}; //NON-NLS
112  Map<Object, Object> uiEntries = new TreeMap<>();
113  for (String key : UI_MENU_ITEM_KEYS) {
114  uiEntries.put(key, UIManager.get(key));
115  }
116 
117  // Use Metal if available.
118  for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
119  if ("Nimbus".equals(info.getName())) { //NON-NLS
120  try {
121  UIManager.setLookAndFeel(info.getClassName());
122  } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
123  logger.log(Level.WARNING, "Error setting OS-X look-and-feel", ex); //NON-NLS
124  }
125  break;
126  }
127  }
128 
129  // Overwrite the Metal menu item keys to use the Aqua versions.
130  uiEntries.entrySet().stream().forEach((entry) -> {
131  UIManager.put(entry.getKey(), entry.getValue());
132  });
133  }
134 
135  private static void setUIFont (javax.swing.plaf.FontUIResource f){
136  java.util.Enumeration<Object> keys = UIManager.getDefaults().keys();
137  while (keys.hasMoreElements()) {
138  Object key = keys.nextElement();
139  Object value = UIManager.getDefaults().get(key);
140  if (value instanceof javax.swing.plaf.FontUIResource)
141  UIManager.put(key, f);
142  }
143  }
144 
145  private void setModuleSettings(String value) {
146  if (ModuleSettings.configExists("timeline")) {
147  ModuleSettings.setConfigSetting("timeline", "enable_timeline", value);
148  } else {
149  ModuleSettings.makeConfigFile("timeline");
150  ModuleSettings.setConfigSetting("timeline", "enable_timeline", value);
151  }
152  }
153 
154  private void setUnixLookAndFeel(){
155  try {
156  UIManager.put("swing.boldMetal", Boolean.FALSE);
157  UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
158  setUIFont (new javax.swing.plaf.FontUIResource("DejaVu Sans Condensed", Font.PLAIN, 11));
159  setModuleSettings("true");
160  } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
161  logger.log(Level.WARNING, "Error setting crossplatform look-and-feel, setting default look-and-feel",ex);
162  setModuleSettings("false");
163  }
164  }
165 }
static synchronized boolean makeConfigFile(String moduleName)
static synchronized Installer getDefault()
Definition: Installer.java:48
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:135
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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