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  // GenomeBrowser Project
18  //
19  // TrackTreeTrack.java
20  // Since: 2007/07/20
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.gwt.utgb.client.track.lib;
26  
27  import java.util.List;
28  
29  import org.utgenome.gwt.utgb.client.track.Track;
30  import org.utgenome.gwt.utgb.client.track.TrackBase;
31  import org.utgenome.gwt.utgb.client.track.TrackFrame;
32  import org.utgenome.gwt.utgb.client.track.TrackGroup;
33  import org.utgenome.gwt.utgb.client.track.TrackInfo;
34  import org.utgenome.gwt.utgb.client.track.TrackUpdateListener;
35  import org.utgenome.gwt.utgb.client.util.CanonicalProperties;
36  
37  import com.google.gwt.user.client.ui.Tree;
38  import com.google.gwt.user.client.ui.TreeItem;
39  import com.google.gwt.user.client.ui.Widget;
40  
41  public class TrackTreeTrack extends TrackBase implements TrackUpdateListener {
42  
43  	public static TrackFactory factory() {
44  		return new TrackFactory() {
45  			public Track newInstance() {
46  				return new TrackTreeTrack();
47  			}
48  		};
49  	}
50  
51  	private TrackGroup rootTrackGroup = null;
52  
53  	private Tree trackTree = new Tree();
54  
55  	public TrackTreeTrack() {
56  		super("Track Tree Track");
57  	}
58  
59  	public TrackTreeTrack(String trackName) {
60  		super(trackName);
61  	}
62  
63  	public TrackTreeTrack(TrackInfo trackInfo) {
64  		super(trackInfo);
65  	}
66  
67  	public Widget getWidget() {
68  		return trackTree;
69  	}
70  
71  	public void draw() {
72  		trackTree.clear();
73  
74  		if (rootTrackGroup != null) {
75  			final TreeItem rootItem = getTreeItem(rootTrackGroup);
76  			trackTree.addItem(rootItem);
77  		}
78  	}
79  
80  	private TreeItem getTreeItem(final TrackGroup trackGroup) {
81  		final TreeItem item = new TreeItem(trackGroup.getTrackGroupName());
82  
83  		{
84  			final List<TrackGroup> trackGroups = trackGroup.getTrackGroupList();
85  			final int SIZE = trackGroups.size();
86  			for (int i = 0; i < SIZE; i++) {
87  				final TrackGroup _group = (TrackGroup) (trackGroups.get(i));
88  				final TreeItem _item = getTreeItem(_group);
89  
90  				item.addItem(_item);
91  			}
92  		}
93  
94  		{
95  			final List<Track> tracks = trackGroup.getTrackList();
96  			final int SIZE = tracks.size();
97  			for (int i = 0; i < SIZE; i++) {
98  				final Track _track = (Track) (tracks.get(i));
99  				final TreeItem _item = getTreeItem(_track);
100 
101 				item.addItem(_item);
102 			}
103 		}
104 
105 		return item;
106 	}
107 
108 	public void setUp(TrackFrame trackFrame, TrackGroup group) {
109 		this.rootTrackGroup = group.getRootTrackGroup();
110 	}
111 
112 	private TreeItem getTreeItem(final Track track) {
113 		return new TreeItem(track.getTrackInfo().getTrackName());
114 	}
115 
116 	public void onAddTrackGroup(TrackGroup trackGroup) {
117 		refresh();
118 	}
119 
120 	public void onInsertTrack(Track track, int beforeIndex) {
121 		refresh();
122 	}
123 
124 	public void onInsertTrack(Track track) {
125 		refresh();
126 	}
127 
128 	public void onRemoveTrack(Track track) {
129 		refresh();
130 	}
131 
132 	public void onRemoveTrackGroup(TrackGroup trackGroup) {
133 		refresh();
134 	}
135 
136 	public void onResizeTrack() {
137 	}
138 
139 	public void saveProperties(CanonicalProperties saveData) {
140 		if (rootTrackGroup != null)
141 			saveData.add("rootTrackGroup", rootTrackGroup.getClass().getName());
142 	}
143 
144 	public void onResizeTrackWindow(int newWindowSize) {
145 		// TODO Auto-generated method stub
146 
147 	}
148 
149 	public void onDetachedFromTrackGroup(TrackGroup trackGroup) {
150 
151 	}
152 
153 }