<commit_before>// PathVisio,
// a tool for data visualization and analysis using Biological Pathways
// Copyright 2006-2007 BiGCaT Bioinformatics
//
// 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.
//
package org.pathvisio.visualization.colorset;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.EventListener;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

public class ColorSetManager {
	public final static String XML_ELEMENT = "color-sets";

	private static List<ColorSet> colorSets = new ArrayList<ColorSet>();

	/**
	 * Gets the {@link ColorSet}s used for the currently loaded Expression data
	 */
	public static List<ColorSet> getColorSets() { return colorSets; }

	public static boolean nameExists(String name) {
		for(ColorSet cs : colorSets) 
			if(cs.getName().equalsIgnoreCase(name)) return true;
		return false;
	}

	public static String getNewName() {
		String prefix = "color set";
		int i = 1;
		String name = prefix;
		while(nameExists(name)) name = prefix + "-" + i++;
		return name;
	}

	public static void newColorSet(String name) {
		if(name == null) name = getNewName();
		addColorSet(new ColorSet(name));
		
	}
	
	public static void addColorSet(ColorSet cs)
	{
		colorSets.add(cs);
		fireColorSetEvent (
			new ColorSetEvent (
				ColorSetManager.class,
				ColorSetEvent.COLORSET_ADDED));
	}

	/**
	 * Removes this {@link ColorSet}
	 * @param cs Colorset to remove
	 */
	public static void removeColorSet(ColorSet cs) {
		if(colorSets.contains(cs))
		{
			colorSets.remove(cs);
			fireColorSetEvent(
				new ColorSetEvent(ColorSetManager.class, ColorSetEvent.COLORSET_REMOVED));
		}
	}
	
	/**
	 * Clears all color-set information
	 */
	public static void clearColorSets() {
		colorSets.clear();
		fireColorSetEvent(
				new ColorSetEvent (null, ColorSetEvent.COLORSET_REMOVED));
	}
	
	public static ColorSet getColorSet(int index) {
		if(index >= 0 && index < colorSets.size())
			return colorSets.get(index);
		else return null;
	}

	/**
	 * Removes this {@link ColorSet}
	 * @param i index of ColorSet to remove<commit_msg>fixed 'null source' exception in colorset event<commit_after>// PathVisio,
// a tool for data visualization and analysis using Biological Pathways
// Copyright 2006-2007 BiGCaT Bioinformatics
//
// 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.
//
package org.pathvisio.visualization.colorset;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.EventListener;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

public class ColorSetManager {
	public final static String XML_ELEMENT = "color-sets";

	private static List<ColorSet> colorSets = new ArrayList<ColorSet>();

	/**
	 * Gets the {@link ColorSet}s used for the currently loaded Expression data
	 */
	public static List<ColorSet> getColorSets() { return colorSets; }

	public static boolean nameExists(String name) {
		for(ColorSet cs : colorSets) 
			if(cs.getName().equalsIgnoreCase(name)) return true;
		return false;
	}

	public static String getNewName() {
		String prefix = "color set";
		int i = 1;
		String name = prefix;
		while(nameExists(name)) name = prefix + "-" + i++;
		return name;
	}

	public static void newColorSet(String name) {
		if(name == null) name = getNewName();
		addColorSet(new ColorSet(name));
		
	}
	
	public static void addColorSet(ColorSet cs)
	{
		colorSets.add(cs);
		fireColorSetEvent (
			new ColorSetEvent (
				ColorSetManager.class,
				ColorSetEvent.COLORSET_ADDED));
	}

	/**
	 * Removes this {@link ColorSet}
	 * @param cs Colorset to remove
	 */
	public static void removeColorSet(ColorSet cs) {
		if(colorSets.contains(cs))
		{
			colorSets.remove(cs);
			fireColorSetEvent(
				new ColorSetEvent(ColorSetManager.class, ColorSetEvent.COLORSET_REMOVED));
		}
	}
	
	/**
	 * Clears all color-set information
	 */
	public static void clearColorSets() {
		colorSets.clear();
		fireColorSetEvent(
				new ColorSetEvent (ColorSetManager.class, ColorSetEvent.COLORSET_REMOVED));
	}
	
	public static ColorSet getColorSet(int index) {
		if(index >= 0 && index < colorSets.size())
			return colorSets.get(index);
		else return null;
	}

	/**
	 * Removes this {@link ColorSet}
	 * @param i index of ColorSet to remove
{'fraction_non_alphanumeric': 0.10404095812762845, 'fraction_numerical': 0.005119765953556409, 'mean_word_length': 3.9279279279279278, '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': '4332977', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1625, 'n_words': 525}