Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.pentaho.gwt.widgets.client.colorpicker;

Copyright (c) 2007, AurorisNET. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble This license establishes the terms under which a given free software Package may be copied, modified, distributed, and/or redistributed. The intent is that the Copyright Holder maintains some artistic control over the development of that Package while still keeping the Package available as open source and free software. You are always permitted to make arrangements wholly outside of this license directly with the Copyright Holder of a given Package. If the terms of this license do not permit the full use that you propose to make of the Package, you should contact the Copyright Holder and seek a different licensing arrangement. Definitions "Copyright Holder" means the individual(s) or organization(s) named in the copyright notice for the entire Package. "Contributor" means any party that has contributed code or other material to the Package, in accordance with the Copyright Holder's procedures. "You" and "your" means any person who would like to copy, distribute, or modify the Package. "Package" means the collection of files distributed by the Copyright Holder, and derivatives of that collection and/or of those files. A given Package may consist of either the Standard Version, or a Modified Version. "Distribute" means providing a copy of the Package or making it accessible to anyone else, or in the case of a company or organization, to others outside of your company or organization. "Distributor Fee" means any fee that you charge for Distributing this Package or providing support for this Package to another party. It does not mean licensing fees. "Standard Version" refers to the Package if it has not been modified, or has been modified only in ways explicitly requested by the Copyright Holder. "Modified Version" means the Package, if it has been changed, and such changes were not explicitly requested by the Copyright Holder. "Original License" means this Artistic License as Distributed with the Standard Version of the Package, in its current version or as it may be modified by The Perl Foundation in the future. "Source" form means the source code, documentation source, and configuration files for the Package. "Compiled" form means the compiled bytecode, object code, binary, or any other form resulting from mechanical transformation or translation of the Source form. Permission for Use and Modification Without Distribution (1) You are permitted to use the Standard Version and create and use Modified Versions for any purpose without restriction, provided that you do not Distribute the Modified Version. Permissions for Redistribution of the Standard Version (2) You may Distribute verbatim copies of the Source form of the Standard Version of this Package in any medium without restriction, either gratis or for a Distributor Fee, provided that you duplicate all of the original copyright notices and associated disclaimers. At your discretion, such verbatim copies may or may not include a Compiled form of the Package. (3) You may apply any bug fixes, portability changes, and other modifications made available from the Copyright Holder. The resulting Package will still be considered the Standard Version, and as such will be subject to the Original License. Distribution of Modified Versions of the Package as Source (4) You may Distribute your Modified Version as Source (either gratis or for a Distributor Fee, and with or without a Compiled form of the Modified Version) provided that you clearly document how it differs from the Standard Version, including, but not limited to, documenting any non-standard features, executables, or modules, and provided that you do at least ONE of the following: (a) make the Modified Version available to the Copyright Holder of the Standard Version, under the Original License, so that the Copyright Holder may include your modifications in the Standard Version. (b) ensure that installation of your Modified Version does not prevent the user installing or running the Standard Version. In addition, the Modified Version must bear a name that is different from the name of the Standard Version. (c) allow anyone who receives a copy of the Modified Version to make the Source form of the Modified Version available to others under (i) the Original License or (ii) a license that permits the licensee to freely copy, modify and redistribute the Modified Version using the same licensing terms that apply to the copy that the licensee received, and requires that the Source form ofthe Modified Version, and of any works derived from it, be made freely available in that license fees are prohibited but Distributor Fees are allowed. Distribution of Compiled Forms of the Standard Version or Modified Versions without the Source (5) You may Distribute Compiled forms of the Standard Version without the Source, provided that you include complete instructions on how to get the Source of the Standard Version. Such instructions must be valid at the time of your distribution. If these instructions, at any time while you are carrying out such distribution, become invalid, you must provide new instructions on demand or cease further distribution. If you provide valid instructions or cease distribution within thirty days after you become aware that the instructions are invalid, then you do not forfeit any of your rights under this license. (6) You may Distribute a Modified Version in Compiled form without the Source, provided that you comply with Section 4 with respect to the Source of the Modified Version. Aggregating or Linking the Package (7) You may aggregate the Package (either the Standard Version or Modified Version) with other packages and Distribute the resulting aggregation provided that you do not charge a licensing fee for the Package. Distributor Fees are permitted, and licensing fees for other components in the aggregation are permitted. The terms of this license apply to the use and Distribution of the Standard or Modified Versions as included in the aggregation. (8) You are permitted to link Modified and Standard Versions with other works, to embed the Package in a larger work of your own, or to build stand-alone binary or bytecode versions of applications that include the Package, and Distribute the result without restriction, provided the result does not expose a direct interface to the Package. Items That are Not Considered Part of a Modified Version (9) Works (including, but not limited to, modules and scripts) that merely extend or make use of the Package, do not, by themselves, cause the Package to be a Modified Version. In addition, such works are not considered parts of the Package itself, and are not subject to the terms of this license. General Provisions (10) Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license. (11) If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license. (12) This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder. (13) This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed. (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import  com.google.gwt.user.client.DOM;
import  com.google.gwt.user.client.ui.ChangeListener;
import  com.google.gwt.user.client.ui.ClickListener;
import  com.google.gwt.user.client.ui.Composite;
import  com.google.gwt.user.client.ui.FlexTable;
import  com.google.gwt.user.client.ui.HTML;
import  com.google.gwt.user.client.ui.HorizontalPanel;
import  com.google.gwt.user.client.ui.KeyboardListener;
import  com.google.gwt.user.client.ui.RadioButton;
import  com.google.gwt.user.client.ui.TextBox;
import  com.google.gwt.user.client.ui.Widget;

