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 final class IngestProfileSelectionPanel 
extends JPanel {
 
   49     @Messages({
"IngestProfileSelectionPanel.customSettings.name=Custom Settings",
 
   50         "IngestProfileSelectionPanel.customSettings.description=configure individual module settings in next step of wizard"})
 
   52     private static final long serialVersionUID = 1L;
 
   53     private static final String CUSTOM_SETTINGS_DISPLAY_NAME = Bundle.IngestProfileSelectionPanel_customSettings_name();
 
   54     private static final String CUSTOM_SETTINGS_DESCRIPTION = Bundle.IngestProfileSelectionPanel_customSettings_description();
 
   55     private final IngestProfileSelectionWizardPanel wizardPanel;
 
   56     private String selectedProfile;
 
   57     private List<IngestProfile> profiles = Collections.emptyList();
 
   58     boolean isLastPanel = 
false;
 
   61     ActionListener buttonGroupActionListener = (ActionEvent e) -> {
 
   62         updateSelectedProfile();
 
   70     IngestProfileSelectionPanel(IngestProfileSelectionWizardPanel panel, String lastSelectedProfile) {
 
   73         selectedProfile = lastSelectedProfile;
 
   74         isLastPanel = !selectedProfile.equals(wizardPanel.getDefaultContext());
 
   76         populateProfilesList();
 
   84     String getLastSelectedProfile() {
 
   85         return selectedProfile;
 
   93     private void updateSelectedProfile() {
 
   95         ButtonModel selectedButton = profileListButtonGroup.getSelection();
 
   96         selectedProfile = selectedButton.getActionCommand();
 
   98         boolean wasLastPanel = isLastPanel;
 
   99         isLastPanel = !selectedProfile.equals(wizardPanel.getDefaultContext());
 
  100         wizardPanel.fireChangeEvent();
 
  101         this.firePropertyChange(
"LAST_ENABLED", wasLastPanel, isLastPanel); 
 
  108     private void populateProfilesList() {
 
  109         profiles = getProfiles();
 
  111         GridBagLayout gridBagLayout = 
new GridBagLayout();
 
  112         GridBagConstraints constraints = 
new GridBagConstraints();
 
  113         constraints.fill = GridBagConstraints.HORIZONTAL;
 
  114         constraints.gridx = 0;
 
  115         constraints.gridy = 0;
 
  116         constraints.weighty = .0;
 
  117         constraints.anchor = GridBagConstraints.LINE_START;
 
  119         addButton(CUSTOM_SETTINGS_DISPLAY_NAME, wizardPanel.getDefaultContext(), CUSTOM_SETTINGS_DESCRIPTION, gridBagLayout, constraints);
 
  121         profiles.forEach((profile) -> {
 
  122             constraints.weightx = 0;
 
  124             constraints.gridx = 0;
 
  126             addButton(profile.toString(), profile.toString(), profile.getDescription(), gridBagLayout, constraints);
 
  131         constraints.gridx = 0;
 
  132         constraints.weighty = 1;
 
  133         Component vertGlue = createVerticalGlue();
 
  134         profileListPanel.add(vertGlue);
 
  135         gridBagLayout.setConstraints(vertGlue, constraints);
 
  136         profileListPanel.setLayout(gridBagLayout);
 
  148     private void addButton(String profileDisplayName, String profileContextName, String profileDesc, GridBagLayout layout, GridBagConstraints constraints) {
 
  151         Dimension spacerBlockDimension = 
new Dimension(6, 4); 
 
  152         Box.Filler spacer = 
new Box.Filler(spacerBlockDimension, spacerBlockDimension, spacerBlockDimension);
 
  153         constraints.weightx = 1;
 
  154         layout.setConstraints(spacer, constraints);
 
  155         profileListPanel.add(spacer);
 
  160         JToggleButton profileButton = 
new JToggleButton();     
 
  161         profileButton.setMaximumSize(
new java.awt.Dimension(48, 48));
 
  162         profileButton.setMinimumSize(
new java.awt.Dimension(48, 48));
 
  163         profileButton.setPreferredSize(
new java.awt.Dimension(48, 48));
 
  165         profileButton.setName(profileContextName);
 
  166         profileButton.setActionCommand(profileContextName);
 
  168         profileButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/timeline/images/magnifier-zoom-in-green.png")));
 
  169         profileButton.setSelectedIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/corecomponents/checkbox24.png")));
 
  170         profileButton.setFocusable(
false);
 
  171         profileButton.setFocusPainted(
false);
 
  172         profileButton.addActionListener(buttonGroupActionListener);
 
  174         if (profileContextName.equals(selectedProfile)) {
 
  175             profileButton.setSelected(
true);
 
  178         profileListButtonGroup.add(profileButton);
 
  179         profileListPanel.add(profileButton);
 
  180         layout.setConstraints(profileButton, constraints);
 
  182         constraints.weightx = 1;
 
  185         String displayText = profileDisplayName;
 
  186         if (!profileDesc.isEmpty()) {
 
  187             displayText += 
" - " + profileDesc;
 
  189         JTextArea myLabel = 
new JTextArea(displayText);
 
  190         Color gray = 
new Color(240, 240, 240);  
 
  191         myLabel.setBackground(gray);
 
  192         myLabel.setEditable(
false);
 
  193         myLabel.setWrapStyleWord(
true);
 
  194         myLabel.setLineWrap(
true);
 
  197         Box.Filler buttonTextSpacer = 
new Box.Filler(spacerBlockDimension, spacerBlockDimension, spacerBlockDimension);
 
  198         layout.setConstraints(buttonTextSpacer, constraints);
 
  199         profileListPanel.add(buttonTextSpacer);
 
  203         profileListPanel.add(myLabel);
 
  204         layout.setConstraints(myLabel, constraints);
 
  213     private List<IngestProfile> getProfiles() {
 
  214         if (profiles.isEmpty()) {
 
  223     private void clearListOfCheckBoxes() {
 
  224         profileListButtonGroup = 
new javax.swing.ButtonGroup();
 
  225         profileListPanel.removeAll();
 
  231     private void fetchProfileList() {
 
  232         profiles = IngestProfiles.getIngestProfiles();
 
  241     private void initComponents() {
 
  243         profileListButtonGroup = 
new javax.swing.ButtonGroup();
 
  244         ingestSettingsButton = 
new javax.swing.JButton();
 
  245         profileListScrollPane = 
new javax.swing.JScrollPane();
 
  246         profileListPanel = 
new javax.swing.JPanel();
 
  247         profileListLabel = 
new javax.swing.JLabel();
 
  249         setMaximumSize(
new java.awt.Dimension(5750, 3000));
 
  250         setPreferredSize(
new java.awt.Dimension(625, 450));
 
  252         org.openide.awt.Mnemonics.setLocalizedText(ingestSettingsButton, 
org.openide.util.NbBundle.getMessage(IngestProfileSelectionPanel.class, 
"IngestProfileSelectionPanel.ingestSettingsButton.text")); 
 
  253         ingestSettingsButton.addActionListener(
new java.awt.event.ActionListener() {
 
  254             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  255                 ingestSettingsButtonActionPerformed(evt);
 
  259         profileListScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
 
  261         profileListPanel.setAutoscrolls(
true);
 
  262         profileListPanel.setLayout(
new java.awt.GridBagLayout());
 
  263         profileListScrollPane.setViewportView(profileListPanel);
 
  265         org.openide.awt.Mnemonics.setLocalizedText(profileListLabel, 
org.openide.util.NbBundle.getMessage(IngestProfileSelectionPanel.class, 
"IngestProfileSelectionPanel.profileListLabel.text")); 
 
  267         javax.swing.GroupLayout layout = 
new javax.swing.GroupLayout(
this);
 
  268         this.setLayout(layout);
 
  269         layout.setHorizontalGroup(
 
  270             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  271             .addGroup(layout.createSequentialGroup()
 
  273                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  274                     .addComponent(profileListScrollPane)
 
  275                     .addGroup(layout.createSequentialGroup()
 
  276                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  277                             .addComponent(ingestSettingsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  278                             .addComponent(profileListLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
 
  279                         .addGap(0, 523, Short.MAX_VALUE)))
 
  282         layout.setVerticalGroup(
 
  283             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  284             .addGroup(layout.createSequentialGroup()
 
  286                 .addComponent(profileListLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  287                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 
  288                 .addComponent(profileListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
 
  289                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
 
  290                 .addComponent(ingestSettingsButton)
 
  301     private void ingestSettingsButtonActionPerformed(java.awt.event.ActionEvent evt) {
 
  302         final AdvancedConfigurationDialog dialog = 
new AdvancedConfigurationDialog(
true);
 
  303         IngestOptionsPanel ingestOptions = 
new IngestOptionsPanel();
 
  304         ingestOptions.load();
 
  305         dialog.addApplyButtonListener(
 
  307                     ingestOptions.store();
 
  308                     clearListOfCheckBoxes();
 
  310                     profileListPanel.revalidate();
 
  311                     profileListPanel.repaint();
 
  312                     populateProfilesList();
 
  316         dialog.display(ingestOptions);
 
  320     private javax.swing.JButton ingestSettingsButton;
 
  321     private javax.swing.ButtonGroup profileListButtonGroup;
 
  322     private javax.swing.JLabel profileListLabel;
 
  323     private javax.swing.JPanel profileListPanel;
 
  324     private javax.swing.JScrollPane profileListScrollPane;