<commit_before>/*******************************************************************************
 * Mission Control Technologies, Copyright (c) 2009-2012, United States Government
 * as represented by the Administrator of the National Aeronautics and Space 
 * Administration. All rights reserved.
 *
 * The MCT platform is 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.
 *
 * MCT includes source code licensed under additional open source licenses. See 
 * the MCT Open Source Licenses file included with this distribution or the About 
 * MCT Licenses dialog available at runtime from the MCT Help menu for additional 
 * information. 
 *******************************************************************************/
package gov.nasa.arc.mct.scenario.component;

import gov.nasa.arc.mct.components.AbstractComponent;

import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JPanel;

public class TagSelectionDialog extends JDialog {
	private static final long serialVersionUID = 270779787729717592L;

	// Maintain selection by id
	private Set<String> selectedIds = new HashSet<String>();
	
	public TagSelectionDialog(
			List<AbstractComponent> repositories, 
			Collection<AbstractComponent> selected,
			Window parent) {
		super(parent);
		
		for (AbstractComponent c : selected) {
			selectedIds.add(c.getComponentId());
		}
		
		JPanel panel = new JPanel();
		panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
		
		for (AbstractComponent repo : repositories) {
			panel.add(makeCheckBoxPanel(repo));
		}
		
		panel.add(makeButtons());
		
		getContentPane().add(panel);
		
		pack();
	}
	
	private JComponent makeButtons() {
		JPanel p = new JPanel();
		
		JButton cancel = new JButton("Cancel");
		JButton ok = new JButton("OK");
		
		cancel.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent evt) {
				TagSelectionDialog.this.dispose();
			}			
		});
		
		ok.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent evt) {
				// TODO: Notify parent object
				TagSelectionDialog.this.dispose();
			}			
		});
		
		p.add(cancel);
		p.add(ok);
		
		return p;
	}
	
	private JComponent makeCheckBoxPanel(AbstractComponent repository) {
		JPanel p = new JPanel();
		
		p.setBorder(BorderFactory.createTitledBorder(repository.getDisplayName()));
		p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
		for (AbstractComponent child : repository.getComponents()) {
			JCheckBox checkBox = new JCheckBox(child.getDisplayName());
			checkBox.setSelected( selectedIds.contains(child.getComponentId()) );
			checkBox.addActionListener( new Selector(child.getComponentId()) );
			p.add(checkBox);
		}
		
		return p;
	}

	private class Selector implements ActionListener {
		private String id;
		
		public Selector(String id) {
			this.id = id;
		}

		@Override
		public void actionPerformed(ActionEvent evt) {
			Object src = evt.getSource();
			if (src instanceof JCheckBox) {
				boolean checked = ((JCheckBox) src).isSelected();
				if (checked) {
					selectedIds.add(id);
				} else {
					selectedIds.remove(id);
				}
			}
		}		
	}
	
}
<commit_msg>[Scenario] Add padding to tag selection dialog<commit_after>/*******************************************************************************
 * Mission Control Technologies, Copyright (c) 2009-2012, United States Government
 * as represented by the Administrator of the National Aeronautics and Space 
 * Administration. All rights reserved.
 *
 * The MCT platform is 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.
 *
 * MCT includes source code licensed under additional open source licenses. See 
 * the MCT Open Source Licenses file included with this distribution or the About 
 * MCT Licenses dialog available at runtime from the MCT Help menu for additional 
 * information. 
 *******************************************************************************/
package gov.nasa.arc.mct.scenario.component;

import gov.nasa.arc.mct.components.AbstractComponent;

import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JPanel;

public class TagSelectionDialog extends JDialog {
	private static final long serialVersionUID = 270779787729717592L;

	// Maintain selection by id
	private Set<String> selectedIds = new HashSet<String>();
	
	public TagSelectionDialog(
			List<AbstractComponent> repositories, 
			Collection<AbstractComponent> selected,
			Window parent) {
		super(parent);
		
		for (AbstractComponent c : selected) {
			selectedIds.add(c.getComponentId());
		}
		
		JPanel panel = new JPanel();
		panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
		
		for (AbstractComponent repo : repositories) {
			panel.add(makeCheckBoxPanel(repo));
		}
		
		panel.add(makeButtons());
		panel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
		getContentPane().add(panel);
		
		pack();
	}
	
	private JComponent makeButtons() {
		JPanel p = new JPanel();
		
		JButton cancel = new JButton("Cancel");
		JButton ok = new JButton("OK");
		
		cancel.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent evt) {
				TagSelectionDialog.this.dispose();
			}			
		});
		
		ok.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent evt) {
				// TODO: Notify parent object
				TagSelectionDialog.this.dispose();
			}			
		});
		
		p.add(cancel);
		p.add(ok);
		p.setBorder(BorderFactory.createEmptyBorder(17, 0, 0, 0));
		
		return p;
	}
	
	private JComponent makeCheckBoxPanel(AbstractComponent repository) {
		JPanel p = new JPanel();
		
		p.setBorder(BorderFactory.createTitledBorder(repository.getDisplayName()));
		p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
		for (AbstractComponent child : repository.getComponents()) {
			JCheckBox checkBox = new JCheckBox(child.getDisplayName());
			checkBox.setSelected( selectedIds.contains(child.getComponentId()) );
			checkBox.addActionListener( new Selector(child.getComponentId()) );
			p.add(checkBox);
		}
		
		return p;
	}

	private class Selector implements ActionListener {
		private String id;
		
		public Selector(String id) {
			this.id = id;
		}

		@Override
		public void actionPerformed(ActionEvent evt) {
			Object src = evt.getSource();
			if (src instanceof JCheckBox) {
				boolean checked = ((JCheckBox) src).isSelected();
				if (checked) {
					selectedIds.add(id);
				} else {
					selectedIds.remove(id);
				}
			}
		}		
	}
	
}

{'fraction_non_alphanumeric': 0.13256413403706885, 'fraction_numerical': 0.008960353504357432, 'mean_word_length': 4.263565891472868, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '986319', 'n_tokens_mistral': 2636, 'n_tokens_neox': 2234, 'n_words': 668}