com.davisor.graphics.data
Class FontData

java.lang.Object
  extended byjava.awt.Font
      extended bycom.davisor.graphics.data.FontData
All Implemented Interfaces:
java.lang.Comparable, Data, DataValue, com.davisor.core.Dupable, Scalable, java.io.Serializable, SerializableData

public class FontData
extends java.awt.Font
implements DataValue, com.davisor.core.Dupable, Scalable

FontData objects represent a concrete font. FontData inherits Font, making it compatible with standard Java graphics tools. This makes FontData immutable, and any operations that would change the FontData value will therefore fail with an appropriate exception.

Since:
JDK1.1
See Also:
FontType, Serialized Form

Field Summary
protected  java.lang.Boolean M_scalable
          Is font scalable or not.
protected  FontType M_type
          The type of this data.
 
Fields inherited from class java.awt.Font
BOLD, CENTER_BASELINE, HANGING_BASELINE, ITALIC, LAYOUT_LEFT_TO_RIGHT, LAYOUT_NO_LIMIT_CONTEXT, LAYOUT_NO_START_CONTEXT, LAYOUT_RIGHT_TO_LEFT, name, PLAIN, pointSize, ROMAN_BASELINE, size, style, TRUETYPE_FONT
 
Constructor Summary
FontData(FontData data, boolean deep)
          Deep or shallow copy constructor.
FontData(FontType type, java.awt.Font font)
          Constructs a font data object from the given font type and value.
FontData(FontType type, java.awt.Font font, java.lang.Boolean scalable)
          Constructs a font data object from the given font type and value.
FontData(FontType type, java.lang.String font, java.text.ParsePosition status, java.awt.Font defaults)
          Constructs a font data object from the given font type and string value.
 
Method Summary
 DataValue abs()
          Returns absolute data value of current value.
 DataValue add(DataValue value)
          Adds data values.
 DataValue ceil(DataValue precision)
          Quantizes the current value up to an even value within given precision.
 int compareTo(java.lang.Object o)
          Compares this font with other font objects.
 double deinterpolate(DataValue min, DataValue max)
          De-interpolates the current data value to a scalar value, in respect, with the given data value range.
 DataValue div(DataValue value)
          Divides current data value with given value.
 com.davisor.core.Dupable dup()
          Makes a deep copy of this object.
 DataValue floor(DataValue precision)
          Quantizes the current value down to an even value within given precision.
 java.lang.String getFormat()
          Gets the type specification optimal for this particular value.
 Type getType()
          Gets the data type.
 DataValue interpolate(double value, DataValue max)
          Interpolates the given scalar value to a data value, in respect, with the range defined by this value and the given maximum value.
 boolean isNull()
          Tests if this data object value is undetermined.
 boolean isScalable()
           
 DataValue max(DataValue value)
          Finds the largest data value.
 DataValue min(DataValue value)
          Finds the smallest data value.
 DataValue mul(DataValue value)
          Multiplies current data value with given value.
 DataValue negate()
          Returns the negation of current value.
 void setValue(java.lang.String value, java.text.ParsePosition status)
          Attempts to set the font value, but since fonts are immutable objects, this will always fail.
 DataValue sub(DataValue value)
          Substracts a data value.
 void toStatement(java.sql.PreparedStatement statement, int parameter)
          Convert data to a prepared statement input parameter.
 java.lang.String toString()
          Converts this font to a string.
 java.lang.String toXML()
          Gets the XML string representation of this value.
 DataValue unit(DataValue targetValue, double maxSteps)
          Gets the largest suitable unit step to represent a value change between this value and the given target value.
 
Methods inherited from class java.awt.Font
canDisplay, canDisplayUpTo, canDisplayUpTo, canDisplayUpTo, createFont, createGlyphVector, createGlyphVector, createGlyphVector, createGlyphVector, decode, deriveFont, deriveFont, deriveFont, deriveFont, deriveFont, deriveFont, equals, finalize, getAttributes, getAvailableAttributes, getBaselineFor, getFamily, getFamily, getFont, getFont, getFont, getFontName, getFontName, getItalicAngle, getLineMetrics, getLineMetrics, getLineMetrics, getLineMetrics, getMaxCharBounds, getMissingGlyphCode, getName, getNumGlyphs, getPeer, getPSName, getSize, getSize2D, getStringBounds, getStringBounds, getStringBounds, getStringBounds, getStyle, getTransform, hashCode, hasUniformLineMetrics, isBold, isItalic, isPlain, isTransformed, layoutGlyphVector
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

