<commit_before>package org.cytoscape.filter.internal.composite;

import java.awt.dnd.DropTarget;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;

import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout.Group;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;

import org.cytoscape.filter.internal.view.DragHandler;
import org.cytoscape.filter.internal.view.DynamicComboBoxModel;
import org.cytoscape.filter.internal.view.FilterPanel;
import org.cytoscape.filter.internal.view.FilterPanelController;
import org.cytoscape.filter.internal.view.IconManager;
import org.cytoscape.filter.internal.view.TransformerElementViewModel;
import org.cytoscape.filter.internal.view.ViewUtil;
import org.cytoscape.filter.model.CompositeFilter;
import org.cytoscape.filter.model.CompositeFilter.Type;
import org.cytoscape.filter.model.Filter;
import org.cytoscape.model.CyIdentifiable;
import org.cytoscape.model.CyNetwork;

@SuppressWarnings("serial")
public class CompositeFilterPanel extends JPanel {
	
	private static final Border NO_BORDER = BorderFactory.createEmptyBorder();

	private Map<Filter<CyNetwork, CyIdentifiable>, TransformerElementViewModel<FilterPanel>> viewModels;
	private GroupLayout layout;
	private int depth;
	private JComboBox combiningMethodComboBox;
	private FilterPanelController filterPanelController;
	private final JButton addButton;
	private FilterPanel parent;
	private CompositeFilter<CyNetwork, CyIdentifiable> model;
	private final IconManager iconManager;
	private JComponent separator; 
	
	public CompositeFilterPanel(FilterPanel parent, FilterPanelController filterPanelController, 
			final CompositeFilter<CyNetwork, CyIdentifiable> model, int depth, IconManager iconManager) {
		this(parent, filterPanelController, new Controller(), model, depth, iconManager);
	}
	
