19 package org.sleuthkit.autopsy.ingest.runIngestModuleWizard;
21 import java.awt.Color;
22 import java.awt.Component;
23 import java.awt.Dimension;
24 import java.awt.GridBagConstraints;
25 import java.awt.GridBagLayout;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.util.Collections;
29 import java.util.List;
30 import javax.swing.Box;
31 import static javax.swing.Box.createVerticalGlue;
32 import javax.swing.ButtonModel;
33 import javax.swing.JPanel;
34 import javax.swing.JScrollPane;
35 import javax.swing.JTextArea;
36 import javax.swing.JToggleButton;
37 import org.openide.util.NbBundle.Messages;
47 @SuppressWarnings(
"PMD.SingularField")
48 final class IngestProfileSelectionPanel extends JPanel {
50 @Messages({
"IngestProfileSelectionPanel.customSettings.name=Custom Settings",
51 "IngestProfileSelectionPanel.customSettings.description=configure individual module settings in next step of wizard"})
53 private static final long serialVersionUID = 1L;
54 private static final String CUSTOM_SETTINGS_DISPLAY_NAME = Bundle.IngestProfileSelectionPanel_customSettings_name();
55 private static final String CUSTOM_SETTINGS_DESCRIPTION = Bundle.IngestProfileSelectionPanel_customSettings_description();
56 private final IngestProfileSelectionWizardPanel wizardPanel;
57 private String selectedProfile;
58 private List<IngestProfile> profiles = Collections.emptyList();
59 boolean isLastPanel =
false;
62 ActionListener buttonGroupActionListener = (ActionEvent e) -> {
63 updateSelectedProfile();
71 IngestProfileSelectionPanel(IngestProfileSelectionWizardPanel panel, String lastSelectedProfile) {
74 selectedProfile = lastSelectedProfile;
75 isLastPanel = !selectedProfile.equals(wizardPanel.getDefaultContext());
77 populateProfilesList();
85 String getLastSelectedProfile() {
86 return selectedProfile;
94 private void updateSelectedProfile() {
96 ButtonModel selectedButton = profileListButtonGroup.getSelection();
97 selectedProfile = selectedButton.getActionCommand();
99 boolean wasLastPanel = isLastPanel;
100 isLastPanel = !selectedProfile.equals(wizardPanel.getDefaultContext());
101 wizardPanel.fireChangeEvent();
102 this.firePropertyChange(
"LAST_ENABLED", wasLastPanel, isLastPanel);
109 private void populateProfilesList() {
110 profiles = getProfiles();
112 GridBagLayout gridBagLayout =
new GridBagLayout();
113 GridBagConstraints constraints =
new GridBagConstraints();
114 constraints.fill = GridBagConstraints.HORIZONTAL;
115 constraints.gridx = 0;
116 constraints.gridy = 0;
117 constraints.weighty = .0;
118 constraints.anchor = GridBagConstraints.LINE_START;
120 addButton(CUSTOM_SETTINGS_DISPLAY_NAME, wizardPanel.getDefaultContext(), CUSTOM_SETTINGS_DESCRIPTION, gridBagLayout, constraints);
122 profiles.forEach((profile) -> {
123 constraints.weightx = 0;
125 constraints.gridx = 0;
127 addButton(profile.toString(), profile.toString(), profile.getDescription(), gridBagLayout, constraints);
132 constraints.gridx = 0;
133 constraints.weighty = 1;
134 Component vertGlue = createVerticalGlue();
135 profileListPanel.add(vertGlue);
136 gridBagLayout.setConstraints(vertGlue, constraints);
137 profileListPanel.setLayout(gridBagLayout);
149 private void addButton(String profileDisplayName, String profileContextName, String profileDesc, GridBagLayout layout, GridBagConstraints constraints) {
152 Dimension spacerBlockDimension =
new Dimension(6, 4);
153 Box.Filler spacer =
new Box.Filler(spacerBlockDimension, spacerBlockDimension, spacerBlockDimension);
154 constraints.weightx = 1;
155 layout.setConstraints(spacer, constraints);
156 profileListPanel.add(spacer);
161 JToggleButton profileButton =
new JToggleButton();
162 profileButton.setMaximumSize(
new java.awt.Dimension(48, 48));
163 profileButton.setMinimumSize(
new java.awt.Dimension(48, 48));
164 profileButton.setPreferredSize(
new java.awt.Dimension(48, 48));
166 profileButton.setName(profileContextName);
167 profileButton.setActionCommand(profileContextName);
169 profileButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/timeline/images/magnifier-zoom-in-green.png")));
170 profileButton.setSelectedIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/checkbox24.png")));
171 profileButton.setFocusable(
false);
172 profileButton.setFocusPainted(
false);
173 profileButton.addActionListener(buttonGroupActionListener);
175 if (profileContextName.equals(selectedProfile)) {
176 profileButton.setSelected(
true);
179 profileListButtonGroup.add(profileButton);
180 profileListPanel.add(profileButton);
181 layout.setConstraints(profileButton, constraints);
183 constraints.weightx = 1;
186 String displayText = profileDisplayName;
187 if (!profileDesc.isEmpty()) {
188 displayText +=
" - " + profileDesc;
190 JTextArea myLabel =
new JTextArea(displayText);
191 Color gray =
new Color(240, 240, 240);
192 myLabel.setBackground(gray);
193 myLabel.setEditable(
false);
194 myLabel.setWrapStyleWord(
true);
195 myLabel.setLineWrap(
true);
198 Box.Filler buttonTextSpacer =
new Box.Filler(spacerBlockDimension, spacerBlockDimension, spacerBlockDimension);
199 layout.setConstraints(buttonTextSpacer, constraints);
200 profileListPanel.add(buttonTextSpacer);
204 profileListPanel.add(myLabel);
205 layout.setConstraints(myLabel, constraints);
214 private List<IngestProfile> getProfiles() {
215 if (profiles.isEmpty()) {
224 private void clearListOfCheckBoxes() {
225 profileListButtonGroup =
new javax.swing.ButtonGroup();
226 profileListPanel.removeAll();
232 private void fetchProfileList() {
233 profiles = IngestProfiles.getIngestProfiles();
242 private void initComponents() {
244 profileListButtonGroup =
new javax.swing.ButtonGroup();
245 ingestSettingsButton =
new javax.swing.JButton();
246 profileListScrollPane =
new javax.swing.JScrollPane();
247 profileListPanel =
new javax.swing.JPanel();
248 profileListLabel =
new javax.swing.JLabel();
250 setMaximumSize(
new java.awt.Dimension(5750, 3000));
251 setPreferredSize(
new java.awt.Dimension(625, 450));
253 org.openide.awt.Mnemonics.setLocalizedText(ingestSettingsButton,
org.openide.util.NbBundle.getMessage(IngestProfileSelectionPanel.class,
"IngestProfileSelectionPanel.ingestSettingsButton.text"));
254 ingestSettingsButton.addActionListener(
new java.awt.event.ActionListener() {
255 public void actionPerformed(java.awt.event.ActionEvent evt) {
256 ingestSettingsButtonActionPerformed(evt);
260 profileListScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
262 profileListPanel.setAutoscrolls(
true);
263 profileListPanel.setLayout(
new java.awt.GridBagLayout());
264 profileListScrollPane.setViewportView(profileListPanel);
266 org.openide.awt.Mnemonics.setLocalizedText(profileListLabel,
org.openide.util.NbBundle.getMessage(IngestProfileSelectionPanel.class,
"IngestProfileSelectionPanel.profileListLabel.text"));
268 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
269 this.setLayout(layout);
270 layout.setHorizontalGroup(
271 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
272 .addGroup(layout.createSequentialGroup()
274 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
275 .addComponent(profileListScrollPane)
276 .addGroup(layout.createSequentialGroup()
277 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
278 .addComponent(ingestSettingsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
279 .addComponent(profileListLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
280 .addGap(0, 523, Short.MAX_VALUE)))
283 layout.setVerticalGroup(
284 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
285 .addGroup(layout.createSequentialGroup()
287 .addComponent(profileListLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
288 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
289 .addComponent(profileListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
290 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
291 .addComponent(ingestSettingsButton)
302 private void ingestSettingsButtonActionPerformed(java.awt.event.ActionEvent evt) {
303 final AdvancedConfigurationDialog dialog =
new AdvancedConfigurationDialog(
true);
304 IngestOptionsPanel ingestOptions =
new IngestOptionsPanel();
305 ingestOptions.load();
306 dialog.addApplyButtonListener(
308 ingestOptions.store();
309 clearListOfCheckBoxes();
311 profileListPanel.revalidate();
312 profileListPanel.repaint();
313 populateProfilesList();
317 dialog.display(ingestOptions);
321 private javax.swing.JButton ingestSettingsButton;
322 private javax.swing.ButtonGroup profileListButtonGroup;
323 private javax.swing.JLabel profileListLabel;
324 private javax.swing.JPanel profileListPanel;
325 private javax.swing.JScrollPane profileListScrollPane;