JavaView® v2.12

jv.number
Class PdColor

java.lang.Object
  |
  +--jv.object.PsObject
        |
        +--jv.number.PdColor
All Implemented Interfaces:
java.lang.Cloneable, PsUpdateIf, java.io.Serializable

public final class PdColor
extends PsObject

RGBA color class with info panel and update functionality.

The class is derived from PsObject rather than java.awt.Color since the focus of this class is the update functionality and handling of an info panel for interactive modifications. The class PdColor allows interactive modification of a color similar to the class PuDouble and PuInteger allow for double and integer numbers. Also, java.awt.Color cannot be modified after construction.

TODO: Subclassing of PsObject will be replaced by implementing interface PsUpdateIf and some methods currently inherited from PsObject.

Version:
11.07.00, 1.30 revised (kp) New conversion methods, slight bug in hsv2rgb removed.
01.01.00, 1.20 revised (kp) Set of methods cleaned up, public interface tightened.
07.08.99, 1.10 revised (kp) Converted to AWT 1.1.
00.00.98, 1.00 created (kp)
Author:
Konrad Polthier
See Also:
PdColor, PdColor_Dialog, Serialized Form

Fields inherited from class jv.object.PsObject
HAS_CONFIG_PANEL, HAS_INFO_PANEL, HAS_MATERIAL_PANEL, HAS_TEXTURE_PANEL, INSPECTOR_INFO, INSPECTOR_INFO_EXT, IS_DELETED, IS_FIXED, IS_SELECTED, IS_USED, NUM_TAGS
 
Constructor Summary
PdColor()
          Constructor of color in RGB mode with alpha disabled.
PdColor(int size, boolean bAlpha)
          Constructor of color in RGB mode with number of color components and possible alpha channel.
PdColor(java.lang.String aName, PsUpdateIf aParent)
          Constructor of color in RGB mode with alpha disabled.
 
Method Summary
static java.awt.Color blend(double a, java.awt.Color v, double b, java.awt.Color w)
          Interpolate between two colors with given weights.
 void blend(double a, PdColor v, double b, PdColor w)
          Interpolate between two colors with given weights.
 void blendBase(PdColor v, double b, PdColor w)
          Interpolate between two colors with given weights.
 java.lang.Object clone()
          Duplicate color and data array.
static boolean copy(java.awt.Color[] dataDest, int destInd, java.awt.Color[] dataSrc, int srcInd, int size)
          Assign some colors of a given array of colors to an existing destination array.
 void copy(double[] anArray, int aSize)
          Copy color components excluding alpha.
 void copy(int[] anArray, int aSize)
          Copy color components excluding alpha.
 void copy(PdColor v)
          Copy color components including alpha.
static boolean copy(PdColor[] dataDest, int destInd, PdColor[] dataSrc, int srcInd, int size)
          Copies some colors of a given array of colors into an existing destination array.
static PdColor copyNew(PdColor v)
          Create a new color as clone of argument color.
static PdColor[] copyNew(PdColor[] data)
          Create an new array with copies of all colors of a given array of colors.
static PdColor[] copyNew(PdColor[] data, int size)
          Create an new array with copies of the first 'size' colors of a given array of colors.
 void enableAlpha(boolean aValue)
          Enable or disable alpha channel.
 boolean equals(java.awt.Color col)
          Determines whether another color is equal to this color.
 boolean equals(PdColor col)
          Determines whether another color is equal to this color.
 int getAlpha()
          Get alpha component if alpha is enabled, otherwise result is 0.
 int getBlue()
          Get blue color component if size==3, otherwise result is 0.
 java.awt.Color getColor()
          Convert color components in a java.awt.Color instance.
static java.awt.Color getDimmedColor(java.awt.Color col, double dim)
          Get a color whose components are dimmed by a factor.
static java.awt.Color getDimmedColor(java.awt.Color col, double dim, double offset)
          Get a color whose components are dimmed by a factor and shifted by an offset.
 int getEntry(int ind)
          Get a color component with given index.
 int getGreen()
          Get green color component if size==3, otherwise result is 0.
 int getGrey()
          Get grey color if size==1, otherwise result is 0.
 int getRed()
          Get red color component if size==3, otherwise result is 0.
 int getSize()
          Return number of components excluding alpha.
 boolean hasAlpha()
          Check whether alpha channel is used.
