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: package org.apache.wicket.extensions.markup.html.tree.table;
018:
019: import org.apache.wicket.IClusterable;
020: import org.apache.wicket.util.lang.EnumeratedType;
021:
022: /**
023: * This class represents location of a column in tree table.
024: * <p>
025: * First attribute of location is <b>alignment</b>. Alignment specifies,
026: * whether the column is located on the left side of the table, on the right
027: * side, or in the middle. Columns in the middle of the table take all space
028: * between columns on the left and columns on the right.
029: * <p>
030: * Next two attributes are <b>size</b> and <b>unit</b>:
031: * <ul>
032: * <li> For columns aligned to the left and to the right, the <b>size</b>
033: * represents the actual width of the column, according to chosen unit. Possible
034: * units for left and right aligned columns are <em>PX</em>, <em>EM</em>
035: * and <em>PERCENT</em>. </li>
036: * <li> For columns in the middle, the only valid unit is <em>PROPORTIONAL</em>.
037: * These columns take all available space between columns on the left and
038: * columns on the right. How this space is divided between middle columns is
039: * determined by the <b>size</b>. In this case the size can be understand as
040: * weight. Columns with bigger size take more space than columns with smaller
041: * size. For example, if there are three columns and their sizes are 2, 1, 1,
042: * the first column thakes 50% of the space and the second two columns take 25%
043: * each. </li>
044: * </ul>
045: *
046: * @author Matej Knopp
047: */
048: public class ColumnLocation implements IClusterable {
049: /**
050: * Alignment of the column.
051: */
052: public static final class Alignment extends EnumeratedType {
053: /** Align left. */
054: public static final Alignment LEFT = new Alignment("LEFT");
055:
056: /** Align middle. */
057: public static final Alignment MIDDLE = new Alignment("MIDDLE");
058:
059: /** Align right. */
060: public static final Alignment RIGHT = new Alignment("RIGHT");
061:
062: private static final long serialVersionUID = 1L;
063:
064: /**
065: * Construct.
066: *
067: * @param name
068: */
069: public Alignment(String name) {
070: super (name);
071: }
072: }
073:
074: /**
075: * Units.
076: */
077: public static final class Unit extends EnumeratedType {
078:
079: /** Size of letter M in the current font. */
080: public static Unit EM = new Unit("EM");
081:
082: /** Percentage. */
083: public static Unit PERCENT = new Unit("PERCENT");
084:
085: /** Proportional. */
086: public static Unit PROPORTIONAL = new Unit("PROPORTIONAL");
087:
088: /** Pixels. */
089: public static Unit PX = new Unit("PX");
090:
091: private static final long serialVersionUID = 1L;
092:
093: /**
094: * Construct.
095: *
096: * @param name
097: */
098: public Unit(String name) {
099: super (name);
100: }
101: };
102:
103: private static final long serialVersionUID = 1L;;
104:
105: private Alignment alignment;
106: private int size;
107: private Unit unit;
108:
109: /**
110: * Constructs the ColumnLocation object.
111: *
112: * @param alignment
113: * The column alignment
114: * @param size
115: * The column size in expressed in the provided unit
116: * @param unit
117: * The unit that the size argument is expressed in
118: * @throws IllegalArgumentException
119: * if the unit does not matche the alignment
120: */
121: public ColumnLocation(Alignment alignment, int size, Unit unit) {
122: this .alignment = alignment;
123: this .size = size;
124: this .unit = unit;
125:
126: if (alignment == Alignment.MIDDLE && unit != Unit.PROPORTIONAL) {
127: throw new IllegalArgumentException(
128: "For alignment MIDDLE the specified unit must be PROPORTIONAL.");
129: } else if (alignment != Alignment.MIDDLE
130: && unit == Unit.PROPORTIONAL) {
131: throw new IllegalArgumentException(
132: "Unit PROPORTIONAL can be specified only for columns with alignment MIDDLE.");
133: }
134: }
135:
136: /**
137: * Returns the allignment of this column.
138: *
139: * @return The alignment of this column
140: */
141: public Alignment getAlignment() {
142: return alignment;
143: }
144:
145: /**
146: * Returns the size of this column.
147: *
148: * @return The size of this column
149: */
150: public int getSize() {
151: return size;
152: }
153:
154: /**
155: * Returns the unit of a column.
156: *
157: * @return The unit of this column
158: */
159: public Unit getUnit() {
160: return unit;
161: }
162: }
|