1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.utgenome.gwt.utgb.client.track;
26
27 import java.util.Iterator;
28
29 import org.utgenome.gwt.utgb.client.UTGBEntryPointBase;
30 import org.utgenome.gwt.utgb.client.ui.DraggableTable;
31 import org.utgenome.gwt.utgb.client.ui.WindowBox;
32 import org.utgenome.gwt.utgb.client.ui.WindowListener;
33
34 import com.google.gwt.user.client.ui.Composite;
35
36
37
38
39
40
41
42 public class TrackQueue extends Composite implements TrackUpdateListener, TrackLayoutManager, WindowListener {
43 private TrackGroup _trackGroup;
44 private final DraggableTable _trackQueue = new DraggableTable();
45
46 public TrackQueue(TrackGroup trackGroup) {
47 this._trackGroup = trackGroup;
48 init();
49 initWidget(_trackQueue);
50 }
51
52 private void init() {
53 _trackQueue.setStyleName("track-queue");
54 initTrackGroup(_trackGroup);
55
56
57
58
59
60
61
62
63
64
65
66
67
68 }
69
70 private void initTrackGroup(TrackGroup trackGroup) {
71 trackGroup.setTrackLayoutManager(this);
72 trackGroup.addTrackUpdateListener(this);
73 }
74
75 private void sync(TrackGroup group) {
76
77 for (Iterator<Track> it = group.getTrackList().iterator(); it.hasNext();) {
78 Track track = it.next();
79 onInsertTrack(track);
80 }
81 for (Iterator<TrackGroup> it = group.getTrackGroupList().iterator(); it.hasNext();) {
82 TrackGroup trackGroup = it.next();
83 sync(trackGroup);
84 }
85 }
86
87 public WindowBox createWindow() {
88 WindowBox win = new WindowBox(this);
89 win.addWindowListener(this);
90 return win;
91 }
92
93 public void adjustHeight() {
94 int height = _trackGroup.getHeight();
95 _trackQueue.setHeight(height + "px");
96 }
97
98 public int getTrackIndex(Track track) {
99 return _trackQueue.getIndex(track.getFrame());
100 }
101
102 public void onRemoveTrack(Track track) {
103 _trackQueue.remove(track.getFrame());
104
105
106
107 }
108
109 public void onInsertTrack(Track track) {
110 onInsertTrack(track, -1);
111 }
112
113 public void onInsertTrack(Track track, int beforeIndex) {
114 TrackFrame frame = new TrackFrame(track, _trackGroup.getTrackWindow().getPixelWidth(), track.getDefaultWindowHeight());
115 if (beforeIndex < 0) {
116
117 _trackQueue.add(frame, frame.getFrameBar());
118 }
119 else
120 _trackQueue.insert(frame, frame.getFrameBar(), beforeIndex);
121
122 track.refresh();
123 }
124
125 public void onAddTrackGroup(TrackGroup trackGroup) {
126 initTrackGroup(trackGroup);
127 for (Track track : trackGroup.getTrackList()) {
128 onInsertTrack(track);
129 }
130 for (TrackGroup group : trackGroup.getTrackGroupList()) {
131 onAddTrackGroup(group);
132 }
133 }
134
135 public void onRemoveTrackGroup(TrackGroup trackGroup) {
136 for (Track track : trackGroup.getTrackList()) {
137 onRemoveTrack(track);
138 }
139 for (TrackGroup group : trackGroup.getTrackGroupList()) {
140 onRemoveTrackGroup(group);
141 }
142 }
143
144 public void onResizeTrack() {
145 adjustHeight();
146 }
147
148 protected void onLoad() {
149 for (Track track : _trackGroup.getAllTrackList()) {
150 track.getFrame().adjustFrameHeight();
151 }
152 adjustHeight();
153
154 UTGBEntryPointBase.hideLoadingMessage();
155 }
156
157 public void onButtonClick(WindowBox window, int buttonType) {
158
159 }
160
161 public void onResizeWindow(WindowBox window, int newWindowSize) {
162 int trackWindowWidth = newWindowSize - TrackFrame.INFOPANEL_WIDTH;
163 if (trackWindowWidth <= 0)
164 trackWindowWidth = 1;
165 TrackWindow trackWindow = _trackGroup.getTrackWindow();
166 TrackGroupPropertyWriter writer = _trackGroup.getPropertyWriter();
167 writer.setTrackWindowSize(trackWindowWidth);
168 }
169
170 public void onResizeTrackWindow(int newWindowSize) {
171 _trackQueue.setWidth((TrackFrame.INFOPANEL_WIDTH + newWindowSize + TrackFrame.SCROLLBAR_WIDTH) + "px");
172 }
173 }