static java.awt.Color hsl2rgb(int hi, int li, int si)
           
static java.awt.Color hsv2rgb(java.awt.Color hsv)
          Conversion of color spaces.
static java.awt.Color hsv2rgb(int h, int s, int v)
          Conversion of color spaces.
static void hsv2rgb(PdColor rgb, PdColor hsv)
          Conversion of color spaces.
 int indexOfMax()
          Find component in color with maximal value.
 int indexOfMin()
          Find component in color with minimal value.
 void init()
          Initialize and reset components to 0.
 boolean isEnabled()
          Check whether color dialog is enabled or disabled.
 int max()
          Find maximal value of component in color.
 int min()
          Find minimal value of component in color.
static java.awt.Color parseColor(java.lang.String colorString)
          Parse rgb color from a given string where each component is integer in the range 0..255 and blank or comma separated.
static java.awt.Color[] realloc(java.awt.Color[] data, int arraySize)
          Allocate an array of Java colors and assign default color black.
static PdColor[] realloc(PdColor[] data, int arraySize, int colorSize)
          Allocate an array of colors, where all colors have the same dimension.
static PdColor[] realloc(PdColor[] data, int arraySize, int colorSize, boolean bAlpha)
          Allocate an array of colors, where all colors have the same dimension.
static java.awt.Color rgb2hsl(int ri, int gi, int bi)
           
static void rgb2hsv(PdColor hsv, PdColor rgb)
          Conversion of color spaces.
static java.awt.Color rgb2yiq(int ri, int gi, int bi)
           
 void set(double grey)
          Set grey component of this color using double arguments in [0., 1.].
 void set(double red, double green, double blue)
          Set components of this color using double arguments in [0., 1.].
 void set(double red, double green, double blue, double alpha)
          Set components of this color using double arguments in [0., 1.].
 void set(int grey)
          Set grey component of this color using integer argument in [0, 255].
 void set(int red, int green, int blue)
          Set components of this color using integer argument in [0, 255].
 void set(int red, int green, int blue, int alpha)
          Set components of this color using double arguments in [0, 255].
 void setAlpha(double x)
          Set alpha component of this color using double argument in [0., 1.].
 void setAlpha(int x)
          Set alpha component of this color using integer argument in [0, 255].
 void setColor(java.awt.Color aColor)
          Set color components to components of argument color.
 void setConstant(int val)
          Set all color components including alpha to the same value.
 void setEnabled(boolean flag)
          Enable or disable the color dialog for interactive use.
 void setEntry(int ind, int value)
          Set a color component with given index to value.
 void setSize(int aSize)
          Set number of components of color excluding alpha.
static java.awt.Color yiq2rgb(int yi, int ii, int qi)
           
 
Methods inherited from class jv.object.PsObject
addInspector, addUpdateListener, assureInspector, clearTag, clone, clone, copy, getFather, getInfoPanel, getInspector, getName, getNumObjects, hasInspector, hasTag, hasUpdateListener, instanceOf, instanceOf, removeInspector, removeUpdateListener, setName, setParent, setTag, toString, update, updatePanels
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PdColor

public PdColor()
Constructor of color in RGB mode with alpha disabled. Calls PdColor(m_numDefColors, false).

PdColor

public PdColor(int size,
               boolean bAlpha)
Constructor of color in RGB mode with number of color components and possible alpha channel.
Parameters:
size - number of color components excluding alpha
bAlpha - true to enable alpha channel

PdColor

public PdColor(java.lang.String aName,
               PsUpdateIf aParent)
Constructor of color in RGB mode with alpha disabled.
Parameters:
aName - name of color, e.g. used as header in info panel
aParent - parent receives update events, e.g. when color changes through info panel
Method Detail

init

public void init()
Initialize and reset components to 0.
Overrides:
init in class PsObject

isEnabled

public boolean isEnabled()
Check whether color dialog is enabled or disabled.

setEnabled

public void setEnabled(boolean flag)
Enable or disable the color dialog for interactive use. If disabled, the color variable can still be modified by calls setValue(double), and the color dialog is always updated.

