12 |
ddelon |
1 |
/*
|
|
|
2 |
* Copyright 2006 Google Inc.
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
5 |
* use this file except in compliance with the License. You may obtain a copy of
|
|
|
6 |
* 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, WITHOUT
|
|
|
12 |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
13 |
* License for the specific language governing permissions and limitations under
|
|
|
14 |
* the License.
|
|
|
15 |
*/
|
|
|
16 |
package org.tela_botanica.client;
|
|
|
17 |
|
|
|
18 |
import java.util.Date;
|
|
|
19 |
|
|
|
20 |
import com.google.gwt.user.client.DOM;
|
|
|
21 |
import com.google.gwt.user.client.Element;
|
|
|
22 |
import com.google.gwt.user.client.ui.Button;
|
|
|
23 |
import com.google.gwt.user.client.ui.ChangeListener;
|
|
|
24 |
import com.google.gwt.user.client.ui.ClickListener;
|
|
|
25 |
import com.google.gwt.user.client.ui.Composite;
|
|
|
26 |
import com.google.gwt.user.client.ui.Grid;
|
|
|
27 |
import com.google.gwt.user.client.ui.HTML;
|
|
|
28 |
import com.google.gwt.user.client.ui.HorizontalPanel;
|
|
|
29 |
import com.google.gwt.user.client.ui.KeyboardListener;
|
|
|
30 |
import com.google.gwt.user.client.ui.PopupPanel;
|
|
|
31 |
import com.google.gwt.user.client.ui.RootPanel;
|
|
|
32 |
import com.google.gwt.user.client.ui.TextBox;
|
|
|
33 |
import com.google.gwt.user.client.ui.UIObject;
|
|
|
34 |
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
35 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Composite permet de wrapper des Widget pour creer un nouveau Widget cf methode initWidget()
|
|
|
39 |
*/
|
|
|
40 |
|
|
|
41 |
public class EntryPanel extends Composite implements ClickListener {
|
|
|
42 |
|
|
|
43 |
private NameAssistant nameAssistant = null;
|
|
|
44 |
private LocationAssistant locationAssistant = null;
|
|
|
45 |
TextBox date = new TextBox();
|
|
|
46 |
TextBox complementLocation = new TextBox();
|
|
|
47 |
TextBox comment = new TextBox();
|
|
|
48 |
Button dateSelector = new Button("...");
|
|
|
49 |
boolean visible=false;
|
|
|
50 |
Mediator mediator=null;
|
|
|
51 |
|
|
|
52 |
final CalendarWidget calendar = new CalendarWidget();
|
|
|
53 |
|
|
|
54 |
private PopupPanel choicesPopup = new PopupPanel(true);
|
|
|
55 |
|
|
|
56 |
public EntryPanel(final Mediator med) {
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
mediator=med;
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
mediator.registerEntryPanel(this);
|
|
|
64 |
|
|
|
65 |
mediator.registerDate(date);
|
|
|
66 |
mediator.registerComment(comment);
|
|
|
67 |
mediator.registerComplementLocation(complementLocation);
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
VerticalPanel outer = new VerticalPanel();
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
outer.add(new HTML("<b>Nouvelle observation:</b>"));
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
Grid inner = new Grid(3,4);
|
|
|
79 |
|
|
|
80 |
for (int i=0; i<3;i++) {
|
|
|
81 |
inner.getCellFormatter().setWidth(i, 0, "3%");
|
|
|
82 |
inner.getCellFormatter().setWidth(i, 1, "47%");
|
|
|
83 |
inner.getCellFormatter().setWidth(i, 2, "3%");
|
|
|
84 |
inner.getCellFormatter().setWidth(i, 3, "47%");
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
nameAssistant = new NameAssistant(mediator);
|
|
|
89 |
locationAssistant = new LocationAssistant(mediator);
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
// Saisie Nom
|
|
|
93 |
|
|
|
94 |
HTML labelNameAssistant = new HTML("Espèce: ");
|
|
|
95 |
inner.setWidget(0,0,labelNameAssistant);
|
|
|
96 |
inner.setWidget(0,1,nameAssistant);
|
|
|
97 |
|
|
|
98 |
nameAssistant.setWidth("100%");
|
|
|
99 |
|
|
|
100 |
// Saisie lieu
|
|
|
101 |
|
|
|
102 |
HTML labelLocationAssistant= new HTML("Commune: ");
|
|
|
103 |
inner.setWidget(1,0,labelLocationAssistant);
|
|
|
104 |
inner.setWidget(1,1,locationAssistant);
|
|
|
105 |
|
|
|
106 |
locationAssistant.setWidth("100%");
|
|
|
107 |
|
|
|
108 |
// Saisie Date
|
|
|
109 |
|
|
|
110 |
choicesPopup.add(calendar);
|
|
|
111 |
|
|
|
112 |
dateSelector.addClickListener(new ClickListener () {
|
|
|
113 |
|
|
|
114 |
public void onClick(Widget w) {
|
|
|
115 |
|
|
|
116 |
if (visible) {
|
|
|
117 |
visible=false;
|
|
|
118 |
choicesPopup.hide();
|
|
|
119 |
}
|
|
|
120 |
else {
|
|
|
121 |
visible=true;
|
|
|
122 |
choicesPopup.show();
|
|
|
123 |
choicesPopup.setPopupPosition(dateSelector.getAbsoluteLeft(),
|
|
|
124 |
dateSelector.getAbsoluteTop() + dateSelector.getOffsetHeight());
|
|
|
125 |
choicesPopup.setWidth(dateSelector.getOffsetWidth() + "px");
|
|
|
126 |
}
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
});
|
|
|
130 |
|
|
|
131 |
calendar.addChangeListener(new ChangeListener() {
|
|
|
132 |
|
|
|
133 |
public void onChange(Widget sender) {
|
|
|
134 |
|
|
|
135 |
Date dateSelected=calendar.getDate();
|
|
|
136 |
date.setText(dateSelected.getDate()+"/"+(dateSelected.getMonth()+1)+"/"+(dateSelected.getYear()+1900));
|
|
|
137 |
|
|
|
138 |
visible=false;
|
|
|
139 |
choicesPopup.hide();
|
|
|
140 |
}
|
|
|
141 |
});
|
|
|
142 |
|
|
|
143 |
HTML labelDate= new HTML("Date: ");
|
|
|
144 |
inner.setWidget(2,0,labelDate);
|
|
|
145 |
|
|
|
146 |
HorizontalPanel datePanel = new HorizontalPanel();
|
|
|
147 |
datePanel.add(date);
|
|
|
148 |
datePanel.add(dateSelector);
|
|
|
149 |
inner.setWidget(2,1,datePanel);
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
date.addKeyboardListener( new KeyboardListener() {
|
|
|
155 |
|
|
|
156 |
public void onKeyDown(Widget arg0, char arg1, int arg2) {
|
|
|
157 |
|
|
|
158 |
|
|
|
159 |
if(arg1 == KEY_ENTER)
|
|
|
160 |
{
|
|
|
161 |
mediator.onAddInventoryItem();
|
|
|
162 |
date.setText("");
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
public void onKeyUp(Widget arg0, char arg1, int arg2) {
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
public void onKeyPress(Widget arg0, char arg1, int arg2) {
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
}
|
|
|
174 |
);
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
|
178 |
// Saisie Complement lieu
|
|
|
179 |
|
|
|
180 |
HTML labelComplementLocation= new HTML("Station: ");
|
|
|
181 |
inner.setWidget(1,2,labelComplementLocation);
|
|
|
182 |
inner.setWidget(1,3,complementLocation);
|
|
|
183 |
|
|
|
184 |
complementLocation.setWidth("100%");
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
complementLocation.addKeyboardListener( new KeyboardListener() {
|
|
|
188 |
|
|
|
189 |
public void onKeyDown(Widget arg0, char arg1, int arg2) {
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
if(arg1 == KEY_ENTER)
|
|
|
193 |
{
|
|
|
194 |
mediator.onAddInventoryItem();
|
|
|
195 |
complementLocation.setText("");
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
public void onKeyUp(Widget arg0, char arg1, int arg2) {
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
public void onKeyPress(Widget arg0, char arg1, int arg2) {
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
}
|
|
|
207 |
);
|
|
|
208 |
|
|
|
209 |
|
|
|
210 |
// Saisie Commentaire
|
|
|
211 |
|
|
|
212 |
HTML labelComment= new HTML("Notes: ");
|
|
|
213 |
inner.setWidget(2,2,labelComment);
|
|
|
214 |
inner.setWidget(2,3,comment);
|
|
|
215 |
|
|
|
216 |
comment.setWidth("100%");
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
comment.addKeyboardListener( new KeyboardListener() {
|
|
|
220 |
|
|
|
221 |
public void onKeyDown(Widget arg0, char arg1, int arg2) {
|
|
|
222 |
|
|
|
223 |
|
|
|
224 |
if(arg1 == KEY_ENTER)
|
|
|
225 |
{
|
|
|
226 |
mediator.onAddInventoryItem();
|
|
|
227 |
comment.setText("");
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
public void onKeyUp(Widget arg0, char arg1, int arg2) {
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
public void onKeyPress(Widget arg0, char arg1, int arg2) {
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
}
|
|
|
239 |
);
|
|
|
240 |
|
|
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
|
244 |
inner.setWidth("100%");
|
|
|
245 |
|
|
|
246 |
outer.add(inner);
|
|
|
247 |
outer.setCellWidth(inner, "100%");
|
|
|
248 |
|
|
|
249 |
|
|
|
250 |
|
|
|
251 |
Button close = new Button("Cacher");
|
|
|
252 |
close.addClickListener(this);
|
|
|
253 |
|
|
|
254 |
outer.setHorizontalAlignment(HorizontalPanel.ALIGN_CENTER);
|
|
|
255 |
|
|
|
256 |
|
|
|
257 |
outer.add(close);
|
|
|
258 |
|
|
|
259 |
|
|
|
260 |
initWidget(outer);
|
|
|
261 |
|
|
|
262 |
setPixelSize(1000,200);
|
|
|
263 |
|
|
|
264 |
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
public void onClick(Widget sender) {
|
|
|
268 |
hide();
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
|
|
|
272 |
public void show() {
|
|
|
273 |
|
|
|
274 |
DOM.setStyleAttribute(getElement(), "backgroundColor", "white");
|
|
|
275 |
this.setOpacity(this,85);
|
|
|
276 |
RootPanel.get().remove(this);
|
|
|
277 |
RootPanel.get().add(this,200,200);
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
public void hide() {
|
|
|
281 |
this.setOpacity(RootPanel.get(),100);
|
|
|
282 |
RootPanel.get().remove(this);
|
|
|
283 |
}
|
|
|
284 |
|
|
|
285 |
|
|
|
286 |
private void setOpacity(UIObject e, int percentage) {
|
|
|
287 |
if ( percentage > 100 ) percentage = 100;
|
|
|
288 |
if ( percentage < 0 ) percentage = 0;
|
|
|
289 |
|
|
|
290 |
String opac;
|
|
|
291 |
if ( percentage == 100 ) opac = "1";
|
|
|
292 |
else if ( percentage == 0 ) opac = "0";
|
|
|
293 |
else if ( percentage < 10 ) opac = ".0" + percentage;
|
|
|
294 |
else opac = "." + percentage;
|
|
|
295 |
|
|
|
296 |
Element h = e.getElement();
|
|
|
297 |
DOM.setStyleAttribute(h, "filter", "alpha(opacity=" + percentage + ")");
|
|
|
298 |
DOM.setStyleAttribute(h, "opacity", opac);
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
}
|