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.utgb.client.ui;
26  
27  import org.utgenome.gwt.widget.client.Style;
28  
29  import com.google.gwt.user.client.ui.Composite;
30  import com.google.gwt.user.client.ui.FlexTable;
31  import com.google.gwt.user.client.ui.Label;
32  
33  public class Border extends Composite {
34  	public static final int UPPER = 0 << 1;
35  	public static final int LOWER = 1 << 1;
36  
37  	protected static final int LEFT = 0;
38  	protected static final int RIGHT = 1;
39  
40  	private final FlexTable layoutFrame = new FlexTable();
41  	private final Label left = new Label();
42  	private final Label center = new Label();
43  	private final Label right = new Label();
44  
45  	private int cornerRadius;
46  
47  	public Border(int cornerRadius, int type, int borderFlag, String color) {
48  		this(cornerRadius, type, borderFlag, color, 1f);
49  	}
50  
51  	public Border(int cornerRadius, int type, int borderFlag, String color, float alpha) {
52  		this.cornerRadius = cornerRadius;
53  		assert (type == UPPER || type == LOWER);
54  
55  		setupWidget(type, borderFlag, color, alpha);
56  		initWidget(layoutFrame);
57  	}
58  
59  	protected void setupWidget(int type, int borderFlag, String color, float alpha) {
60  		int index = 0;
61  		if ((borderFlag & RoundCornerFrame.WEST) != 0)
62  			layoutFrame.setWidget(0, index++, left);
63  		layoutFrame.setWidget(0, index, center);
64  		layoutFrame.getCellFormatter().setWidth(0, index, "100%");
65  		index++;
66  		if ((borderFlag & RoundCornerFrame.EAST) != 0)
67  			layoutFrame.setWidget(0, index++, right);
68  
69  		layoutFrame.setCellPadding(0);
70  		layoutFrame.setCellSpacing(0);
71  		layoutFrame.setHeight(cornerRadius + "px");
72  
73  		left.setPixelSize(cornerRadius, cornerRadius);
74  		right.setPixelSize(cornerRadius, cornerRadius);
75  
76  		Style.backgroundImage(center, "utgb-core/transparent?color=" + color + "&opacity=" + alpha);
77  		//Style.backgroundColor(center, color);
78  		Style.fontSize(center, 0);
79  		center.setSize("100%", cornerRadius + "px");
80  		//layoutFrame.setBorderWidth(1);
81  
82  		setCorner(left, type | LEFT, cornerRadius, color, alpha);
83  		setCorner(right, type | RIGHT, cornerRadius, color, alpha);
84  
85  	}
86  
87  	private void setCorner(Label l, int positionType, int cornerRadius, String color, float alpha) {
88  		assert (positionType >= 0 && positionType <= 4);
89  
90  		int backgroundXPos = (positionType & RIGHT) != 0 ? -cornerRadius : 0;
91  		int backgroundYPos = (positionType & LOWER) != 0 ? -cornerRadius : 0;
92  
93  		Style.backgroundImage(l, "utgb-core.roundcircle.action?color=" + color + "&size=" + cornerRadius + "&opacity=" + alpha);
94  		Style.backgroundNoRepeat(l);
95  		Style.backgroundPosition(l, backgroundXPos + "px " + backgroundYPos + "px");
96  		Style.overflowHidden(l);
97  		Style.fontSize(l, 0);
98  
99  		l.setPixelSize(cornerRadius, cornerRadius);
100 
101 	}
102 
103 	public void setWidth(int width) {
104 		this.setWidth(width + "px");
105 	}
106 
107 }