gishur.core
Class ParameterContainer

java.lang.Object
  |
  +--gishur.core.ParameterContainer

public class ParameterContainer
extends java.lang.Object
implements Parameters

Class able to store parameter sets. ParameterContainers are used for example by Painters to get local information and additional parameter objects which may be relevant for the drawing process.

Version:
1.0
Author:
Christoph Sachse

Constructor Summary
ParameterContainer(int length)
          Creates a new ParamterContainer which is able to store up to length parameter objects.
ParameterContainer(java.lang.Object o)
          Constructor receiving an java.lang.Object.
ParameterContainer(java.lang.Object[] oa, int offset, int length)
          Constructor receiving a subarray of java.lang.Objects.
 
Method Summary
 boolean getBoolean(int index)
          Returns the parameter with index index as a boolean value, if possible.
 double getDouble(int index)
          Returns the parameter with index index as a double value, if possible.
 float getFloat(int index)
          Returns the parameter with index index as a float value, if possible.
 int getInt(int index)
          Returns the parameter with index index as an int value, if possible.
 long getLong(int index)
          Returns the parameter with index index as a long value, if possible.
 short getShort(int index)
          Returns the parameter with index index as a short value, if possible.
 int globalLength()
          Returns the total number of storable parameters for this ParameterContainer.
 int length()
          Returns the length of the visible part of the parameters array.
 int offset()
          Returns the offset index of the visible part of the parameters array.
 java.lang.Object parameter(int index)
          Returns the parameter with index index, i.e. the index+1-th within the setted mask.
 java.lang.Object[] parameter(int offset, int length)
          Returns a subarray of paramter objects.
 java.awt.Point point(int index)
          Returns the parameter with index index, i.e. the index+1-th one within the visible part of the parameters array as a java.awt.Point.
 java.awt.Point[] point(int offset, int length)
          Returns a subarray of paramter objects as a java.awt.Point array.
 void setLength(int length)
          Sets the length of the visible part of the parameter array.
 void setMask(int offset, int length)
          Sets the mask to the given values, i.e. the offset index of the visible part of the parameters will be set to index and the number of visible parameters will be set to length.
 void setOffset(int offset)
          Sets the offset index of the visible part of the parameter array.
 void setParameter(int index, boolean b)
          Sets a boolean-value as parameter with index index.
 void setParameter(int index, double d)
          Sets a double-value as parameter with index index.
 void setParameter(int index, float f)
          Sets a float-value as parameter with index index.
 void setParameter(int index, int i)
          Sets an int-value as parameter with index index.
 void setParameter(int index, long l)
          Sets a long-value as parameter with index index.
 void setParameter(int index, java.lang.Object o)
          Sets o as new parameter object at index index within the visible mask of the parameter array.
 void setParameter(int offset, java.lang.Object[] oa, int ooffset, int length)
          Sets a subarray of new parameter objects.
 void setParameter(int index, short s)
          Sets a short-value as parameter with index index.
 void setParameterGlobal(int index, java.lang.Object o)
          Sets o as new parameter object at index index within the the parameter array, i.e.
 void setParameterGlobal(int offset, java.lang.Object[] oa, int ooffset, int length)
          Sets a subarray of new parameter objects.
 void setParameterPoint(int index, int x, int y)
          Sets the given point (x,y) as new parameter object (of type java.awt.Point) at index index within the visible mask of the parameter array.
 java.lang.String toString()
          Overridden toString-method which returns a string of the form "gishur.core.ParameterContainer[offset=...,length=...,{-parameters-}]", where offset is the offset of the visible part of the parameter array and length is its length.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ParameterContainer

public ParameterContainer(int length)
Creates a new ParamterContainer which is able to store up to length parameter objects.

ParameterContainer

public ParameterContainer(java.lang.Object o)
Constructor receiving an java.lang.Object.

ParameterContainer

public ParameterContainer(java.lang.Object[] oa,
                          int offset,
                          int length)