This is the implementation of the Colorpicker. It defines the user interface, the glue and calculations necessary for colorpicker functionality.

Example

public class ColorPickerExample implements EntryPoint { public void onModuleLoad() { // Make a new colorpicker ColorPicker picker = new ColorPicker(); // Add it to the root panel. RootPanel.get().add(picker); // Make a new button that does something when you click it. Button b = new Button("Pick!", new ClickListener() { public void onClick(Widget sender) { Window.alert("You chose " + picker.getHexColor()); } }); // Add it to the root panel. RootPanel.get().add(b); } }

Author(s):
AurorisNET
Copyright:
(C) 2007 AurorisNET. All Rights Reserved.
@SuppressWarnings("deprecation")
public class ColorPicker extends Composite implements ClickListener, KeyboardListener, ChangeListener
	// Elements
	private HTML colorpreview;
	private SliderMap slidermap// main color picking slider. Leftmost UI component.
	private SliderBar sliderbar// auxilliary color picking slider. Center UI component.
	// Textboxes
        private TextBox tbHue;
	private TextBox tbSaturation;
	private TextBox tbBrightness;
	private TextBox tbRed;
	private TextBox tbGreen;
	private TextBox tbBlue;
	private TextBox tbHexColor;
	// Radiobuttons
        private RadioButton rbHue;
	private RadioButton rbSaturation;
	private RadioButton rbBrightness;
	private RadioButton rbRed;
	private RadioButton rbGreen;
	private RadioButton rbBlue;
	private int colorMode// Which color picking mode we are in
	private int red;
	private int green;
	private int blue;
	private int hue;
	private int saturation;
	private int brightness;
	public ColorPicker()
	{
		// UI Drawing
		//------------------
		 = 0;
		 = 100;
		 = 100;
		 = 255;
		 = 0;
		 = 0;
		HorizontalPanel panel = new HorizontalPanel();
		FlexTable table = new FlexTable();
		// Add the large slider map
		 = new SliderMap(this);
		panel.add();
		panel.setCellWidth("258px"); //$NON-NLS-1$
		panel.setCellHeight("258px"); //$NON-NLS-1$
		// Add the small slider bar
		 = new SliderBar(this);
		panel.add();
		panel.setCellWidth("40px"); //$NON-NLS-1$
		panel.setCellHeight("258px"); //$NON-NLS-1$
		// Define the Flextable's content
		// Color preview at the top
		 = new HTML(""); //$NON-NLS-1$
		.setWidth("50px"); //$NON-NLS-1$
		.setHeight("50px"); //$NON-NLS-1$
		DOM.setStyleAttribute(.getElement(), "border""1px solid black"); //$NON-NLS-1$ //$NON-NLS-2$
		// Radio buttons
		 = new RadioButton("color""H:"); //$NON-NLS-1$ //$NON-NLS-2$
		.addClickListener(this);
		 = new RadioButton("color""S:"); //$NON-NLS-1$ //$NON-NLS-2$
		.addClickListener(this);
		 = new RadioButton("color""V:"); //$NON-NLS-1$ //$NON-NLS-2$
		.addClickListener(this);
		 = new RadioButton("color""R:"); //$NON-NLS-1$ //$NON-NLS-2$
		.addClickListener(this);
		 = new RadioButton("color""G:"); //$NON-NLS-1$ //$NON-NLS-2$
		.addClickListener(this);
		 = new RadioButton("color""B:"); //$NON-NLS-1$ //$NON-NLS-2$
		.addClickListener(this);
		// Textboxes
		 = new TextBox();
		.setText(new Integer().toString());
		.setMaxLength(3);
		.setVisibleLength(4);
		.addKeyboardListener(this);
		.addChangeListener(this);
		 = new TextBox();
		.setMaxLength(3);
		.setVisibleLength(4);
		.addKeyboardListener(this);
		.addChangeListener(this);
		 = new TextBox();
		.setMaxLength(3);
		.setVisibleLength(4);
		.addKeyboardListener(this);
		.addChangeListener(this);
		 = new TextBox();
		.setText(new Integer().toString());
		.setMaxLength(3);
		.setVisibleLength(4);
		.addKeyboardListener(this);
		.addChangeListener(this);
		 = new TextBox();
		.setText(new Integer().toString());
		.setMaxLength(3);
		.setVisibleLength(4);
		.addKeyboardListener(this);
		.addChangeListener(this);
		 = new TextBox();
		.setText(new Integer().toString());
		.setMaxLength(3);
		.setVisibleLength(4);
		.addKeyboardListener(this);
		.addChangeListener(this);
		 = new TextBox();
		.setText("ff0000"); //$NON-NLS-1$
		.setMaxLength(6);
		.setVisibleLength(6);
		.addKeyboardListener(this);
		.addChangeListener(this);
		// Put together the FlexTable
		table.setWidget(0, 0, );
		table.getFlexCellFormatter().setColSpan(0, 0, 3);
		table.setWidget(1, 0, );
		table.setWidget(1, 1, );
		table.setWidget(1, 2, new HTML("°")); //$NON-NLS-1$
		table.setWidget(2, 0, );
		table.setWidget(2, 1, );
		table.setText(2, 2, "%"); //$NON-NLS-1$
		table.setWidget(3, 0, );
		table.setWidget(3, 1, );
		table.setText(3, 2, "%"); //$NON-NLS-1$
		table.setWidget(4, 0, );
		table.setWidget(4, 1, );
		table.setWidget(5, 0, );
		table.setWidget(5, 1, );
		table.setWidget(6, 0, );
		table.setWidget(6, 1, );
		table.setText(7,0, "#:"); //$NON-NLS-1$
		table.setWidget(7,1, );
		table.getFlexCellFormatter().setColSpan(7, 1, 2);
		// Final setup
		panel.add(table);
		.setChecked(true);
		setPreview("ff0000"); //$NON-NLS-1$
		DOM.setStyleAttribute(.getElement(), "cursor""default"); //$NON-NLS-1$ //$NON-NLS-2$
		// First event
		initWidget(panel);
	}

This method is called when a widget is attached to the browser's document. To receive notification after a Widget has been added to the document, override the Widget.onLoad() method. Subclasses that override this method must call super.onAttach() before doing anything else to ensure that the Widget has been properly attached to its underlying Element.
	public void onAttach()
	{
		// Called when we are shown (from being hidden)
		super.onAttach();
		 = -1;
	}

Called when the widget wants to update the preview color sample box in the top-right corner of the UI.

Parameters:
hex Hexadecimal notation of RGB
	private void setPreview(String hex)
	{
		DOM.setStyleAttribute(.getElement(), "backgroundColor""#" + hex); //$NON-NLS-1$ //$NON-NLS-2$
	}

Fires whenever the user generates picking events on the color picker map. Subclasses that override this method must call super.onMapSelected(x,y) to ensure that the Widget recieves its events.

Parameters:
x the distance along the x-axis of the user's selection, between 0 and 255, inclusive.
y the distance along the y-axis of the user's selection, between 0 and 255, inclusive.
	public void onMapSelected(int xint y)
	{
		switch ()
		{
				 = percentOf(x, 100);
				 = 100 - percentOf(y, 100);
				.setText(Integer.toString());
				.setText(Integer.toString());
				break;
				 = percentOf(x, 360);
				 = 100 - percentOf(y, 100);
				.setText(Integer.toString());
				.setText(Integer.toString());
				break;
				 = percentOf(x, 360);
				 = 100 - percentOf(y, 100);
				.setText(Integer.toString());
				.setText(Integer.toString());
				break;
				 = x;
				 = 256 - y;
				.setText(Integer.toString());
				.setText(Integer.toString());
				break;
				 = x;
				 = 256 - y;
				.setText(Integer.toString());
				.setText(Integer.toString());
				break;
				 = x;
				 = 256 - y;
				.setText(Integer.toString());
				.setText(Integer.toString());
				break;
		}
	}

Fires whenever the user generates picking events along the color picker bar. Subclasses that override this method must call super.onBarSelected(y) to ensure that the Widget recieves its events.

Parameters:
y the distance along the y-axis of the user's selection, between 0 and 255, inclusive.
	public void onBarSelected(int y)
	{
		switch ()
		{
				 = 360 - percentOf(y, 360);
				.setText(Integer.toString());
				break;
				 = 100 - percentOf(y, 100);
				.setText(Integer.toString());
				break;
				 = 100 - percentOf(y, 100);
				.setText(Integer.toString());
				break;
				 = 255 - y;
				.setText(Integer.toString());
				break;
				 = 255 - y;
				.setText(Integer.toString());
				break;
				 = 255 - y;
				.setText(Integer.toString());
				break;
		}
	}

Fired when the user clicks on a widget. Subclasses that override this method must call super.onClick(sender) to ensure that the Widget recieves its events.

Parameters:
sender the widget sending the event.
	public void onClick(Widget sender)
	{
		if (sender == )
		{
			{
			}
			try
			{
				Color color = new Color();
				color.setHSV(, 100, 100);
				.setOverlayColor("#" + color.getHex()); //$NON-NLS-1$
			}
			catch (Exception e) {}
			.setSliderPosition(256 - (int)((new Integer().floatValue() / 360) * 256));
			.setSliderPosition((int)((new Integer().floatValue() / 100) * 256),
										256 - (int)((new Integer().floatValue() / 100) * 256));
		}
		else if(sender == )
		{
			{
				.setOverlayColor("transparent"); //$NON-NLS-1$
				.setLayerColor("#ffffff".); //$NON-NLS-1$
			}
			.setSliderPosition(256 - (int)((new Integer().floatValue() / 100) * 256));
			.setSliderPosition((int)((new Integer().floatValue() / 360) * 256),
										256 - (int)((new Integer().floatValue() / 100) * 256));
		}
		else if(sender == )
		{
			{
				.setUnderlayColor("#000000"); //$NON-NLS-1$
				.setOverlayColor("transparent"); //$NON-NLS-1$
			}
			try
			{
				Color color = new Color();
				color.setHSV(, 100);
				.setLayerColor("#" + color.getHex(), .); //$NON-NLS-1$
			}
			catch (Exception e) {}
			.setSliderPosition(256 - (int)((new Integer().floatValue() / 100) * 256));
			.setSliderPosition((int)((new Integer().floatValue() / 360) * 256),
										256 - (int)((new Integer().floatValue() / 100) * 256));
		}
		else if(sender == )
		{
			{
			}
		}
		else if(sender == )
		{
			{
			}
		}
		else if(sender == )
		{
			{
			}
		}
		{
			int x = 0;
			int y = 0;
			{
				x = ;
				y = ;
			}
			{
				x = ;
				y = ;
			}
			{
				x = ;
				y = ;
			}
			int horzPer = (int)((new Float(x).floatValue() / 256) * 100);
			int vertPer = (int)((new Float(y).floatValue() / 256) * 100);
			int horzPerRev = (int)(((256 - new Float(x).floatValue()) / 256) * 100);
			int vertPerRev = (int)(((256 - new Float(y).floatValue()) / 256) * 100);
			if (vertPerRev > horzPerRev)
			else
			if (vertPerRev > horzPer)
			else
			if (vertPer > horzPer)
			else
			if (vertPer > horzPerRev)
			else
		}
	}

Fired whenever something in this widget changes. Subclasses that override this method must call super.onChange(sender) to ensure that the Widget recieves its events.

Parameters:
sender the widget that has changed.
	public void onChange(Widget sender)
	{
	    if (sender == )
        {
			// Figure out colors
			// Color class will do bounds check on hex input
			try
			{
				Color color = new Color();
				color.setHex(.getText());
				.setText(Integer.toString(color.getHue()));
				.setText(Integer.toString(color.getSaturation()));
				.setText(Integer.toString(color.getValue()));
				.setText(Integer.toString(color.getRed()));
				.setText(Integer.toString(color.getGreen()));
				.setText(Integer.toString(color.getBlue()));
				.setText(color.getHex());
			}
			catch (Exception e)
			{
			}
		}
		if (sender ==  || sender ==  || sender == )
		{
			// Don't allow this value to overflow or underflow
			try
			{
				if (Integer.parseInt(((TextBox)sender).getText()) > 255)
				{
					((TextBox)sender).setText("255"); //$NON-NLS-1$
				}
				if (Integer.parseInt(((TextBox)sender).getText()) < 0)
				{
					((TextBox)sender).setText("0"); //$NON-NLS-1$
				}
			}
			catch (Exception e)
			{
			}
			 = Integer.parseInt(.getText());
			 = Integer.parseInt(.getText());
			 = Integer.parseInt(.getText());
			 = Integer.parseInt(.getText());
			 = Integer.parseInt(.getText());
			 = Integer.parseInt(.getText());
			// Figure out the colors
			try
			{
				Color color = new Color();
				color.setRGB();
				.setText(Integer.toString(color.getHue()));
				.setText(Integer.toString(color.getSaturation()));
				.setText(Integer.toString(color.getValue()));
				.setText(color.getHex());
			}
			catch (Exception e)
			{
			}
		}
		else if (sender ==  || sender ==  || sender == )
		{
			// Don't allow this value to overflow
			try
			{
				if (Integer.parseInt(.getText()) > 359)
				{
					.setText("359"); //$NON-NLS-1$
				}
				if (Integer.parseInt(.getText()) > 100)
				{
					.setText("100"); //$NON-NLS-1$
				}
				if (Integer.parseInt(.getText()) > 100)
				{
					.setText("100"); //$NON-NLS-1$
				}
			}
			catch (Exception e)
			{
			}
			 = Integer.parseInt(.getText());
			 = Integer.parseInt(.getText());
			 = Integer.parseInt(.getText());
			 = Integer.parseInt(.getText());
			 = Integer.parseInt(.getText());
			 = Integer.parseInt(.getText());
			// Figure out colors
			try
			{
				Color color = new Color();
				.setText(Integer.toString(color.getRed()));
				.setText(Integer.toString(color.getGreen()));
				.setText(Integer.toString(color.getBlue()));
				.setText(color.getHex());
			}
			catch (Exception e)
			{
			}
		}
		// Let the sliders know something's changed
	}

Fired when a keyboard action generates a character. This occurs after onKeyDown and onKeyUp are fired for the physical key that was pressed. It should be noted that many browsers do not generate keypress events for non-printing keyCode values, such as KEY_ENTER or arrow keys. These keyCodes can be reliably captured either with onKeyDown(Widget, char, int) or onKeyUp(Widget, char, int). Subclasses that override this method must call super.onKeyPress(sender, keyCode, modifiers) to ensure that the Widget recieves its events.

Parameters:
sender the widget that was focused when the event occurred.
keyCode the Unicode character that was generated by the keyboard action.
modifiers the modifier keys pressed at when the event occurred. This value is a combination of the bits defined by MODIFIER_SHIFT, MODIFIER_CTRL, and MODIFIER_ALT.
See also:
com.google.gwt.user.client.ui.KeyboardListener
	public void onKeyPress(Widget senderchar keyCodeint modifiers)
	{
        if (sender == )
        {
			// Disallow non-hex in hexadecimal boxes
			if ((!Character.isDigit(keyCode))
				&& (keyCode != 'A') && (keyCode != 'a')
				&& (keyCode != 'B') && (keyCode != 'b')
				&& (keyCode != 'C') && (keyCode != 'c')
				&& (keyCode != 'D') && (keyCode != 'd')
				&& (keyCode != 'E') && (keyCode != 'e')
				&& (keyCode != 'F') && (keyCode != 'f')
				&& (keyCode != (char) KeyboardListener.KEY_TAB)
				&& (keyCode != (char) KeyboardListener.KEY_BACKSPACE)
				&& (keyCode != (char) KeyboardListener.KEY_DELETE) && (keyCode != (char) KeyboardListener.KEY_ENTER)
				&& (keyCode != (char) KeyboardListener.KEY_HOME) && (keyCode != (char) KeyboardListener.KEY_END)
				&& (keyCode != (char) KeyboardListener.KEY_LEFT) && (keyCode != (char) KeyboardListener.KEY_UP)
				&& (keyCode != (char) KeyboardListener.KEY_RIGHT) && (keyCode != (char) KeyboardListener.KEY_DOWN))
			{
				((TextBox)sender).cancelKey();
			}
		}
		else
		{
			// Disallow non-numerics in numeric boxes
			if ((!Character.isDigit(keyCode))
				&& (keyCode != (char) KeyboardListener.KEY_TAB)
				&& (keyCode != (char) KeyboardListener.KEY_BACKSPACE)
				&& (keyCode != (char) KeyboardListener.KEY_DELETE) && (keyCode != (char) KeyboardListener.KEY_ENTER)
				&& (keyCode != (char) KeyboardListener.KEY_HOME) && (keyCode != (char) KeyboardListener.KEY_END)
				&& (keyCode != (char) KeyboardListener.KEY_LEFT) && (keyCode != (char) KeyboardListener.KEY_UP)
				&& (keyCode != (char) KeyboardListener.KEY_RIGHT) && (keyCode != (char) KeyboardListener.KEY_DOWN))
			{
				((TextBox)sender).cancelKey();
			}
		}
	}

Fired when the user releases a physical key. Subclasses that override this method must call super.onKeyUp(sender, keyCode, modifiers) to ensure that the Widget recieves its events.

Parameters:
sender the widget that was focused when the event occurred.
keyCode the physical key that was released. Constants for this value are defined in this interface with the KEY prefix.
modifiers the modifier keys pressed at when the event occurred. This value is a combination of the bits defined by MODIFIER_SHIFT, MODIFIER_CTRL, and MODIFIER_ALT.
See also:
com.google.gwt.user.client.ui.KeyboardListener
	public void onKeyUp(Widget senderchar keyCodeint modifiers)
	{
		onChange(sender);
	}

Fired when the user depresses a physical key. Subclasses that override this method must call super.onKeyDown(sender, keyCode, modifiers) to ensure that the Widget recieves its events.

Parameters:
sender the widget that was focused when the event occurred.
keyCode the physical key that was depressed. Constants for this value are defined in this interface with the KEY prefix.
modifiers he modifier keys pressed at when the event occurred. This value is a combination of the bits defined by MODIFIER_SHIFT, MODIFIER_CTRL, and MODIFIER_ALT.
See also:
com.google.gwt.user.client.ui.KeyboardListener
	public void onKeyDown(Widget senderchar keyCodeint modifiers) { }

Sets the Red, Green, and Blue color variables. This will automatically populate the Hue, Saturation and Brightness and Hexadecimal fields, too. The RGB color model is an additive color model in which red, green, and blue light are added together in various ways to reproduce a broad array of colors. The name of the model comes from the initials of the three additive primary colors, red, green, and blue.

Parameters:
red strength - valid range is 0-255
green strength - valid range is 0-255
blue strength - valid range is 0-255
Throws:
java.lang.Exception Exception if the Red, Green or Blue variables are out of range.
	public void setRGB(int redint greenint bluethrows Exception
	{
		Color color = new Color();
		color.setRGB(redgreenblue);
		this. = red;
		this. = green;
		this. = blue;
		this. = color.getHue();
		this. = color.getSaturation();
		this. = color.getValue();
		.setText(Integer.toString(this.));
		.setText(Integer.toString(this.));
		.setText(Integer.toString(this.));
		.setText(Integer.toString(this.));
		.setText(Integer.toString(this.));
		.setText(Integer.toString(this.));
		.setText(color.getHex());
	}

Set the Hue, Saturation and Value (Brightness) variables. This will automatically populate the Red, Green, Blue, and Hexadecimal fields, too. HSV represents points in the RGB color space, which attempt to describe perceptual color relationships more accurately than RGB. HSV describes colors as points in a cylinder whose central axis ranges from black at the bottom to white at the top with neutral colors between them, where angle around the axis corresponds to hue, distance from the axis corresponds to saturation, and distance along the axis corresponds to lightness, value, or brightness.

Parameters:
hue angle - valid range is 0-359
saturation percent - valid range is 0-100
value percent (Brightness) - valid range is 0-100
Throws:
java.lang.Exception A general exception if the Hue, Saturation, or Value variables are out of range.
	public void setHSV(int hueint saturationint valuethrows Exception
	{
		Color color = new Color();
		color.setHSV(huesaturationvalue);
		this. = color.getRed();
		this. = color.getGreen();
		this. = color.getBlue();
		this. = hue;
		this. = saturation;
		this. = value;
		.setText(Integer.toString(this.));
		.setText(Integer.toString(this.));
		.setText(Integer.toString(this.));
		.setText(Integer.toString(this.));
		.setText(Integer.toString(this.));
		.setText(Integer.toString(this.));
		.setText(color.getHex());
	}

Sets the hexadecimal notation for Red, Green, and Blue. This will automatically populate all the other fields, too.

Parameters:
hex Hexadecimal notation of Red, Green and Blue in the range of 000000-FFFFFF
Throws:
java.lang.Exception A generic exception if the hexadecimal notation is bad.
	public void setHex(String hexthrows Exception
	{
    if (hex.startsWith("#")) { //$NON-NLS-1$
      hex = hex.substring(1);
    }
	  
		Color color = new Color();
		color.setHex(hex);
		this. = color.getRed();
		this. = color.getGreen();
		this. = color.getBlue();
		this. = color.getHue();
		this. = color.getSaturation();
		this. = color.getValue();
		.setText(Integer.toString(this.));
		.setText(Integer.toString(this.));
		.setText(Integer.toString(this.));
		.setText(Integer.toString(this.));
		.setText(Integer.toString(this.));
		.setText(Integer.toString(this.));
		.setText(color.getHex());
	}

Returns the hexadecimal notation of the current selected color.

Returns:
Hexadecimal in the range of 000000-FFFFFF
	{
		return .getText();
	}
	/*Helper functions -- for common calculations
	 */
Divides the first value by 256, then multiplies it by the second value.

Parameters:
val1 first value.
val2 second value.
Returns:
result.
	private int percentOf(int val1int val2)
	{
	 	return (int)(new Float(val1).floatValue() / 256 * val2);
	}

Called whenever the internal state has been changed and needs to synchronize the other components.
	private void updateSliders()
	{
		// Let the sliders know something's changed
		if (.isChecked()) onClick();
		if (.isChecked()) onClick();
		if (.isChecked()) onClick();
		if (.isChecked()) onClick();
		if (.isChecked()) onClick();
		if (.isChecked()) onClick();
	}
New to GrepCode? Check out our FAQ X