<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.fontys.sofa.limo.view.action;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import nl.fontys.sofa.limo.view.chain.ChainGraphScene;
import nl.fontys.sofa.limo.view.util.LIMOResourceBundle;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle.Messages;
import org.openide.windows.TopComponent;

/**
 *
 * @author <NAME>
 */
@ActionID(
        category = "Window",
        id = "nl.fontys.sofa.limo.view.action.CompareSupplyChainsAction"
)
@ActionRegistration(
        iconBase = "icons/gui/Compare_24x24.png",
        displayName = "#CTL_CompareSupplyChainsAction"
)
@ActionReferences({
    @ActionReference(path = "Toolbars/Run", position = 40),
    @ActionReference(path = "Shortcuts", name = "D-B"),})

@Messages({
    "CTL_CompareSupplyChainsAction=Compare Supply Chains"
})

public class CompareSupplyChainsAction extends AbstractAction {
    
    private List<ChainGraphScene> scenes;

    
    @Override
    public void actionPerformed(ActionEvent e) {
         scenes = new ArrayList<>();
        for (TopComponent tc : TopComponent.getRegistry().getOpened()) {
            ChainGraphScene scene = tc.getLookup().lookup(ChainGraphScene.class);
            if (scene != null) {
                scenes.add(scene);
            }
        }
        
        if (scenes.size() < 2) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(LIMOResourceBundle.getString("NOT_ENOUGH_SUPPLY_CHAIN_OPEN"), 2));
            return;
        }
        
        CompareSupplyChainPanel panel = new CompareSupplyChainPanel(scenes);
        DialogDescriptor dd = new DialogDescriptor(panel, LIMOResourceBundle.getString("COMPARISON_SELECTION_MESSAGE"));
        panel.setDialogDesriptor(dd);
        dd.setValid(false);
        
        if (DialogDisplayer.getDefault().notify(dd) == NotifyDescriptor.OK_OPTION) {
            SimulateAction action = new SimulateAction(panel.getSelectedScenes());
            action.actionPerformed(e);
        }
        
    }
    
    private class CompareSupplyChainPanel extends JPanel implements ItemListener {
        
        private Map<JCheckBox, ChainGraphScene> scenes;
        private List<ChainGraphScene> selectedScenes;
        private DialogDescriptor descriptor;
        
        public CompareSupplyChainPanel(List<ChainGraphScene> scenes) {
            super();
            this.scenes = new HashMap<>();
            this.selectedScenes = new ArrayList<>();
            this.setLayout(new BorderLayout()); 
            
            JLabel explenationText = new JLabel(LIMOResourceBundle.getString("EXPLENATION_TEXT_COMPARISON"));            
            explenationText.setHorizontalAlignment(JLabel.CENTER);    
            explenationText.setBorder( BorderFactory.createEmptyBorder(5, 5, 10, 5));
            this.add(explenationText, BorderLayout.NORTH);
            JPanel checkboxesPanel= new JPanel();
            
            checkboxesPanel.setLayout(new GridLayout(0, 3));
            
            for (ChainGraphScene scene : scenes) {
                String name = scene.getSupplyChain().getName();
                JCheckBox box = new JCheckBox(name);<commit_msg>Checkbox name in compare dialog does not include .lsc anymore<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.fontys.sofa.limo.view.action;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import nl.fontys.sofa.limo.view.chain.ChainGraphScene;
import nl.fontys.sofa.limo.view.util.LIMOResourceBundle;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionRegistration;
import org.openide.util.NbBundle.Messages;
import org.openide.windows.TopComponent;

/**
 *
 * @author <NAME>
 */
@ActionID(
        category = "Window",
        id = "nl.fontys.sofa.limo.view.action.CompareSupplyChainsAction"
)
@ActionRegistration(
        iconBase = "icons/gui/Compare_24x24.png",
        displayName = "#CTL_CompareSupplyChainsAction"
)
@ActionReferences({
    @ActionReference(path = "Toolbars/Run", position = 40),
    @ActionReference(path = "Shortcuts", name = "D-B"),})

@Messages({
    "CTL_CompareSupplyChainsAction=Compare Supply Chains"
})

public class CompareSupplyChainsAction extends AbstractAction {
    
    private List<ChainGraphScene> scenes;

    
    @Override
    public void actionPerformed(ActionEvent e) {
         scenes = new ArrayList<>();
        for (TopComponent tc : TopComponent.getRegistry().getOpened()) {
            ChainGraphScene scene = tc.getLookup().lookup(ChainGraphScene.class);
            if (scene != null) {
                scenes.add(scene);
            }
        }
        
        if (scenes.size() < 2) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(LIMOResourceBundle.getString("NOT_ENOUGH_SUPPLY_CHAIN_OPEN"), 2));
            return;
        }
        
        CompareSupplyChainPanel panel = new CompareSupplyChainPanel(scenes);
        DialogDescriptor dd = new DialogDescriptor(panel, LIMOResourceBundle.getString("COMPARISON_SELECTION_MESSAGE"));
        panel.setDialogDesriptor(dd);
        dd.setValid(false);
        
        if (DialogDisplayer.getDefault().notify(dd) == NotifyDescriptor.OK_OPTION) {
            SimulateAction action = new SimulateAction(panel.getSelectedScenes());
            action.actionPerformed(e);
        }
        
    }
    
    private class CompareSupplyChainPanel extends JPanel implements ItemListener {
        
        private Map<JCheckBox, ChainGraphScene> scenes;
        private List<ChainGraphScene> selectedScenes;
        private DialogDescriptor descriptor;
        
        public CompareSupplyChainPanel(List<ChainGraphScene> scenes) {
            super();
            this.scenes = new HashMap<>();
            this.selectedScenes = new ArrayList<>();
            this.setLayout(new BorderLayout()); 
            
            JLabel explenationText = new JLabel(LIMOResourceBundle.getString("EXPLENATION_TEXT_COMPARISON"));            
            explenationText.setHorizontalAlignment(JLabel.CENTER);    
            explenationText.setBorder( BorderFactory.createEmptyBorder(5, 5, 10, 5));
            this.add(explenationText, BorderLayout.NORTH);
            JPanel checkboxesPanel= new JPanel();
            
            checkboxesPanel.setLayout(new GridLayout(0, 3));
            
            for (ChainGraphScene scene : scenes) {
                String name = scene.getSupplyChain().getName().replace(".lsc", "");
                JCheckBox box = new JCheckBox(name);
{'fraction_non_alphanumeric': 0.10099255583126551, 'fraction_numerical': 0.0037220843672456576, 'mean_word_length': 3.100203458799593, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6747223', 'n_tokens_mistral': 2315, 'n_tokens_neox': 2273, 'n_words': 444}