Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AutopsyOptionsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2019 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.image.BufferedImage;
22 import java.io.File;
23 import java.io.IOException;
24 import java.lang.management.ManagementFactory;
25 import java.nio.charset.Charset;
26 import java.nio.file.Files;
27 import java.nio.file.Path;
28 import java.util.ArrayList;
29 import java.util.List;
30 import java.util.Optional;
31 import java.util.StringJoiner;
32 import java.util.logging.Level;
33 import javax.imageio.ImageIO;
34 import javax.swing.ImageIcon;
35 import javax.swing.JFileChooser;
36 import javax.swing.JOptionPane;
37 import javax.swing.event.DocumentEvent;
38 import javax.swing.event.DocumentListener;
39 import org.netbeans.spi.options.OptionsPanelController;
40 import org.openide.util.NbBundle;
42 import org.openide.util.NbBundle.Messages;
49 
53 @Messages({
54  "AutopsyOptionsPanel.invalidImageFile.msg=The selected file was not able to be used as an agency logo.",
55  "AutopsyOptionsPanel.invalidImageFile.title=Invalid Image File",
56  "AutopsyOptionsPanel.memFieldValidationLabel.not64BitInstall.text=JVM memory settings only enabled for 64 bit version",
57  "AutopsyOptionsPanel.memFieldValidationLabel.noValueEntered.text=No value entered",
58  "AutopsyOptionsPanel.memFieldValidationLabel.invalidCharacters.text=Invalid characters, value must be a positive integer",
59  "# {0} - minimumMemory",
60  "AutopsyOptionsPanel.memFieldValidationLabel.underMinMemory.text=Value must be at least {0}GB",
61  "# {0} - systemMemory",
62  "AutopsyOptionsPanel.memFieldValidationLabel.overMaxMemory.text=Value must be less than the total system memory of {0}GB",
63  "AutopsyOptionsPanel.memFieldValidationLabel.developerMode.text=Memory settings are not available while running in developer mode",
64  "AutopsyOptionsPanel.agencyLogoPathFieldValidationLabel.invalidPath.text=Path is not valid.",
65  "AutopsyOptionsPanel.agencyLogoPathFieldValidationLabel.invalidImageSpecified.text=Invalid image file specified.",
66  "AutopsyOptionsPanel.agencyLogoPathFieldValidationLabel.pathNotSet.text=Agency logo path must be set.",
67  "AutopsyOptionsPanel.logNumAlert.invalidInput.text=A positive integer is required here."
68 })
69 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
70 final class AutopsyOptionsPanel extends javax.swing.JPanel {
71 
72  private static final long serialVersionUID = 1L;
73  private final JFileChooser fileChooser;
74  private final TextFieldListener textFieldListener;
75  private static final String ETC_FOLDER_NAME = "etc";
76  private static final String CONFIG_FILE_EXTENSION = ".conf";
77  private static final long ONE_BILLION = 1000000000L; //used to roughly convert system memory from bytes to gigabytes
78  private static final int MEGA_IN_GIGA = 1024; //used to convert memory settings saved as megabytes to gigabytes
79  private static final int MIN_MEMORY_IN_GB = 2; //the enforced minimum memory in gigabytes
80  private static final Logger logger = Logger.getLogger(AutopsyOptionsPanel.class.getName());
81  private String initialMemValue = Long.toString(Runtime.getRuntime().maxMemory() / ONE_BILLION);
82 
86  AutopsyOptionsPanel() {
87  initComponents();
88  fileChooser = new JFileChooser();
89  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
90  fileChooser.setMultiSelectionEnabled(false);
91  fileChooser.setAcceptAllFileFilterUsed(false);
92  fileChooser.setFileFilter(new GeneralFilter(GeneralFilter.GRAPHIC_IMAGE_EXTS, GeneralFilter.GRAPHIC_IMG_DECR));
93  if (!PlatformUtil.is64BitJVM() || Version.getBuildType() == Version.Type.DEVELOPMENT) {
94  //32 bit JVM has a max heap size of 1.4 gb to 4 gb depending on OS
95  //So disabling the setting of heap size when the JVM is not 64 bit
96  //Is the safest course of action
97  //And the file won't exist in the install folder when running through netbeans
98  memField.setEnabled(false);
99  solrMaxHeapSpinner.setEnabled(false);
100  }
101  systemMemoryTotal.setText(Long.toString(getSystemMemoryInGB()));
102  // The cast to int in the following is to ensure that the correct SpinnerNumberModel
103  // constructor is called.
104  solrMaxHeapSpinner.setModel(new javax.swing.SpinnerNumberModel(UserPreferences.getMaxSolrVMSize(),
105  512, ((int)getSystemMemoryInGB()) * MEGA_IN_GIGA, 512));
106 
107  textFieldListener = new TextFieldListener();
108  agencyLogoPathField.getDocument().addDocumentListener(textFieldListener);
109  logFileCount.setText(String.valueOf(UserPreferences.getLogFileCount()));
110  }
111 
118  private long getSystemMemoryInGB() {
119  long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory
120  .getOperatingSystemMXBean()).getTotalPhysicalMemorySize();
121  return memorySize / ONE_BILLION;
122  }
123 
129  private long getCurrentJvmMaxMemoryInGB() throws IOException {
130  String currentXmx = getCurrentXmxValue();
131  char units = '-';
132  Long value = 0L;
133  if (currentXmx.length() > 1) {
134  units = currentXmx.charAt(currentXmx.length() - 1);
135  value = Long.parseLong(currentXmx.substring(0, currentXmx.length() - 1));
136  } else {
137  throw new IOException("No memory setting found in String: " + currentXmx);
138  }
139  //some older .conf files might have the units as megabytes instead of gigabytes
140  switch (units) {
141  case 'g':
142  case 'G':
143  return value;
144  case 'm':
145  case 'M':
146  return value / MEGA_IN_GIGA;
147  default:
148  throw new IOException("Units were not recognized as parsed: " + units);
149  }
150  }
151 
152  /*
153  * The value currently saved in the conf file as the max java heap space
154  * available to this application. Form will be an integer followed by a
155  * character indicating units. Helper method for
156  * getCurrentJvmMaxMemoryInGB()
157  *
158  * @return the saved value for the max java heap space
159  *
160  * @throws IOException if the conf file does not exist in either the user
161  * directory or the install directory
162  */
163  private String getCurrentXmxValue() throws IOException {
164  String[] settings;
165  String currentSetting = "";
166  File userConfFile = getUserFolderConfFile();
167  if (!userConfFile.exists()) {
168  settings = getDefaultsFromFileContents(readConfFile(getInstallFolderConfFile()));
169  } else {
170  settings = getDefaultsFromFileContents(readConfFile(userConfFile));
171  }
172  for (String option : settings) {
173  if (option.startsWith("-J-Xmx")) {
174  currentSetting = option.replace("-J-Xmx", "").trim();
175  }
176  }
177  return currentSetting;
178  }
179 
188  private static File getInstallFolderConfFile() throws IOException {
189  String confFileName = UserPreferences.getAppName() + CONFIG_FILE_EXTENSION;
190  String installFolder = PlatformUtil.getInstallPath();
191  File installFolderEtc = new File(installFolder, ETC_FOLDER_NAME);
192  File installFolderConfigFile = new File(installFolderEtc, confFileName);
193  if (!installFolderConfigFile.exists()) {
194  throw new IOException("Conf file could not be found" + installFolderConfigFile.toString());
195  }
196  return installFolderConfigFile;
197  }
198 
206  private static File getUserFolderConfFile() {
207  String confFileName = UserPreferences.getAppName() + CONFIG_FILE_EXTENSION;
208  File userFolder = PlatformUtil.getUserDirectory();
209  File userEtcFolder = new File(userFolder, ETC_FOLDER_NAME);
210  if (!userEtcFolder.exists()) {
211  userEtcFolder.mkdir();
212  }
213  return new File(userEtcFolder, confFileName);
214  }
215 
224  private void writeEtcConfFile() throws IOException {
225  StringBuilder content = new StringBuilder();
226  List<String> confFile = readConfFile(getInstallFolderConfFile());
227  for (String line : confFile) {
228  if (line.contains("-J-Xmx")) {
229  String[] splitLine = line.split(" ");
230  StringJoiner modifiedLine = new StringJoiner(" ");
231  for (String piece : splitLine) {
232  if (piece.contains("-J-Xmx")) {
233  piece = "-J-Xmx" + memField.getText() + "g";
234  }
235  modifiedLine.add(piece);
236  }
237  content.append(modifiedLine.toString());
238  } else {
239  content.append(line);
240  }
241  content.append("\n");
242  }
243  Files.write(getUserFolderConfFile().toPath(), content.toString().getBytes());
244  }
245 
255  private static List<String> readConfFile(File configFile) {
256  List<String> lines = new ArrayList<>();
257  if (null != configFile) {
258  Path filePath = configFile.toPath();
259  Charset charset = Charset.forName("UTF-8");
260  try {
261  lines = Files.readAllLines(filePath, charset);
262  } catch (IOException e) {
263  logger.log(Level.SEVERE, "Error reading config file contents. {}", configFile.getAbsolutePath());
264  }
265  }
266  return lines;
267  }
268 
280  private static String[] getDefaultsFromFileContents(List<String> list) {
281  Optional<String> defaultSettings = list.stream().filter(line -> line.startsWith("default_options=")).findFirst();
282 
283  if (defaultSettings.isPresent()) {
284  return defaultSettings.get().replace("default_options=", "").replaceAll("\"", "").split(" ");
285  }
286  return new String[]{};
287  }
288 
292  void load() {
293  String path = ModuleSettings.getConfigSetting(ReportBranding.MODULE_NAME, ReportBranding.AGENCY_LOGO_PATH_PROP);
294  boolean useDefault = (path == null || path.isEmpty());
295  defaultLogoRB.setSelected(useDefault);
296  specifyLogoRB.setSelected(!useDefault);
297  agencyLogoPathField.setEnabled(!useDefault);
298  browseLogosButton.setEnabled(!useDefault);
299  logFileCount.setText(String.valueOf(UserPreferences.getLogFileCount()));
300  solrMaxHeapSpinner.setValue(UserPreferences.getMaxSolrVMSize());
301  try {
302  updateAgencyLogo(path);
303  } catch (IOException ex) {
304  logger.log(Level.WARNING, "Error loading image from previously saved agency logo path", ex);
305  }
306  if (memField.isEnabled()) {
307  try {
308  initialMemValue = Long.toString(getCurrentJvmMaxMemoryInGB());
309  } catch (IOException ex) {
310  logger.log(Level.SEVERE, "Can't read current Jvm max memory setting from file", ex);
311  memField.setEnabled(false);
312  }
313  memField.setText(initialMemValue);
314  }
315 
316  valid(); //ensure the error messages are up to date
317  }
318 
326  private void updateAgencyLogo(String path) throws IOException {
327  agencyLogoPathField.setText(path);
328  ImageIcon agencyLogoIcon = new ImageIcon();
329  agencyLogoPreview.setText(NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.agencyLogoPreview.text"));
330  if (!agencyLogoPathField.getText().isEmpty()) {
331  File file = new File(agencyLogoPathField.getText());
332  if (file.exists()) {
333  BufferedImage image = ImageIO.read(file); //create it as an image first to support BMP files
334  if (image == null) {
335  throw new IOException("Unable to read file as a BufferedImage for file " + file.toString());
336  }
337  agencyLogoIcon = new ImageIcon(image.getScaledInstance(64, 64, 4));
338  agencyLogoPreview.setText("");
339  }
340  }
341  agencyLogoPreview.setIcon(agencyLogoIcon);
342  agencyLogoPreview.repaint();
343  }
344 
348  void store() {
349  UserPreferences.setLogFileCount(Integer.parseInt(logFileCount.getText()));
350  if (!agencyLogoPathField.getText().isEmpty()) {
351  File file = new File(agencyLogoPathField.getText());
352  if (file.exists()) {
353  ModuleSettings.setConfigSetting(ReportBranding.MODULE_NAME, ReportBranding.AGENCY_LOGO_PATH_PROP, agencyLogoPathField.getText());
354  }
355  } else {
356  ModuleSettings.setConfigSetting(ReportBranding.MODULE_NAME, ReportBranding.AGENCY_LOGO_PATH_PROP, "");
357  }
358  UserPreferences.setMaxSolrVMSize((int)solrMaxHeapSpinner.getValue());
359  if (memField.isEnabled()) { //if the field could of been changed we need to try and save it
360  try {
361  writeEtcConfFile();
362  } catch (IOException ex) {
363  logger.log(Level.WARNING, "Unable to save config file to " + PlatformUtil.getUserDirectory() + "\\" + ETC_FOLDER_NAME, ex);
364  }
365  }
366  }
367 
373  boolean valid() {
374  boolean valid = true;
375 
376  if (!isAgencyLogoPathValid()) {
377  valid = false;
378  }
379  if (!isMemFieldValid()) {
380  valid = false;
381  }
382  if (!isLogNumFieldValid()) {
383  valid = false;
384  }
385 
386  return valid;
387  }
388 
395  boolean isAgencyLogoPathValid() {
396  boolean valid = true;
397 
398  if (defaultLogoRB.isSelected()) {
399  agencyLogoPathFieldValidationLabel.setText("");
400  } else {
401  String agencyLogoPath = agencyLogoPathField.getText();
402  if (agencyLogoPath.isEmpty()) {
403  agencyLogoPathFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_agencyLogoPathFieldValidationLabel_pathNotSet_text());
404  valid = false;
405  } else {
406  File file = new File(agencyLogoPathField.getText());
407  if (file.exists() && file.isFile()) {
408  BufferedImage image;
409  try { //ensure the image can be read
410  image = ImageIO.read(file); //create it as an image first to support BMP files
411  if (image == null) {
412  throw new IOException("Unable to read file as a BufferedImage for file " + file.toString());
413  }
414  agencyLogoPathFieldValidationLabel.setText("");
415  } catch (IOException | IndexOutOfBoundsException ignored) {
416  agencyLogoPathFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_agencyLogoPathFieldValidationLabel_invalidImageSpecified_text());
417  valid = false;
418  }
419  } else {
420  agencyLogoPathFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_agencyLogoPathFieldValidationLabel_invalidPath_text());
421  valid = false;
422  }
423  }
424  }
425 
426  return valid;
427  }
428 
434  private boolean isMemFieldValid() {
435  String memText = memField.getText();
436  memFieldValidationLabel.setText("");
437  if (!PlatformUtil.is64BitJVM()) {
438  memFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_memFieldValidationLabel_not64BitInstall_text());
439  //the panel should be valid when it is a 32 bit jvm because the memfield will be disabled.
440  return true;
441  }
442  if (Version.getBuildType() == Version.Type.DEVELOPMENT) {
443  memFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_memFieldValidationLabel_developerMode_text());
444  //the panel should be valid when you are running in developer mode because the memfield will be disabled
445  return true;
446  }
447  if (memText.length() == 0) {
448  memFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_memFieldValidationLabel_noValueEntered_text());
449  return false;
450  }
451  if (memText.replaceAll("[^\\d]", "").length() != memText.length()) {
452  memFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_memFieldValidationLabel_invalidCharacters_text());
453  return false;
454  }
455  int parsedInt = Integer.parseInt(memText);
456  if (parsedInt < MIN_MEMORY_IN_GB) {
457  memFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_memFieldValidationLabel_underMinMemory_text(MIN_MEMORY_IN_GB));
458  return false;
459  }
460  if (parsedInt > getSystemMemoryInGB()) {
461  memFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_memFieldValidationLabel_overMaxMemory_text(getSystemMemoryInGB()));
462  return false;
463  }
464  return true;
465  }
466 
472  private boolean isLogNumFieldValid() {
473  String count = logFileCount.getText();
474  logNumAlert.setText("");
475  try {
476  int count_num = Integer.parseInt(count);
477  if (count_num < 1) {
478  logNumAlert.setText(Bundle.AutopsyOptionsPanel_logNumAlert_invalidInput_text());
479  return false;
480  }
481  } catch (NumberFormatException e) {
482  logNumAlert.setText(Bundle.AutopsyOptionsPanel_logNumAlert_invalidInput_text());
483  return false;
484  }
485  return true;
486  }
491  private class TextFieldListener implements DocumentListener {
492 
493  @Override
494  public void insertUpdate(DocumentEvent e) {
495  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
496  }
497 
498  @Override
499  public void removeUpdate(DocumentEvent e) {
500  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
501  }
502 
503  @Override
504  public void changedUpdate(DocumentEvent e) {
505  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
506  }
507  }
508 
514  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
515  private void initComponents() {
516 
517  fileSelectionButtonGroup = new javax.swing.ButtonGroup();
518  displayTimesButtonGroup = new javax.swing.ButtonGroup();
519  logoSourceButtonGroup = new javax.swing.ButtonGroup();
520  jScrollPane1 = new javax.swing.JScrollPane();
521  jPanel1 = new javax.swing.JPanel();
522  logoPanel = new javax.swing.JPanel();
523  agencyLogoPathField = new javax.swing.JTextField();
524  browseLogosButton = new javax.swing.JButton();
525  agencyLogoPreview = new javax.swing.JLabel();
526  defaultLogoRB = new javax.swing.JRadioButton();
527  specifyLogoRB = new javax.swing.JRadioButton();
528  agencyLogoPathFieldValidationLabel = new javax.swing.JLabel();
529  runtimePanel = new javax.swing.JPanel();
530  maxMemoryLabel = new javax.swing.JLabel();
531  maxMemoryUnitsLabel = new javax.swing.JLabel();
532  totalMemoryLabel = new javax.swing.JLabel();
533  systemMemoryTotal = new javax.swing.JLabel();
534  restartNecessaryWarning = new javax.swing.JLabel();
535  memField = new javax.swing.JTextField();
536  memFieldValidationLabel = new javax.swing.JLabel();
537  maxMemoryUnitsLabel1 = new javax.swing.JLabel();
538  maxLogFileCount = new javax.swing.JLabel();
539  logFileCount = new javax.swing.JTextField();
540  logNumAlert = new javax.swing.JTextField();
541  maxSolrMemoryLabel = new javax.swing.JLabel();
542  maxMemoryUnitsLabel2 = new javax.swing.JLabel();
543  solrMaxHeapSpinner = new javax.swing.JSpinner();
544  solrJVMHeapWarning = new javax.swing.JLabel();
545 
546  setPreferredSize(new java.awt.Dimension(1022, 488));
547 
548  jScrollPane1.setBorder(null);
549  jScrollPane1.setPreferredSize(new java.awt.Dimension(1022, 407));
550 
551  jPanel1.setPreferredSize(new java.awt.Dimension(1022, 407));
552 
553  logoPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.logoPanel.border.title"))); // NOI18N
554  logoPanel.setPreferredSize(new java.awt.Dimension(533, 87));
555 
556  agencyLogoPathField.setText(org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.agencyLogoPathField.text")); // NOI18N
557 
558  org.openide.awt.Mnemonics.setLocalizedText(browseLogosButton, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.browseLogosButton.text")); // NOI18N
559  browseLogosButton.addActionListener(new java.awt.event.ActionListener() {
560  public void actionPerformed(java.awt.event.ActionEvent evt) {
561  browseLogosButtonActionPerformed(evt);
562  }
563  });
564 
565  agencyLogoPreview.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
566  org.openide.awt.Mnemonics.setLocalizedText(agencyLogoPreview, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.agencyLogoPreview.text")); // NOI18N
567  agencyLogoPreview.setBorder(javax.swing.BorderFactory.createEtchedBorder());
568  agencyLogoPreview.setMaximumSize(new java.awt.Dimension(64, 64));
569  agencyLogoPreview.setMinimumSize(new java.awt.Dimension(64, 64));
570  agencyLogoPreview.setPreferredSize(new java.awt.Dimension(64, 64));
571 
572  logoSourceButtonGroup.add(defaultLogoRB);
573  org.openide.awt.Mnemonics.setLocalizedText(defaultLogoRB, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.defaultLogoRB.text")); // NOI18N
574  defaultLogoRB.addActionListener(new java.awt.event.ActionListener() {
575  public void actionPerformed(java.awt.event.ActionEvent evt) {
576  defaultLogoRBActionPerformed(evt);
577  }
578  });
579 
580  logoSourceButtonGroup.add(specifyLogoRB);
581  org.openide.awt.Mnemonics.setLocalizedText(specifyLogoRB, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.specifyLogoRB.text")); // NOI18N
582  specifyLogoRB.addActionListener(new java.awt.event.ActionListener() {
583  public void actionPerformed(java.awt.event.ActionEvent evt) {
584  specifyLogoRBActionPerformed(evt);
585  }
586  });
587 
588  agencyLogoPathFieldValidationLabel.setForeground(new java.awt.Color(255, 0, 0));
589  org.openide.awt.Mnemonics.setLocalizedText(agencyLogoPathFieldValidationLabel, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.agencyLogoPathFieldValidationLabel.text")); // NOI18N
590 
591  javax.swing.GroupLayout logoPanelLayout = new javax.swing.GroupLayout(logoPanel);
592  logoPanel.setLayout(logoPanelLayout);
593  logoPanelLayout.setHorizontalGroup(
594  logoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
595  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, logoPanelLayout.createSequentialGroup()
596  .addContainerGap()
597  .addGroup(logoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
598  .addComponent(specifyLogoRB)
599  .addComponent(defaultLogoRB))
600  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
601  .addGroup(logoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
602  .addGroup(logoPanelLayout.createSequentialGroup()
603  .addComponent(agencyLogoPathField, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)
604  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
605  .addComponent(browseLogosButton))
606  .addComponent(agencyLogoPathFieldValidationLabel))
607  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
608  .addComponent(agencyLogoPreview, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
609  .addContainerGap(456, Short.MAX_VALUE))
610  );
611  logoPanelLayout.setVerticalGroup(
612  logoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
613  .addGroup(logoPanelLayout.createSequentialGroup()
614  .addGap(6, 6, 6)
615  .addGroup(logoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
616  .addComponent(defaultLogoRB)
617  .addComponent(agencyLogoPathFieldValidationLabel))
618  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
619  .addGroup(logoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
620  .addComponent(specifyLogoRB)
621  .addComponent(agencyLogoPathField)
622  .addComponent(browseLogosButton)))
623  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, logoPanelLayout.createSequentialGroup()
624  .addComponent(agencyLogoPreview, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
625  .addGap(0, 0, Short.MAX_VALUE))
626  );
627 
628  runtimePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.runtimePanel.border.title"))); // NOI18N
629 
630  org.openide.awt.Mnemonics.setLocalizedText(maxMemoryLabel, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.maxMemoryLabel.text")); // NOI18N
631 
632  org.openide.awt.Mnemonics.setLocalizedText(maxMemoryUnitsLabel, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.maxMemoryUnitsLabel.text")); // NOI18N
633 
634  org.openide.awt.Mnemonics.setLocalizedText(totalMemoryLabel, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.totalMemoryLabel.text")); // NOI18N
635 
636  systemMemoryTotal.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
637 
638  restartNecessaryWarning.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/warning16.png"))); // NOI18N
639  org.openide.awt.Mnemonics.setLocalizedText(restartNecessaryWarning, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.restartNecessaryWarning.text")); // NOI18N
640 
641  memField.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
642  memField.addKeyListener(new java.awt.event.KeyAdapter() {
643  public void keyReleased(java.awt.event.KeyEvent evt) {
644  memFieldKeyReleased(evt);
645  }
646  });
647 
648  memFieldValidationLabel.setForeground(new java.awt.Color(255, 0, 0));
649 
650  org.openide.awt.Mnemonics.setLocalizedText(maxMemoryUnitsLabel1, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.maxMemoryUnitsLabel.text")); // NOI18N
651 
652  org.openide.awt.Mnemonics.setLocalizedText(maxLogFileCount, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.maxLogFileCount.text")); // NOI18N
653 
654  logFileCount.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
655  logFileCount.addKeyListener(new java.awt.event.KeyAdapter() {
656  public void keyReleased(java.awt.event.KeyEvent evt) {
657  logFileCountKeyReleased(evt);
658  }
659  });
660 
661  logNumAlert.setEditable(false);
662  logNumAlert.setForeground(new java.awt.Color(255, 0, 0));
663  logNumAlert.setText(org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.logNumAlert.text")); // NOI18N
664  logNumAlert.setBorder(null);
665 
666  org.openide.awt.Mnemonics.setLocalizedText(maxSolrMemoryLabel, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.maxSolrMemoryLabel.text")); // NOI18N
667 
668  org.openide.awt.Mnemonics.setLocalizedText(maxMemoryUnitsLabel2, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.maxMemoryUnitsLabel2.text")); // NOI18N
669 
670  solrMaxHeapSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
671  public void stateChanged(javax.swing.event.ChangeEvent evt) {
672  solrMaxHeapSpinnerStateChanged(evt);
673  }
674  });
675 
676  org.openide.awt.Mnemonics.setLocalizedText(solrJVMHeapWarning, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.solrJVMHeapWarning.text")); // NOI18N
677 
678  javax.swing.GroupLayout runtimePanelLayout = new javax.swing.GroupLayout(runtimePanel);
679  runtimePanel.setLayout(runtimePanelLayout);
680  runtimePanelLayout.setHorizontalGroup(
681  runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
682  .addGroup(runtimePanelLayout.createSequentialGroup()
683  .addContainerGap()
684  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
685  .addGroup(runtimePanelLayout.createSequentialGroup()
686  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
687  .addComponent(totalMemoryLabel)
688  .addComponent(maxSolrMemoryLabel)
689  .addComponent(maxMemoryLabel)
690  .addComponent(maxLogFileCount))
691  .addGap(12, 12, 12)
692  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
693  .addComponent(logFileCount, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
694  .addComponent(solrMaxHeapSpinner, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
695  .addComponent(memField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
696  .addComponent(systemMemoryTotal, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
697  .addGap(18, 18, 18)
698  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
699  .addComponent(maxMemoryUnitsLabel1)
700  .addComponent(maxMemoryUnitsLabel)
701  .addComponent(maxMemoryUnitsLabel2))
702  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
703  .addGroup(runtimePanelLayout.createSequentialGroup()
704  .addGap(23, 23, 23)
705  .addComponent(memFieldValidationLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 478, javax.swing.GroupLayout.PREFERRED_SIZE)
706  .addContainerGap(246, Short.MAX_VALUE))
707  .addGroup(runtimePanelLayout.createSequentialGroup()
708  .addGap(18, 18, 18)
709  .addComponent(solrJVMHeapWarning, javax.swing.GroupLayout.DEFAULT_SIZE, 717, Short.MAX_VALUE)
710  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
711  .addComponent(logNumAlert)
712  .addContainerGap())))
713  .addComponent(restartNecessaryWarning, javax.swing.GroupLayout.DEFAULT_SIZE, 994, Short.MAX_VALUE)))
714  );
715 
716  runtimePanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {maxLogFileCount, maxMemoryLabel, totalMemoryLabel});
717 
718  runtimePanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {logFileCount, memField});
719 
720  runtimePanelLayout.setVerticalGroup(
721  runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
722  .addGroup(runtimePanelLayout.createSequentialGroup()
723  .addContainerGap()
724  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
725  .addComponent(totalMemoryLabel)
726  .addComponent(maxMemoryUnitsLabel1)
727  .addComponent(systemMemoryTotal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
728  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
729  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
730  .addComponent(memFieldValidationLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
731  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
732  .addComponent(maxMemoryLabel)
733  .addComponent(memField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
734  .addComponent(maxMemoryUnitsLabel)))
735  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
736  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
737  .addComponent(logNumAlert, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
738  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
739  .addComponent(maxSolrMemoryLabel)
740  .addComponent(maxMemoryUnitsLabel2)
741  .addComponent(solrMaxHeapSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
742  .addComponent(solrJVMHeapWarning)))
743  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
744  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
745  .addComponent(maxLogFileCount)
746  .addComponent(logFileCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
747  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
748  .addComponent(restartNecessaryWarning)
749  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
750  );
751 
752  javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
753  jPanel1.setLayout(jPanel1Layout);
754  jPanel1Layout.setHorizontalGroup(
755  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
756  .addGroup(jPanel1Layout.createSequentialGroup()
757  .addContainerGap()
758  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
759  .addComponent(runtimePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
760  .addComponent(logoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 1002, Short.MAX_VALUE))
761  .addContainerGap())
762  );
763  jPanel1Layout.setVerticalGroup(
764  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
765  .addGroup(jPanel1Layout.createSequentialGroup()
766  .addContainerGap()
767  .addComponent(runtimePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
768  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
769  .addComponent(logoPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
770  .addContainerGap(171, Short.MAX_VALUE))
771  );
772 
773  jScrollPane1.setViewportView(jPanel1);
774 
775  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
776  this.setLayout(layout);
777  layout.setHorizontalGroup(
778  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
779  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
780  );
781  layout.setVerticalGroup(
782  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
783  .addGroup(layout.createSequentialGroup()
784  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
785  .addGap(0, 0, Short.MAX_VALUE))
786  );
787  }// </editor-fold>//GEN-END:initComponents
788 
789  private void logFileCountKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_logFileCountKeyReleased
790  String count = logFileCount.getText();
791  if (count.equals(String.valueOf(UserPreferences.getDefaultLogFileCount()))) {
792  //if it is still the default value don't fire change
793  return;
794  }
795  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
796  }//GEN-LAST:event_logFileCountKeyReleased
797 
798  private void memFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_memFieldKeyReleased
799  String memText = memField.getText();
800  if (memText.equals(initialMemValue)) {
801  //if it is still the initial value don't fire change
802  return;
803  }
804  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
805  }//GEN-LAST:event_memFieldKeyReleased
806 
807  private void specifyLogoRBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_specifyLogoRBActionPerformed
808  agencyLogoPathField.setEnabled(true);
809  browseLogosButton.setEnabled(true);
810  try {
811  if (agencyLogoPathField.getText().isEmpty()) {
812  String path = ModuleSettings.getConfigSetting(ReportBranding.MODULE_NAME, ReportBranding.AGENCY_LOGO_PATH_PROP);
813  if (path != null && !path.isEmpty()) {
814  updateAgencyLogo(path);
815  }
816  }
817  } catch (IOException ex) {
818  logger.log(Level.WARNING, "Error loading image from previously saved agency logo path.", ex);
819  }
820  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
821  }//GEN-LAST:event_specifyLogoRBActionPerformed
822 
823  private void defaultLogoRBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_defaultLogoRBActionPerformed
824  agencyLogoPathField.setEnabled(false);
825  browseLogosButton.setEnabled(false);
826  try {
827  updateAgencyLogo("");
828  } catch (IOException ex) {
829  // This should never happen since we're not reading from a file.
830  logger.log(Level.SEVERE, "Unexpected error occurred while updating the agency logo.", ex);
831  }
832  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
833  }//GEN-LAST:event_defaultLogoRBActionPerformed
834 
835  private void browseLogosButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLogosButtonActionPerformed
836  String oldLogoPath = agencyLogoPathField.getText();
837  int returnState = fileChooser.showOpenDialog(this);
838  if (returnState == JFileChooser.APPROVE_OPTION) {
839  String path = fileChooser.getSelectedFile().getPath();
840  try {
841  updateAgencyLogo(path);
842  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
843  } catch (IOException | IndexOutOfBoundsException ex) {
844  JOptionPane.showMessageDialog(this,
845  NbBundle.getMessage(this.getClass(),
846  "AutopsyOptionsPanel.invalidImageFile.msg"),
847  NbBundle.getMessage(this.getClass(), "AutopsyOptionsPanel.invalidImageFile.title"),
848  JOptionPane.ERROR_MESSAGE);
849  try {
850  updateAgencyLogo(oldLogoPath); //restore previous setting if new one is invalid
851  } catch (IOException ex1) {
852  logger.log(Level.WARNING, "Error loading image from previously saved agency logo path", ex1);
853  }
854  }
855  }
856  }//GEN-LAST:event_browseLogosButtonActionPerformed
857 
858  private void solrMaxHeapSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_solrMaxHeapSpinnerStateChanged
859  int value = (int)solrMaxHeapSpinner.getValue();
860  if (value == UserPreferences.getMaxSolrVMSize()) {
861  // if the value hasn't changed there's nothing to do.
862  return;
863  }
864  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
865  }//GEN-LAST:event_solrMaxHeapSpinnerStateChanged
866 
867  // Variables declaration - do not modify//GEN-BEGIN:variables
868  private javax.swing.JTextField agencyLogoPathField;
869  private javax.swing.JLabel agencyLogoPathFieldValidationLabel;
870  private javax.swing.JLabel agencyLogoPreview;
871  private javax.swing.JButton browseLogosButton;
872  private javax.swing.JRadioButton defaultLogoRB;
873  private javax.swing.ButtonGroup displayTimesButtonGroup;
874  private javax.swing.ButtonGroup fileSelectionButtonGroup;
875  private javax.swing.JPanel jPanel1;
876  private javax.swing.JScrollPane jScrollPane1;
877  private javax.swing.JTextField logFileCount;
878  private javax.swing.JTextField logNumAlert;
879  private javax.swing.JPanel logoPanel;
880  private javax.swing.ButtonGroup logoSourceButtonGroup;
881  private javax.swing.JLabel maxLogFileCount;
882  private javax.swing.JLabel maxMemoryLabel;
883  private javax.swing.JLabel maxMemoryUnitsLabel;
884  private javax.swing.JLabel maxMemoryUnitsLabel1;
885  private javax.swing.JLabel maxMemoryUnitsLabel2;
886  private javax.swing.JLabel maxSolrMemoryLabel;
887  private javax.swing.JTextField memField;
888  private javax.swing.JLabel memFieldValidationLabel;
889  private javax.swing.JLabel restartNecessaryWarning;
890  private javax.swing.JPanel runtimePanel;
891  private javax.swing.JLabel solrJVMHeapWarning;
892  private javax.swing.JSpinner solrMaxHeapSpinner;
893  private javax.swing.JRadioButton specifyLogoRB;
894  private javax.swing.JLabel systemMemoryTotal;
895  private javax.swing.JLabel totalMemoryLabel;
896  // End of variables declaration//GEN-END:variables
897 
898 }

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.