1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
|
/* DefaultHSBChooserPanel.java --
Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package javax.swing.colorchooser;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.image.MemoryImageSource;
import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.Icon;
import javax.swing.JColorChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSlider;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
* This is the Default HSB Panel displayed in the JColorChooser.
*/
class DefaultHSBChooserPanel extends AbstractColorChooserPanel
{
/** The gradient image displayed. */
private transient Image gradientImage;
/** The Panel that holds the gradient image. */
private transient JPanel gradientPanel;
/** The track gradient image. */
private transient Image trackImage;
/** The panel that holds the track. */
private transient JPanel trackPanel;
/** The slider for the locked HSB value. */
private transient JSlider slider;
/** The RadioButton that controls the Hue. */
private transient JRadioButton hRadio;
/** The RadioButton that controls the Saturation. */
private transient JRadioButton sRadio;
/** The RadioButton that controls the Brightness. */
private transient JRadioButton bRadio;
/** The JSpinner that controls the Hue. */
private transient JSpinner hSpinner;
/** The JSpinner that controls the Saturation. */
private transient JSpinner sSpinner;
/** The JSpinner that controls the Brightness. */
private transient JSpinner bSpinner;
/** The default width of the gradient image. */
private static final int imgWidth = 200;
/** The default height of the gradient image. */
private static final int imgHeight = 200;
/** The default width of the track gradient. */
private static final int trackWidth = 30;
/** The JLabel for Red. */
private static final JLabel R = new JLabel("R");
/** The JLabel for Green. */
private static final JLabel G = new JLabel("G");
/** The JLabel for Blue. */
private static final JLabel B = new JLabel("B");
// FIXME: Should be textfields.
/** The JLabel that displays the value of Red. */
private transient JLabel rFull;
/** The JLabel that displays the value of Green. */
private transient JLabel gFull;
/** The JLabel that displays the value of Blue. */
private transient JLabel bFull;
/** The point that is displayed in the gradient image. */
private transient Point gradientPoint = new Point();
/**
* This indicates that the change to the slider or point is triggered
* internally.
*/
private transient boolean internalChange = false;
/** This indicates that the change to the spinner is triggered internally. */
private transient boolean spinnerTrigger = false;
/** This int identifies which spinner is currently locked. */
private transient int locked = -1;
/** This value indicates that the Hue spinner is locked. */
static final int HLOCKED = 0;
/** This value indicates that the Saturation spinner is locked. */
static final int SLOCKED = 1;
/** This value indicates that the Brightness spinner is locked. */
static final int BLOCKED = 2;
/**
* This method indicates that the mouse event is in the process of being
* handled.
*/
private transient boolean handlingMouse;
/**
* This helper class handles mouse events on the gradient image.
*/
class MainGradientMouseListener extends MouseAdapter
implements MouseMotionListener
{
/**
* This method is called when the mouse is pressed over the gradient
* image. The JColorChooser is then updated with new HSB values.
*
* @param e The MouseEvent.
*/
public void mousePressed(MouseEvent e)
{
gradientPoint = e.getPoint();
update(e.getPoint());
}
/**
* This method is called when the mouse is dragged over the gradient
* image. The JColorChooser is then updated with the new HSB values.
*
* @param e The MouseEvent.
*/
public void mouseDragged(MouseEvent e)
{
Point p = e.getPoint();
if (p.x < 0 || p.y < 0 || p.y > imgHeight || p.x > imgWidth)
return;
gradientPoint = p;
update(p);
}
/**
* This method is called when the mouse is moved over the gradient image.
*
* @param e The MouseEvent.
*/
public void mouseMoved(MouseEvent e)
{
// Do nothing.
}
/**
* This method updates the JColorChooser with the new values.
*
* @param p The Point where the MouseEvent occurred.
*/
private void update(Point p)
{
handlingMouse = true;
if (hSpinner.isEnabled())
updateH(p);
else if (sSpinner.isEnabled())
updateS(p);
else
updateB(p);
handlingMouse = false;
}
/**
* This method updates the SB values if Hue is locked.
*
* @param p The point where the MouseEvent occurred.
*/
private void updateH(Point p)
{
float s = (imgWidth - p.x * 1f) / imgWidth;
float b = (imgHeight - p.y * 1f) / imgHeight;
// Avoid two changes to the model by changing internalChange to true.
internalChange = true;
sSpinner.setValue(new Integer((int) (s * 100)));
internalChange = false;
bSpinner.setValue(new Integer((int) (b * 100)));
revalidate();
}
/**
* This method updates the HB values if Saturation is locked.
*
* @param p The point where the MouseEvent occurred.
*/
private void updateS(Point p)
{
float h = p.x * 1f / imgWidth;
float b = (imgHeight - p.y * 1f) / imgHeight;
internalChange = true;
hSpinner.setValue(new Integer((int) (h * 365)));
internalChange = false;
bSpinner.setValue(new Integer((int) (b * 100)));
revalidate();
}
/**
* This method updates the HS values if Brightness is locked.
*
* @param p The point where the MouseEvent occurred.
*/
private void updateB(Point p)
{
float h = p.x * 1f / imgWidth;
float s = (imgHeight - p.y * 1f) / imgHeight;
internalChange = true;
hSpinner.setValue(new Integer((int) (h * 365)));
internalChange = false;
sSpinner.setValue(new Integer((int) (s * 100)));
revalidate();
}
}
/**
* This method listens for slider value changes.
*/
class SliderChangeListener implements ChangeListener
{
/**
* This method is called when the slider value changes. It should change
* the color of the JColorChooser.
*
* @param e The ChangeEvent.
*/
public void stateChanged(ChangeEvent e)
{
if (internalChange)
return;
Integer value = new Integer(slider.getValue());
switch (locked)
{
case HLOCKED:
hSpinner.setValue(value);
break;
case SLOCKED:
sSpinner.setValue(value);
break;
case BLOCKED:
bSpinner.setValue(value);
break;
}
}
}
/**
* This helper class determines the active JSpinner.
*/
class RadioStateListener implements ChangeListener
{
/**
* This method is called when there is a new JRadioButton that was
* selected. As a result, it should activate the associated JSpinner.
*
* @param e The ChangeEvent.
*/
public void stateChanged(ChangeEvent e)
{
JSpinner change;
if (e.getSource() == hRadio)
{
locked = HLOCKED;
change = hSpinner;
}
else if (e.getSource() == sRadio)
{
locked = SLOCKED;
change = sSpinner;
}
else
{
locked = BLOCKED;
change = bSpinner;
}
change.setEnabled(((AbstractButton) e.getSource()).isSelected());
updateSlider();
updateTrack();
updateImage();
repaint();
}
}
/**
* This class listens to the JSpinners for changes.
*/
class ImageScrollListener implements ChangeListener
{
/**
* This method is called whenever one of the JSpinner values change. The
* JColorChooser should be updated with the new HSB values.
*
* @param e The ChangeEvent.
*/
public void stateChanged(ChangeEvent e)
{
if (internalChange)
return;
float h = ((Number) hSpinner.getValue()).intValue() / 360f;
float s = ((Number) sSpinner.getValue()).intValue() / 100f;
float b = ((Number) bSpinner.getValue()).intValue() / 100f;
spinnerTrigger = true;
getColorSelectionModel().setSelectedColor(new Color(Color.HSBtoRGB(h, s,
b)));
spinnerTrigger = false;
if (! handlingMouse && slider != null && ! slider.getValueIsAdjusting())
{
updateImage();
updateTrack();
}
repaint();
}
}
/**
* Creates a new DefaultHSBChooserPanel object.
*/
DefaultHSBChooserPanel()
{
super();
}
/**
* This method returns the name displayed by the JColorChooser tab that
* holds this panel.
*
* @return The name displayed in the JColorChooser tab.
*/
public String getDisplayName()
{
return "HSB";
}
/**
* This method updates the various components inside the HSBPanel (the
* JSpinners, the JSlider, and the gradient image point) with updated
* values when the JColorChooser color value changes.
*/
public void updateChooser()
{
Color c = getColorSelectionModel().getSelectedColor();
float[] hsbVals = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(),
null);
internalChange = true;
if (! spinnerTrigger)
{
hSpinner.setValue(new Integer((int) (hsbVals[0] * 360)));
sSpinner.setValue(new Integer((int) (hsbVals[1] * 100)));
bSpinner.setValue(new Integer((int) (hsbVals[2] * 100)));
}
switch (locked)
{
case HLOCKED:
if (slider != null)
slider.setValue(((Number) hSpinner.getValue()).intValue());
if (! handlingMouse)
{
gradientPoint.x = (int) ((1
- ((Number) sSpinner.getValue()).intValue() / 100f) * imgWidth);
gradientPoint.y = (int) ((1
- ((Number) bSpinner.getValue()).intValue() / 100f) * imgHeight);
}
break;
case SLOCKED:
if (slider != null)
slider.setValue(((Number) sSpinner.getValue()).intValue());
if (! handlingMouse)
{
gradientPoint.x = (int) (((Number) hSpinner.getValue()).intValue() / 360f * imgWidth);
gradientPoint.y = (int) ((1
- ((Number) bSpinner.getValue()).intValue() / 100f) * imgHeight);
}
break;
case BLOCKED:
if (slider != null)
slider.setValue(((Number) bSpinner.getValue()).intValue());
if (! handlingMouse)
{
gradientPoint.x = (int) (((Number) hSpinner.getValue()).intValue() / 360f * imgWidth);
gradientPoint.y = (int) ((1
- ((Number) sSpinner.getValue()).intValue() / 100f) * imgHeight);
}
break;
}
internalChange = false;
if (! handlingMouse && slider != null && ! slider.getValueIsAdjusting())
updateImage();
if (! handlingMouse || locked != HLOCKED)
updateTrack();
updateTextFields();
}
/**
* This method builds the DefaultHSBChooserPanel.
*/
protected void buildChooser()
{
setLayout(new BorderLayout());
add(buildRightPanel(), BorderLayout.EAST);
JPanel container = new JPanel();
container.setLayout(new BorderLayout());
gradientPanel = new JPanel()
{
public Dimension getPreferredSize()
{
return new Dimension(imgWidth, imgHeight);
}
public void paint(Graphics g)
{
if (gradientImage != null)
g.drawImage(gradientImage, 0, 0, this);
Color saved = g.getColor();
g.setColor(Color.WHITE);
g.drawOval(gradientPoint.x - 3, gradientPoint.y - 3, 6, 6);
g.setColor(saved);
}
};
MouseAdapter ml = new MainGradientMouseListener();
gradientPanel.addMouseListener(ml);
gradientPanel.addMouseMotionListener((MouseMotionListener) ml);
trackPanel = new JPanel()
{
public Dimension getPreferredSize()
{
return new Dimension(trackWidth, imgHeight);
}
public void paint(Graphics g)
{
if (trackImage != null)
g.drawImage(trackImage, 0, 0, this);
}
};
slider = new JSlider();
slider.setPaintTrack(false);
slider.setPaintTicks(false);
slider.setOrientation(SwingConstants.VERTICAL);
updateSlider();
container.add(gradientPanel, BorderLayout.WEST);
container.add(slider, BorderLayout.CENTER);
container.add(trackPanel, BorderLayout.EAST);
add(container, BorderLayout.WEST);
slider.addChangeListener(new SliderChangeListener());
repaint();
}
/**
* This method uninstalls the DefaultHSBPanel.
*
* @param chooser The JColorChooser to remove this panel from.
*/
public void uninstallChooserPanel(JColorChooser chooser)
{
trackImage = null;
gradientImage = null;
gradientPanel = null;
slider = null;
hSpinner = null;
sSpinner = null;
bSpinner = null;
hRadio = null;
sRadio = null;
bRadio = null;
removeAll();
super.uninstallChooserPanel(chooser);
}
/**
* This helper method creates the right side panel (the panel with the
* Spinners and TextFields).
*
* @return The right side panel.
*/
private Container buildRightPanel()
{
JPanel container = new JPanel();
container.setLayout(new GridLayout(6, 2));
hRadio = new JRadioButton("H");
sRadio = new JRadioButton("S");
bRadio = new JRadioButton("B");
ButtonGroup group = new ButtonGroup();
group.add(hRadio);
group.add(sRadio);
group.add(bRadio);
hSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 359, 1));
sSpinner = new JSpinner(new SpinnerNumberModel(0, 0, 100, 1));
bSpinner = new JSpinner(new SpinnerNumberModel(100, 0, 100, 1));
hSpinner.setEnabled(false);
sSpinner.setEnabled(false);
bSpinner.setEnabled(false);
ChangeListener cl = new RadioStateListener();
ChangeListener scroll = new ImageScrollListener();
hRadio.addChangeListener(cl);
sRadio.addChangeListener(cl);
bRadio.addChangeListener(cl);
hSpinner.addChangeListener(scroll);
sSpinner.addChangeListener(scroll);
bSpinner.addChangeListener(scroll);
hRadio.setSelected(true);
container.add(hRadio);
container.add(hSpinner);
container.add(sRadio);
container.add(sSpinner);
container.add(bRadio);
container.add(bSpinner);
rFull = new JLabel("red full");
gFull = new JLabel("green full");
bFull = new JLabel("blue full");
container.add(R);
container.add(rFull);
container.add(G);
container.add(gFull);
container.add(B);
container.add(bFull);
return container;
}
/**
* This method returns the small display icon.
*
* @return The small display icon.
*/
public Icon getSmallDisplayIcon()
{
return null;
}
/**
* This method returns the large display icon.
*
* @return The large display icon.
*/
public Icon getLargeDisplayIcon()
{
return null;
}
/**
* This method paints the chooser panel.
*
* @param g The graphics object to paint with.
*/
public void paint(Graphics g)
{
super.paint(g);
}
/**
* This method updates the gradient image with a new one taking the Hue
* value as the constant.
*/
private void updateHLockImage()
{
int index = 0;
int[] pix = new int[imgWidth * imgHeight];
float hValue = ((Number) hSpinner.getValue()).intValue() / 360f;
for (int j = 0; j < imgHeight; j++)
for (int i = 0; i < imgWidth; i++)
pix[index++] = Color.HSBtoRGB(hValue, (imgWidth - i * 1f) / imgWidth,
(imgHeight - j * 1f) / imgHeight)
| (255 << 24);
gradientImage = createImage(new MemoryImageSource(imgWidth, imgHeight,
pix, 0, imgWidth));
}
/**
* This method updates the gradient image with a new one taking the
* Brightness value as the constant.
*/
private void updateBLockImage()
{
int[] pix = new int[imgWidth * imgHeight];
float bValue = ((Number) bSpinner.getValue()).intValue() / 100f;
int index = 0;
for (int j = 0; j < imgHeight; j++)
for (int i = 0; i < imgWidth; i++)
pix[index++] = Color.HSBtoRGB(i * 1f / imgWidth,
(imgHeight - j * 1f) / imgHeight, bValue)
| (255 << 24);
gradientImage = createImage(new MemoryImageSource(imgWidth, imgHeight,
pix, 0, imgWidth));
}
/**
* This method updates the gradient image with a new one taking the
* Saturation value as the constant.
*/
private void updateSLockImage()
{
int[] pix = new int[imgWidth * imgHeight];
float sValue = ((Number) sSpinner.getValue()).intValue() / 100f;
int index = 0;
for (int j = 0; j < imgHeight; j++)
for (int i = 0; i < imgWidth; i++)
pix[index++] = Color.HSBtoRGB(i * 1f / imgWidth, sValue,
(imgHeight - j * 1f) / imgHeight)
| (255 << 24);
gradientImage = createImage(new MemoryImageSource(imgWidth, imgHeight,
pix, 0, imgWidth));
}
/**
* This method calls the appropriate method to update the gradient image
* depending on which HSB value is constant.
*/
private void updateImage()
{
switch (locked)
{
case HLOCKED:
updateHLockImage();
break;
case SLOCKED:
updateSLockImage();
break;
case BLOCKED:
updateBLockImage();
break;
}
}
/**
* This method updates the TextFields with the correct RGB values.
*/
private void updateTextFields()
{
int c = getColorSelectionModel().getSelectedColor().getRGB();
rFull.setText("" + (c >> 16 & 0xff));
gFull.setText("" + (c >> 8 & 0xff));
bFull.setText("" + (c & 0xff));
repaint();
}
/**
* This method updates the slider in response to making a different HSB
* property the constant.
*/
private void updateSlider()
{
if (slider == null)
return;
slider.setMinimum(0);
if (locked == HLOCKED)
{
slider.setMaximum(359);
;
slider.setValue(((Number) hSpinner.getValue()).intValue());
slider.setInverted(true);
}
else
{
slider.setMaximum(100);
slider.setInverted(false);
if (sRadio.isSelected())
slider.setValue(((Number) sSpinner.getValue()).intValue());
else
slider.setValue(((Number) bSpinner.getValue()).intValue());
}
repaint();
}
/**
* This method updates the track gradient image depending on which HSB
* property is constant.
*/
private void updateTrack()
{
switch (locked)
{
case HLOCKED:
updateHTrack();
break;
case SLOCKED:
updateSTrack();
break;
case BLOCKED:
updateBTrack();
break;
}
}
/**
* This method updates the track gradient image if the Hue value is allowed
* to change (according to the JRadioButtons).
*/
private void updateHTrack()
{
int trackIndex = 0;
int[] trackPix = new int[trackWidth * imgHeight];
for (int j = 0; j < imgHeight; j++)
for (int i = 0; i < trackWidth; i++)
trackPix[trackIndex++] = Color.HSBtoRGB(j * 1f / imgHeight, 1f, 1f)
| (255 << 24);
trackImage = createImage(new MemoryImageSource(trackWidth, imgHeight,
trackPix, 0, trackWidth));
}
/**
* This method updates the track gradient image if the Saturation value is
* allowed to change (according to the JRadioButtons).
*/
private void updateSTrack()
{
int[] trackPix = new int[trackWidth * imgHeight];
float hValue = ((Number) hSpinner.getValue()).intValue() / 360f;
float bValue = ((Number) bSpinner.getValue()).intValue() / 100f;
int trackIndex = 0;
for (int j = 0; j < imgHeight; j++)
for (int i = 0; i < trackWidth; i++)
trackPix[trackIndex++] = Color.HSBtoRGB(hValue,
(imgHeight - j * 1f) / imgHeight,
bValue) | (255 << 24);
trackImage = createImage(new MemoryImageSource(trackWidth, imgHeight,
trackPix, 0, trackWidth));
}
/**
* This method updates the track gradient image if the Brightness value is
* allowed to change (according to the JRadioButtons).
*/
private void updateBTrack()
{
int[] trackPix = new int[trackWidth * imgHeight];
float hValue = ((Number) hSpinner.getValue()).intValue() / 360f;
float sValue = ((Number) sSpinner.getValue()).intValue() / 100f;
int trackIndex = 0;
for (int j = 0; j < imgHeight; j++)
for (int i = 0; i < trackWidth; i++)
trackPix[trackIndex++] = Color.HSBtoRGB(hValue, sValue,
(imgHeight - j * 1f) / imgHeight)
| (255 << 24);
trackImage = createImage(new MemoryImageSource(trackWidth, imgHeight,
trackPix, 0, trackWidth));
}
/**
* This method returns the HSB values for the currently selected color.
*
* @return The HSB values for the currently selected color.
*/
private float[] getHSBValues()
{
Color c = getColorFromModel();
float[] f = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null);
return f;
}
}
|