Skip to content

Commit f78dbbe

Browse files
committed
Implement RequireResize interface and don't upate viewRange or zoom when
it hasn't changed.
1 parent 22a6bae commit f78dbbe

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

src/at/gmi/nordborglab/widgets/geneviewer/client/GeneViewer.java

100644100755
Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,23 @@
4343
import com.google.gwt.user.client.Element;
4444
import com.google.gwt.user.client.Window;
4545
import com.google.gwt.user.client.ui.Composite;
46+
import com.google.gwt.user.client.ui.DockLayoutPanel;
4647
import com.google.gwt.user.client.ui.FlowPanel;
4748
import com.google.gwt.user.client.ui.HTMLPanel;
4849
import com.google.gwt.user.client.ui.Label;
50+
import com.google.gwt.user.client.ui.LayoutPanel;
4951
import com.google.gwt.user.client.ui.PopupPanel;
52+
import com.google.gwt.user.client.ui.ProvidesResize;
53+
import com.google.gwt.user.client.ui.RequiresResize;
5054
import com.google.gwt.user.client.ui.PopupPanel.PositionCallback;
55+
import com.google.gwt.user.client.ui.ResizeComposite;
5156
import com.google.gwt.user.client.ui.Widget;
5257
import com.processingjs.client.Processing;
5358

5459

5560
public class GeneViewer extends Composite implements HasMouseMoveHandlers, HasZoomResizeHandlers,HasHandlers,
5661
HasFetchGenesHandlers,FetchGeneHandler, HasHighlightGeneHandlers,
57-
HasUnhighlightGeneHandlers,HasClickGeneHandlers,HighlightGeneHandler,UnhighlightGeneHandler,ClickGeneHandler{
62+
HasUnhighlightGeneHandlers,HasClickGeneHandlers,HighlightGeneHandler,UnhighlightGeneHandler,ClickGeneHandler,RequiresResize{
5863

5964
interface Resources extends ClientBundle
6065
{
@@ -69,22 +74,26 @@ interface Resources extends ClientBundle
6974
interface GeneViewerUiBinder extends UiBinder<Widget, GeneViewer> {
7075
}
7176

77+
public enum SHOW_RANGE_SELECTOR {None,Bottom,Top};
78+
7279
protected boolean fetchGenes = true;
80+
protected boolean dynamicWidth = false;
7381
protected int viewStart = 0;
7482
protected int viewEnd = 0;
7583
protected int width = 1000;
76-
protected int height = 200;
84+
protected int height = 250;
7785
protected String chromosome;
7886
protected DataSource datasource;
7987
protected boolean isShowDescription = true;
8088
protected HashMap<String, String> descriptions = new HashMap<String, String>();
8189
protected String geneInfoUrl = null;
90+
protected SHOW_RANGE_SELECTOR show_range_selector = SHOW_RANGE_SELECTOR.Bottom;
8291

8392
@UiField Processing<GeneViewerInstance> processing;
84-
@UiField FlowPanel container;
8593
@UiField PopupPanel description_popup;
8694
@UiField Label description_label;
8795
@UiField Label position_label;
96+
@UiField FlowPanel container;
8897
//@UiField Label chromosome_label;
8998
@UiField SpanElement name_label;
9099

@@ -97,7 +106,9 @@ public GeneViewer() {
97106

98107
public void setSize(Integer width,Integer height)
99108
{
100-
this.width= width;
109+
if (!dynamicWidth) {
110+
this.width= width;
111+
}
101112
this.height = height;
102113
}
103114

@@ -111,6 +122,8 @@ public void setLength(int length) {
111122
}
112123

113124
public void setViewRegion(int start, int end) {
125+
if (this.viewStart == start && this.viewEnd == end)
126+
return;
114127
this.viewStart = start;
115128
this.viewEnd = end;
116129
if (processing.isLoaded()) {
@@ -126,12 +139,20 @@ public void setGeneInfoUrl(String geneInfoUrl) {
126139
this.geneInfoUrl = geneInfoUrl;
127140
}
128141

142+
public void setRangeSelectorPosition(SHOW_RANGE_SELECTOR show_range_selector) {
143+
this.show_range_selector = show_range_selector;
144+
if (processing.isLoaded())
145+
processing.getInstance().showRangeSelector(this.show_range_selector.ordinal());
146+
}
147+
129148

130149
public void setChromosome(String chromosome) {
131150
this.chromosome = chromosome;
132151
}
133152

134153
public void updateZoom(Integer start,Integer end) {
154+
if (processing.getInstance().getZoomStart() == start && processing.getInstance().getZoomEnd() == end)
155+
return;
135156
if (processing.isLoaded())
136157
processing.getInstance().updateZoom(start,end);
137158
}
@@ -152,14 +173,16 @@ public void setGeneData(JavaScriptObject geneData)
152173
processing.getInstance().setGeneData(geneData);
153174
}
154175

176+
177+
155178
public void load(final Runnable onLoad) throws ResourceException {
156179
Runnable onLoadCode = new Runnable()
157180
{
158181
@Override
159182
public void run() {
160183
if (!processing.isLoaded())
161184
return;
162-
processing.getInstance().setSize(width,height);
185+
processing.getInstance().setLayoutSize(width,height);
163186
processing.getInstance().setViewRegion(viewStart,viewEnd);
164187
processing.getInstance().setChromosome(chromosome);
165188
addFetchGeneHandler(GeneViewer.this);
@@ -327,4 +350,19 @@ public void onClickGene(ClickGeneEvent event) {
327350
if (geneInfoUrl != null && !geneInfoUrl.isEmpty())
328351
Window.open(geneInfoUrl.replace("{0}", event.getGene().getName()),"","");
329352
}
353+
354+
@Override
355+
public void onResize() {
356+
if (!dynamicWidth)
357+
return;
358+
width = container.getOffsetWidth();
359+
if (processing.isLoaded()) {
360+
processing.getInstance().setLayoutSize(width,height);
361+
processing.getInstance().redraw(false);
362+
}
363+
}
364+
365+
public void setDynamicWidth(boolean flag) {
366+
this.dynamicWidth = flag;
367+
}
330368
}

0 commit comments

Comments
 (0)