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: CollapsingBorderModel.java 433291 2006-08-21 17:18:37Z adelmelle $ */
019:
020: package org.apache.fop.layoutmgr.table;
021:
022: import org.apache.fop.fo.Constants;
023: import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
024: import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo;
025:
026: /**
027: * This class is a superclass for the two collapsing border models defined
028: * in the XSL 1.0 specification.
029: */
030: public abstract class CollapsingBorderModel {
031:
032: /** before side */
033: protected static final int BEFORE = CommonBorderPaddingBackground.BEFORE;
034: /** after side */
035: protected static final int AFTER = CommonBorderPaddingBackground.AFTER;
036: /** start side */
037: protected static final int START = CommonBorderPaddingBackground.START;
038: /** end side */
039: protected static final int END = CommonBorderPaddingBackground.END;
040:
041: /** Flag: current grid unit is either start or end of the table. */
042: public static final int VERTICAL_START_END_OF_TABLE = 1;
043:
044: /** Indicates that the cell is/starts in the first row being painted on a particular page */
045: //public static final int FIRST_ROW_IN_TABLE_PART = 1;
046: /** Indicates that the cell is/ends in the last row being painted on a particular page */
047: //public static final int LAST_ROW_IN_TABLE_PART = 2;
048: /** Indicates that the cell is/starts in the first row of a body/table-header/table-footer */
049: //public static final int FIRST_ROW_IN_GROUP = 4;
050: /** Indicates that the cell is/end in the last row of a body/table-header/table-footer */
051: //public static final int LAST_ROW_IN_GROUP = 8;
052: //These statics are used singleton-style. No MT issues here.
053: private static CollapsingBorderModel collapse = null;
054: private static CollapsingBorderModel collapseWithPrecedence = null;
055:
056: /**
057: * @param borderCollapse border collapse control
058: * @return the border model for the cell
059: */
060: public static CollapsingBorderModel getBorderModelFor(
061: int borderCollapse) {
062: switch (borderCollapse) {
063: case Constants.EN_COLLAPSE:
064: if (collapse == null) {
065: collapse = new CollapsingBorderModelEyeCatching();
066: }
067: return collapse;
068: case Constants.EN_COLLAPSE_WITH_PRECEDENCE:
069: if (collapseWithPrecedence == null) {
070: //collapseWithPrecedence = new CollapsingBorderModelWithPrecedence();
071: }
072: return collapseWithPrecedence;
073: default:
074: throw new IllegalArgumentException(
075: "Illegal border-collapse mode.");
076: }
077: }
078:
079: /**
080: * @param side the side on the current cell
081: * @return the adjacent side on the neighbouring cell
082: */
083: public static int getOtherSide(int side) {
084: switch (side) {
085: case CommonBorderPaddingBackground.BEFORE:
086: return CommonBorderPaddingBackground.AFTER;
087: case CommonBorderPaddingBackground.AFTER:
088: return CommonBorderPaddingBackground.BEFORE;
089: case CommonBorderPaddingBackground.START:
090: return CommonBorderPaddingBackground.END;
091: case CommonBorderPaddingBackground.END:
092: return CommonBorderPaddingBackground.START;
093: default:
094: throw new IllegalArgumentException(
095: "Illegal parameter: side");
096: }
097: }
098:
099: /**
100: * @param side the side to investigate
101: * @return true if the adjacent cell is before or after
102: */
103: protected boolean isVerticalRelation(int side) {
104: return (side == CommonBorderPaddingBackground.BEFORE || side == CommonBorderPaddingBackground.AFTER);
105: }
106:
107: /**
108: * See rule 4 in 6.7.10 for the collapsing border model.
109: * @param style the border style to get the preference value for
110: * @return the preference value of the style
111: */
112: public int getPreferenceValue(int style) {
113: switch (style) {
114: case Constants.EN_DOUBLE:
115: return 0;
116: case Constants.EN_SOLID:
117: return -1;
118: case Constants.EN_DASHED:
119: return -2;
120: case Constants.EN_DOTTED:
121: return -3;
122: case Constants.EN_RIDGE:
123: return -4;
124: case Constants.EN_OUTSET:
125: return -5;
126: case Constants.EN_GROOVE:
127: return -6;
128: case Constants.EN_INSET:
129: return -7;
130: default:
131: throw new IllegalStateException("Illegal border style: "
132: + style);
133: }
134: }
135:
136: /**
137: * Determines the winning BorderInfo.
138: * @param current grid unit of the current element
139: * @param neighbour grid unit of the neighbouring element
140: * @return the winning BorderInfo
141: */
142: public abstract BorderInfo determineWinner(GridUnit current,
143: GridUnit neighbour, int side, int flags);
144:
145: }
|