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

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.