View Javadoc

1   /*
2    * $HeadURL: $
3    * $Date: $
4    * $Revision: $
5    * $Author: $
6    * 
7    * Copyright (c) 2005 MindTree Consulting Ltd. 
8    * 
9    * This file is part of Insight.
10   * 
11   * Insight is free software: you can redistribute it and/or modify it under the 
12   * terms of the GNU General Public License as published by the Free Software 
13   * Foundation, either version 3 of the License, or (at your option) any later 
14   * version.
15   * 
16   * Insight is distributed in the hope that it will be useful, but 
17   * WITHOUT ANY WARRANTY; without even the implied warranty of 
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General 
19   * Public License for more details.
20   * 
21   * You should have received a copy of the GNU General Public License along with 
22   * Insight.  If not, see <http://www.gnu.org/licenses/>.
23   */
24  package com.mindtree.techworks.insight.receiver;
25  
26  import java.awt.Color;
27  import java.util.HashMap;
28  import java.util.LinkedList;
29  import java.util.List;
30  
31  import com.mindtree.techworks.insight.InsightConstants;
32  import com.mindtree.techworks.insight.spi.LogNamespace;
33  
34  /**
35  *
36  * The <code>RuntimeNamespaceContainer</code> class is a container for runtime
37  * namespace data. Holds data on loaded namespaces and available namespace
38  * colors 
39  *
40  * @author  Regunath B
41  * @version 1.0, 05/08/08
42  * @see     com.mindtree.techworks.insight.gui.Insight
43  */
44  public class RuntimeNamespaceContainer {
45  
46  	/**
47  	 * LinkedList that contains the namespace colors
48  	 */
49  	private static LinkedList availableNamespaceColors = new LinkedList();
50  	
51  	/**
52  	 * Hashmap that contains the namepace color for display
53  	 */
54  	private static HashMap namespaceColorMap = new HashMap();	
55  	
56  	/**
57  	 * Set that contains the list of namespaces from which events have been loaded already
58  	 */
59  	private static List loadedNamespaces = new LinkedList();		
60  	
61  	/**
62  	 * Gets the Color for distinguishing the specified LogNamespace in the display
63  	 * @param namespace the LogNamespace for which a Color is needed
64  	 * @return default Insight background color if all available colors are exhausted or the Color to distinguish the specified LogNamespace
65  	 */
66  	public static Color getNamespaceColor(LogNamespace namespace) {
67  		String namespaceString = namespace.getNamespaceAsString();
68  		Color namespaceColor = (Color)namespaceColorMap.get(namespaceString);		
69  		if (namespaceColor == null) { // its a new namespace
70  			if (!availableNamespaceColors.isEmpty()) { // unique predefined colors exist
71  				namespaceColor = (Color)availableNamespaceColors.removeFirst();
72  			} else { // return the default color
73  				namespaceColor = InsightConstants.DEFAULT_BACKGROUND;
74  			}
75  			namespaceColorMap.put(namespaceString,namespaceColor);
76  		}
77  		return namespaceColor;
78  	}
79  	
80  	/**
81  	 * Returns the list of loaded namespaces
82  	 * @return Returns the loadedNamespaces.
83  	 */
84  	public static List getLoadedNamespaces() {
85  		return loadedNamespaces;
86  	}	
87  		
88  	/**
89  	 * Returns the Map of loaded namespaces
90  	 * @return Returns the namespaceColorMap.
91  	 */
92  	public static HashMap getNamespaceColorMap() {
93  		return namespaceColorMap;
94  	}
95  	/**
96  	 * Returns the list of vailable namespace colors
97  	 * @return Returns the availableNamespaceColors.
98  	 */
99  	public static LinkedList getAvailableNamespaceColors() {
100 		return availableNamespaceColors;
101 	}
102 	
103 	/**
104 	 * Initializes the available namespace colors
105 	 */
106 	public static final void initializeAvailableNamespaceColorList() {
107 		availableNamespaceColors.clear();
108 		for (int i = 0; i < InsightConstants.NAMESPACE_COLORS.length; i++) {
109 			availableNamespaceColors.add(InsightConstants.NAMESPACE_COLORS[i]);
110 		}
111 	}
112 	
113 	/**
114 	 * Clears the set of namespaces contained by this container
115 	 */
116 	public static void clearLoadedNamespaces() {
117 		loadedNamespaces.clear();
118 		namespaceColorMap.clear();
119 		initializeAvailableNamespaceColorList();
120 	}		
121 	
122 }