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.lib;
26
27 import org.utgenome.gwt.utgb.client.db.datatype.StringType;
28 import org.utgenome.gwt.utgb.client.track.Design;
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.TrackConfig;
32 import org.utgenome.gwt.utgb.client.track.TrackConfigChange;
33 import org.utgenome.gwt.utgb.client.track.TrackFrame;
34 import org.utgenome.gwt.utgb.client.track.TrackGroup;
35 import org.utgenome.gwt.utgb.client.util.CanonicalProperties;
36 import org.utgenome.gwt.widget.client.Style;
37
38 import com.google.gwt.event.dom.client.ErrorEvent;
39 import com.google.gwt.event.dom.client.ErrorHandler;
40 import com.google.gwt.event.dom.client.LoadEvent;
41 import com.google.gwt.event.dom.client.LoadHandler;
42 import com.google.gwt.user.client.DOM;
43 import com.google.gwt.user.client.ui.FlexTable;
44 import com.google.gwt.user.client.ui.Frame;
45 import com.google.gwt.user.client.ui.Image;
46 import com.google.gwt.user.client.ui.Widget;
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 public class MiniBrowserTrack extends TrackBase {
66 private String type = "frame";
67 private String trackBaseURL;
68 private FlexTable layoutPanel = new FlexTable();
69 private Image trackImage = new Image();
70 private Frame frame = new Frame();
71 private boolean isWidgetReady = false;
72
73 protected TrackConfig config = new TrackConfig(this);
74
75 public static TrackFactory factory() {
76 return new TrackFactory() {
77 public Track newInstance() {
78 return new MiniBrowserTrack();
79 }
80 };
81 }
82
83 public MiniBrowserTrack() {
84 super("Mini Browser");
85
86 Style.fullWidth(layoutPanel);
87 layoutPanel.setCellPadding(0);
88 layoutPanel.setCellSpacing(0);
89 Style.fontSize(layoutPanel, 0);
90
91 Style.fullWidth(frame);
92 Style.margin(frame, 0);
93 Style.padding(frame, 0);
94 DOM.setElementProperty(frame.getElement(), "align", "left");
95 DOM.setElementPropertyInt(frame.getElement(), "marginHight", 0);
96 DOM.setElementPropertyInt(frame.getElement(), "marginWidth", 0);
97 DOM.setElementPropertyInt(frame.getElement(), "frameBorder", 0);
98
99 Style.hideHorizontalScrollBar(layoutPanel);
100 Style.hideHorizontalScrollBar(frame);
101 }
102
103 public Widget getWidget() {
104 return layoutPanel;
105 }
106
107 @Override
108 public void draw() {
109
110
111
112 String trackURL = getTrackURL();
113 if (type.equals("frame")) {
114 if (!isWidgetReady) {
115 layoutPanel.setWidget(0, 0, frame);
116 isWidgetReady = true;
117 }
118 frame.setUrl(trackURL);
119 }
120 else if (type.equals("image")) {
121
122 if (!isWidgetReady) {
123 layoutPanel.setWidget(0, 0, trackImage);
124 isWidgetReady = true;
125 }
126 trackImage.setUrl(getTrackURL());
127 getFrame().setNowLoading();
128 }
129 }
130
131 protected String getTrackURL() {
132 return trackBaseURL;
133 }
134
135 @Override
136 public TrackConfig getConfig() {
137 return config;
138 }
139
140 @Override
141 public void setUp(TrackFrame trackFrame, TrackGroup group) {
142
143 trackImage.addLoadHandler(new LoadHandler() {
144 public void onLoad(LoadEvent e) {
145 getFrame().onUpdateTrackWidget();
146 getFrame().loadingDone();
147 }
148 });
149 trackImage.addErrorHandler(new ErrorHandler() {
150 public void onError(ErrorEvent e) {
151 trackImage.setUrl(Design.IMAGE_NOT_AVAILABLE);
152 getFrame().loadingDone();
153 }
154 });
155
156 int height = this.getDefaultWindowHeight();
157 if (height > 0) {
158 frame.setHeight(height + "px");
159 layoutPanel.setHeight(height + "px");
160 }
161
162
163
164 config.addConfig("URL", new StringType("URL"), trackBaseURL);
165 }
166
167 @Override
168 public void onChangeTrackConfig(TrackConfigChange change) {
169 if (change.contains("URL")) {
170 trackBaseURL = change.getValue("URL");
171 draw();
172 }
173 }
174
175 @Override
176 public void saveProperties(CanonicalProperties saveData) {
177 saveData.add("type", type);
178 saveData.add("URL", trackBaseURL);
179 }
180
181 @Override
182 public void restoreProperties(CanonicalProperties properties) {
183 trackBaseURL = properties.get("URL", trackBaseURL);
184 type = properties.get("type", type);
185 }
186 }