getSize

public int getSize()
Return number of components excluding alpha.

setSize

public void setSize(int aSize)
Set number of components of color excluding alpha. Note, alpha must be enabled separately. Note, alpha should be enabled before this method is called to allow this method to allocate alpha channel simultaneously with of other channels. All memory allocations are done in this method.
Parameters:
aSize - number of color components, e.g. 3 in rgb mode.

equals

public boolean equals(java.awt.Color col)
Determines whether another color is equal to this color. The result is true if both colors have same color components excluding alpha. Result is also true if argument color is null and this color has no entries.

Alpha is not compared since Java1.1 does not support alpha in java.awt.Color.

Parameters:
col - the color to compare with
Returns:
true if the color component are the same; false otherwise.

equals

public boolean equals(PdColor col)
Determines whether another color is equal to this color. The result is true if both colors have same size and equal components including alpha. Result is also true if argument color is null and this color has no entries.
Parameters:
col - the color to compare with
Returns:
true if the objects are the same; false otherwise.

getGrey

public int getGrey()
Get grey color if size==1, otherwise result is 0.

getRed

public int getRed()
Get red color component if size==3, otherwise result is 0.

getGreen

public int getGreen()
Get green color component if size==3, otherwise result is 0.

getBlue

public int getBlue()
Get blue color component if size==3, otherwise result is 0.

getAlpha

public int getAlpha()
Get alpha component if alpha is enabled, otherwise result is 0.

getDimmedColor

public static java.awt.Color getDimmedColor(java.awt.Color col,
                                            double dim)
Get a color whose components are dimmed by a factor. Product of factor and color component is constraint to interval [0,255]. Method does not change components of this color.
Parameters:
col - color to modify.
dim - factor to be multiplied to all color components.
Returns:
new color

getDimmedColor

public static java.awt.Color getDimmedColor(java.awt.Color col,
                                            double dim,
                                            double offset)
Get a color whose components are dimmed by a factor and shifted by an offset. Offset plus product of factor and color component is constraint to interval [0,255]. Method does not change components of this color.
Parameters:
col - color to modify.
dim - factor to be multiplied to all color components.
offset - constant to be added to all color components after dimming.
Returns:
new color

getColor

public java.awt.Color getColor()
Convert color components in a java.awt.Color instance.
Returns:
java.awt.Color instance of color components, null if less than 3 components available.

setColor

public void setColor(java.awt.Color aColor)
Set color components to components of argument color. This color must have enough color components. Alpha channel remains unchanged. Info panel is updated if it exists.

hasAlpha

public boolean hasAlpha()
Check whether alpha channel is used.
Returns:
true of alpha channel is used; false otherwise.
See Also:
enableAlpha(boolean)

enableAlpha

public void enableAlpha(boolean aValue)
Enable or disable alpha channel. Internally, an alpha channel is allocated or removed.
Parameters:
true - to enable alpha channel.
See Also:
setSize(int)

getEntry

public int getEntry(int ind)
Get a color component with given index.
Parameters:
ind - index of requested color component
Returns:
value in [0,255] of color component; 0 if index out of bounds

setEntry

public void setEntry(int ind,
                     int value)
Set a color component with given index to value.
Parameters:
ind - index of color component to be modified
val - value in [0,255] for all components of color

setConstant

public void setConstant(int val)
Set all color components including alpha to the same value.
Parameters:
val - value in [0,255] for all components of color

setAlpha

public void setAlpha(int x)
Set alpha component of this color using integer argument in [0, 255]. Alpha must be enabled to allow assignment of new value.
Parameters:
alpha - new alpha component in [0, 255]

setAlpha

public void setAlpha(double x)
Set alpha component of this color using double argument in [0., 1.]. Alpha must be enabled to allow assignment of new value.
Parameters:
alpha - new alpha component in [0., 1.]

set

public void set(int grey)
Set grey component of this color using integer argument in [0, 255]. Color must have size == 1 excluding alpha. If this color has too few components then a warning is issued without changes.
Parameters:
grey - new grey component in [0, 255]

set

public void set(int red,
                int green,
                int blue)
Set components of this color using integer argument in [0, 255]. Color must have size == 3 excluding alpha. If this color has too few components then a warning is issued without changes.
Parameters:
red, - green, blue new color components in [0, 255]

