<commit_before>/*
 * Autopsy Forensic Browser
 *
 * Copyright 2011-2017 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.communications;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.stream.Collectors;
import javax.swing.JCheckBox;
import org.openide.explorer.ExplorerManager;
import org.openide.nodes.AbstractNode;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.ThreadConfined;
import org.sleuthkit.datamodel.Account;
import org.sleuthkit.datamodel.AccountDeviceInstance;
import org.sleuthkit.datamodel.CommunicationsFilter;
import org.sleuthkit.datamodel.CommunicationsManager;
import org.sleuthkit.datamodel.DataSource;
import org.sleuthkit.datamodel.DeviceFilter;
import org.sleuthkit.datamodel.TskCoreException;

/**
 *
 */
final public class FiltersPanel extends javax.swing.JPanel {

    private static final Logger logger = Logger.getLogger(FiltersPanel.class.getName());
    private static final long serialVersionUID = 1L;

    private ExplorerManager em;

    @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
    private final Map<Account.Type, JCheckBox> accountTypeMap = new HashMap<>();
    @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
    private final Map<String, JCheckBox> devicesMap = new HashMap<>();

    public FiltersPanel() {
        initComponents();
        updateFilters();
    }

    void updateFilters() {
        updateAccountTypeFilter();
        updateDeviceFilter();
    }

    @Override
    public void addNotify() {
        super.addNotify();
        em = ExplorerManager.find(this);
    }

    /**
     * Populate the Account Types filter widgets
     */
    private void updateAccountTypeFilter() {

        //TODO: something like this commented code could be used to show only
        //the account types that are found:
        //final CommunicationsManager communicationsManager = Case.getCurrentCase().getSleuthkitCase().getCommunicationsManager();
        //List<Account.Type> accountTypesInUse = communicationsManager.getAccountTypesInUse();
        //accountTypesInUSe.forEach(...)
        Account.Type.PREDEFINED_ACCOUNT_TYPES.forEach(
                type -> accountTypeMap.computeIfAbsent(type, t -> {
                    final JCheckBox jCheckBox = new JCheckBox(
                            "<html><table cellpadding=0><tr><td><img src=\""
                            + FiltersPanel.class.getResource("/org/sleuthkit/autopsy/communications/images/"
                                    + AccountUtils.getIconFileName(type))
                            + "\"/></td><td width=" + 3 + "><td>" + type.getDisplayName() + "</td></tr></table></html>",
                            true
                    );
                    accountTypePane.add(jCheckBox);
                    return jCheckBox;
                })
        );
    }

    /**
     * Populate the devices filter widgets
     */
    private void updateDeviceFilter() {
        try {
            final List<DataSource> dataSources = Case.getCurrentCase().getSleuthkitCase().getDataSources();
            dataSources.forEach(
                    dataSource -> devicesMap.computeIfAbsent(dataSource.getDeviceId(), ds -> {
                        final JCheckBox jCheckBox = new JCheckBox(dataSource.getDeviceId(), true);
                        devicesPane.add(jCheckBox);
                        return jCheckBox;
                    })
            );
        } catch (IllegalStateException ex) {
            logger.log(Level.WARNING, "Communications Visualization Tool opened with no open case.", ex);
        } catch (TskCoreException tskCoreException) {
            logger.log(Level.SEVERE, "There was a error loading the datasources for the case.", tskCoreException);
        }
    }
<commit_msg>don't shown credit cards or device  in the account type filter widget<commit_after>/*
 * Autopsy Forensic Browser
 *
 * Copyright 2011-2017 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.communications;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.stream.Collectors;
import javax.swing.JCheckBox;
import org.openide.explorer.ExplorerManager;
import org.openide.nodes.AbstractNode;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.ThreadConfined;
import org.sleuthkit.datamodel.Account;
import org.sleuthkit.datamodel.AccountDeviceInstance;
import org.sleuthkit.datamodel.CommunicationsFilter;
import org.sleuthkit.datamodel.CommunicationsManager;
import org.sleuthkit.datamodel.DataSource;
import org.sleuthkit.datamodel.DeviceFilter;
import org.sleuthkit.datamodel.TskCoreException;

/**
 *
 */
final public class FiltersPanel extends javax.swing.JPanel {

    private static final Logger logger = Logger.getLogger(FiltersPanel.class.getName());
    private static final long serialVersionUID = 1L;

    private ExplorerManager em;

    @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
    private final Map<Account.Type, JCheckBox> accountTypeMap = new HashMap<>();
    @ThreadConfined(type = ThreadConfined.ThreadType.AWT)
    private final Map<String, JCheckBox> devicesMap = new HashMap<>();

    public FiltersPanel() {
        initComponents();
        updateFilters();
    }

    void updateFilters() {
        updateAccountTypeFilter();
        updateDeviceFilter();
    }

    @Override
    public void addNotify() {
        super.addNotify();
        em = ExplorerManager.find(this);
    }

    /**
     * Populate the Account Types filter widgets
     */
    private void updateAccountTypeFilter() {

        //TODO: something like this commented code could be used to show only
        //the account types that are found:
        //final CommunicationsManager communicationsManager = Case.getCurrentCase().getSleuthkitCase().getCommunicationsManager();
        //List<Account.Type> accountTypesInUse = communicationsManager.getAccountTypesInUse();
        //accountTypesInUSe.forEach(...)
        Account.Type.PREDEFINED_ACCOUNT_TYPES.forEach(
                type -> {
                    if (type.equals(Account.Type.CREDIT_CARD)) {
                        //don't show a check box for credit cards
                    } else if (type.equals(Account.Type.DEVICE)) {
                        //don't show a check box fro device
                    } else {
                        accountTypeMap.computeIfAbsent(type, t -> {
                            final JCheckBox jCheckBox = new JCheckBox(
                                    "<html><table cellpadding=0><tr><td><img src=\""
                                    + FiltersPanel.class.getResource("/org/sleuthkit/autopsy/communications/images/"
                                            + AccountUtils.getIconFileName(type))
                                    + "\"/></td><td width=" + 3 + "><td>" + type.getDisplayName() + "</td></tr></table></html>",
                                    true
                            );
                            accountTypePane.add(jCheckBox);
                            return jCheckBox;
                        });
                    }
                }
        );
    }

    /**
     * Populate the devices filter widgets
     */
    private void updateDeviceFilter() {
        try {
            final List<DataSource> dataSources = Case.getCurrentCase().getSleuthkitCase().getDataSources();
            dataSources.forEach(
                    dataSource -> devicesMap.computeIfAbsent(dataSource.getDeviceId(), ds -> {
                        final JCheckBox jCheckBox = new JCheckBox(dataSource.getDeviceId(), true);
                        devicesPane.add(jCheckBox);
                        return jCheckBox;
                    })
            );
        } catch (IllegalStateException ex) {
            logger.log(Level.WARNING, "Communications Visualization Tool opened with no open case.", ex);
        } catch (TskCoreException tskCoreException) {
            logger.log(Level.SEVERE, "There was a error loading the datasources for the case.", tskCoreException);
        }
    }

{'fraction_non_alphanumeric': 0.09665970772442589, 'fraction_numerical': 0.003131524008350731, 'mean_word_length': 2.4663531114327064, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5450643', 'n_tokens_mistral': 2604, 'n_tokens_neox': 2498, 'n_words': 636}