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  // ToolBoxTrack.java
20  // Since: Jun 13, 2007
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.gwt.utgb.client.track.lib;
26  
27  import java.util.ArrayList;
28  import java.util.Iterator;
29  
30  import org.utgenome.gwt.utgb.client.track.Track;
31  import org.utgenome.gwt.utgb.client.track.TrackBase;
32  import org.utgenome.gwt.utgb.client.track.TrackFrame;
33  import org.utgenome.gwt.utgb.client.track.TrackGroup;
34  import org.utgenome.gwt.utgb.client.track.lib.debug.DebugToolBoxTrack;
35  
36  import com.google.gwt.event.dom.client.ClickEvent;
37  import com.google.gwt.event.dom.client.ClickHandler;
38  import com.google.gwt.user.client.ui.Anchor;
39  import com.google.gwt.user.client.ui.FlowPanel;
40  import com.google.gwt.user.client.ui.Widget;
41  
42  /**
43   * {@link ToolBoxTrack} has a list of {@link Track}s. When you click one of the elements, the corresponding
44   * {@link Track} will be inserted to the {@link TrackGroup} in which the {@link ToolBoxTrack} belongs.
45   * 
46   * @author leo
47   * 
48   */
49  public class ToolBoxTrack extends TrackBase {
50  	public static TrackFactory factory() {
51  		return new TrackFactory() {
52  			public Track newInstance() {
53  				return new ToolBoxTrack();
54  			}
55  		};
56  	}
57  
58  	private FlowPanel _panel = new FlowPanel();
59  	private ArrayList<TrackLink> trackTable = new ArrayList<TrackLink>();
60  	private Track _self = this;
61  
62  	class TrackLink extends Anchor implements ClickHandler {
63  		TrackFactory trackFactory;
64  
65  		public TrackLink(String label, TrackFactory trackFactory) {
66  			super(label, label);
67  			this.trackFactory = trackFactory;
68  			setStyleName("selector-item");
69  			addClickHandler(this);
70  		}
71  
72  		public void onClick(ClickEvent e) {
73  			int trackIndex = getTrackGroup().getTrackIndex(_self);
74  			Track newTrackInstance = trackFactory.newInstance();
75  			getTrackGroup().insertTrack(newTrackInstance, trackIndex + 1);
76  		}
77  	}
78  
79  	public ToolBoxTrack() {
80  		super("Tool Box");
81  		init();
82  	}
83  
84  	public ToolBoxTrack(String trackName) {
85  		super(trackName);
86  		init();
87  	}
88  
89  	private void init() {
90  		_panel.setWidth("600px");
91  		_panel.setStyleName("selector");
92  		this.setupToolbox();
93  	}
94  
95  	/**
96  	 * override this method to implement your own tool box
97  	 */
98  	public void setupToolbox() {
99  
100 		addTrackFactory("Scroll Button", ScrollButtonTrack.factory());
101 		addTrackFactory("Window Controller", WindowControlTrack.factory());
102 		addTrackFactory("Sequence Ruler", SequenceRulerTrack.factory());
103 		addTrackFactory("Track Ruler", RulerTrack.factory());
104 		addTrackFactory("Debug Toolbox", DebugToolBoxTrack.factory());
105 
106 	}
107 
108 	public void addTrackFactory(String label, TrackFactory trackFactory) {
109 		trackTable.add(new TrackLink(label, trackFactory));
110 	}
111 
112 	public int getDefaultWindowHeight() {
113 		return 15;
114 	}
115 
116 	public Widget getWidget() {
117 		return _panel;
118 	}
119 
120 	public void draw() {
121 		_panel.clear();
122 		for (Iterator<TrackLink> it = trackTable.iterator(); it.hasNext();) {
123 			TrackLink tl = it.next();
124 			_panel.add(tl);
125 		}
126 	}
127 
128 	public void setUp(TrackFrame trackFrame, TrackGroup group) {
129 
130 	}
131 
132 }