<commit_before>/**
 * New BSD License
 * http://www.opensource.org/licenses/bsd-license.php
 * Copyright (c) 2009, RaptorProject (http://code.google.com/p/raptor-chess-interface/)
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 * Neither the name of the RaptorProject nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package raptor.pref.page;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.ColorSelector;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import raptor.Raptor;
import raptor.chat.ChatType;
import raptor.pref.PreferenceKeys;
import raptor.pref.RaptorPreferenceStore;

public class ChatConsoleChannelColorsPage extends PreferencePage {
	Text channelName;
	Combo channels;
	ColorSelector colorSelector;
	Button deleteButton;
	Composite parent;
	RaptorPreferenceStore raptorPreferenceStore;
	Button saveButton;

	public ChatConsoleChannelColorsPage() {
		// Use the "flat" layout
		super();
		setPreferenceStore(raptorPreferenceStore = Raptor.getInstance()
				.getPreferences());
		setTitle("Channel Colors");
	}

	public String getKey(String channel) {
		return PreferenceKeys.CHAT_CHAT_EVENT_TYPE_COLOR_APPEND_TO
				+ ChatType.CHANNEL_TELL + "-" + channel + "-color";
	}

	public void updateChannelsCombo() {
		for (int i = 0; i < 255; i++) {
			String key = getKey("" + i);
			if (raptorPreferenceStore.contains(key)) {
				boolean contains = false;
				for (int j = 0; j < channels.getItemCount(); j++) {
					if (channels.getItem(j).equals("" + i)) {
						contains = true;
						break;
					}
				}

				if (!contains) {
					channels.add("" + i);
				}
			}
		}
	}

	@Override
	protected Control createContents(Composite parent) {
		parent = new Composite(parent, SWT.NONE);
		parent.setLayout(new GridLayout(3, false));

		Label channelNamesLabel = new Label(parent, SWT.NONE);
		channelNamesLabel.setText("Channels:");
		channelNamesLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER,<commit_msg>Fixed Issue 228.<commit_after>/**
 * New BSD License
 * http://www.opensource.org/licenses/bsd-license.php
 * Copyright (c) 2009, RaptorProject (http://code.google.com/p/raptor-chess-interface/)
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 * Neither the name of the RaptorProject nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package raptor.pref.page;

import org.apache.commons.lang.WordUtils;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.ColorSelector;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import raptor.Raptor;
import raptor.chat.ChatType;
import raptor.pref.PreferenceKeys;
import raptor.pref.RaptorPreferenceStore;

public class ChatConsoleChannelColorsPage extends PreferencePage {
	Text channelName;
	Combo channels;
	ColorSelector colorSelector;
	Button deleteButton;
	Composite parent;
	RaptorPreferenceStore raptorPreferenceStore;
	Button saveButton;

	public ChatConsoleChannelColorsPage() {
		// Use the "flat" layout
		super();
		setPreferenceStore(raptorPreferenceStore = Raptor.getInstance()
				.getPreferences());
		setTitle("Channel Colors");
	}

	public String getKey(String channel) {
		return PreferenceKeys.CHAT_CHAT_EVENT_TYPE_COLOR_APPEND_TO
				+ ChatType.CHANNEL_TELL + "-" + channel + "-color";
	}

	public void updateChannelsCombo() {
		for (int i = 0; i < 255; i++) {
			String key = getKey("" + i);
			if (raptorPreferenceStore.contains(key)) {
				boolean contains = false;
				for (int j = 0; j < channels.getItemCount(); j++) {
					if (channels.getItem(j).equals("" + i)) {
						contains = true;
						break;
					}
				}

				if (!contains) {
					channels.add("" + i);
				}
			}
		}
	}

	@Override
	protected Control createContents(Composite parent) {
		parent = new Composite(parent, SWT.NONE);
		parent.setLayout(new GridLayout(3, false));

		Label label = new Label(parent, SWT.NONE);
		label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3,
				1));
		label
				.setText(WordUtils
						.wrap(
								"\tTo set the channel color for an existing channel, select it from the Channels Combo Box. "
										+ "Use the color selector to adjust the color and click the 'Save/Add Channel Color' button. "
										+ "Ignore the buttons on the bottom right don't use those.",
								70)
						+ WordUtils
								.wrap(
										"\n\tTo add a new channel color "
												+ "type in the channel number in the box provided set the color and click the 'Save/Add Channel Color'. "
												+ "Ignore the buttons on the bottom right.",
										70));

		Label channelNamesLabel = new Label(parent, SWT.NONE);
		channelNamesLabel.setText("Channels:");
		channelNamesLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER,
{'fraction_non_alphanumeric': 0.0865127582017011, 'fraction_numerical': 0.0035236938031591738, 'mean_word_length': 4.3832570307390455, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '3107640', 'n_tokens_mistral': 2637, 'n_tokens_neox': 2270, 'n_words': 814}