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  // TabTrackPanel.java
20  // Since: May 1, 2008
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.gwt.widget.client;
26  
27  import java.util.ArrayList;
28  
29  import com.google.gwt.event.dom.client.MouseDownEvent;
30  import com.google.gwt.event.dom.client.MouseDownHandler;
31  import com.google.gwt.user.client.ui.AbsolutePanel;
32  import com.google.gwt.user.client.ui.Composite;
33  import com.google.gwt.user.client.ui.Panel;
34  import com.google.gwt.user.client.ui.TabPanel;
35  import com.google.gwt.user.client.ui.Widget;
36  
37  /**
38   * Tabbed frame
39   * 
40   * @author leo
41   * 
42   */
43  public class TabbedTrackFrame extends Composite {
44  
45  	private AbsolutePanel boundaryPanel = new AbsolutePanel();
46  	private TabPanel tabPanel = new TabPanel();
47  	// private PickupDragController dragController;
48  
49  	private ArrayList<Tab> tabList = new ArrayList<Tab>();
50  
51  	public TabbedTrackFrame() {
52  		Style.fullSize(boundaryPanel);
53  		Style.fullSize(tabPanel);
54  		boundaryPanel.add(tabPanel);
55  		// dragController = new PickupDragController(boundaryPanel, false);
56  
57  		initWidget(boundaryPanel);
58  	}
59  
60  	public Panel getTabContent(int index) {
61  		return (Panel) tabPanel.getWidget(index);
62  	}
63  
64  	private class TabClickListener implements MouseDownHandler {
65  		private final int tabIndex;
66  
67  		public TabClickListener(int tabIndex) {
68  			this.tabIndex = tabIndex;
69  		}
70  
71  		public void onMouseDown(MouseDownEvent arg0) {
72  			selectTab(tabIndex);
73  		}
74  	}
75  
76  	public void addTab(TrackPanel panel, Tab tabWidget) {
77  
78  		tabPanel.add((Widget) panel, tabWidget);
79  		int tabIndex = tabPanel.getTabBar().getTabCount() - 1;
80  		tabList.add(tabWidget);
81  
82  		tabWidget.setParenTabPanel(tabPanel, (Widget) panel);
83  		tabWidget.addMouseDownHandler(new TabClickListener(tabIndex));
84  
85  		// TabDropController tabDropController = new TabDropController(tabWidget, tabPanel, tabIndex);
86  		// dragController.registerDropController(tabDropController);
87  
88  	}
89  
90  	//	
91  	// public void makeDraggable(TrackFrame trackPanel) {
92  	// dragController.makeDraggable(trackPanel, trackPanel.getDraggableWidget());
93  	// }
94  
95  	public void enableClose(int tabIndex, boolean enableClose) {
96  		if (tabIndex > tabList.size())
97  			throw new IndexOutOfBoundsException("out of bound tab index: " + tabIndex);
98  
99  		tabList.get(tabIndex).enableCloseButton(enableClose);
100 	}
101 
102 	public void selectTab(int index) {
103 		tabPanel.selectTab(index);
104 
105 		for (int i = 0; i < tabList.size(); i++) {
106 			Tab tab = tabList.get(i);
107 			tabList.get(i).setSelect(i == index);
108 		}
109 	}
110 
111 }