/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A color chooser panel mimicking that of GTK's: a color wheel showing
* hue and a triangle that varies saturation and brightness.
*
* @author Scott Violet
*/
private boolean settingColor;
// The colors are mirrored to avoid creep in adjusting an individual
// value.
private float hue;
private float saturation;
private float brightness;
/**
* Convenience method to transfer focus to the next child of component.
*/
// PENDING: remove this when a variant of this is added to awt.
if (container.isFocusCycleRoot()) {
comp.requestFocus();
return;
}
}
if (rootAncestor!=null) {
if (direction) {
}
else {
}
comp.requestFocus();
return;
}
}
}
}
/**
* Returns a user presentable description of this GTKColorChooserPane.
*/
}
/**
* Returns the mnemonic to use with <code>getDisplayName</code>.
*/
public int getMnemonic() {
if (m != null) {
try {
return value;
} catch (NumberFormatException nfe) {}
}
return -1;
}
/**
* Character to underline that represents the mnemonic.
*/
public int getDisplayedMnemonicIndex() {
"GTKColorChooserPanel.displayedMnemonicIndex");
if (m != null) {
try {
return value;
} catch (NumberFormatException nfe) {}
}
return -1;
}
return null;
}
return null;
}
removeAll();
}
/**
* Builds and configures the widgets for the GTKColorChooserPanel.
*/
protected void buildChooser() {
triangle = new ColorTriangle();
// PENDING: when we straighten out user setting opacity, this should
// be changed.
label = new OpaqueLabel();
// PENDING: when we straighten out user setting opacity, this should
// be changed.
lastLabel = new OpaqueLabel();
"GTKColorChooserPanel.saturationSpinner");
setLayout(new GridBagLayout());
}
/**
* Configures the spinner.
*/
spinner.addChangeListener(this);
getTextField();
}
}
/**
* Adds the widget creating a JLabel with the specified name.
*/
int x, int y) {
getLocale()));
try {
} catch (NumberFormatException nfe) {
}
getLocale());
if (mnemonicIndex != null) {
try {
} catch (NumberFormatException nfe) {
}
}
}
if (x < 0) {
}
if (y < 0) {
}
if (y == 0) {
}
}
/**
* Refreshes the display from the model.
*/
public void updateChooser() {
if (!settingColor) {
setColor(getColorFromModel(), true, true, false);
}
}
/**
* Resets the red component of the selected color.
*/
}
/**
* Resets the green component of the selected color.
*/
}
/**
* Resets the blue component of the selected color.
*/
}
/**
* Sets the hue of the selected color and updates the display if
* necessary.
*/
if (update) {
settingColor = true;
settingColor = false;
}
}
/**
* Returns the current amount of hue.
*/
private float getHue() {
return hue;
}
/**
* Resets the saturation.
*/
}
/**
* Returns the saturation.
*/
private float getSaturation() {
return saturation;
}
/**
* Sets the brightness.
*/
}
/**
* Returns the brightness.
*/
private float getBrightness() {
return brightness;
}
/**
* Sets the saturation and brightness and updates the display if
* necessary.
*/
if (update) {
settingColor = true;
settingColor = false;
}
}
/**
* Resets the rgb values.
*/
settingColor = true;
settingColor = false;
}
/**
* Resets the hsb values.
*/
private void setHSB(float h, float s, float b) {
this.hue = h;
this.saturation = s;
this.brightness = b;
settingColor = true;
settingColor = false;
}
/**
* Rests the color.
*
* @param color new Color
* @param updateSpinners whether or not to update the spinners.
* @param updateHSB if true, the hsb fields are updated based on the
* new color
* @param updateModel if true, the model is set.
*/
boolean updateHSB, boolean updateModel) {
}
settingColor = true;
if (updateHSB) {
}
if (updateModel) {
}
}
// Force Integer to pad the string with 0's by adding 0x1000000 and
// then removing the first character.
if (updateSpinners) {
}
settingColor = false;
}
return label.getBackground();
}
/**
* ChangeListener method, updates the necessary display widgets.
*/
if (settingColor) {
return;
}
if (e.getSource() == hueSpinner) {
}
else if (e.getSource() == saturationSpinner) {
floatValue() / 255);
}
else if (e.getSource() == valueSpinner) {
floatValue() / 255);
}
else if (e.getSource() == redSpinner) {
}
else if (e.getSource() == greenSpinner) {
}
else if (e.getSource() == blueSpinner) {
}
}
/**
* Flag indicating the angle, or hue, has changed and the triangle
* needs to be recreated.
*/
/**
* Indicates the wheel is being dragged.
*/
/**
* Indicates the triangle is being dragged.
*/
/**
* Indicates a color is being set and we should ignore setColor
*/
/**
* Indicates the wheel has focus.
*/
/**
* Indicates the triangle has focus.
*/
/**
* Class responsible for rendering a color wheel and color triangle.
*/
/**
* Cached image of the wheel.
*/
/**
* Cached image of the triangle.
*/
/**
* Angle triangle is rotated by.
*/
private double angle;
/**
* Boolean bitmask.
*/
private int flags;
/**
* X location of selected color indicator.
*/
private int circleX;
/**
* Y location of selected color indicator.
*/
private int circleY;
public ColorTriangle() {
// We want to handle tab ourself.
setFocusTraversalKeysEnabled(false);
// PENDING: this should come from the style.
"GTKColorChooserPanel.actionMap");
map = new ActionMapUIResource();
"GTKColorChooserPanel.actionMap", map);
}
}
/**
* Returns the GTKColorChooserPanel.
*/
return GTKColorChooserPanel.this;
}
/**
* Gives focus to the wheel.
*/
void focusWheel() {
setFocusType(1);
}
/**
* Gives focus to the triangle.
*/
void focusTriangle() {
setFocusType(2);
}
/**
* Returns true if the wheel currently has focus.
*/
boolean isWheelFocused() {
return isSet(FLAGS_FOCUSED_WHEEL);
}
/**
* Resets the selected color.
*/
public void setColor(float h, float s, float b) {
if (isSet(FLAGS_SETTING_COLOR)) {
return;
}
setAngleFromHue(h);
setSaturationAndBrightness(s, b);
}
/**
* Returns the selected color.
*/
return GTKColorChooserPanel.this.getColor();
}
/**
* Returns the x location of the selected color indicator.
*/
int getColorX() {
}
/**
* Returns the y location of the selected color indicator.
*/
int getColorY() {
}
// Assign focus to either the wheel or triangle and attempt
// to drag either the wheel or triangle.
int size = getWheelRadius();
if (!hasFocus()) {
requestFocus();
}
if (!isSet(FLAGS_DRAGGING_TRIANGLE) &&
setFlag(FLAGS_DRAGGING, true);
setFocusType(1);
}
setFlag(FLAGS_DRAGGING_TRIANGLE, true);
setFocusType(2);
}
else {
setFocusType(2);
}
}
// Stopped dragging
setFlag(FLAGS_DRAGGING_TRIANGLE, false);
setFlag(FLAGS_DRAGGING, false);
}
// Reset the flags to indicate no one has focus
setFocusType(0);
}
// Gained focus, reassign focus to the wheel if no one
// currently has focus.
if (!isSet(FLAGS_FOCUSED_TRIANGLE) &&
!isSet(FLAGS_FOCUSED_WHEEL)) {
setFlag(FLAGS_FOCUSED_WHEEL, true);
setFocusType(1);
}
repaint();
}
super.processEvent(e);
}
super.paintComponent(g);
// Draw the wheel and triangle
int size = getWheelRadius();
int width = getWheelWidth();
// Draw the focus indicator for the wheel
}
// Draw a line on the wheel indicating the selected hue.
}
else {
}
// Draw the focus indicator on the triangle
int innerR = getTriangleCircumscribedRadius();
}
// Draw the selected color indicator.
getIndicatorSize() - 1);
getIndicatorSize() - 3);
}
/**
* Returns an image representing the triangle and wheel.
*/
return wheelImage;
}
}
int innerR = getTriangleCircumscribedRadius();
triangleImage = new BufferedImage(a, a,
}
g.dispose();
g = wheelImage.getGraphics();
setFlag(FLAGS_CHANGED_ANGLE, false);
return wheelImage;
}
for (int y = 0; y < size; y++) {
if (maxX > 0) {
}
}
else {
}
}
}
/**
* Returns a color wheel image for the specified size.
*
* @param size Integer giving size of color wheel.
* @return Color wheel image
*/
int ySquared = y * y;
0xFF000000;
}
}
}
wheelImage = image;
return wheelImage;
}
/**
* Adjusts the saturation and brightness. <code>x</code> and
* <code>y</code> give the location to adjust to and are relative
*
* @param x X coordinate on the triangle to adjust to
* @param y Y coordinate on the triangle to adjust to
* @param checkLoc if true the location is checked to make sure
* it is contained in the triangle, if false the location is
* constrained to fit in the triangle.
* @return true if the location is valid
*/
boolean resetXY = false;
// Invert the axis.
y = -y;
y > innerR)) {
return false;
}
// Rotate to origin and and verify x is valid.
if (checkLoc) {
return false;
}
resetXY = true;
}
if (checkLoc) {
return false;
}
resetXY = true;
}
// Verify y location is valid.
if (checkLoc) {
return false;
}
resetXY = true;
}
if (checkLoc) {
return false;
}
resetXY = true;
}
// Rotate again to determine value and scale
(double)triangleSize));
setFlag(FLAGS_SETTING_COLOR, true);
if (resetXY) {
}
else {
getWheelXOrigin(),getWheelYOrigin() - y);
}
value, true);
setFlag(FLAGS_SETTING_COLOR, false);
return true;
}
/**
* Sets the saturation and brightness.
*/
private void setSaturationAndBrightness(float s, float b) {
int innerR = getTriangleCircumscribedRadius();
double x = b * triangleSize;
x = x - innerR;
}
/**
* Sets the saturation and brightness.
*/
private void setSaturationAndBrightness(float s, float b,
int newCircleX, int newCircleY) {
}
/**
* Adjusts the hue based on the passed in location.
*
* @param x X location to adjust to, relative to the origin of the
* wheel
* @param y Y location to adjust to, relative to the origin of the
* wheel
* @param check if true the location is checked to make sure
* it is contained in the wheel, if false the location is
* constrained to fit in the wheel
* @return true if the location is valid.
*/
int size = getWheelRadius();
// Map the location to an angle and reset hue
double angle;
if (x == 0) {
if (y > 0) {
}
else {
}
}
else {
if (x < 0) {
}
else if (angle < 0) {
}
}
setFlag(FLAGS_SETTING_COLOR, true);
setFlag(FLAGS_SETTING_COLOR, false);
return true;
}
return false;
}
/**
* Rotates the triangle to accomodate the passed in hue.
*/
}
/**
* Sets the angle representing the hue.
*/
setFlag(FLAGS_CHANGED_ANGLE, true);
repaint();
}
}
/**
* Returns the size of the color indicator.
*/
private int getIndicatorSize() {
return 8;
}
/**
* Returns the circumscribed radius of the triangle.
*/
private int getTriangleCircumscribedRadius() {
return 72;
}
/**
* Returns the x origin of the wheel and triangle.
*/
private int getWheelXOrigin() {
return 85;
}
/**
* Returns y origin of the wheel and triangle.
*/
private int getWheelYOrigin() {
return 85;
}
/**
* Returns the width of the wheel.
*/
private int getWheelWidth() {
return 13;
}
/**
* Sets the focus to one of: 0 no one, 1 the wheel or 2 the triangle.
*/
if (type == 0) {
setFlag(FLAGS_FOCUSED_WHEEL, false);
setFlag(FLAGS_FOCUSED_TRIANGLE, false);
repaint();
}
else {
int toSet = FLAGS_FOCUSED_WHEEL;
int toUnset = FLAGS_FOCUSED_TRIANGLE;
if (type == 2) {
}
repaint();
}
}
}
/**
* Returns the radius of the wheel.
*/
private int getWheelRadius() {
// As far as I can tell, GTK doesn't allow stretching this
// widget
return 85;
}
/**
* Updates the flags bitmask.
*/
if (value) {
}
else {
}
}
/**
* Returns true if a particular flag has been set.
*/
}
/**
* Returns the RGB color to use for the specified location. The
* passed in point must be on the color wheel and be relative to the
* origin of the color wheel.
*
* @param x X location to get color for
* @param y Y location to get color for
* @param rad Radius from center of color wheel
* @return integer with red, green and blue components
*/
int rgb;
if (y < 0) {
// FFFF00 - FF0000
}
else {
// FF0000 - FF00FF
}
}
if (y < 0) {
// 00FF00 - FFFF00
}
else {
// FF00FF - 0000FF
}
}
else {
if (y < 0) {
// 00FFFF - 00FF00
}
else {
// 0000FF - 00FFFF
}
}
return rgb;
}
/**
* Increments the hue.
*/
if (positive) {
}
else {
}
if (hue > 1) {
hue -= 1;
}
else if (hue < 0) {
hue += 1;
}
}
}
/**
* Action class used for colors.
*/
private int type;
super(name);
}
if (triangle.isWheelFocused()) {
switch (type) {
case 0:
case 2:
triangle.incrementHue(true);
break;
case 1:
case 3:
triangle.incrementHue(false);
break;
case 4:
break;
case 5:
compositeRequestFocus(triangle, false);
break;
}
}
else {
int xDelta = 0;
int yDelta = 0;
switch (type) {
case 0:
// up
yDelta--;
break;
case 1:
// down
yDelta++;
break;
case 2:
// left
xDelta--;
break;
case 3:
// right
xDelta++;
break;
case 4:
compositeRequestFocus(triangle, true);
return;
case 5:
return;
}
}
}
}
public boolean isOpaque() {
return true;
}
}
}