You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by pb...@apache.org on 2002/07/29 18:05:05 UTC

cvs commit: xml-fop/src/org/apache/fop/datatypes IntegerType.java Angle.java Frequency.java Time.java

pbwest      2002/07/29 09:05:05

  Modified:    src/org/apache/fop/datatypes Tag: FOP_0-20-0_Alt-Design
                        IntegerType.java Angle.java Frequency.java
                        Time.java
  Log:
  IntegerType, Angle, Frequency and Time separated from Numeric following communication from XSL editors.  These values will not be able to participate in expressions with other Numeric quantities.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +45 -19    xml-fop/src/org/apache/fop/datatypes/Attic/IntegerType.java
  
  Index: IntegerType.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/datatypes/Attic/IntegerType.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- IntegerType.java	17 Jun 2002 00:24:49 -0000	1.1.2.2
  +++ IntegerType.java	29 Jul 2002 16:05:05 -0000	1.1.2.3
  @@ -2,52 +2,78 @@
   package org.apache.fop.datatypes;
   
   import org.apache.fop.fo.expr.PropertyException;
  +import org.apache.fop.fo.expr.AbstractPropertyValue;
  +import org.apache.fop.fo.Properties;
   
   /*
    * IntegerType.java
    *
  - * Created: Wed Nov 21 15:39:30 2001
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
    * @author <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
    * @version $Revision$ $Name$
    */
  -/**
  - * Constructor for Integer datatype.  Constructs a <tt>Numeric</tt>.
  - */
   
  -public class IntegerType {
  +public class IntegerType extends AbstractPropertyValue {
   
       private static final String tag = "$Name$";
       private static final String revision = "$Revision$";
   
       /**
  -     * Construct a <tt>Numeric</tt> with a given quantity.
  -     * The unit power is assumed as 0.  The base unit is NUMERIC.
  +     * The integer value of the type
  +     */
  +    private int intval = 0;
  +
  +    /**
        * @param property the index of the property with which this value
        * is associated.
        * @param value the integer value.
  -     * @return a <tt>Numeric</tt> representing this <i>IntegerType</i>.
  +     * @exception PropertyException
        */
  -    public static Numeric makeInteger(int property, long value)
  +    public IntegerType (int property, int value)
           throws PropertyException
       {
  -        return new Numeric(property, (double)value, Numeric.NUMBER, 0, 0);
  +        super(property);
  +        intval = value;
       }
   
       /**
  -     * Construct a numeric with a given unit and quantity.
  -     * The unit power is assumed as 0.  The base unit is NUMERIC.
  -     * @param propertyName the name of the property with which this value
  -     * is associated.
  +     * @param propertyName the <tt>String</tt< name of the property on which
  +     * this value is being defined.
        * @param value the integer value.
  -     * @return a <tt>Numeric</tt> representing this <i>IntegerType</i>.
  +     * @exception PropertyException
        */
  -    public static Numeric makeInteger(String propertyName, long value)
  +    public IntegerType (String propertyName, int value)
           throws PropertyException
       {
  -        return new Numeric(propertyName, (double)value, Numeric.NUMBER, 0, 0);
  +        super(propertyName);
  +        intval = value;
  +    }
  +
  +    /**
  +     * @return <tt>int</tt> integer contents
  +     */
  +    public int getInt() {
  +        return intval;
  +    }
  +
  +    /**
  +     * @param value <tt>int</tt> value to set
  +     */
  +    public void setInt(int value) {
  +        intval = value;
  +    }
  +
  +    /**
  +     * validate the <i>IntegerType</i> against the associated property.
  +     */
  +    public void validate() throws PropertyException {
  +        super.validate(Properties.INTEGER);
  +    }
  +
  +    public String toString() {
  +        return "" + intval + "\n" + super.toString();
       }
   
   }
  
  
  
  1.1.2.3   +76 -50    xml-fop/src/org/apache/fop/datatypes/Attic/Angle.java
  
  Index: Angle.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/datatypes/Attic/Angle.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- Angle.java	17 Jun 2002 00:24:49 -0000	1.1.2.2
  +++ Angle.java	29 Jul 2002 16:05:05 -0000	1.1.2.3
  @@ -1,36 +1,33 @@
  -
   package org.apache.fop.datatypes;
   
   import org.apache.fop.fo.expr.PropertyException;
  +import org.apache.fop.fo.expr.AbstractPropertyValue;
  +import org.apache.fop.fo.Properties;
   
   /*
    * Angle.java
    * $Id$
  - * Created: Wed Nov 21 15:39:30 2001
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
    */
  -/**
  - * Constructor class for Angle datatype.  Constructs a <tt>Numeric</tt>.
  - * @author <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
  - * @version $Revision$ $Name$
  - */
   
  -public class Angle {
  +public class Angle extends AbstractPropertyValue {
   
       private static final String tag = "$Name$";
       private static final String revision = "$Revision$";
  -    /*
  -     * Constants for UnitNames
  +    /**
  +     * Constant for Unit name
        */
  -    public static final int NOUNIT = 0;
  -    public static final int DEG = 1;
  -    public static final int GRAD = 2;
  -    public static final int RAD = 3;
  +    public static final int
  +        NOUNIT = 0
  +          ,DEG = 1
  +         ,GRAD = 2
  +          ,RAD = 3
  +            ;
   
       /**
  -     * Array of constant conversion factors from unit to milliseconds,
  +     * Array of constant conversion factors from unit to degrees,
        * indexed by integer unit constant.  Keep this array in sync with
        * the integer constants or bear the consequences.
        */
  @@ -41,41 +38,71 @@
           ,63.661977      // Degrees per radian
       };
   
  -    /**
  -     * Private constructor - don't instantiate a <i>Time</i> object.
  -     */
  -    private Angle() {}
  +    private double degrees = 0.0;
  +    private int units = 0;
   
       /**
  -     * Construct a <tt>Numeric</tt> with a given unit and quantity.
  -     * The unit power is
  -     * assumed as 1.  The base unit is degrees.
  -     * @param property <tt>int</tt> index of the property.
  -     * @param value the number of units.
  -     * @param unit an integer value representing the unit of definition.
  +     * @param property the <tt>int</tt> index of the property on which
  +     * this value is being defined.
  +     * @param unit the <tt>int</tt> unit name code, as defined in the
  +     * constants of this class.
  +     * @param value the <tt>double</tt> value.
  +     * @exception PropertyException
        */
  -    public static Numeric makeAngle(int property, double value, int unit)
  +    public Angle(int property, int unit, double value)
           throws PropertyException
       {
  -        return new Numeric(property, value * degPerUnit[unit],
  -                           Numeric.DEGREES, 1, unit);
  +        super(property);
  +        units = unit;
  +        degrees = value * degPerUnit[unit];
       }
   
       /**
  -     * Construct a <tt>Numeric</tt> with a given unit and quantity.
  -     * The unit power is
  -     * assumed as 1.  The base unit is degrees.
  -     * @param propertyName the name of the property with which this value
  -     * is associated.
  -     * @param value the number of units.
  -     * @param unit an integer value representing the unit of definition.
  +     * @param propertyName the <tt>String</tt< name of the property on which
  +     * this value is being defined.
  +     * @param unit the <tt>int</tt> unit name code, as defined in the
  +     * constants of this class.
  +     * @param value the <tt>double</tt> value.
  +     * @exception PropertyException
        */
  -    public static Numeric makeAngle
  -        (String propertyName, double value, int unit)
  +    public Angle(String propertyName, int unit, double value)
           throws PropertyException
       {
  -        return new Numeric(propertyName, value * degPerUnit[unit],
  -                           Numeric.DEGREES, 1, unit);
  +        super(propertyName);
  +        units = unit;
  +        degrees = value * degPerUnit[unit];
  +    }
  +
  +    /**
  +     * @return <tt>double</tt> angle in degrees
  +     */
  +    public double getAngle() {
  +        return degrees;
  +    }
  +
  +    /**
  +     * @param <tt>int</tt> unit as per constants defined in this class
  +     * @return <tt>double</tt> degrees value
  +     */
  +    public double getAngle(int unit) {
  +        return degrees / degPerUnit[unit];
  +    }
  +
  +    /**
  +     * @param <tt>int</tt> unit as per constants defined in this class
  +     * @param <tt>double</tt> angle in specified units
  +     */
  +    public void setAngle(int unit, double value) {
  +        units = unit;
  +        degrees = value * degPerUnit[unit];
  +    }
  +
  +    /**
  +     * @param <tt>double</tt> angle in degrees
  +     */
  +    public void setAngle(double degrees) {
  +        units = DEG;
  +        this.degrees = degrees;
       }
   
       /**
  @@ -97,15 +124,14 @@
       }
   
       /**
  -     * Normalize the angle value in the range 0 <= angle <= 360
  -     * @param numeric a <tt>Numeric</tt> representing the value to be
  -     * normalized.
  -     * @return a <tt>double</tt> containing the normalized value.
  -     */
  -    public static double normalize(Numeric numeric) {
  -        if (numeric.power == 1)
  -            return numeric.value % 360;  // Negative angles still negative
  -        return numeric.value;
  +     * validate the <i>Angle</i> against the associated property.
  +     */
  +    public void validate() throws PropertyException {
  +        super.validate(Properties.ANGLE);
  +    }
  +
  +    public String toString() {
  +        return "" + degrees + getUnitName(units) + "\n" + super.toString();
       }
   
   }
  
  
  
  1.1.2.3   +75 -38    xml-fop/src/org/apache/fop/datatypes/Attic/Frequency.java
  
  Index: Frequency.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/datatypes/Attic/Frequency.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- Frequency.java	17 Jun 2002 00:24:49 -0000	1.1.2.2
  +++ Frequency.java	29 Jul 2002 16:05:05 -0000	1.1.2.3
  @@ -1,33 +1,30 @@
  -
   package org.apache.fop.datatypes;
   
   import org.apache.fop.fo.expr.PropertyException;
  +import org.apache.fop.fo.expr.AbstractPropertyValue;
  +import org.apache.fop.fo.Properties;
   
   /*
    * Frequency.java
    *
  - * Created: Wed Nov 21 15:39:30 2001
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
    */
  -/**
  - * Constructor class for Frequency datatype.  Constructs a <tt>Numeric</tt>.
  - * @author <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
  - * @version $Revision$ $Name$
  - */
   
  -public class Frequency {
  +public class Frequency extends AbstractPropertyValue {
   
       private static final String tag = "$Name$";
       private static final String revision = "$Revision$";
   
       /*
  -     * Constants for UnitNames
  +     * Constant for Unit names
        */
  -    public static final int NOUNIT = 0;
  -    public static final int HZ = 1;
  -    public static final int KHZ = 2;
  +    public static final int
  +        NOUNIT = 0
  +           ,HZ = 1
  +          ,KHZ = 2
  +            ;
   
       /**
        * Array of constant conversion factors from unit to Hertz,
  @@ -40,42 +37,71 @@
           ,1000.0
       };
   
  -    /**
  -     * Private constructor - don't instantiate a <i>Frequency</i> object.
  -     */
  -    private Frequency() {}
  +    private double frequency = 0.0;
  +    private int units = 0;
   
       /**
  -     * Construct a <tt>Numeric</tt> with a given unit and quantity.
  -     * The unit power is assumed as 1.  The base unit is Hertz.
  -     * @param property the index of the property with which this value
  -     * is associated.
  -     * @param value the number of units.
  -     * @param unit an integer constant representing the unit
  -     * @return a <tt>Numeric</tt> representing this <i>Frequency</i>.
  +     * @param property the <tt>int</tt> index of the property on which
  +     * this value is being defined.
  +     * @param unit the <tt>int</tt> unit name code, as defined in the
  +     * constants of this class.
  +     * @param value the <tt>double</tt> value.
  +     * @exception PropertyException
        */
  -    public static Numeric makeFrequency(int property, double value, int unit)
  +    public Frequency(int property, int unit, double value)
           throws PropertyException
       {
  -        return new Numeric(property, value * hzPerUnit[unit],
  -                           Numeric.HERTZ, 1, unit);
  +        super(property);
  +        units = unit;
  +        frequency = value * hzPerUnit[unit];
       }
   
       /**
  -     * Construct a <tt>Numeric</tt> with a given unit and quantity.
  -     * The unit power is assumed as 1.  The base unit is Hertz.
  -     * @param propertyName the name of the property with which this value
  -     * is associated.
  -     * @param value the number of units.
  -     * @param unit an integer constant representing the unit
  -     * @return a <tt>Numeric</tt> representing this <i>Frequency</i>.
  +     * @param propertyName the <tt>String</tt< name of the property on which
  +     * this value is being defined.
  +     * @param unit the <tt>int</tt> unit name code, as defined in the
  +     * constants of this class.
  +     * @param value the <tt>double</tt> value.
  +     * @exception PropertyException
        */
  -    public static Numeric makeFrequency
  -        (String propertyName, double value, int unit)
  +    public Frequency(String propertyName, int unit, double value)
           throws PropertyException
       {
  -        return new Numeric(propertyName, value * hzPerUnit[unit],
  -                           Numeric.HERTZ, 1, unit);
  +        super(propertyName);
  +        units = unit;
  +        frequency = value * hzPerUnit[unit];
  +    }
  +
  +    /**
  +     * @return <tt>double</tt> frequency in hertz
  +     */
  +    public double getFrequency() {
  +        return frequency;
  +    }
  +
  +    /**
  +     * @param <tt>int</tt> unit as per constants defined in this class
  +     * @return <tt>double</tt> frequency value
  +     */
  +    public double getFrequency(int unit) {
  +        return frequency / hzPerUnit[unit];
  +    }
  +
  +    /**
  +     * @param <tt>int</tt> unit as per constants defined in this class
  +     * @param <tt>double</tt> frequency in specified units
  +     */
  +    public void setFrequency(int unit, double value) {
  +        units = unit;
  +        frequency = value * hzPerUnit[unit];
  +    }
  +
  +    /**
  +     * @param <tt>double</tt> frequency in hertz
  +     */
  +    public void setFrequency(double frequency) {
  +        units = HZ;
  +        this.frequency = frequency;
       }
   
       /**
  @@ -92,6 +118,17 @@
           default:
               return "";
           }
  +    }
  +
  +    /**
  +     * validate the <i>Frequency</i> against the associated property.
  +     */
  +    public void validate() throws PropertyException {
  +        super.validate(Properties.FREQUENCY);
  +    }
  +
  +    public String toString() {
  +        return "" + frequency + getUnitName(units) + "\n" + super.toString();
       }
   
   }
  
  
  
  1.1.2.3   +77 -45    xml-fop/src/org/apache/fop/datatypes/Attic/Time.java
  
  Index: Time.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/datatypes/Attic/Time.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- Time.java	17 Jun 2002 00:24:49 -0000	1.1.2.2
  +++ Time.java	29 Jul 2002 16:05:05 -0000	1.1.2.3
  @@ -1,40 +1,31 @@
  -
   package org.apache.fop.datatypes;
   
   import org.apache.fop.fo.expr.PropertyException;
  -//import org.apache.fop.fo.Properties;
  -//import org.apache.fop.fo.PropertyConsts;
  -//import org.apache.fop.fo.PropNames;
  +import org.apache.fop.fo.expr.AbstractPropertyValue;
  +import org.apache.fop.fo.Properties;
   
   /*
    * Time.java
    * $Id$
  - * Created: Wed Nov 21 15:39:30 2001
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
    * LICENSE file included with these sources.
    * @author <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
    * @version $Revision$ $Name$
    */
  -/**
  - * Time is a front for the manufacture of <tt>Numeric</tt> objects.
  - * Because Numerics are so malleable, it makes no sense to tie
  - * a Numeric object to any particular type by subclassing <tt>Numeric</tt>.
  - * Instead, each of the Numeric types provides static methods to generate
  - * a Numeric representing, as originally created, a particular type of
  - * number or measure.  The constructor for this class is <tt>private</tt>.
  - */
   
  -public class Time {
  +public class Time extends AbstractPropertyValue {
   
       private static final String tag = "$Name$";
       private static final String revision = "$Revision$";
       /*
  -     * Constants for UnitNames
  +     * Constant for Unit name
        */
  -    public static final int NOUNIT = 0;
  -    public static final int MSEC = 1;
  -    public static final int SEC = 2;
  +    public static final int
  +        NOUNIT = 0
  +         ,MSEC = 1
  +          ,SEC = 2
  +            ;
   
       /**
        * Array of constant conversion factors from unit to milliseconds,
  @@ -47,41 +38,71 @@
           ,1000.0
       };
   
  -    /**
  -     * Private constructor - don't instantiate a <i>Time</i> object.
  -     */
  -    private Time() {}
  +    private double time = 0.0;
  +    private int units = 0;
   
       /**
  -     * Construct a <tt>Numeric</tt> with a given unit and quantity.
  -     * The unit power is assumed as 1.  The base unit is milliseconds.
  -     * @param property the index of the property with which this value
  -     * is associated.
  -     * @param value the number of units.
  -     * @param unit an integer constant representing the unit
  -     * @return a <tt>Numeric</tt> representing this <i>Time</i>.
  +     * @param property the <tt>int</tt> index of the property on which
  +     * this value is being defined.
  +     * @param unit the <tt>int</tt> unit name code, as defined in the
  +     * constants of this class.
  +     * @param value the <tt>double</tt> value.
  +     * @exception PropertyException
        */
  -    public static Numeric makeTime(int property, double value, int unit)
  +    public Time(int property, int unit, double value)
           throws PropertyException
       {
  -        return new Numeric(property, value * msPerUnit[unit],
  -                           Numeric.MILLISECS, 1, unit);
  +        super(property);
  +        units = unit;
  +        time = value * msPerUnit[unit];
       }
   
       /**
  -     * Construct a <tt>Numeric</tt> with a given unit and quantity.
  -     * The unit power is assumed as 1.  The base unit is milliseconds.
  -     * @param propertyName the name of the property with which this value
  -     * is associated.
  -     * @param value the number of units.
  -     * @param unit an integer constant representing the unit
  -     * @return a <tt>Numeric</tt> representing this <i>Time</i>.
  +     * @param propertyName the <tt>String</tt< name of the property on which
  +     * this value is being defined.
  +     * @param unit the <tt>int</tt> unit name code, as defined in the
  +     * constants of this class.
  +     * @param value the <tt>double</tt> value.
  +     * @exception PropertyException
        */
  -    public static Numeric makeTime(String propertyName, double value, int unit)
  +    public Time(String propertyName, int unit, double value)
           throws PropertyException
       {
  -        return new Numeric(propertyName, value * msPerUnit[unit],
  -                           Numeric.MILLISECS, 1, unit);
  +        super(propertyName);
  +        units = unit;
  +        time = value * msPerUnit[unit];
  +    }
  +
  +    /**
  +     * @return <tt>double</tt> time in millisecs
  +     */
  +    public double getTime() {
  +        return time;
  +    }
  +
  +    /**
  +     * @param <tt>int</tt> unit as per constants defined in this class
  +     * @return <tt>double</tt> time value
  +     */
  +    public double getTime(int unit) {
  +        return time / msPerUnit[unit];
  +    }
  +
  +    /**
  +     * @param <tt>int</tt> unit as per constants defined in this class
  +     * @param <tt>double</tt> time in specified units
  +     */
  +    public void setTime(int unit, double value) {
  +        units = unit;
  +        time = value * msPerUnit[unit];
  +    }
  +
  +    /**
  +     * @param <tt>double</tt> time in millisecs
  +     */
  +    public void setTime(double time) {
  +        units = MSEC;
  +        this.time = time;
       }
   
       /**
  @@ -97,6 +118,17 @@
           default:
               return "";
           }
  +    }
  +
  +    /**
  +     * validate the <i>Time</i> against the associated property.
  +     */
  +    public void validate() throws PropertyException {
  +        super.validate(Properties.TIME);
  +    }
  +
  +    public String toString() {
  +        return "" + time + getUnitName(units) + "\n" + super.toString();
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org