Mercurial > hg > STI-GWT
comparison src/econnect/wp3_3/client/widgets/timeplot/Timeplot.java @ 3:cf06b77a8bbd
Committed branch of the e4D repos sti-gwt branch 16384.
git-svn-id: http://dev.dariah.eu/svn/repos/eu.dariah.de/ap1/sti-gwt-dariah-geobrowser@36 f2b5be40-def6-11e0-8a09-b3c1cc336c6b
author | StefanFunk <StefanFunk@f2b5be40-def6-11e0-8a09-b3c1cc336c6b> |
---|---|
date | Tue, 17 Jul 2012 13:34:40 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
2:2897af43ccc6 | 3:cf06b77a8bbd |
---|---|
1 package econnect.wp3_3.client.widgets.timeplot; | |
2 | |
3 import com.google.gwt.user.client.ui.AbsolutePanel; | |
4 import com.google.gwt.user.client.ui.Grid; | |
5 import com.google.gwt.user.client.ui.Image; | |
6 import com.google.gwt.user.client.ui.SimplePanel; | |
7 import com.google.gwt.core.client.GWT; | |
8 import com.google.gwt.dom.client.DivElement; | |
9 import com.google.gwt.dom.client.Document; | |
10 import com.google.gwt.event.dom.client.ClickEvent; | |
11 import com.google.gwt.event.dom.client.ClickHandler; | |
12 | |
13 import econnect.wp3_3.client.slider.Slider; | |
14 import econnect.wp3_3.client.core.ApplicationConstants; | |
15 import econnect.wp3_3.client.core.StiConstants; | |
16 import econnect.wp3_3.client.core.StiCore; | |
17 import econnect.wp3_3.client.widgets.timeplot.StiTimeplot; | |
18 | |
19 /** | |
20 * Implementation of the Java component of the timeplot widget | |
21 */ | |
22 public class Timeplot { | |
23 | |
24 /** | |
25 * The Javascript timeplot object | |
26 */ | |
27 private StiTimeplot jsTimeplot; | |
28 | |
29 /** | |
30 * The slider component of the timeplot controls | |
31 */ | |
32 private Slider zoomSlider; | |
33 | |
34 /** | |
35 * The animation control image container | |
36 */ | |
37 private Image animation; | |
38 | |
39 /** | |
40 * If animation is possible (selected time range) | |
41 */ | |
42 private boolean enableAnimation = false; | |
43 | |
44 /** | |
45 * Constructor for the timeplot widget java component | |
46 * | |
47 * @param core object to allow interaction with all javascript components | |
48 * @param window id of the window to embed the timeplot widget | |
49 * @param container id of the container, the window will be added | |
50 */ | |
51 public Timeplot( StiCore core, String window, String container ){ | |
52 this.jsTimeplot = StiTimeplot.createStiTimeplot(core, window, container); | |
53 } | |
54 | |
55 /** | |
56 * initializes the controls needed for timeplot interaction | |
57 * | |
58 * @return a grid of control elements | |
59 */ | |
60 public Grid initPlotControls(){ | |
61 | |
62 final ApplicationConstants constants = (ApplicationConstants) GWT.create(ApplicationConstants.class); | |
63 final StiConstants textConstants = (StiConstants) GWT.create(StiConstants.class); | |
64 | |
65 this.animation = new Image(); | |
66 this.animation.setTitle(textConstants.animation0()); | |
67 this.animation.setUrl(constants.playDisabled()); | |
68 this.animation.addClickHandler(new ClickHandler() { | |
69 public void onClick(ClickEvent event) { | |
70 if( enableAnimation ){ | |
71 if( jsTimeplot.paused() ){ | |
72 jsTimeplot.play(); | |
73 } | |
74 else { | |
75 jsTimeplot.pause(); | |
76 } | |
77 } | |
78 } | |
79 }); | |
80 | |
81 final Grid controlGrid = new Grid(2,1); | |
82 controlGrid.setWidget(0, 0, this.animation); | |
83 | |
84 DivElement zoomDiv = Document.get().createDivElement(); | |
85 zoomSlider = new Slider(zoomDiv,"vertical"); | |
86 zoomSlider.getSlider().setMaximum(100); | |
87 zoomSlider.getSlider().setValue(0); | |
88 zoomSlider.getSlider().addChangeListener(jsTimeplot,Document.get(),false); | |
89 | |
90 Image zoomIn = new Image(constants.zoomInImage()); | |
91 zoomIn.addClickHandler(new ClickHandler() { | |
92 public void onClick(ClickEvent event) { | |
93 jsTimeplot.zoom(1); | |
94 } | |
95 }); | |
96 Image zoomOut = new Image(constants.zoomOutImage()); | |
97 zoomOut.addClickHandler(new ClickHandler() { | |
98 public void onClick(ClickEvent event) { | |
99 jsTimeplot.zoom(-1); | |
100 } | |
101 }); | |
102 | |
103 SimplePanel zoom = new SimplePanel(); | |
104 zoom.getElement().appendChild(zoomDiv); | |
105 | |
106 AbsolutePanel zoomPanel = new AbsolutePanel(); | |
107 zoomPanel.addStyleName("sliderStyle"); | |
108 zoomPanel.addStyleName("cellStyle"); | |
109 zoomPanel.addStyleName("center"); | |
110 zoomPanel.add(zoomIn,2,0); | |
111 zoomPanel.add(zoom,0,10); | |
112 zoomPanel.add(zoomOut,2,84); | |
113 zoomIn.addStyleName("zHigh"); | |
114 zoomOut.addStyleName("zHigh"); | |
115 zoomPanel.setTitle(textConstants.plotZoom()); | |
116 | |
117 controlGrid.setWidget(1, 0, zoomPanel); | |
118 return controlGrid; | |
119 | |
120 } | |
121 | |
122 /** | |
123 * changes images of animation controls | |
124 */ | |
125 public void animationImage( boolean enable ){ | |
126 final ApplicationConstants constants = (ApplicationConstants) GWT.create(ApplicationConstants.class); | |
127 final StiConstants textConstants = (StiConstants) GWT.create(StiConstants.class); | |
128 this.enableAnimation = enable; | |
129 if( enable ){ | |
130 if( jsTimeplot.paused() ){ | |
131 animation.setUrl(constants.playEnabled()); | |
132 animation.setTitle(textConstants.animation1()); | |
133 } | |
134 else { | |
135 animation.setUrl(constants.pauseEnabled()); | |
136 animation.setTitle(textConstants.animation2()); | |
137 } | |
138 } | |
139 else { | |
140 animation.setUrl(constants.playDisabled()); | |
141 animation.setTitle(textConstants.animation0()); | |
142 } | |
143 } | |
144 | |
145 /** | |
146 * sets zoom levels of corresponding zoom slider | |
147 * | |
148 * @param levels number of zoom levels | |
149 */ | |
150 public void setZoomLevels( int levels ){ | |
151 zoomSlider.getSlider().setMaximum(levels); | |
152 } | |
153 | |
154 /** | |
155 * sets value of corresponding zoom slider | |
156 * | |
157 * @param value value to set | |
158 */ | |
159 public void setValue( int value ){ | |
160 zoomSlider.getSlider().setValue(value); | |
161 } | |
162 | |
163 /** | |
164 * Getter for the value of corresponding zoom slider | |
165 * | |
166 * @return actual zoom slider value | |
167 */ | |
168 public int getValue(){ | |
169 return zoomSlider.getSlider().getValue(); | |
170 } | |
171 | |
172 /** | |
173 * Getter for the corresponding Javascript component of the Timeplot | |
174 * | |
175 * @return the Javascript component of the Timeplot | |
176 */ | |
177 public StiTimeplot getJsTimeplot(){ | |
178 return this.jsTimeplot; | |
179 } | |
180 | |
181 } |