M_type

protected FontType M_type
The type of this data.


M_scalable

protected java.lang.Boolean M_scalable
Is font scalable or not.

Constructor Detail

FontData

public FontData(FontData data,
                boolean deep)
Deep or shallow copy constructor. If it is shallow, then the new object shares an underlying type with the original object. If is is deep, then the type is dupped.

Parameters:
data - source data
deep - determine if the copying is deep or shallow
See Also:
getType(), Type.dup()

FontData

public FontData(FontType type,
                java.awt.Font font)
Constructs a font data object from the given font type and value.

Parameters:
type - custom font type
font - font value

FontData

public FontData(FontType type,
                java.awt.Font font,
                java.lang.Boolean scalable)
Constructs a font data object from the given font type and value.

Parameters:
type - custom font type
font - font value
scalable - is font scalable or not (may be null)
See Also:
isScalable()

FontData

public FontData(FontType type,
                java.lang.String font,
                java.text.ParsePosition status,
                java.awt.Font defaults)
         throws InvalidDataException
Constructs a font data object from the given font type and string value.

Parameters:
type - custom font type
font - font value
status - parse status
defaults - font to inherit default font values from (may be null)
Method Detail

compareTo

public int compareTo(java.lang.Object o)
Compares this font with other font objects. The comparison is primarily based on the font's 2D size, and secondarily on the font style.

Specified by:
compareTo in interface java.lang.Comparable

getType

public Type getType()
             throws InvalidDataException
Gets the data type.

Specified by:
getType in interface Data
Returns:
Data type.
Throws:
InvalidDataException - if type retrieval fails

isNull

public boolean isNull()
Tests if this data object value is undetermined.

Specified by:
isNull in interface SerializableData
See Also:
Type.isNull(com.davisor.data.SerializableData)

abs

public DataValue abs()
              throws InvalidDataException
Returns absolute data value of current value.

Specified by:
abs in interface DataValue
Returns:
a new data object, sharing the current type of this object
Throws:
InvalidDataException - if absolute value can not be computed

add

public DataValue add(DataValue value)
              throws InvalidDataException
Adds data values.

Specified by:
add in interface DataValue
Parameters:
value - a data value to be added to this data value
Returns:
Returns an added data value.
Throws:
InvalidDataException - if the data values cannot be added.

ceil

public DataValue ceil(DataValue precision)
Quantizes the current value up to an even value within given precision. The returned value is more than, or equal with the current value, but not more than the current value added by given precision.

Specified by:
ceil in interface DataValue
Parameters:
precision - the precision within quantization occurs
Returns:
a new data object, sharing the current type of this object
See Also:
floor(com.davisor.data.DataValue)

deinterpolate

public double deinterpolate(DataValue min,
                            DataValue max)
                     throws InvalidDataException
De-interpolates the current data value to a scalar value, in respect, with the given data value range. This gives scalar values between [0,1], when the current data value in within the range, negative scalar values when the data value falls below the range and scalar values greater than 1.0, otherwise.

Font values do not support this operation, but they always throw an InvalidDataException instead.

Specified by:
deinterpolate in interface DataValue
Parameters:
min - a data value representing a range's lower limit
max - a data value representing a range's higher limit
Returns:
de-interpolated scalar value
Throws:
InvalidDataException - if the de-interpolation fails
See Also:
DataValue.interpolate(double, com.davisor.data.DataValue), DeinterpolationException, TupleData.deinterpolate(com.davisor.data.DataValue, com.davisor.data.DataValue)

div

public DataValue div(DataValue value)
              throws InvalidDataException
Divides current data value with given value.

Specified by:
div in interface DataValue
Parameters:
value - the divider.
Returns:
the result of division.
Throws:
InvalidDataException - if the data value cannot be divided.

floor

public DataValue floor(DataValue precision)
Quantizes the current value down to an even value within given precision. The returned value is less than, or equal with the current value, but not less than the current value substracted by given precision.

Specified by:
floor in interface DataValue
Parameters:
precision - the precision within quantization occurs
Returns:
a new data object, sharing the current type of this object
See Also:
ceil(com.davisor.data.DataValue)

getFormat

