001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /* $Id: LengthPairProperty.java 426576 2006-07-28 15:44:37Z jeremias $ */
019:
020: package org.apache.fop.fo.properties;
021:
022: import org.apache.fop.datatypes.CompoundDatatype;
023: import org.apache.fop.fo.FObj;
024: import org.apache.fop.fo.PropertyList;
025: import org.apache.fop.fo.expr.PropertyException;
026:
027: /**
028: * Superclass for properties wrapping a LengthPair value
029: */
030: public class LengthPairProperty extends Property implements
031: CompoundDatatype {
032: private Property ipd;
033: private Property bpd;
034:
035: /**
036: * Inner class for creating instances of LengthPairProperty
037: */
038: public static class Maker extends CompoundPropertyMaker {
039:
040: /**
041: * @param propId name of property for which this Maker should be created
042: */
043: public Maker(int propId) {
044: super (propId);
045: }
046:
047: /**
048: * Create a new empty instance of LengthPairProperty.
049: * @return the new instance.
050: */
051: public Property makeNewProperty() {
052: return new LengthPairProperty();
053: }
054:
055: /**
056: * @see CompoundPropertyMaker#convertProperty
057: */
058: public Property convertProperty(Property p,
059: PropertyList propertyList, FObj fo)
060: throws PropertyException {
061: if (p instanceof LengthPairProperty) {
062: return p;
063: }
064: return super .convertProperty(p, propertyList, fo);
065: }
066: }
067:
068: /**
069: * Creates a new LengthPairProperty with empty values.
070: */
071: public LengthPairProperty() {
072: super ();
073: }
074:
075: /**
076: * Creates a new LengthPairProperty.
077: * @param ipd inline-progression-dimension
078: * @param bpd block-progression-dimension
079: */
080: public LengthPairProperty(Property ipd, Property bpd) {
081: this ();
082: this .ipd = ipd;
083: this .bpd = bpd;
084: }
085:
086: /**
087: * Creates a new LengthPairProperty which sets both bpd and ipd to the
088: * same value.
089: * @param len length for both dimensions
090: */
091: public LengthPairProperty(Property len) {
092: this (len, len);
093: }
094:
095: /**
096: * @see org.apache.fop.datatypes.CompoundDatatype#setComponent(int, Property, boolean)
097: */
098: public void setComponent(int cmpId, Property cmpnValue,
099: boolean bIsDefault) {
100: if (cmpId == CP_BLOCK_PROGRESSION_DIRECTION) {
101: bpd = cmpnValue;
102: } else if (cmpId == CP_INLINE_PROGRESSION_DIRECTION) {
103: ipd = cmpnValue;
104: }
105: }
106:
107: /**
108: * @see org.apache.fop.datatypes.CompoundDatatype#getComponent(int)
109: */
110: public Property getComponent(int cmpId) {
111: if (cmpId == CP_BLOCK_PROGRESSION_DIRECTION) {
112: return getBPD();
113: } else if (cmpId == CP_INLINE_PROGRESSION_DIRECTION) {
114: return getIPD();
115: } else {
116: return null; // SHOULDN'T HAPPEN
117: }
118: }
119:
120: /**
121: * @return Property holding the ipd length
122: */
123: public Property getIPD() {
124: return this .ipd;
125: }
126:
127: /**
128: * @return Property holding the bpd length
129: */
130: public Property getBPD() {
131: return this .bpd;
132: }
133:
134: /** @see java.lang.Object#toString() */
135: public String toString() {
136: return "LengthPair[" + "ipd:" + getIPD().getObject() + ", bpd:"
137: + getBPD().getObject() + "]";
138: }
139:
140: /**
141: * @return this.lengthPair
142: */
143: public LengthPairProperty getLengthPair() {
144: return this ;
145: }
146:
147: /**
148: * @return this.lengthPair cast as an Object
149: */
150: public Object getObject() {
151: return this;
152: }
153:
154: }
|