KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > layoutmgr > table > CollapsingBorderModel


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: CollapsingBorderModel.java 433291 2006-08-21 19:18:37 +0200 (Mon, 21 Aug 2006) adelmelle $ */
19
20 package org.apache.fop.layoutmgr.table;
21
22 import org.apache.fop.fo.Constants;
23 import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
24 import org.apache.fop.fo.properties.CommonBorderPaddingBackground.BorderInfo;
25
26 /**
27  * This class is a superclass for the two collapsing border models defined
28  * in the XSL 1.0 specification.
29  */

30 public abstract class CollapsingBorderModel {
31
32     /** before side */
33     protected static final int BEFORE = CommonBorderPaddingBackground.BEFORE;
34     /** after side */
35     protected static final int AFTER = CommonBorderPaddingBackground.AFTER;
36     /** start side */
37     protected static final int START = CommonBorderPaddingBackground.START;
38     /** end side */
39     protected static final int END = CommonBorderPaddingBackground.END;
40     
41     /** Flag: current grid unit is either start or end of the table. */
42     public static final int VERTICAL_START_END_OF_TABLE = 1;
43     
44     /** Indicates that the cell is/starts in the first row being painted on a particular page */
45     //public static final int FIRST_ROW_IN_TABLE_PART = 1;
46
/** Indicates that the cell is/ends in the last row being painted on a particular page */
47     //public static final int LAST_ROW_IN_TABLE_PART = 2;
48
/** Indicates that the cell is/starts in the first row of a body/table-header/table-footer */
49     //public static final int FIRST_ROW_IN_GROUP = 4;
50
/** Indicates that the cell is/end in the last row of a body/table-header/table-footer */
51     //public static final int LAST_ROW_IN_GROUP = 8;
52

53     //These statics are used singleton-style. No MT issues here.
54
private static CollapsingBorderModel collapse = null;
55     private static CollapsingBorderModel collapseWithPrecedence = null;
56     
57     /**
58      * @param borderCollapse border collapse control
59      * @return the border model for the cell
60      */

61     public static CollapsingBorderModel getBorderModelFor(int borderCollapse) {
62         switch (borderCollapse) {
63             case Constants.EN_COLLAPSE:
64                 if (collapse == null) {
65                     collapse = new CollapsingBorderModelEyeCatching();
66                 }
67                 return collapse;
68             case Constants.EN_COLLAPSE_WITH_PRECEDENCE:
69                 if (collapseWithPrecedence == null) {
70                     //collapseWithPrecedence = new CollapsingBorderModelWithPrecedence();
71
}
72                 return collapseWithPrecedence;
73             default:
74                 throw new IllegalArgumentException JavaDoc("Illegal border-collapse mode.");
75         }
76     }
77     
78     /**
79      * @param side the side on the current cell
80      * @return the adjacent side on the neighbouring cell
81      */

82     public static int getOtherSide(int side) {
83         switch (side) {
84             case CommonBorderPaddingBackground.BEFORE:
85                 return CommonBorderPaddingBackground.AFTER;
86             case CommonBorderPaddingBackground.AFTER:
87                 return CommonBorderPaddingBackground.BEFORE;
88             case CommonBorderPaddingBackground.START:
89                 return CommonBorderPaddingBackground.END;
90             case CommonBorderPaddingBackground.END:
91                 return CommonBorderPaddingBackground.START;
92             default:
93                 throw new IllegalArgumentException JavaDoc("Illegal parameter: side");
94         }
95     }
96     
97     /**
98      * @param side the side to investigate
99      * @return true if the adjacent cell is before or after
100      */

101     protected boolean isVerticalRelation(int side) {
102         return (side == CommonBorderPaddingBackground.BEFORE
103                 || side == CommonBorderPaddingBackground.AFTER);
104     }
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: return 0;
115             case Constants.EN_SOLID: return -1;
116             case Constants.EN_DASHED: return -2;
117             case Constants.EN_DOTTED: return -3;
118             case Constants.EN_RIDGE: return -4;
119             case Constants.EN_OUTSET: return -5;
120             case Constants.EN_GROOVE: return -6;
121             case Constants.EN_INSET: return -7;
122             default: throw new IllegalStateException JavaDoc("Illegal border style: " + style);
123         }
124     }
125     
126     /**
127      * Determines the winning BorderInfo.
128      * @param current grid unit of the current element
129      * @param neighbour grid unit of the neighbouring element
130      * @return the winning BorderInfo
131      */

132     public abstract BorderInfo determineWinner(
133             GridUnit current, GridUnit neighbour, int side, int flags);
134     
135 }
136
Popular Tags