From 1d56106d6ef100c6f01844638ebaa026f4e7bdee Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Thu, 28 Jan 2016 16:58:01 -0500 Subject: [PATCH] Tidy up corecomponents.Installer --- .../sleuthkit/autopsy/casemodule/Case.java | 7 +--- .../autopsy/casemodule/CaseOpenAction.java | 9 +++-- .../autopsy/corecomponents/Installer.java | 37 ++++++++----------- 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java index 71906df653..fbf53a99fc 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/Case.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/Case.java @@ -554,11 +554,7 @@ public class Case implements SleuthkitCase.ErrorObserver { * * @throws CaseActionException */ - /** - * TODO: Deprecate this and throw a more general exception. - */ public static void open(String caseMetadataFilePath) throws CaseActionException { - if (!caseMetadataFilePath.endsWith(CASE_DOT_EXTENSION)) { throw new CaseActionException(NbBundle.getMessage(Case.class, "Case.open.exception.checkFile.msg", CASE_DOT_EXTENSION)); } @@ -590,8 +586,7 @@ public class Case implements SleuthkitCase.ErrorObserver { db = SleuthkitCase.openCase(metadata.getCaseDatabaseName(), UserPreferences.getDatabaseConnectionInfo(), caseDir); } catch (UserPreferencesException ex) { logger.log(Level.SEVERE, "Error accessing case database connection info", ex); //NON-NLS - throw new CaseActionException( - NbBundle.getMessage(Case.class, "Case.databaseConnectionInfo.error.msg"), ex); + throw new CaseActionException(NbBundle.getMessage(Case.class, "Case.databaseConnectionInfo.error.msg"), ex); } } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/CaseOpenAction.java b/Core/src/org/sleuthkit/autopsy/casemodule/CaseOpenAction.java index 7c5a5ca9e0..5ea268adf4 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/CaseOpenAction.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/CaseOpenAction.java @@ -45,6 +45,7 @@ import org.sleuthkit.autopsy.ingest.IngestManager; @ServiceProvider(service = CaseOpenAction.class) public final class CaseOpenAction implements ActionListener { + private static final Logger logger = Logger.getLogger(CaseOpenAction.class.getName()); private static final String PROP_BASECASE = "LBL_BaseCase_PATH"; //NON-NLS private final JFileChooser fileChooser = new JFileChooser(); private final FileFilter caseMetadataFileFilter; @@ -71,7 +72,6 @@ public final class CaseOpenAction implements ActionListener { */ @Override public void actionPerformed(ActionEvent e) { - /* * If ingest is running, do a dialog to warn the user and confirm * abandoning the ingest. @@ -87,7 +87,7 @@ public final class CaseOpenAction implements ActionListener { try { Case.getCurrentCase().closeCase(); } catch (Exception ex) { - Logger.getLogger(NewCaseWizardAction.class.getName()).log(Level.WARNING, "Error closing case", ex); //NON-NLS + logger.log(Level.SEVERE, "Error closing case", ex); //NON-NLS } } else { return; @@ -121,10 +121,11 @@ public final class CaseOpenAction implements ActionListener { try { Case.open(path); } catch (CaseActionException ex) { + logger.log(Level.SEVERE, String.format("Could not open case at %s", path), ex); SwingUtilities.invokeLater(() -> { WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), ex.getMessage() + " " - + NbBundle.getMessage(this.getClass(), "CaseExceptionWarning.CheckMultiUserOptions"), + JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), + ex.getMessage(), NbBundle.getMessage(this.getClass(), "CaseOpenAction.msgDlg.cantOpenCase.title"), JOptionPane.ERROR_MESSAGE); //NON-NLS if (!Case.isCaseOpen()) { StartupWindowProvider.getInstance().open(); diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/Installer.java b/Core/src/org/sleuthkit/autopsy/corecomponents/Installer.java index c2e989635e..d6c641734e 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/Installer.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/Installer.java @@ -1,7 +1,7 @@ /* * Autopsy Forensic Browser * - * Copyright 2011-2015 Basis Technology Corp. + * Copyright 2011-2016 Basis Technology Corp. * Contact: carrier sleuthkit org * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -43,8 +43,9 @@ import org.sleuthkit.autopsy.coreutils.Logger; */ public class Installer extends ModuleInstall { - private static Installer instance; + private static final long serialVersionUID = 1L; private static final Logger logger = Logger.getLogger(Installer.class.getName()); + private static Installer instance; public synchronized static Installer getDefault() { if (instance == null) { @@ -61,13 +62,15 @@ public class Installer extends ModuleInstall { public void restored() { super.restored(); - setupLAF(); + setLookAndFeel(); UIManager.put("ViewTabDisplayerUI", "org.sleuthkit.autopsy.corecomponents.NoTabsTabDisplayerUI"); UIManager.put(DefaultTabbedContainerUI.KEY_VIEW_CONTENT_BORDER, BorderFactory.createEmptyBorder()); UIManager.put("TabbedPane.contentBorderInsets", new Insets(0, 0, 0, 0)); /* - * Open the passed in case, if an aut file was double clicked. + * Open the case if a case metadata file was double-clicked. This only + * works if the user has associated files with ".aut" extensions with + * Autopsy. */ WindowManager.getDefault().invokeWhenUIReady(() -> { Collection processors = Lookup.getDefault().lookupAll(OptionProcessor.class); @@ -77,11 +80,10 @@ public class Installer extends ModuleInstall { final String caseFile = argsProcessor.getDefaultArg(); if (caseFile != null && !caseFile.equals("") && caseFile.endsWith(".aut") && new File(caseFile).exists()) { //NON-NLS new Thread(() -> { - // Create case. try { Case.open(caseFile); } catch (Exception ex) { - logger.log(Level.SEVERE, "Error opening case: ", ex); //NON-NLS + logger.log(Level.SEVERE, "Error opening case", ex); //NON-NLS } }).start(); return; @@ -105,22 +107,16 @@ public class Installer extends ModuleInstall { if (Case.isCaseOpen()) { Case.getCurrentCase().closeCase(); } - } catch (CaseActionException | IllegalStateException unused) { + } catch (CaseActionException | IllegalStateException ignored) { // Exception already logged. Shutting down, no need to do popup. } }).start(); } - private void setupLAF() { - - //TODO apply custom skinning - //UIManager.put("nimbusBase", new Color()); - //UIManager.put("nimbusBlueGrey", new Color()); - //UIManager.put("control", new Color()); + private void setLookAndFeel() { if (System.getProperty("os.name").toLowerCase().contains("mac")) { //NON-NLS - setupMacOsXLAF(); + setOSXLookAndFeel(); } - } /** @@ -128,24 +124,21 @@ public class Installer extends ModuleInstall { * dependent elements that set the Menu Bar to be in the correct place on * Mac OS X. */ - private void setupMacOsXLAF() { + private void setOSXLookAndFeel() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { logger.log(Level.WARNING, "Unable to set theme. ", ex); //NON-NLS } - final String[] UI_MENU_ITEM_KEYS = new String[]{"MenuBarUI", //NON-NLS - }; - - Map uiEntries = new TreeMap<>(); - // Store the keys that deal with menu items + final String[] UI_MENU_ITEM_KEYS = new String[]{"MenuBarUI",}; //NON-NLS + Map uiEntries = new TreeMap<>(); for (String key : UI_MENU_ITEM_KEYS) { uiEntries.put(key, UIManager.get(key)); } - //use Metal if available + // Use Metal if available for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { //NON-NLS try {