public java.lang.String getFormat()
Gets the type specification optimal for this particular value. The specification returned may differ from the current type specification. If so, setting the current type specification equal with the value returned by this method, will ensure optimal value formatting and parsing for values of the same magnitude as this one.

The font data optimal specification string is always the current specification string for the current type.

Specified by:
getFormat in interface DataValue
See Also:
Data.getType(), Type.getFormat(), Type.setFormat(java.lang.String)

interpolate

public DataValue interpolate(double value,
                             DataValue max)
                      throws InvalidDataException
Interpolates the given scalar value to a data value, in respect, with the range defined by this value and the given maximum value. Scalar values between [0,1] result in data values between the current value and the given maximum value. Negative scalar values result in values smaller than this value, and scalar values higher than 1.0 return data values above the given maximum.

Font values do not support this operation, but they always throw an InvalidDataException instead.

Specified by:
interpolate in interface DataValue
Parameters:
value - the scalar value to be interpolated
max - a data value representing a range's higher limit
Returns:
interpolated data value
Throws:
InvalidDataException - if the interpolation fails
See Also:
DataValue.deinterpolate(com.davisor.data.DataValue, com.davisor.data.DataValue)

max

public DataValue max(DataValue value)
              throws InvalidDataException
Finds the largest data value.

Specified by:
max in interface DataValue
Parameters:
value - a data value to be compared with this data value
Returns:
the largest of the compared data values.
Throws:
InvalidDataException - if the data value cannot be compared.

min

public DataValue min(DataValue value)
              throws InvalidDataException
Finds the smallest data value.

Specified by:
min in interface DataValue
Parameters:
value - a data value to be compared with this data value
Returns:
the smallest of the compared data values.
Throws:
InvalidDataException - if the data value cannot be compared.

mul

public DataValue mul(DataValue value)
              throws InvalidDataException
Multiplies current data value with given value.

Specified by:
mul in interface DataValue
Parameters:
value - the multiplier.
Returns:
the result of multiplication.
Throws:
InvalidDataException - if the data value cannot be multiplied.

negate

public DataValue negate()
                 throws InvalidDataException
Returns the negation of current value.

Specified by:
negate in interface DataValue
Returns:
a new data object, sharing the current type of this object
Throws:
InvalidDataException - if absolute value can not be computed

setValue

public void setValue(java.lang.String value,
                     java.text.ParsePosition status)
              throws InvalidDataException
Attempts to set the font value, but since fonts are immutable objects, this will always fail.

Specified by:
setValue in interface DataValue
Parameters:
value - string value to be parsed (may be null)
status - parse status (may be null)
Throws:
InvalidDataException - always.
See Also:
CountType.countValue(String,ParsePosition)

sub

public DataValue sub(DataValue value)
              throws InvalidDataException
Substracts a data value.

Specified by:
sub in interface DataValue
Parameters:
value - a data value to be substracted from this data value
Returns:
Returns a substracted data value.
Throws:
InvalidDataException - if the value cannot be substracted.

toStatement

public void toStatement(java.sql.PreparedStatement statement,
                        int parameter)
                 throws java.sql.SQLException
Convert data to a prepared statement input parameter.

Specified by:
toStatement in interface DataValue
Parameters:
statement - statement to be updated
parameter - index of statement parameter to be updated
Throws:
java.sql.SQLException - if a SQL error occurs.

toXML

public java.lang.String toXML()
Gets the XML string representation of this value.

Specified by:
toXML in interface DataValue
Returns:
complete string representing the data.
See Also:
toString()

unit

public DataValue unit(DataValue targetValue,
                      double maxSteps)
Gets the largest suitable unit step to represent a value change between this value and the given target value.

The font data does not support the concept of unit values. Calling this method raises a runtime error.

Specified by:
unit in interface DataValue
Parameters:
targetValue - target value to be reached (may be null)
maxSteps - maximum number of steps (zero leaves the choise open)
Returns:
step value, as described above

dup

public com.davisor.core.Dupable dup()
Makes a deep copy of this object.

Specified by:
dup in interface com.davisor.core.Dupable

toString

public java.lang.String toString()
Converts this font to a string. The conversion is made by the FontParameters class' toString method.

Specified by:
toString in interface DataValue
Returns:
string representation of the font value of this object
See Also:
FontParameters.FontParameters(Font), FontParameters.toString()

isScalable

public boolean isScalable()
Specified by:
isScalable in interface Scalable


Copyright © 2001-2004 Davisor Oy. All Rights Reserved.