<commit_before>/***
    Copyright 2017 by <NAME>
    Licensed under the Apache License version 2.0
*/

package edisyn.gui;

import edisyn.*;
import java.awt.*;
import java.awt.geom.*;
import javax.swing.border.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;

/**
   A pretty container for widgets to categorize them

   @author <NAME>
*/

public class Category extends JComponent implements Gatherable
    {             
    Color color;
      
    /** If synth is non-null, then double-clicking on the category will select or deselect all the
    	components inside it for mutation purposes. */
    public Category(final Synth synth, String label, Color color)
        {
        setLayout(new BorderLayout());
        this.color = color;     
        setName(label);

		if (synth != null)
			{
			addMouseListener(new MouseAdapter()
				{
				public void mouseClicked(MouseEvent e)
					{
					boolean inBorder = ( e.getPoint().y < getInsets().top);
					if (e.getClickCount() == 2 && inBorder)
						{
						boolean turnOn = true;
						ArrayList comps = new ArrayList();
						gatherAllComponents(comps);
						for(int i = 0; i < comps.size(); i++)
							{
							if (comps.get(i) instanceof NumericalComponent)
								{
								NumericalComponent nc = (NumericalComponent)(comps.get(i));
								String key = nc.getKey();
								if (synth.mutationMap.isFree(key) && synth.getModel().getStatus(key) != Model.STATUS_IMMUTABLE)
									{ turnOn = false; break; }
								}
							}
										
						for(int i = 0; i < comps.size(); i++)
							{
							if (comps.get(i) instanceof NumericalComponent)
								{
								NumericalComponent nc = (NumericalComponent)(comps.get(i));
								String key = nc.getKey();
								if (synth.getModel().getStatus(key) != Model.STATUS_IMMUTABLE)
									synth.mutationMap.setFree(key, turnOn);
								}
							}
						repaint();
						}
					}
				});
			}
                        
        }
    
    public Insets getInsets() 
        { 
        Insets insets = (Insets)(super.getInsets().clone());
        insets.bottom = 0;
        return insets;
        }
    
    public void setName(String label)
        {
        
        // here we're going to do a little hack.  TitledBorder doesn't put the title
        // on the FAR LEFT of the line, so when we draw the border we get a little square
        // dot to the left of the title which looks really annoying.  Rather than build a
        // totally new border, we're just going to change the insets.  Titled border uses
        // the insets of the underlying border as part of its calculation of where to put
        // the border, so if we subtract 5 from the insets of the underlying border this
        // counteracts the 5 pixels that titledBorder adds in to shift the title over to
        // the right annoyingly.  So during paintBorder, we turn off a flag, then when<commit_msg>Double-click should only work in mutation parameter mode<commit_after>/***
    Copyright 2017 by <NAME>
    Licensed under the Apache License version 2.0
*/

package edisyn.gui;

import edisyn.*;
import java.awt.*;
import java.awt.geom.*;
import javax.swing.border.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;

/**
   A pretty container for widgets to categorize them

   @author <NAME>
*/

public class Category extends JComponent implements Gatherable
    {             
    Color color;
      
    /** If synth is non-null, then double-clicking on the category will select or deselect all the
    	components inside it for mutation purposes. */
    public Category(final Synth synth, String label, Color color)
        {
        setLayout(new BorderLayout());
        this.color = color;     
        setName(label);

		if (synth != null)
			{
			addMouseListener(new MouseAdapter()
				{
				public void mouseClicked(MouseEvent e)
					{
					if (synth.isShowingMutation())
						{
						boolean inBorder = ( e.getPoint().y < getInsets().top);
						if (e.getClickCount() == 2 && inBorder)
							{
							boolean turnOn = true;
							ArrayList comps = new ArrayList();
							gatherAllComponents(comps);
							for(int i = 0; i < comps.size(); i++)
								{
								if (comps.get(i) instanceof NumericalComponent)
									{
									NumericalComponent nc = (NumericalComponent)(comps.get(i));
									String key = nc.getKey();
									if (synth.mutationMap.isFree(key) && synth.getModel().getStatus(key) != Model.STATUS_IMMUTABLE)
										{ turnOn = false; break; }
									}
								}
									
							for(int i = 0; i < comps.size(); i++)
								{
								if (comps.get(i) instanceof NumericalComponent)
									{
									NumericalComponent nc = (NumericalComponent)(comps.get(i));
									String key = nc.getKey();
									if (synth.getModel().getStatus(key) != Model.STATUS_IMMUTABLE)
										synth.mutationMap.setFree(key, turnOn);
									}
								}
							repaint();
							}
						}
					}
				});
			}
                        
        }
    
    public Insets getInsets() 
        { 
        Insets insets = (Insets)(super.getInsets().clone());
        insets.bottom = 0;
        return insets;
        }
    
    public void setName(String label)
        {
        
        // here we're going to do a little hack.  TitledBorder doesn't put the title
        // on the FAR LEFT of the line, so when we draw the border we get a little square
        // dot to the left of the title which looks really annoying.  Rather than build a
        // totally new border, we're just going to change the insets.  Titled border uses
        // the insets of the underlying border as part of its calculation of where to put
        // the border, so if we subtract 5 from the insets of the underlying border this
        // counteracts the 5 pixels that titledBorder adds in to shift the title over to
        // the right annoyingly.  So during paintBorder, we turn off a flag, then when
{'fraction_non_alphanumeric': 0.09895658027600135, 'fraction_numerical': 0.004039044092898014, 'mean_word_length': 2.0953125, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, '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': '2231795', 'n_tokens_mistral': 2187, 'n_tokens_neox': 1681, 'n_words': 570}