Autopsy  4.9.1
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-2018 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 long 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  }
100  systemMemoryTotal.setText(Long.toString(getSystemMemoryInGB()));
101 
102  textFieldListener = new TextFieldListener();
103  agencyLogoPathField.getDocument().addDocumentListener(textFieldListener);
104  logFileCount.setText(String.valueOf(UserPreferences.getLogFileCount()));
105  }
106 
113  private long getSystemMemoryInGB() {
114  long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory
115  .getOperatingSystemMXBean()).getTotalPhysicalMemorySize();
116  return memorySize / ONE_BILLION;
117  }
118 
124  private long getCurrentJvmMaxMemoryInGB() throws IOException {
125  String currentXmx = getCurrentXmxValue();
126  char units = '-';
127  Long value = 0L;
128  if (currentXmx.length() > 1) {
129  units = currentXmx.charAt(currentXmx.length() - 1);
130  value = Long.parseLong(currentXmx.substring(0, currentXmx.length() - 1));
131  } else {
132  throw new IOException("No memory setting found in String: " + currentXmx);
133  }
134  //some older .conf files might have the units as megabytes instead of gigabytes
135  switch (units) {
136  case 'g':
137  case 'G':
138  return value;
139  case 'm':
140  case 'M':
141  return value / MEGA_IN_GIGA;
142  default:
143  throw new IOException("Units were not recognized as parsed: " + units);
144  }
145  }
146 
147  /*
148  * The value currently saved in the conf file as the max java heap space
149  * available to this application. Form will be an integer followed by a
150  * character indicating units. Helper method for
151  * getCurrentJvmMaxMemoryInGB()
152  *
153  * @return the saved value for the max java heap space
154  *
155  * @throws IOException if the conf file does not exist in either the user
156  * directory or the install directory
157  */
158  private String getCurrentXmxValue() throws IOException {
159  String[] settings;
160  String currentSetting = "";
161  File userConfFile = getUserFolderConfFile();
162  if (!userConfFile.exists()) {
163  settings = getDefaultsFromFileContents(readConfFile(getInstallFolderConfFile()));
164  } else {
165  settings = getDefaultsFromFileContents(readConfFile(userConfFile));
166  }
167  for (String option : settings) {
168  if (option.startsWith("-J-Xmx")) {
169  currentSetting = option.replace("-J-Xmx", "").trim();
170  }
171  }
172  return currentSetting;
173  }
174 
183  private static File getInstallFolderConfFile() throws IOException {
184  String confFileName = UserPreferences.getAppName() + CONFIG_FILE_EXTENSION;
185  String installFolder = PlatformUtil.getInstallPath();
186  File installFolderEtc = new File(installFolder, ETC_FOLDER_NAME);
187  File installFolderConfigFile = new File(installFolderEtc, confFileName);
188  if (!installFolderConfigFile.exists()) {
189  throw new IOException("Conf file could not be found" + installFolderConfigFile.toString());
190  }
191  return installFolderConfigFile;
192  }
193 
201  private static File getUserFolderConfFile() {
202  String confFileName = UserPreferences.getAppName() + CONFIG_FILE_EXTENSION;
203  File userFolder = PlatformUtil.getUserDirectory();
204  File userEtcFolder = new File(userFolder, ETC_FOLDER_NAME);
205  if (!userEtcFolder.exists()) {
206  userEtcFolder.mkdir();
207  }
208  return new File(userEtcFolder, confFileName);
209  }
210 
219  private void writeEtcConfFile() throws IOException {
220  StringBuilder content = new StringBuilder();
221  List<String> confFile = readConfFile(getInstallFolderConfFile());
222  for (String line : confFile) {
223  if (line.contains("-J-Xmx")) {
224  String[] splitLine = line.split(" ");
225  StringJoiner modifiedLine = new StringJoiner(" ");
226  for (String piece : splitLine) {
227  if (piece.contains("-J-Xmx")) {
228  piece = "-J-Xmx" + memField.getText() + "g";
229  }
230  modifiedLine.add(piece);
231  }
232  content.append(modifiedLine.toString());
233  } else {
234  content.append(line);
235  }
236  content.append("\n");
237  }
238  Files.write(getUserFolderConfFile().toPath(), content.toString().getBytes());
239  }
240 
250  private static List<String> readConfFile(File configFile) {
251  List<String> lines = new ArrayList<>();
252  if (null != configFile) {
253  Path filePath = configFile.toPath();
254  Charset charset = Charset.forName("UTF-8");
255  try {
256  lines = Files.readAllLines(filePath, charset);
257  } catch (IOException e) {
258  logger.log(Level.SEVERE, "Error reading config file contents. {}", configFile.getAbsolutePath());
259  }
260  }
261  return lines;
262  }
263 
275  private static String[] getDefaultsFromFileContents(List<String> list) {
276  Optional<String> defaultSettings = list.stream().filter(line -> line.startsWith("default_options=")).findFirst();
277 
278  if (defaultSettings.isPresent()) {
279  return defaultSettings.get().replace("default_options=", "").replaceAll("\"", "").split(" ");
280  }
281  return new String[]{};
282  }
283 
287  void load() {
288  String path = ModuleSettings.getConfigSetting(ReportBranding.MODULE_NAME, ReportBranding.AGENCY_LOGO_PATH_PROP);
289  boolean useDefault = (path == null || path.isEmpty());
290  defaultLogoRB.setSelected(useDefault);
291  specifyLogoRB.setSelected(!useDefault);
292  agencyLogoPathField.setEnabled(!useDefault);
293  browseLogosButton.setEnabled(!useDefault);
294  logFileCount.setText(String.valueOf(UserPreferences.getLogFileCount()));
295  try {
296  updateAgencyLogo(path);
297  } catch (IOException ex) {
298  logger.log(Level.WARNING, "Error loading image from previously saved agency logo path", ex);
299  }
300  if (memField.isEnabled()) {
301  try {
302  initialMemValue = Long.toString(getCurrentJvmMaxMemoryInGB());
303  } catch (IOException ex) {
304  logger.log(Level.SEVERE, "Can't read current Jvm max memory setting from file", ex);
305  memField.setEnabled(false);
306  }
307  memField.setText(initialMemValue);
308  }
309 
310  valid(); //ensure the error messages are up to date
311  }
312 
320  private void updateAgencyLogo(String path) throws IOException {
321  agencyLogoPathField.setText(path);
322  ImageIcon agencyLogoIcon = new ImageIcon();
323  agencyLogoPreview.setText(NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.agencyLogoPreview.text"));
324  if (!agencyLogoPathField.getText().isEmpty()) {
325  File file = new File(agencyLogoPathField.getText());
326  if (file.exists()) {
327  BufferedImage image = ImageIO.read(file); //create it as an image first to support BMP files
328  if (image == null) {
329  throw new IOException("Unable to read file as a BufferedImage for file " + file.toString());
330  }
331  agencyLogoIcon = new ImageIcon(image.getScaledInstance(64, 64, 4));
332  agencyLogoPreview.setText("");
333  }
334  }
335  agencyLogoPreview.setIcon(agencyLogoIcon);
336  agencyLogoPreview.repaint();
337  }
338 
342  void store() {
343  UserPreferences.setLogFileCount(Integer.parseInt(logFileCount.getText()));
344  if (!agencyLogoPathField.getText().isEmpty()) {
345  File file = new File(agencyLogoPathField.getText());
346  if (file.exists()) {
347  ModuleSettings.setConfigSetting(ReportBranding.MODULE_NAME, ReportBranding.AGENCY_LOGO_PATH_PROP, agencyLogoPathField.getText());
348  }
349  } else {
350  ModuleSettings.setConfigSetting(ReportBranding.MODULE_NAME, ReportBranding.AGENCY_LOGO_PATH_PROP, "");
351  }
352  if (memField.isEnabled()) { //if the field could of been changed we need to try and save it
353  try {
354  writeEtcConfFile();
355  } catch (IOException ex) {
356  logger.log(Level.WARNING, "Unable to save config file to " + PlatformUtil.getUserDirectory() + "\\" + ETC_FOLDER_NAME, ex);
357  }
358  }
359  }
360 
366  boolean valid() {
367  boolean valid = true;
368 
369  if (!isAgencyLogoPathValid()) {
370  valid = false;
371  }
372  if (!isMemFieldValid()) {
373  valid = false;
374  }
375  if (!isLogNumFieldValid()) {
376  valid = false;
377  }
378 
379  return valid;
380  }
381 
388  boolean isAgencyLogoPathValid() {
389  boolean valid = true;
390 
391  if (defaultLogoRB.isSelected()) {
392  agencyLogoPathFieldValidationLabel.setText("");
393  } else {
394  String agencyLogoPath = agencyLogoPathField.getText();
395  if (agencyLogoPath.isEmpty()) {
396  agencyLogoPathFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_agencyLogoPathFieldValidationLabel_pathNotSet_text());
397  valid = false;
398  } else {
399  File file = new File(agencyLogoPathField.getText());
400  if (file.exists() && file.isFile()) {
401  BufferedImage image;
402  try { //ensure the image can be read
403  image = ImageIO.read(file); //create it as an image first to support BMP files
404  if (image == null) {
405  throw new IOException("Unable to read file as a BufferedImage for file " + file.toString());
406  }
407  agencyLogoPathFieldValidationLabel.setText("");
408  } catch (IOException | IndexOutOfBoundsException ignored) {
409  agencyLogoPathFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_agencyLogoPathFieldValidationLabel_invalidImageSpecified_text());
410  valid = false;
411  }
412  } else {
413  agencyLogoPathFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_agencyLogoPathFieldValidationLabel_invalidPath_text());
414  valid = false;
415  }
416  }
417  }
418 
419  return valid;
420  }
421 
427  private boolean isMemFieldValid() {
428  String memText = memField.getText();
429  memFieldValidationLabel.setText("");
430  if (!PlatformUtil.is64BitJVM()) {
431  memFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_memFieldValidationLabel_not64BitInstall_text());
432  //the panel should be valid when it is a 32 bit jvm because the memfield will be disabled.
433  return true;
434  }
435  if (Version.getBuildType() == Version.Type.DEVELOPMENT) {
436  memFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_memFieldValidationLabel_developerMode_text());
437  //the panel should be valid when you are running in developer mode because the memfield will be disabled
438  return true;
439  }
440  if (memText.length() == 0) {
441  memFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_memFieldValidationLabel_noValueEntered_text());
442  return false;
443  }
444  if (memText.replaceAll("[^\\d]", "").length() != memText.length()) {
445  memFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_memFieldValidationLabel_invalidCharacters_text());
446  return false;
447  }
448  int parsedInt = Integer.parseInt(memText);
449  if (parsedInt < MIN_MEMORY_IN_GB) {
450  memFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_memFieldValidationLabel_underMinMemory_text(MIN_MEMORY_IN_GB));
451  return false;
452  }
453  if (parsedInt > getSystemMemoryInGB()) {
454  memFieldValidationLabel.setText(Bundle.AutopsyOptionsPanel_memFieldValidationLabel_overMaxMemory_text(getSystemMemoryInGB()));
455  return false;
456  }
457  return true;
458  }
459 
465  private boolean isLogNumFieldValid() {
466  String count = logFileCount.getText();
467  logNumAlert.setText("");
468  try {
469  int count_num = Integer.parseInt(count);
470  if (count_num < 1) {
471  logNumAlert.setText(Bundle.AutopsyOptionsPanel_logNumAlert_invalidInput_text());
472  return false;
473  }
474  } catch (NumberFormatException e) {
475  logNumAlert.setText(Bundle.AutopsyOptionsPanel_logNumAlert_invalidInput_text());
476  return false;
477  }
478  return true;
479  }
484  private class TextFieldListener implements DocumentListener {
485 
486  @Override
487  public void insertUpdate(DocumentEvent e) {
488  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
489  }
490 
491  @Override
492  public void removeUpdate(DocumentEvent e) {
493  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
494  }
495 
496  @Override
497  public void changedUpdate(DocumentEvent e) {
498  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
499  }
500  }
501 
507  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
508  private void initComponents() {
509 
510  fileSelectionButtonGroup = new javax.swing.ButtonGroup();
511  displayTimesButtonGroup = new javax.swing.ButtonGroup();
512  logoSourceButtonGroup = new javax.swing.ButtonGroup();
513  jScrollPane1 = new javax.swing.JScrollPane();
514  jPanel1 = new javax.swing.JPanel();
515  logoPanel = new javax.swing.JPanel();
516  agencyLogoPathField = new javax.swing.JTextField();
517  browseLogosButton = new javax.swing.JButton();
518  agencyLogoPreview = new javax.swing.JLabel();
519  defaultLogoRB = new javax.swing.JRadioButton();
520  specifyLogoRB = new javax.swing.JRadioButton();
521  agencyLogoPathFieldValidationLabel = new javax.swing.JLabel();
522  runtimePanel = new javax.swing.JPanel();
523  maxMemoryLabel = new javax.swing.JLabel();
524  maxMemoryUnitsLabel = new javax.swing.JLabel();
525  totalMemoryLabel = new javax.swing.JLabel();
526  systemMemoryTotal = new javax.swing.JLabel();
527  restartNecessaryWarning = new javax.swing.JLabel();
528  memField = new javax.swing.JTextField();
529  memFieldValidationLabel = new javax.swing.JLabel();
530  maxMemoryUnitsLabel1 = new javax.swing.JLabel();
531  maxLogFileCount = new javax.swing.JLabel();
532  logFileCount = new javax.swing.JTextField();
533  logNumAlert = new javax.swing.JTextField();
534 
535  setPreferredSize(new java.awt.Dimension(1022, 488));
536 
537  jScrollPane1.setBorder(null);
538  jScrollPane1.setPreferredSize(new java.awt.Dimension(1022, 407));
539 
540  jPanel1.setPreferredSize(new java.awt.Dimension(1022, 407));
541 
542  logoPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.logoPanel.border.title"))); // NOI18N
543  logoPanel.setPreferredSize(new java.awt.Dimension(533, 87));
544 
545  agencyLogoPathField.setText(org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.agencyLogoPathField.text")); // NOI18N
546 
547  org.openide.awt.Mnemonics.setLocalizedText(browseLogosButton, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.browseLogosButton.text")); // NOI18N
548  browseLogosButton.addActionListener(new java.awt.event.ActionListener() {
549  public void actionPerformed(java.awt.event.ActionEvent evt) {
550  browseLogosButtonActionPerformed(evt);
551  }
552  });
553 
554  agencyLogoPreview.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
555  org.openide.awt.Mnemonics.setLocalizedText(agencyLogoPreview, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.agencyLogoPreview.text")); // NOI18N
556  agencyLogoPreview.setBorder(javax.swing.BorderFactory.createEtchedBorder());
557  agencyLogoPreview.setMaximumSize(new java.awt.Dimension(64, 64));
558  agencyLogoPreview.setMinimumSize(new java.awt.Dimension(64, 64));
559  agencyLogoPreview.setPreferredSize(new java.awt.Dimension(64, 64));
560 
561  logoSourceButtonGroup.add(defaultLogoRB);
562  org.openide.awt.Mnemonics.setLocalizedText(defaultLogoRB, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.defaultLogoRB.text")); // NOI18N
563  defaultLogoRB.addActionListener(new java.awt.event.ActionListener() {
564  public void actionPerformed(java.awt.event.ActionEvent evt) {
565  defaultLogoRBActionPerformed(evt);
566  }
567  });
568 
569  logoSourceButtonGroup.add(specifyLogoRB);
570  org.openide.awt.Mnemonics.setLocalizedText(specifyLogoRB, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.specifyLogoRB.text")); // NOI18N
571  specifyLogoRB.addActionListener(new java.awt.event.ActionListener() {
572  public void actionPerformed(java.awt.event.ActionEvent evt) {
573  specifyLogoRBActionPerformed(evt);
574  }
575  });
576 
577  agencyLogoPathFieldValidationLabel.setForeground(new java.awt.Color(255, 0, 0));
578  org.openide.awt.Mnemonics.setLocalizedText(agencyLogoPathFieldValidationLabel, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.agencyLogoPathFieldValidationLabel.text")); // NOI18N
579 
580  javax.swing.GroupLayout logoPanelLayout = new javax.swing.GroupLayout(logoPanel);
581  logoPanel.setLayout(logoPanelLayout);
582  logoPanelLayout.setHorizontalGroup(
583  logoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
584  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, logoPanelLayout.createSequentialGroup()
585  .addContainerGap()
586  .addGroup(logoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
587  .addComponent(specifyLogoRB)
588  .addComponent(defaultLogoRB))
589  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
590  .addGroup(logoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
591  .addGroup(logoPanelLayout.createSequentialGroup()
592  .addComponent(agencyLogoPathField, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)
593  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
594  .addComponent(browseLogosButton))
595  .addComponent(agencyLogoPathFieldValidationLabel))
596  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
597  .addComponent(agencyLogoPreview, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
598  .addContainerGap(479, Short.MAX_VALUE))
599  );
600  logoPanelLayout.setVerticalGroup(
601  logoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
602  .addGroup(logoPanelLayout.createSequentialGroup()
603  .addGap(6, 6, 6)
604  .addGroup(logoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
605  .addComponent(defaultLogoRB)
606  .addComponent(agencyLogoPathFieldValidationLabel))
607  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
608  .addGroup(logoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
609  .addComponent(specifyLogoRB)
610  .addComponent(agencyLogoPathField)
611  .addComponent(browseLogosButton)))
612  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, logoPanelLayout.createSequentialGroup()
613  .addComponent(agencyLogoPreview, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
614  .addGap(0, 0, Short.MAX_VALUE))
615  );
616 
617  runtimePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.runtimePanel.border.title"))); // NOI18N
618 
619  org.openide.awt.Mnemonics.setLocalizedText(maxMemoryLabel, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.maxMemoryLabel.text")); // NOI18N
620 
621  org.openide.awt.Mnemonics.setLocalizedText(maxMemoryUnitsLabel, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.maxMemoryUnitsLabel.text")); // NOI18N
622 
623  org.openide.awt.Mnemonics.setLocalizedText(totalMemoryLabel, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.totalMemoryLabel.text")); // NOI18N
624 
625  systemMemoryTotal.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
626 
627  restartNecessaryWarning.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/warning16.png"))); // NOI18N
628  org.openide.awt.Mnemonics.setLocalizedText(restartNecessaryWarning, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.restartNecessaryWarning.text")); // NOI18N
629 
630  memField.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
631  memField.addKeyListener(new java.awt.event.KeyAdapter() {
632  public void keyReleased(java.awt.event.KeyEvent evt) {
633  memFieldKeyReleased(evt);
634  }
635  });
636 
637  memFieldValidationLabel.setForeground(new java.awt.Color(255, 0, 0));
638 
639  org.openide.awt.Mnemonics.setLocalizedText(maxMemoryUnitsLabel1, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.maxMemoryUnitsLabel.text")); // NOI18N
640 
641  org.openide.awt.Mnemonics.setLocalizedText(maxLogFileCount, org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.maxLogFileCount.text")); // NOI18N
642 
643  logFileCount.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
644  logFileCount.addKeyListener(new java.awt.event.KeyAdapter() {
645  public void keyReleased(java.awt.event.KeyEvent evt) {
646  logFileCountKeyReleased(evt);
647  }
648  });
649 
650  logNumAlert.setEditable(false);
651  logNumAlert.setFont(logNumAlert.getFont().deriveFont(logNumAlert.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
652  logNumAlert.setForeground(new java.awt.Color(255, 0, 0));
653  logNumAlert.setText(org.openide.util.NbBundle.getMessage(AutopsyOptionsPanel.class, "AutopsyOptionsPanel.logNumAlert.text")); // NOI18N
654  logNumAlert.setBorder(null);
655 
656  javax.swing.GroupLayout runtimePanelLayout = new javax.swing.GroupLayout(runtimePanel);
657  runtimePanel.setLayout(runtimePanelLayout);
658  runtimePanelLayout.setHorizontalGroup(
659  runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
660  .addGroup(runtimePanelLayout.createSequentialGroup()
661  .addContainerGap()
662  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
663  .addGroup(runtimePanelLayout.createSequentialGroup()
664  .addComponent(totalMemoryLabel)
665  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
666  .addComponent(systemMemoryTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
667  .addGap(6, 6, 6)
668  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
669  .addGroup(runtimePanelLayout.createSequentialGroup()
670  .addComponent(maxMemoryUnitsLabel1)
671  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
672  .addComponent(restartNecessaryWarning, javax.swing.GroupLayout.DEFAULT_SIZE, 783, Short.MAX_VALUE))
673  .addGroup(runtimePanelLayout.createSequentialGroup()
674  .addComponent(maxMemoryUnitsLabel)
675  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
676  .addComponent(memFieldValidationLabel)
677  .addGap(0, 0, Short.MAX_VALUE))))
678  .addGroup(runtimePanelLayout.createSequentialGroup()
679  .addComponent(maxMemoryLabel)
680  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
681  .addComponent(memField, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
682  .addGap(0, 0, Short.MAX_VALUE))
683  .addGroup(runtimePanelLayout.createSequentialGroup()
684  .addComponent(maxLogFileCount)
685  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
686  .addComponent(logFileCount, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
687  .addGap(18, 18, 18)
688  .addComponent(logNumAlert)))
689  .addContainerGap())
690  );
691 
692  runtimePanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {maxLogFileCount, maxMemoryLabel, totalMemoryLabel});
693 
694  runtimePanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {logFileCount, memField});
695 
696  runtimePanelLayout.setVerticalGroup(
697  runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
698  .addGroup(runtimePanelLayout.createSequentialGroup()
699  .addContainerGap()
700  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
701  .addComponent(totalMemoryLabel)
702  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
703  .addComponent(restartNecessaryWarning)
704  .addComponent(maxMemoryUnitsLabel1))
705  .addComponent(systemMemoryTotal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
706  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
707  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
708  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
709  .addComponent(maxMemoryLabel)
710  .addComponent(memField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
711  .addComponent(maxMemoryUnitsLabel))
712  .addComponent(memFieldValidationLabel))
713  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
714  .addGroup(runtimePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
715  .addComponent(maxLogFileCount)
716  .addComponent(logFileCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
717  .addComponent(logNumAlert, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
718  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
719  );
720 
721  javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
722  jPanel1.setLayout(jPanel1Layout);
723  jPanel1Layout.setHorizontalGroup(
724  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
725  .addGroup(jPanel1Layout.createSequentialGroup()
726  .addContainerGap()
727  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
728  .addComponent(runtimePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
729  .addComponent(logoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 1002, Short.MAX_VALUE))
730  .addContainerGap())
731  );
732  jPanel1Layout.setVerticalGroup(
733  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
734  .addGroup(jPanel1Layout.createSequentialGroup()
735  .addContainerGap()
736  .addComponent(runtimePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
737  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
738  .addComponent(logoPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
739  .addContainerGap(185, Short.MAX_VALUE))
740  );
741 
742  jScrollPane1.setViewportView(jPanel1);
743 
744  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
745  this.setLayout(layout);
746  layout.setHorizontalGroup(
747  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
748  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
749  );
750  layout.setVerticalGroup(
751  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
752  .addGroup(layout.createSequentialGroup()
753  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
754  .addGap(0, 0, Short.MAX_VALUE))
755  );
756  }// </editor-fold>//GEN-END:initComponents
757 
758  private void logFileCountKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_logFileCountKeyReleased
759  String count = logFileCount.getText();
760  if (count.equals(String.valueOf(UserPreferences.getDefaultLogFileCount()))) {
761  //if it is still the default value don't fire change
762  return;
763  }
764  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
765  }//GEN-LAST:event_logFileCountKeyReleased
766 
767  private void memFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_memFieldKeyReleased
768  String memText = memField.getText();
769  if (memText.equals(initialMemValue)) {
770  //if it is still the initial value don't fire change
771  return;
772  }
773  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
774  }//GEN-LAST:event_memFieldKeyReleased
775 
776  private void specifyLogoRBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_specifyLogoRBActionPerformed
777  agencyLogoPathField.setEnabled(true);
778  browseLogosButton.setEnabled(true);
779  try {
780  if (agencyLogoPathField.getText().isEmpty()) {
781  String path = ModuleSettings.getConfigSetting(ReportBranding.MODULE_NAME, ReportBranding.AGENCY_LOGO_PATH_PROP);
782  if (path != null && !path.isEmpty()) {
783  updateAgencyLogo(path);
784  }
785  }
786  } catch (IOException ex) {
787  logger.log(Level.WARNING, "Error loading image from previously saved agency logo path.", ex);
788  }
789  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
790  }//GEN-LAST:event_specifyLogoRBActionPerformed
791 
792  private void defaultLogoRBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_defaultLogoRBActionPerformed
793  agencyLogoPathField.setEnabled(false);
794  browseLogosButton.setEnabled(false);
795  try {
796  updateAgencyLogo("");
797  } catch (IOException ex) {
798  // This should never happen since we're not reading from a file.
799  logger.log(Level.SEVERE, "Unexpected error occurred while updating the agency logo.", ex);
800  }
801  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
802  }//GEN-LAST:event_defaultLogoRBActionPerformed
803 
804  private void browseLogosButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseLogosButtonActionPerformed
805  String oldLogoPath = agencyLogoPathField.getText();
806  int returnState = fileChooser.showOpenDialog(this);
807  if (returnState == JFileChooser.APPROVE_OPTION) {
808  String path = fileChooser.getSelectedFile().getPath();
809  try {
810  updateAgencyLogo(path);
811  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
812  } catch (IOException | IndexOutOfBoundsException ex) {
813  JOptionPane.showMessageDialog(this,
814  NbBundle.getMessage(this.getClass(),
815  "AutopsyOptionsPanel.invalidImageFile.msg"),
816  NbBundle.getMessage(this.getClass(), "AutopsyOptionsPanel.invalidImageFile.title"),
817  JOptionPane.ERROR_MESSAGE);
818  try {
819  updateAgencyLogo(oldLogoPath); //restore previous setting if new one is invalid
820  } catch (IOException ex1) {
821  logger.log(Level.WARNING, "Error loading image from previously saved agency logo path", ex1);
822  }
823  }
824  }
825  }//GEN-LAST:event_browseLogosButtonActionPerformed
826 
827  // Variables declaration - do not modify//GEN-BEGIN:variables
828  private javax.swing.JTextField agencyLogoPathField;
829  private javax.swing.JLabel agencyLogoPathFieldValidationLabel;
830  private javax.swing.JLabel agencyLogoPreview;
831  private javax.swing.JButton browseLogosButton;
832  private javax.swing.JRadioButton defaultLogoRB;
833  private javax.swing.ButtonGroup displayTimesButtonGroup;
834  private javax.swing.ButtonGroup fileSelectionButtonGroup;
835  private javax.swing.JPanel jPanel1;
836  private javax.swing.JScrollPane jScrollPane1;
837  private javax.swing.JTextField logFileCount;
838  private javax.swing.JTextField logNumAlert;
839  private javax.swing.JPanel logoPanel;
840  private javax.swing.ButtonGroup logoSourceButtonGroup;
841  private javax.swing.JLabel maxLogFileCount;
842  private javax.swing.JLabel maxMemoryLabel;
843  private javax.swing.JLabel maxMemoryUnitsLabel;
844  private javax.swing.JLabel maxMemoryUnitsLabel1;
845  private javax.swing.JTextField memField;
846  private javax.swing.JLabel memFieldValidationLabel;
847  private javax.swing.JLabel restartNecessaryWarning;
848  private javax.swing.JPanel runtimePanel;
849  private javax.swing.JRadioButton specifyLogoRB;
850  private javax.swing.JLabel systemMemoryTotal;
851  private javax.swing.JLabel totalMemoryLabel;
852  // End of variables declaration//GEN-END:variables
853 
854 }

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.