Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CTOptionsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2023 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 com.basistech.df.cybertriage.autopsy.ctoptions;
20 
22 import java.awt.Dimension;
23 import java.awt.GridBagConstraints;
24 import java.beans.PropertyChangeEvent;
25 import java.beans.PropertyChangeListener;
26 import java.util.Collection;
27 import java.util.Comparator;
28 import java.util.List;
29 import java.util.logging.Logger;
30 import java.util.stream.Collectors;
31 import java.util.stream.Stream;
32 import javax.swing.JPanel;
33 import org.netbeans.spi.options.OptionsPanelController;
34 import org.openide.util.Lookup;
36 
41 
42  private static final int MAX_SUBPANEL_WIDTH = 650;
43 
44  private static final Logger logger = Logger.getLogger(CTOptionsPanel.class.getName());
45 
46  private final List<CTOptionsSubPanel> subPanels;
47 
52  public CTOptionsPanel() {
54  Collection<? extends CTOptionsSubPanel> coll = Lookup.getDefault().lookupAll(CTOptionsSubPanel.class);
55  Stream<? extends CTOptionsSubPanel> panelStream = coll != null ? coll.stream() : Stream.empty();
56  this.subPanels = panelStream
57  .map(panel -> {
58  try {
59  // lookup is returning singleton instances which means this panel gets messed up when accessed
60  // from multiple places because the panel's children are being added to a different CTOptionsPanel
61  return (CTOptionsSubPanel) panel.getClass().getConstructor().newInstance();
62  } catch (Exception ex) {
63  return null;
64  }
65  })
66  .filter(item -> item != null)
67  .sorted(Comparator.comparing(p -> p.getClass().getSimpleName().toUpperCase()))
68  .collect(Collectors.toList());
69  addSubOptionsPanels(new LicenseDisclaimerPanel(), this.subPanels);
70  }
71 
72  private void addSubOptionsPanels(JPanel disclaimerPanel, List<CTOptionsSubPanel> subPanels) {
73  GridBagConstraints disclaimerConstraints = new GridBagConstraints();
74  disclaimerConstraints.gridx = 0;
75  disclaimerConstraints.gridy = 0;
76  disclaimerConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
77  disclaimerConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
78  disclaimerConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
79  disclaimerConstraints.weighty = 0;
80  disclaimerConstraints.weightx = 0;
81 
82  contentPane.add(disclaimerPanel, disclaimerConstraints);
83 
84  for (int i = 0; i < subPanels.size(); i++) {
85  CTOptionsSubPanel subPanel = subPanels.get(i);
86 
87  subPanel.addPropertyChangeListener(new PropertyChangeListener() {
88  @Override
89  public void propertyChange(PropertyChangeEvent evt) {
90  if (evt.getPropertyName().equals(OptionsPanelController.PROP_CHANGED)) {
91  CTOptionsPanel.this.firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
92  }
93  }
94  });
95 
96  GridBagConstraints gridBagConstraints = new GridBagConstraints();
97  gridBagConstraints.gridx = 0;
98  gridBagConstraints.gridy = i + 1;
99  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
100  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
101  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
102  gridBagConstraints.weighty = 0;
103  gridBagConstraints.weightx = 0;
104 
105  contentPane.add(subPanel, gridBagConstraints);
106  }
107 
108  GridBagConstraints verticalConstraints = new GridBagConstraints();
109  verticalConstraints.gridx = 0;
110  verticalConstraints.gridy = subPanels.size() + 1;
111  verticalConstraints.weighty = 1;
112  verticalConstraints.weightx = 0;
113 
114  JPanel verticalSpacer = new JPanel();
115 
116  verticalSpacer.setMinimumSize(new Dimension(MAX_SUBPANEL_WIDTH, 0));
117  verticalSpacer.setPreferredSize(new Dimension(MAX_SUBPANEL_WIDTH, 0));
118  verticalSpacer.setMaximumSize(new Dimension(MAX_SUBPANEL_WIDTH, Short.MAX_VALUE));
119  contentPane.add(verticalSpacer, verticalConstraints);
120 
121  GridBagConstraints horizontalConstraints = new GridBagConstraints();
122  horizontalConstraints.gridx = 1;
123  horizontalConstraints.gridy = 0;
124  horizontalConstraints.weighty = 0;
125  horizontalConstraints.weightx = 1;
126 
127  JPanel horizontalSpacer = new JPanel();
128  contentPane.add(horizontalSpacer, horizontalConstraints);
129  }
130 
136  @SuppressWarnings("unchecked")
137  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
138  private void initComponents() {
139 
140  javax.swing.JScrollPane scrollPane = new javax.swing.JScrollPane();
141  contentPane = new javax.swing.JPanel();
142 
143  setLayout(new java.awt.BorderLayout());
144 
145  contentPane.setLayout(new java.awt.GridBagLayout());
146  scrollPane.setViewportView(contentPane);
147 
148  add(scrollPane, java.awt.BorderLayout.CENTER);
149  }// </editor-fold>//GEN-END:initComponents
150 
151  @Override
152  public void saveSettings() {
153  subPanels.forEach(panel -> panel.saveSettings());
154  }
155 
156  public void loadSavedSettings() {
157  subPanels.forEach(panel -> panel.loadSettings());
158  }
159 
160  public boolean valid() {
161  return subPanels.stream().allMatch(panel -> panel.valid());
162  }
163 
164 
165  // Variables declaration - do not modify//GEN-BEGIN:variables
166  private javax.swing.JPanel contentPane;
167  // End of variables declaration//GEN-END:variables
168 }
void addSubOptionsPanels(JPanel disclaimerPanel, List< CTOptionsSubPanel > subPanels)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.