Constructor receiving a subarray of java.lang.Objects.
Parameters:
pa - the source array containing the Objects
offset - the first element to copy as a parameter
length - the number of Objects to copy
Method Detail

toString

public java.lang.String toString()
Overridden toString-method which returns a string of the form "gishur.core.ParameterContainer[offset=...,length=...,{-parameters-}]", where offset is the offset of the visible part of the parameter array and length is its length.
Returns:
a string representation of this ParameterContainer
Overrides:
toString in class java.lang.Object

setOffset

public void setOffset(int offset)
Sets the offset index of the visible part of the parameter array. If offset has an invalid value, the offset is set to an invalid value and the length of the visible part is set to zero. If the new offset is bigger than the old one and the length of the visible part would become invalid by this, the length will be decreased until it reaches the end of the parameter array.
Parameters:
the - new offset index of the mask

setLength

public void setLength(int length)
Sets the length of the visible part of the parameter array. If length, counted from the offset of the visible mask, would exceed the valid indices, it will be increased to the maximal valid value, i.e. the visible part is enlarged to the end of the parameter array.
Parameters:
length - the new length of the mask

setMask

public void setMask(int offset,
                    int length)
Sets the mask to the given values, i.e. the offset index of the visible part of the parameters will be set to index and the number of visible parameters will be set to length. If offset has an invalid value or if offset+length would exceed the valid indices, the same rules as in setLength(int) and setOffset(int) are applied.
Parameters:
offset - the offset index of the visible part of the parameters
length - the number of visible parameters

offset

public int offset()
Returns the offset index of the visible part of the parameters array.
Returns:
the offset index of the mask

length

public int length()
Returns the length of the visible part of the parameters array.
Specified by:
length in interface Parameters
Returns:
the length of the mask

globalLength

public int globalLength()
Returns the total number of storable parameters for this ParameterContainer.
Returns:
the length of the parameter array of this ParameterContainer

parameter

public java.lang.Object parameter(int index)
Returns the parameter with index index, i.e. the index+1-th within the setted mask.
Specified by:
parameter in interface Parameters
Parameters:
index - index of the parameter to return
Returns:
the index-th visible parameter, or null, if index has an invalid value

parameter

public java.lang.Object[] parameter(int offset,
                                    int length)
Returns a subarray of paramter objects. The returned array contains the length elements stored in the visible mask of this ParameterContainer following index offset (inclusive).
Parameters:
offset - first parameter to return (within the visible part)
length - number of parameters to return
Returns:
a subarray containing number parameter obects, or null, if offset has an invalid value or if offset+length exceeds the valid indices

point

public java.awt.Point point(int index)
Returns the parameter with index index, i.e. the index+1-th one within the visible part of the parameters array as a java.awt.Point.
Specified by:
point in interface Parameters
Parameters:
index - index of the parameter to return as a Point
Returns:
the index-th visible parameter, or null, if index has an invalid value or if it is not a java.awt.Point

point

public java.awt.Point[] point(int offset,
                              int length)
Returns a subarray of paramter objects as a java.awt.Point array. The returned array contains the length elements stored in the visible mask of this ParameterContainer following index offset (inclusive) casted to Points.
Parameters:
offset - first parameter to return (within the visible part)
length - number of parameters to return
Returns:
a subarray containing number Points, or null, if offset has an invalid value or if offset+length exceeds the valid indices or if at least one of the parameter objects is not a Point

getInt

public int getInt(int index)
Returns the parameter with index index as an int value, if possible. Otherwise, the maximal possible value will be returned.
Specified by:
getInt in interface Parameters

getShort

public short getShort(int index)
Returns the parameter with index index as a short value, if possible. Otherwise, the maximal possible value will be returned.
Specified by:
getShort in interface Parameters

getLong

public long getLong(int index)
Returns the parameter with index index as a long value, if possible. Otherwise, the maximal possible value will be returned.
Specified by:
getLong in interface Parameters

