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  // HorizontalTrackPanel.java
20  // Since: Apr 24, 2008
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.gwt.widget.client;
26  
27  import org.utgenome.gwt.widget.client.impl.TrackPanelBase;
28  
29  import com.google.gwt.user.client.ui.FlexTable;
30  import com.google.gwt.user.client.ui.FocusPanel;
31  import com.google.gwt.user.client.ui.HorizontalPanel;
32  import com.google.gwt.user.client.ui.Label;
33  import com.google.gwt.user.client.ui.ScrollPanel;
34  import com.google.gwt.user.client.ui.SimplePanel;
35  import com.google.gwt.user.client.ui.VerticalPanel;
36  import com.google.gwt.user.client.ui.Widget;
37  
38  /**
39   * Track panel that has the horizontal layout.
40   * 
41   * @author leo
42   * 
43   */
44  public class HorizontalTrackFrame extends TrackPanelBase {
45  
46  	// layout panels
47  	private final FlexTable layoutTable = new FlexTable();
48  	private FocusPanel labelFrame = new FocusPanel();
49  	private SimplePanel trackInfoPanel = new SimplePanel();
50  	private String trackTitle;
51  	private FrameBorder trackInfoFrame = new FrameBorder(2, FrameBorder.WEST | FrameBorder.SOUTH);
52  	private Label trackLabel = new Label();
53  	private int buttonVisibilityFlag = ~0; // show all buttons in default
54  
55  	private ScrollPanel scrollPanel = new ScrollPanel();
56  
57  	public HorizontalTrackFrame() {
58  
59  		enableResizeWidth(false);
60  
61  		drawWidget();
62  		initWidget(layoutTable);
63  	}
64  
65  	public Widget getDraggableWidget() {
66  		return labelFrame;
67  	}
68  
69  	protected void drawWidget() {
70  
71  		setTrackTitle("Track");
72  
73  		Style.fullWidth(layoutTable);
74  		layoutTable.setCellPadding(0);
75  		layoutTable.setCellSpacing(0);
76  
77  		// label
78  		Style.fontSize(trackLabel, 11);
79  		Style.fontFamily(trackLabel, "Arial, Tahoma, Verdana");
80  		Style.set(trackLabel, "color", "white");
81  		Style.margin(trackLabel, Style.LEFT, 2);
82  		Style.verticalAlign(trackLabel, "middle");
83  		Style.overflowHidden(trackLabel);
84  
85  		// label frame
86  		labelFrame.add(trackLabel);
87  		Style.cursor(labelFrame, Style.CURSOR_MOVE);
88  
89  		// title bar (label + icon)
90  		HorizontalPanel hp = new HorizontalPanel();
91  		Style.fullWidth(hp);
92  		hp.add(labelFrame);
93  		hp.setCellWidth(labelFrame, "100%");
94  		hp.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
95  		hp.add(getIconSetPanel());
96  
97  		// track info panel
98  		Style.fullSize(trackInfoPanel);
99  		Style.backgroundImage(trackInfoPanel, "theme/default/track-base.png");
100 		Style.backgroundColor(trackInfoPanel, "00a7bf");
101 		trackInfoPanel.add(hp);
102 
103 		// track info border
104 		trackInfoFrame.setWidget(trackInfoPanel);
105 		trackInfoFrame.setSize("180px", "100%");
106 
107 		// layout (track info | track content | resize bar)
108 		layoutTable.setWidget(0, 0, trackInfoFrame);
109 
110 		// scroll panel
111 		layoutTable.setWidget(0, 1, scrollPanel);
112 		layoutTable.getCellFormatter().setHeight(0, 1, "100%");
113 		layoutTable.getCellFormatter().setWidth(0, 1, "100%");
114 
115 		// resize bar
116 		VerticalPanel resizeBarPanel = new VerticalPanel();
117 		Style.fullSize(resizeBarPanel);
118 		Style.backgroundColor(resizeBarPanel, "D0F0F0");
119 		resizeBarPanel.setVerticalAlignment(VerticalPanel.ALIGN_BOTTOM);
120 		resizeBarPanel.add(getResizeButton());
121 
122 		// resize bar frame
123 		FrameBorder resizeBarBorder = new FrameBorder(2, FrameBorder.EAST | FrameBorder.SOUTH);
124 		resizeBarBorder.setSize("16px", "100%");
125 		resizeBarBorder.setWidget(resizeBarPanel);
126 		layoutTable.getCellFormatter().setHeight(0, 2, "100%");
127 		layoutTable.getCellFormatter().setWidth(0, 2, "100%");
128 		layoutTable.setWidget(0, 2, resizeBarBorder);
129 
130 		// Style.hideHorizontalScrollBar(scrollPanel);
131 	}
132 
133 	@Override
134 	public void setHeight(int pixelHeight) {
135 		if (pixelHeight >= 20) {
136 			layoutTable.setHeight(pixelHeight + "px");
137 			scrollPanel.setHeight(pixelHeight + "px");
138 		}
139 	}
140 
141 	@Override
142 	public void setWidth(int pixelWidth) {
143 		if (pixelWidth >= 200) {
144 			layoutTable.setWidth(pixelWidth + "px");
145 			scrollPanel.setWidth(pixelWidth - 200 + "px");
146 		}
147 	}
148 
149 	/**
150 	 * Checks the visibility of the button
151 	 * 
152 	 * @param buttonType
153 	 * @return
154 	 */
155 	public boolean isVisible(int buttonType) {
156 		return (buttonVisibilityFlag & buttonType) != 0;
157 	}
158 
159 	public String getTrackTitle() {
160 		return trackTitle;
161 	}
162 
163 	public void setTrackTitle(String title) {
164 		this.trackTitle = title;
165 		if (trackTitle.length() > 20)
166 			trackLabel.setText(trackTitle.substring(0, 20) + "...");
167 		else
168 			trackLabel.setText(trackTitle);
169 
170 		trackLabel.setTitle(trackTitle);
171 	}
172 
173 	public void setTrackContent(Widget w) {
174 		scrollPanel.setWidget(w);
175 	}
176 
177 }