View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2007 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // utgb-core Project
18  //
19  // Border.java
20  // Since: 2007/11/29
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.gwt.widget.client;
26  
27  import com.google.gwt.user.client.ui.Composite;
28  import com.google.gwt.user.client.ui.FlexTable;
29  import com.google.gwt.user.client.ui.Label;
30  
31  /**
32   * Horizontal Border for {@link FrameBorder}
33   * 
34   * @author leo
35   * 
36   */
37  public class HorizontalBorder extends Composite {
38  	public static final int UPPER = 0 << 1;
39  	public static final int LOWER = 1 << 1;
40  
41  	protected static final int LEFT = 0;
42  	protected static final int RIGHT = 1;
43  
44  	private final FlexTable layoutFrame = new FlexTable();
45  	private final Label left = new Label();
46  	private final Label center = new Label();
47  	private final Label right = new Label();
48  
49  	private int cornerRadius;
50  
51  	/**
52  	 * @param cornerRadius
53  	 * @param type
54  	 *            HorizontalBorder.UPPER or {@link HorizontalBorder}.LOWER
55  	 * @param borderFlag
56  	 *            bit vector or {@link FrameBorder}.{NORTH, EAST, SOUTH, WEST}
57  	 * @param color
58  	 */
59  	public HorizontalBorder(int cornerRadius, int type, int borderFlag, String color) {
60  		this.cornerRadius = cornerRadius;
61  		assert (type == UPPER || type == LOWER);
62  
63  		setupWidget(type, borderFlag, color);
64  		initWidget(layoutFrame);
65  	}
66  
67  	protected void setupWidget(int type, int borderFlag, String color) {
68  		int index = 0;
69  		if ((borderFlag & FrameBorder.WEST) != 0)
70  			layoutFrame.setWidget(0, index++, left);
71  		layoutFrame.setWidget(0, index, center);
72  		layoutFrame.getCellFormatter().setWidth(0, index, "100%");
73  		index++;
74  		if ((borderFlag & FrameBorder.EAST) != 0)
75  			layoutFrame.setWidget(0, index++, right);
76  
77  		layoutFrame.setCellPadding(0);
78  		layoutFrame.setCellSpacing(0);
79  		layoutFrame.setHeight(cornerRadius + "px");
80  
81  		left.setPixelSize(cornerRadius, cornerRadius);
82  		right.setPixelSize(cornerRadius, cornerRadius);
83  
84  		Style.backgroundColor(center, color);
85  		Style.fontSize(center, 0);
86  		center.setSize("100%", cornerRadius + "px");
87  		// layoutFrame.setBorderWidth(1);
88  
89  		setCorner(left, type | LEFT, cornerRadius, color);
90  		setCorner(right, type | RIGHT, cornerRadius, color);
91  
92  	}
93  
94  	private void setCorner(Label label, int positionType, int cornerRadius, String color) {
95  		assert (positionType >= 0 && positionType <= 4);
96  
97  		int backgroundXPos = (positionType & RIGHT) != 0 ? -cornerRadius : 0;
98  		int backgroundYPos = (positionType & LOWER) != 0 ? -cornerRadius : 0;
99  
100 		Style.backgroundImage(label, "theme/default/rc" + cornerRadius + ((positionType & LOWER) != 0 ? "d" : "") + ".png");
101 		Style.backgroundNoRepeat(label);
102 		Style.backgroundPosition(label, backgroundXPos + "px " + backgroundYPos + "px");
103 		Style.overflowHidden(label);
104 		Style.fontSize(label, 0);
105 
106 		label.setPixelSize(cornerRadius, cornerRadius);
107 
108 	}
109 
110 	public void setWidth(int width) {
111 		this.setWidth(width + "px");
112 	}
113 
114 }