View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2008 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-widget Project
18  //
19  // WindowFrame.java
20  // Since: Apr 30, 2008
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  import com.google.gwt.user.client.ui.SimplePanel;
31  import com.google.gwt.user.client.ui.Widget;
32  import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
33  
34  /**
35   * Bordered Window
36   * 
37   * @author leo
38   * 
39   */
40  public class FrameBorder extends Composite {
41  
42  	public static final int NORTH = 1;
43  	public static final int EAST = 1 << 1;
44  	public static final int WEST = 1 << 2;
45  	public static final int SOUTH = 1 << 3;
46  	public static final int BORDER_FULL = NORTH | EAST | WEST | SOUTH;
47  
48  	private final FlexTable layoutFrame = new FlexTable();
49  	private HorizontalBorder upperFrame;
50  	private VerticalBar westBar;
51  	private final FlexTable contentFrame = new FlexTable();
52  	private Widget widget = new SimplePanel();
53  	private VerticalBar eastBar;
54  	private HorizontalBorder lowerFrame;
55  
56  	private int borderFlag;
57  	private int cornerRadius;
58  	private String borderColor;
59  	private String borderColorDark;
60  
61  	public FrameBorder(String color) {
62  		this(color, 4);
63  	}
64  
65  	public FrameBorder(String color, int borderWidth) {
66  		this(color, color, borderWidth, BORDER_FULL);
67  	}
68  
69  	public FrameBorder(int borderWidth, int borderFlag) {
70  		this(UTGBDesignFactory.getWindowBorderColor(), UTGBDesignFactory.getWindowBorderColorDark(), borderWidth, borderFlag);
71  	}
72  
73  	public FrameBorder(String borderColor, String borderColorDark, int borderWidth, int borderFlag) {
74  		assert (borderFlag <= BORDER_FULL);
75  
76  		this.borderFlag = borderFlag;
77  		this.cornerRadius = borderWidth;
78  		this.borderColor = borderColor;
79  		this.borderColorDark = borderColorDark;
80  
81  		drawFrame();
82  
83  		initWidget(layoutFrame);
84  	}
85  
86  	public void setWidget(Widget w) {
87  		this.widget = w;
88  		contentFrame.setWidget(0, 1, widget);
89  	}
90  
91  	public void setBorderWidth(int borderWidth) {
92  		this.cornerRadius = borderWidth;
93  		drawFrame();
94  	}
95  
96  	private void drawFrame() {
97  		layoutFrame.clear();
98  		contentFrame.clear();
99  
100 		layoutFrame.setPixelSize(100, 50);
101 
102 		upperFrame = new HorizontalBorder(cornerRadius, HorizontalBorder.UPPER, borderFlag, borderColor);
103 		lowerFrame = new HorizontalBorder(cornerRadius, HorizontalBorder.LOWER, borderFlag, borderColorDark);
104 		westBar = new VerticalBar(cornerRadius, borderColor);
105 		eastBar = new VerticalBar(cornerRadius, borderColorDark);
106 
107 		layoutFrame.setCellPadding(0);
108 		layoutFrame.setCellSpacing(0);
109 		// layoutFrame.setBorderWidth(1);
110 
111 		contentFrame.setCellPadding(0);
112 		contentFrame.setCellSpacing(0);
113 		// contentFrame.setBorderWidth(1);
114 		contentFrame.setSize("100%", "100%");
115 
116 		CellFormatter cf = layoutFrame.getCellFormatter();
117 		cf.setHeight(1, 0, "100%");
118 		cf.setWidth(1, 0, "100%");
119 
120 		if ((borderFlag & NORTH) != 0) {
121 			layoutFrame.setWidget(0, 0, upperFrame);
122 			cf.setHeight(0, 0, cornerRadius + "px");
123 		}
124 
125 		layoutFrame.setWidget(1, 0, contentFrame);
126 		if ((borderFlag & WEST) != 0) {
127 			contentFrame.setWidget(0, 0, westBar);
128 		}
129 		contentFrame.setWidget(0, 1, widget);
130 		contentFrame.getCellFormatter().setWidth(0, 1, "100%");
131 		if ((borderFlag & EAST) != 0) {
132 			contentFrame.setWidget(0, 2, eastBar);
133 		}
134 
135 		if ((borderFlag & SOUTH) != 0) {
136 			layoutFrame.setWidget(2, 0, lowerFrame);
137 			cf.setHeight(2, 0, cornerRadius + "px");
138 		}
139 
140 	}
141 
142 	static class VerticalBar extends Label {
143 		public VerticalBar(int radius, String color) {
144 			this.setSize(radius + "px", "100%");
145 			Style.fontSize(this, 0);
146 			Style.backgroundColor(this, color);
147 		}
148 	}
149 
150 }