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  // ScrollButtonTrack.java
20  // Since: Jun 13, 2007
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.gwt.utgb.client.track.lib;
26  
27  import org.utgenome.gwt.utgb.client.track.Track;
28  import org.utgenome.gwt.utgb.client.track.TrackBase;
29  import org.utgenome.gwt.utgb.client.track.TrackFrame;
30  import org.utgenome.gwt.utgb.client.track.TrackGroup;
31  import org.utgenome.gwt.utgb.client.track.TrackWindow;
32  
33  import com.google.gwt.event.dom.client.ClickEvent;
34  import com.google.gwt.event.dom.client.ClickHandler;
35  import com.google.gwt.user.client.ui.Button;
36  import com.google.gwt.user.client.ui.Composite;
37  import com.google.gwt.user.client.ui.HorizontalPanel;
38  import com.google.gwt.user.client.ui.Widget;
39  
40  /**
41   * ScrollButtonTrack has several move buttons that relocate a TrackWindow.
42   * 
43   * @author leo
44   * 
45   */
46  public class ScrollButtonTrack extends TrackBase {
47  	public static TrackFactory factory() {
48  		return new TrackFactory() {
49  			public Track newInstance() {
50  				return new ScrollButtonTrack();
51  			}
52  		};
53  	}
54  
55  	class ScrollButtonSet extends Composite {
56  		HorizontalPanel _panel = new HorizontalPanel();
57  
58  		class WindowScrollButton extends Button implements ClickHandler {
59  			int movePercentageOnWindow;
60  
61  			public WindowScrollButton(String label, int movePercentageOnWindow) {
62  				super(label);
63  				setStyleName("scrollbutton");
64  				addClickHandler(this);
65  				this.movePercentageOnWindow = movePercentageOnWindow;
66  			}
67  
68  			public void onClick(ClickEvent e) {
69  				TrackWindow window = getTrackGroup().getTrackWindow();
70  				int genomeRange = window.getEndOnGenome() - window.getStartOnGenome();
71  				if (genomeRange < 0)
72  					genomeRange = -genomeRange;
73  
74  				int offset = (int) (genomeRange * ((double) movePercentageOnWindow / 100.0));
75  				getTrackGroup().getPropertyWriter().setTrackWindow(window.getStartOnGenome() + offset, window.getEndOnGenome() + offset);
76  			}
77  		}
78  
79  		public ScrollButtonSet() {
80  			_panel.add(new WindowScrollButton("<<<< ", -95));
81  			_panel.add(new WindowScrollButton("<<< ", -50));
82  			_panel.add(new WindowScrollButton("<< ", -25));
83  			_panel.add(new WindowScrollButton("< ", -10));
84  			_panel.add(new WindowScrollButton("> ", 10));
85  			_panel.add(new WindowScrollButton(">> ", 25));
86  			_panel.add(new WindowScrollButton(">>> ", 50));
87  			_panel.add(new WindowScrollButton(">>>> ", 95));
88  
89  			initWidget(_panel);
90  		}
91  
92  	}
93  
94  	private ScrollButtonSet _buttonSet = new ScrollButtonSet();
95  
96  	public ScrollButtonTrack() {
97  		super("Scroll Button");
98  	}
99  
100 	public int getDefaultWindowHeight() {
101 		return 20;
102 	}
103 
104 	public Widget getWidget() {
105 		return _buttonSet;
106 	}
107 
108 	public void setUp(TrackFrame trackFrame, TrackGroup group) {
109 		trackFrame.disablePack();
110 	}
111 
112 }