sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.util/src/com/nokia/carbide/cpp/pi/util/DataMiningPalette.java
changeset 12 ae255c9aa552
parent 2 b9ab3b238396
equal deleted inserted replaced
11:5b9d4d8641ce 12:ae255c9aa552
    28 import org.eclipse.swt.widgets.MessageBox;
    28 import org.eclipse.swt.widgets.MessageBox;
    29 import org.eclipse.swt.widgets.Shell;
    29 import org.eclipse.swt.widgets.Shell;
    30 
    30 
    31 public class DataMiningPalette {
    31 public class DataMiningPalette {
    32 
    32 
    33 	private Map<Object, RGB> palette = new HashMap<Object, RGB>();
    33 	private transient final Map<Object, RGB> palette = new HashMap<Object, RGB>();
    34 
    34 
    35 	private boolean haveEntry(Object entry) {
    35 	private boolean haveEntry(Object entry) {
    36 		return palette.containsKey(entry);
    36 		return palette.containsKey(entry);
    37 	}
    37 	}
    38 
    38 
    39 	private boolean haveColor(RGB color) {
    39 	private boolean haveColor(final RGB color) {
    40 		return palette.containsValue(color);
    40 		return palette.containsValue(color);
    41 	}
    41 	}
    42 
    42 
    43 	private void add(Object entry, RGB color) {
    43 	private void add(final Object entry, final RGB color) {
    44 		palette.put(entry, color);
    44 		palette.put(entry, color);
    45 	}
    45 	}
    46 
    46 
    47 	private void update(Object entry, RGB color) {
    47 	private void update(final Object entry, final RGB color) {
    48 		palette.remove(entry);
    48 		palette.remove(entry);
    49 		palette.put(entry, color);
    49 		palette.put(entry, color);
    50 	}
    50 	}
    51 
    51 
    52 	private RGB hsv2rgb(int hue, double saturation, double value) {
    52 	private RGB hsv2rgb(int hue, double saturation, double value) {
    53 
    53 
    54 		if (hue >= 360)
    54 		if (hue >= 360){
    55 			hue %= 360;
    55 			hue %= 360;
       
    56 		}
    56 		int Hi = (hue / 60) % 6;
    57 		int Hi = (hue / 60) % 6;
    57 		double f = (double) hue / (double) 60 - Hi;
    58 		double f = (double) hue / (double) 60 - Hi;
    58 
    59 
    59 		int p = (int) ((value * (1 - saturation)) * 255);
    60 		int p = (int) ((value * (1 - saturation)) * 255);
    60 		int q = (int) ((value * (1 - f * saturation)) * 255);
    61 		int q = (int) ((value * (1 - f * saturation)) * 255);
   139 			int indexG = (index / 6) % 6;
   140 			int indexG = (index / 6) % 6;
   140 			int indexB = (index / 36) % 6;
   141 			int indexB = (index / 36) % 6;
   141 			
   142 			
   142 			RGB myRGB = new RGB(channelValue[indexR], channelValue[indexG], channelValue[indexB]);
   143 			RGB myRGB = new RGB(channelValue[indexR], channelValue[indexG], channelValue[indexB]);
   143 
   144 
   144 			if (haveColor(myRGB))
   145 			if (haveColor(myRGB)){
   145 				continue;
   146 				continue;
   146 
   147 			}
   147 			add(entry, myRGB);
   148 			add(entry, myRGB);
   148 			
   149 			
   149 			if (!entryListItr.hasNext())
   150 			if (!entryListItr.hasNext())
   150 				return;
   151 				return;
   151 			else
   152 			else
   180 //				if (haveEntry(entry)) {
   181 //				if (haveEntry(entry)) {
   181 //				}
   182 //				}
   182 
   183 
   183 				RGB myRGB = hsv2rgb(hueEntry[i], saturation, saturation);
   184 				RGB myRGB = hsv2rgb(hueEntry[i], saturation, saturation);
   184 
   185 
   185 				if (haveColor(myRGB))
   186 				if (haveColor(myRGB)){
   186 					continue;
   187 					continue;
   187 
   188 				}
   188 				add(entry, myRGB);
   189 				add(entry, myRGB);
   189 				--remain;
   190 				--remain;
   190 
   191 
   191 				if (!entryListItr.hasNext())
   192 				if (!entryListItr.hasNext())
   192 					return;
   193 					return;