getFloat

public float getFloat(int index)
Returns the parameter with index index as a float value, if possible. Otherwise, the maximal possible value will be returned.
Specified by:
getFloat in interface Parameters

getDouble

public double getDouble(int index)
Returns the parameter with index index as a double value, if possible. Otherwise, the maximal possible value will be returned.
Specified by:
getDouble in interface Parameters

getBoolean

public boolean getBoolean(int index)
Returns the parameter with index index as a boolean value, if possible. Otherwise, false will be returned.
Specified by:
getBoolean in interface Parameters

setParameter

public void setParameter(int index,
                         java.lang.Object o)
Sets o as new parameter object at index index within the visible mask of the parameter array. Nothing happens if index is invalid.
Parameters:
index - the index (counted from the offset of the visible mask) of the parameter to set
o - the new parameter object

setParameter

public void setParameter(int offset,
                         java.lang.Object[] oa,
                         int ooffset,
                         int length)
Sets a subarray of new parameter objects. The length new parameters are taken from oa, following index ooffset and are placed at the visible parameter mask at index offset and following indices. Nothing happens, if offset or ooffset are invalid or if oa does not provide enough elements or if offset+length would exceed the valid indices.
Parameters:
offset - the offset index for the mask of visible parameters
oa - the source array containing the new parameters
ooffset - the offset index for oa
length - the number of objects to copy

setParameterPoint

public void setParameterPoint(int index,
                              int x,
                              int y)
Sets the given point (x,y) as new parameter object (of type java.awt.Point) at index index within the visible mask of the parameter array. Nothing happens if index is invalid.
Parameters:
index - the index (counted from the offset of the visible mask) of the parameter to set
x,y - the new point

setParameter

public void setParameter(int index,
                         int i)
Sets an int-value as parameter with index index. If index is invalid, nothing happens.
Parameters:
index - the index of the parameter to set
i - the int-value to set as parameter

setParameter

public void setParameter(int index,
                         short s)
Sets a short-value as parameter with index index. If index is invalid, nothing happens.
Parameters:
index - the index of the parameter to set
s - the short-value to set as parameter

setParameter

public void setParameter(int index,
                         long l)
Sets a long-value as parameter with index index. If index is invalid, nothing happens.
Parameters:
index - the index of the parameter to set
l - the long-value to set as parameter

setParameter

public void setParameter(int index,
                         float f)
Sets a float-value as parameter with index index. If index is invalid, nothing happens.
Parameters:
index - the index of the parameter to set
f - the float-value to set as parameter

setParameter

public void setParameter(int index,
                         double d)
Sets a double-value as parameter with index index. If index is invalid, nothing happens.
Parameters:
index - the index of the parameter to set
d - the double-value to set as parameter

setParameter

public void setParameter(int index,
                         boolean b)
Sets a boolean-value as parameter with index index. If index is invalid, nothing happens.
Parameters:
index - the index of the parameter to set
b - the boolean-value to set as parameter

setParameterGlobal

public void setParameterGlobal(int index,
                               java.lang.Object o)
Sets o as new parameter object at index index within the the parameter array, i.e. index is interpreted as an index for the whole parameter array, not for the visible part only. Nothing happens if index is invalid.
Parameters:
index - the index of the parameter to set
o - the new parameter object

setParameterGlobal

public void setParameterGlobal(int offset,
                               java.lang.Object[] oa,
                               int ooffset,
                               int length)
Sets a subarray of new parameter objects. The length new parameters are taken from oa, following index offset and are placed at index offset and following indices in the parameter array. Remark that this method interprets offset as an index for the whole parameter array, not for the visible part only (like setParameter(int,Object[],int,int)). Nothing happens, if offset or ooffset are invalid or if oa does not provide enough elements or if offset+length would exceed the valid indices.
Parameters:
offset - the offset index for the new parameters
oa - the source array containing the new parameters
ooffset - the offset index for oa
length - the number of objects to copy