set

public void set(int red,
                int green,
                int blue,
                int alpha)
Set components of this color using double arguments in [0, 255]. If this color has too few components then a warning is issued without changes. If alpha is disabled then its value is ignored.
Parameters:
red, - green, blue new color components in [0, 255]
alpha - new alpha components in [0, 255]

set

public void set(double grey)
Set grey component of this color using double arguments in [0., 1.]. Color must have size == 1 excluding alpha. If this color has too few components then a warning is issued without changes.
Parameters:
grey - new grey component in [0., 1.]

set

public void set(double red,
                double green,
                double blue)
Set components of this color using double arguments in [0., 1.]. If this color has too few components then a warning is issued without changes.
Parameters:
red, - green, blue new color components in [0., 1.]

set

public void set(double red,
                double green,
                double blue,
                double alpha)
Set components of this color using double arguments in [0., 1.]. If this color has too few components then a warning is issued without changes. If alpha is disabled then its value is ignored.
Parameters:
red, - green, blue new color components in [0., 1.]
alpha - new alpha components in [0., 1.]

clone

public java.lang.Object clone()
Duplicate color and data array. Method just returns result of copyNew(PdColor).
Overrides:
clone in class PsObject
See Also:
copyNew(PdColor)

copyNew

public static PdColor copyNew(PdColor v)
Create a new color as clone of argument color.
Parameters:
v - source color to clone

copy

public void copy(PdColor v)
Copy color components including alpha. Source and destination colors must have same size, except if destination color is empty then allocated space of size of source color.
Parameters:
v - source color to copy

copy

public void copy(int[] anArray,
                 int aSize)
Copy color components excluding alpha. Source and destination colors must have same size, except if destination color is empty then method allocates of size of source array.
Parameters:
anArray - new color components in [0, 255]

copy

public void copy(double[] anArray,
                 int aSize)
Copy color components excluding alpha. Source and destination colors must have same size, except if destination color is empty then method allocates space of size of source array.
Parameters:
anArray - new color components in [0., 1.]

max

public int max()
Find maximal value of component in color.
Returns:
value of maximal component
See Also:
min(), indexOfMax()

min

public int min()
Find minimal value of component in color.
Returns:
value of minimal component
See Also:
min(), indexOfMax()

indexOfMax

public int indexOfMax()
Find component in color with maximal value.
Returns:
index of maximal component

indexOfMin

public int indexOfMin()
Find component in color with minimal value.
Returns:
index of minimal component

blend

public static java.awt.Color blend(double a,
                                   java.awt.Color v,
                                   double b,
                                   java.awt.Color w)
Interpolate between two colors with given weights. Uses this = v*a + w*b including alpha component. If result color 'this' is empty then its size is set to size if color v, otherwise no interpolation is performed.
Parameters:
v - first color
a - weight of color v
w - second color
b - weight of color w
See Also:
blend(double, PdColor, double, PdColor)

blend

public void blend(double a,
                  PdColor v,
                  double b,
                  PdColor w)
Interpolate between two colors with given weights. Uses this = v*a + w*b including alpha component. If result color 'this' is empty then its size is set to size if color v, otherwise no interpolation is performed.
Parameters:
v - first color
a - weight of color v
w - second color
b - weight of color w
See Also:
blendBase(PdColor, double, PdColor)

blendBase

public void blendBase(PdColor v,
                      double b,
                      PdColor w)
Interpolate between two colors with given weights. Uses this = v + w*b including alpha component. If result color 'this' is empty then its size is set to size if color v, otherwise no interpolation is performed.
Parameters:
v - first color
w - second color
b - weight of color w
See Also:
blend(double, PdColor, double, PdColor)

realloc

public static java.awt.Color[] realloc(java.awt.Color[] data,
                                       int arraySize)
Allocate an array of Java colors and assign default color black. If argument data!=null then as most as possible of the content of existing colors is copied into (possibly reused) colors of the reallocated array. Assignment of default color does not waist memory since assignment is made to a static class.

If requested array size is 0 then method returns an array of length 0.

Parameters:
data - possibly empty array of colors
arraySize - number of colors in new array

