<commit_before>/*
 * Autopsy Forensic Browser
 *
 * Copyright 2012 Basis Technology Corp.
 * Contact: carrier <at> sleuthkit <dot> org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sleuthkit.autopsy.report;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.ListModel;
import javax.swing.event.ListDataListener;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.BlackboardArtifact;
import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
import org.sleuthkit.datamodel.TskCoreException;

public class ArtifactSelectionDialog extends javax.swing.JDialog {
    private static final Logger logger = Logger.getLogger(ArtifactSelectionDialog.class.getName());
    private static ArtifactSelectionDialog instance;
    private ArtifactModel model;
    private ArtifactRenderer renderer;
    
    private Map<BlackboardArtifact.ARTIFACT_TYPE, Boolean> artifactStates;
    private List<BlackboardArtifact.ARTIFACT_TYPE> artifacts;
    
    /**
     * Creates new form ArtifactSelectionDialog
     */
    public ArtifactSelectionDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        populateList();
        customInit();
    }
    
    /**
     * Populate the list of artifacts with all important artifacts.
     */
    private void populateList() {
        try {
            ArrayList<BlackboardArtifact.ARTIFACT_TYPE> doNotReport = new ArrayList();
            doNotReport.add(BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO);
            
            artifacts = Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifactTypesInUse();
            
            artifacts.removeAll(doNotReport);
            
            artifactStates = new EnumMap<BlackboardArtifact.ARTIFACT_TYPE, Boolean>(BlackboardArtifact.ARTIFACT_TYPE.class);
            for (BlackboardArtifact.ARTIFACT_TYPE type : artifacts) {
                artifactStates.put(type, Boolean.TRUE);
            }
        } catch (TskCoreException ex) {
            Logger.getLogger(ArtifactSelectionDialog.class.getName()).log(Level.SEVERE, "Error getting list of artifacts in use: " + ex.getLocalizedMessage());
            return;
        }
    }
    
    private void customInit() {
        model = new ArtifactModel();
        renderer = new ArtifactRenderer();
        artifactList.setModel(model);
        artifactList.setCellRenderer(renderer);
        artifactList.setVisibleRowCount(-1);
        
        artifactList.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent evt) {
                JList list = (JList) evt.getSource();
                int index = list.locationToIndex(evt.getPoint());
                BlackboardArtifact.ARTIFACT_TYPE type = (BlackboardArtifact.ARTIFACT_TYPE) model.getElementAt(index);
                artifactStates.put(type, !artifactStates.get(type));<commit_msg>Sort artifact types alphabetically in artifact selection dialog.<commit_after>/*
 * Autopsy Forensic Browser
 *
 * Copyright 2012 Basis Technology Corp.
 * Contact: carrier <at> sleuthkit <dot> org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sleuthkit.autopsy.report;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.ListModel;
import javax.swing.event.ListDataListener;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.BlackboardArtifact;
import org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE;
import org.sleuthkit.datamodel.TskCoreException;

public class ArtifactSelectionDialog extends javax.swing.JDialog {
    private static final Logger logger = Logger.getLogger(ArtifactSelectionDialog.class.getName());
    private static ArtifactSelectionDialog instance;
    private ArtifactModel model;
    private ArtifactRenderer renderer;
    
    private Map<BlackboardArtifact.ARTIFACT_TYPE, Boolean> artifactStates;
    private List<BlackboardArtifact.ARTIFACT_TYPE> artifacts;
    
    /**
     * Creates new form ArtifactSelectionDialog
     */
    public ArtifactSelectionDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        populateList();
        customInit();
    }
    
    /**
     * Populate the list of artifacts with all important artifacts.
     */
    private void populateList() {
        try {
            ArrayList<BlackboardArtifact.ARTIFACT_TYPE> doNotReport = new ArrayList();
            doNotReport.add(BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO);
            
            artifacts = Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifactTypesInUse();
            
            artifacts.removeAll(doNotReport);
            
            Collections.sort(artifacts, new Comparator<BlackboardArtifact.ARTIFACT_TYPE>() {
                @Override
                public int compare(ARTIFACT_TYPE o1, ARTIFACT_TYPE o2) {
                    return o1.getDisplayName().compareTo(o2.getDisplayName());
                }
            });
                        
            artifactStates = new EnumMap<BlackboardArtifact.ARTIFACT_TYPE, Boolean>(BlackboardArtifact.ARTIFACT_TYPE.class);
            for (BlackboardArtifact.ARTIFACT_TYPE type : artifacts) {
                artifactStates.put(type, Boolean.TRUE);
            }
        } catch (TskCoreException ex) {
            Logger.getLogger(ArtifactSelectionDialog.class.getName()).log(Level.SEVERE, "Error getting list of artifacts in use: " + ex.getLocalizedMessage());
            return;
        }
    }
    
    private void customInit() {
        model = new ArtifactModel();
        renderer = new ArtifactRenderer();
        artifactList.setModel(model);
        artifactList.setCellRenderer(renderer);
        artifactList.setVisibleRowCount(-1);
        
        artifactList.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent evt) {
                JList list = (JList) evt.getSource();
                int index = list.locationToIndex(evt.getPoint());
                BlackboardArtifact.ARTIFACT_TYPE type = (BlackboardArtifact.ARTIFACT_TYPE) model.getElementAt(index);
                artifactStates.put(type, !artifactStates.get(type));
{'fraction_non_alphanumeric': 0.08683370179317121, 'fraction_numerical': 0.002702038811102923, 'mean_word_length': 3.1609606540623405, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '374901', 'n_tokens_mistral': 2288, 'n_tokens_neox': 2200, 'n_words': 532}