<commit_before>package org.clubrockisen.view.parameter;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Logger;

import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

import org.clubrockisen.service.abstracts.ParametersEnum;
import org.clubrockisen.view.renderers.LafRenderer;

/**
 * A combo box for editing an look and feel parameter.<br />
 * @author Alex
 */
public class LAFComboBox extends ParameterComponent {
	/** Logger */
	private static Logger				lg	= Logger.getLogger(LAFComboBox.class.getName());
	
	/** Combo box for Look and Feel */
	private JComboBox<LookAndFeelInfo>	comboBox;
	
	/**
	 * Constructor #1.<br />
	 * @param parameter
	 *        the parameter displayed.
	 */
	public LAFComboBox (final ParametersEnum parameter) {
		super(parameter);
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.clubrockisen.view.parameter.ParameterComponent#getComponent()
	 */
	@Override
	public JComponent getComponent () {
		if (comboBox == null) {
			comboBox = new JComboBox<>(UIManager.getInstalledLookAndFeels());
			comboBox.setRenderer(new LafRenderer());
			// TODO add listener on user action
		}
		return comboBox;
	}
	
	/*
	 * (non-Javadoc)
	 * @see
	 * org.clubrockisen.view.parameter.ParameterComponent#installListener(org.clubrockisen.view.
	 * parameter.ParameterChangeListener)
	 */
	@Override
	public void installListener (final ParameterChangeListener listener) {
		if (comboBox == null) {
			lg.warning("Cannot set value on null combo box for parameter " + getParameter().getName());
			return;
		}
		
		comboBox.addActionListener(new ActionListener() {
			/*
			 * (non-Javadoc)
			 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
			 */
			@Override
			public void actionPerformed (final ActionEvent e) {
				listener.parameterChangeValue(getParameter(), getValue());
			}
		});
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.clubrockisen.view.parameter.ParameterComponent#getValue()
	 */
	@Override
	public String getValue () {
		return comboBox == null ? null : ((LookAndFeelInfo) comboBox.getSelectedItem()).getName();
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.clubrockisen.view.parameter.ParameterComponent#setValue(java.lang.Object)
	 */
	@Override
	public void setValue (final Object value) {
		if (comboBox == null) {
			lg.warning("Cannot set value on null combo box for parameter " + getParameter().getName());
			return;
		}
		
		// TODO exception on not found LAF?
		boolean found = false;
		for (int lafIndex = 0; lafIndex < comboBox.getItemCount() && !found; lafIndex++) {
			if (comboBox.getItemAt(lafIndex).getName().equals(value)) {
				comboBox.setSelectedIndex(lafIndex);
				found = true;
			}
		}
		if (!found) {
			lg.warning("Look and feel not found: " + value);
		}
	}
}
<commit_msg>Refreshing application LaF when changing the parameter. LaF should be reverted when canceling the parameter view (TBD).<commit_after>package org.clubrockisen.view.parameter;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Logger;

import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

import org.clubrockisen.service.abstracts.ParametersEnum;
import org.clubrockisen.view.Utils;
import org.clubrockisen.view.renderers.LafRenderer;

/**
 * A combo box for editing an look and feel parameter.<br />
 * @author Alex
 */
public class LAFComboBox extends ParameterComponent {
	/** Logger */
	private static Logger				lg	= Logger.getLogger(LAFComboBox.class.getName());
	
	/** Combo box for Look and Feel */
	private JComboBox<LookAndFeelInfo>	comboBox;
	
	/**
	 * Constructor #1.<br />
	 * @param parameter
	 *        the parameter displayed.
	 */
	public LAFComboBox (final ParametersEnum parameter) {
		super(parameter);
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.clubrockisen.view.parameter.ParameterComponent#getComponent()
	 */
	@Override
	public JComponent getComponent () {
		if (comboBox == null) {
			comboBox = new JComboBox<>(UIManager.getInstalledLookAndFeels());
			comboBox.setRenderer(new LafRenderer());
		}
		return comboBox;
	}
	
	/*
	 * (non-Javadoc)
	 * @see
	 * org.clubrockisen.view.parameter.ParameterComponent#installListener(org.clubrockisen.view.
	 * parameter.ParameterChangeListener)
	 */
	@Override
	public void installListener (final ParameterChangeListener listener) {
		if (comboBox == null) {
			lg.warning("Cannot set value on null combo box for parameter " + getParameter().getName());
			return;
		}
		
		comboBox.addActionListener(new ActionListener() {
			/*
			 * (non-Javadoc)
			 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
			 */
			@Override
			public void actionPerformed (final ActionEvent e) {
				listener.parameterChangeValue(getParameter(), getValue());
				SwingUtilities.invokeLater(new Runnable() {
					/*
					 * (non-Javadoc)
					 * @see java.lang.Runnable#run()
					 */
					@Override
					public void run () {
						Utils.setLookAndFeel(getValue());
					}
				});
			}
		});
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.clubrockisen.view.parameter.ParameterComponent#getValue()
	 */
	@Override
	public String getValue () {
		return comboBox == null ? null : ((LookAndFeelInfo) comboBox.getSelectedItem()).getName();
	}
	
	/*
	 * (non-Javadoc)
	 * @see org.clubrockisen.view.parameter.ParameterComponent#setValue(java.lang.Object)
	 */
	@Override
	public void setValue (final Object value) {
		if (comboBox == null) {
			lg.warning("Cannot set value on null combo box for parameter " + getParameter().getName());
			return;
		}
		
		// TODO exception on not found LAF?
		boolean found = false;
		for (int lafIndex = 0; lafIndex < comboBox.getItemCount() && !found; lafIndex++) {
			if (comboBox.getItemAt(lafIndex).getName().equals(value)) {
				comboBox.setSelectedIndex(lafIndex);
				found = true;
			}
		}
		if (!found) {
			lg.warning("Look and feel not found: " + value);
		}
	}
}

{'fraction_non_alphanumeric': 0.12247793190416141, 'fraction_numerical': 0.0006305170239596469, 'mean_word_length': 3.272727272727273, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '4887491', 'n_tokens_mistral': 2223, 'n_tokens_neox': 1928, 'n_words': 412}