realloc

public static PdColor[] realloc(PdColor[] data,
                                int arraySize,
                                int colorSize)
Allocate an array of colors, where all colors have the same dimension. If argument data!=null then as most as possible of the content of existing colors is copied into (possibly reused) colors of the reallocated array. Colors have no alpha channel.
Parameters:
data - possibly empty array of colors
arraySize - number of colors in new array
colorSize - dimension of colors in new array

realloc

public static PdColor[] realloc(PdColor[] data,
                                int arraySize,
                                int colorSize,
                                boolean bAlpha)
Allocate an array of colors, where all colors have the same dimension. If argument data!=null then as most as possible of the content of existing colors is copied into (possibly reused) colors of the reallocated array.
Parameters:
data - possibly empty array of colors
arraySize - number of colors in new array
colorSize - dimension of colors in new array
bAlpha - flag whether alpha is enabled

copyNew

public static PdColor[] copyNew(PdColor[] data)
Create an new array with copies of all colors of a given array of colors. The new array contains new colors containing the same data as the original colors.
Parameters:
data - array of colors
Returns:
new array with same number of colors as argument array
See Also:
copyNew(PdColor [], int), copy(PdColor [], int, PdColor [], int, int)

copyNew

public static PdColor[] copyNew(PdColor[] data,
                                int size)
Create an new array with copies of the first 'size' colors of a given array of colors. The new array contains new colors containing the same data as the original colors.
Parameters:
data - array of colors
size - number of copied colors of array
Returns:
new array with number of colors equal to argument 'size'
See Also:
copyNew(PdColor []), copy(PdColor [], int, PdColor [], int, int)

copy

public static boolean copy(java.awt.Color[] dataDest,
                           int destInd,
                           java.awt.Color[] dataSrc,
                           int srcInd,
                           int size)
Assign some colors of a given array of colors to an existing destination array. Both source and destination array must exist already.
   for (int i=0; i
 Destination array must be large enough, i.e. dataDest.length >= destInd+size.
Parameters:
dataDest - destination array of colors
destInd - index of first destination color in dataDest
dataSrc - source array of colors
srcInd - index of first source color in dataSrc used for copying
size - number of assigned colors of array
Returns:
true if destination array is large enough
See Also:
copy(PdColor)

copy

public static boolean copy(PdColor[] dataDest,
                           int destInd,
                           PdColor[] dataSrc,
                           int srcInd,
                           int size)
Copies some colors of a given array of colors into an existing destination array. All colors in source and destination array must exist already.
   for (int i=0; i
 Destination array must be large enough, i.e. dataDest.length >= destInd+size.
Parameters:
dataDest - destination array of colors
destInd - index of first destination color in dataDest
dataSrc - source array of colors
srcInd - index of first source color in dataSrc used for copying
size - number of copied colors of array
Returns:
true if destination array is large enough
See Also:
copy(PdColor)

rgb2hsv

public static void rgb2hsv(PdColor hsv,
                           PdColor rgb)
Conversion of color spaces.

hsv2rgb

public static void hsv2rgb(PdColor rgb,
                           PdColor hsv)
Conversion of color spaces.

hsv2rgb

public static java.awt.Color hsv2rgb(java.awt.Color hsv)
Conversion of color spaces.

hsv2rgb

public static java.awt.Color hsv2rgb(int h,
                                     int s,
                                     int v)
Conversion of color spaces.

hsl2rgb

public static java.awt.Color hsl2rgb(int hi,
                                     int li,
                                     int si)

rgb2hsl

public static java.awt.Color rgb2hsl(int ri,
                                     int gi,
                                     int bi)

yiq2rgb

public static java.awt.Color yiq2rgb(int yi,
                                     int ii,
                                     int qi)

rgb2yiq

public static java.awt.Color rgb2yiq(int ri,
                                     int gi,
                                     int bi)

parseColor

public static java.awt.Color parseColor(java.lang.String colorString)
Parse rgb color from a given string where each component is integer in the range 0..255 and blank or comma separated.
Parameters:
colorString - string with integer color components
Returns:
java.awt.Color instance of color components, null if less than 3 components available.

JavaView® v2.12

The software JavaView® is copyright protected. All Rights Reserved.