	public CompositeFilterPanel(FilterPanel parent, FilterPanelController filterPanelController, 
			final Controller controller, final CompositeFilter<CyNetwork, CyIdentifiable> model, int depth,
			IconManager iconManager) {
		this.parent = parent;
		this.filterPanelController = filterPanelController;
		this.depth = depth;
		this.model = model;
		this.iconManager = iconManager;
		
		separator = new CompositeSeparator();
		new DropTarget(separator, new DragHandler<FilterPanel>(separator, filterPanelController, parent, null));

		ViewUtil.configureFilterView(this);
		
		viewModels = new WeakHashMap<Filter<CyNetwork,CyIdentifiable>, TransformerElementViewModel<FilterPanel>>();
		layout = new GroupLayout(this);
		setLayout(layout);
		updateBorder();
		
		combiningMethodComboBox = new JComboBox(controller.getCombiningMethodComboBoxModel());
		combiningMethodComboBox.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent event) {
				controller.handleCombiningMethodSelected(combiningMethodComboBox, model);
			}
		});
		
		addButton = createAddConditionButton();
		
		for (int i = 0; i < model.getLength(); i++) {
			Filter<CyNetwork, CyIdentifiable> filter = model.get(i);
			JComponent component = filterPanelController.createView(parent, filter, depth + 1);
			TransformerElementViewModel<FilterPanel> viewModel = new TransformerElementViewModel<FilterPanel>(component, filterPanelController, parent, iconManager);
			viewModels.put(filter, viewModel);
		}
	}
	
	private void updateBorder() {
		if (depth > 0) {
			setBorder(ViewUtil.COMPOSITE_PANEL_BORDER);
		} else {
			setBorder(NO_BORDER);
		}
	}

	public void updateLayout() {
		if (!SwingUtilities.isEventDispatchThread()) {
			SwingUtilities.invokeLater(new Runnable() {
				@Override
				public void run() {<commit_msg>References #2575: Fixed bug where deserialized CompositeFilters aren't completely synchronized with their UI.<commit_after>package org.cytoscape.filter.internal.composite;

import java.awt.dnd.DropTarget;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;

import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout.Group;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;

import org.cytoscape.filter.internal.view.DragHandler;
import org.cytoscape.filter.internal.view.DynamicComboBoxModel;
import org.cytoscape.filter.internal.view.FilterPanel;
import org.cytoscape.filter.internal.view.FilterPanelController;
import org.cytoscape.filter.internal.view.IconManager;
import org.cytoscape.filter.internal.view.Matcher;
import org.cytoscape.filter.internal.view.TransformerElementViewModel;
import org.cytoscape.filter.internal.view.ViewUtil;
import org.cytoscape.filter.model.CompositeFilter;
import org.cytoscape.filter.model.CompositeFilter.Type;
import org.cytoscape.filter.model.Filter;
import org.cytoscape.model.CyIdentifiable;
import org.cytoscape.model.CyNetwork;

@SuppressWarnings("serial")
public class CompositeFilterPanel extends JPanel {
	
	private static final Border NO_BORDER = BorderFactory.createEmptyBorder();

	private Map<Filter<CyNetwork, CyIdentifiable>, TransformerElementViewModel<FilterPanel>> viewModels;
	private GroupLayout layout;
	private int depth;
	private JComboBox combiningMethodComboBox;
	private FilterPanelController filterPanelController;
	private final JButton addButton;
	private FilterPanel parent;
	private CompositeFilter<CyNetwork, CyIdentifiable> model;
	private final IconManager iconManager;
	private JComponent separator; 
	
	public CompositeFilterPanel(FilterPanel parent, FilterPanelController filterPanelController, 
			final CompositeFilter<CyNetwork, CyIdentifiable> model, int depth, IconManager iconManager) {
		this(parent, filterPanelController, new Controller(), model, depth, iconManager);
	}
	
	public CompositeFilterPanel(FilterPanel parent, FilterPanelController filterPanelController, 
			final Controller controller, final CompositeFilter<CyNetwork, CyIdentifiable> model, int depth,
			IconManager iconManager) {
		this.parent = parent;
		this.filterPanelController = filterPanelController;
		this.depth = depth;
		this.model = model;
		this.iconManager = iconManager;
		
		separator = new CompositeSeparator();
		new DropTarget(separator, new DragHandler<FilterPanel>(separator, filterPanelController, parent, null));

		ViewUtil.configureFilterView(this);
		
		viewModels = new WeakHashMap<Filter<CyNetwork,CyIdentifiable>, TransformerElementViewModel<FilterPanel>>();
		layout = new GroupLayout(this);
		setLayout(layout);
		updateBorder();
		
		combiningMethodComboBox = new JComboBox(controller.getCombiningMethodComboBoxModel());
		combiningMethodComboBox.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent event) {
				controller.handleCombiningMethodSelected(combiningMethodComboBox, model);
			}
		});
		
		DynamicComboBoxModel.select(combiningMethodComboBox, 0, new Matcher<CombiningMethodElement>() {
			@Override
			public boolean matches(CombiningMethodElement item) {
				return model.getType().equals(item.combiningMethod);
			}
		});
		
		addButton = createAddConditionButton();
		
		for (int i = 0; i < model.getLength(); i++) {
			Filter<CyNetwork, CyIdentifiable> filter = model.get(i);
			JComponent component = filterPanelController.createView(parent, filter, depth + 1);
			TransformerElementViewModel<FilterPanel> viewModel = new TransformerElementViewModel<FilterPanel>(component, filterPanelController, parent, iconManager);
			viewModels.put(filter, viewModel);
		}
	}
	
	private void updateBorder() {
		if (depth > 0) {
			setBorder(ViewUtil.COMPOSITE_PANEL_BORDER);
		} else {
			setBorder(NO_BORDER);
		}
	}

	public void updateLayout() {
		if (!SwingUtilities.isEventDispatchThread()) {
			SwingUtilities.invokeLater(new Runnable() {
				@Override
				public void run() {
{'fraction_non_alphanumeric': 0.09146908414690841, 'fraction_numerical': 0.0012784751278475128, 'mean_word_length': 6.405335628227195, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, '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': '264163', 'n_tokens_mistral': 2637, 'n_tokens_neox': 2397, 'n_words': 507}