sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.util/src/com/nokia/carbide/cpp/pi/util/TestDataMiningPalette.java
author Toni Pulkkinen <ext-toni.p.pulkkinen@nokia.com>
Wed, 23 Jun 2010 15:05:09 +0300
changeset 12 ae255c9aa552
parent 5 844b047e260d
permissions -rw-r--r--
Performance Investigator Carbide extension 2.4.0

/*
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of the License "Eclipse Public License v1.0"
 * which accompanies this distribution, and is available
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
 *
 * Initial Contributors:
 * Nokia Corporation - initial contribution.
 *
 * Contributors:
 *
 * Description: 
 *
 */

package com.nokia.carbide.cpp.pi.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/* 
 * 
 * This class just make a list of numbers and assign color to them
 * Testers should 
 * 1.visually verify color if it looks good to them 
 * 2.try to assign different color to different entries
 * 3.try to assign the same color to different entries and observe error message
 * 
 * */

public class TestDataMiningPalette {

	private Shell sShell = null;

	private final Map<Button,CLabel> dataMiningColors = new HashMap<Button,CLabel>();
	private final DataMiningPalette palette = new DataMiningPalette();
	private final List<Integer> sosThreadlist = new ArrayList<Integer>();
	private final List<Integer> threadlist = new ArrayList<Integer>();

	
	/**
	 * @param args
	 */
	public static void main(final String[] args) {
		Display display = Display.getDefault();
		TestDataMiningPalette thisClass = new TestDataMiningPalette();
		thisClass.createSShell();
		thisClass.sShell.open();

		while (!thisClass.sShell.isDisposed()) {
			if (!display.readAndDispatch()){
				display.sleep();
			}
		}
		display.dispose();
	}

	/**
	 * This method initializes sShell
	 */
	private void createSShell() {
		sShell = new Shell();
		sShell.setText(Messages.getString("TestDataMiningPalette.shell")); //$NON-NLS-1$
		sShell.setSize(new Point(1000, 700));

		RowLayout layout = new RowLayout();
		sShell.setLayout(layout);

		for (int i = 0; i < 216; i++) {
			sosThreadlist.add(i);
		}
		for (int i = 216; i < 216 + 255; i++) {
			threadlist.add(i);
		}
		palette.assignSOSColor(sosThreadlist);
		palette.assignColor(threadlist);
		
		sosThreadlist.addAll(threadlist);
		
		Iterator entryItr = sosThreadlist.iterator();

		while(entryItr.hasNext())
		{
			Object entry = entryItr.next();
			
			final Button button = new Button(sShell, SWT.NONE);
			button.setText(entry.toString());
			button.setBackground(new Color(Display.getCurrent(), palette.getRGB(entry)));
			button.addSelectionListener(new SelectionAdapter() {
            	public void widgetSelected(final SelectionEvent e) {
            		Integer index = Integer.valueOf(button.getText());
            		if(palette.recolorEntryDialog(sShell, index))
            		{
            			RGB newRGB = palette.getRGB(index);
            			CLabel myLabel = dataMiningColors.get(button);
            			myLabel.setBackground(new Color(Display.getCurrent(), newRGB));
            		}
            	}
			});
			CLabel cLabel = new CLabel(sShell, SWT.NONE);
			cLabel.setText(entry.toString());
			cLabel.setBackground(new Color(Display.getCurrent(), palette.getRGB(entry)));
			dataMiningColors.put(button, cLabel);
		}
	}

}