2 * Copyright (C) 2008 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.web.generator.client;
19 import com.google.gwt.user.client.ui.ChangeListener;
20 import com.google.gwt.user.client.ui.Grid;
21 import com.google.gwt.user.client.ui.TextBox;
22 import com.google.gwt.user.client.ui.Widget;
25 * Generator for email address.
27 * @author Yohann Coppel
29 public class EmailGenerator implements GeneratorSource {
31 TextBox email = new TextBox();
33 public EmailGenerator(ChangeListener listener) {
34 email.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED);
35 email.addChangeListener(listener);
38 public String getName() {
39 return "Email address";
42 public String getText() throws GeneratorException {
43 String email = getEmailField();
44 return "mailto:"+email;
47 private String getEmailField() throws GeneratorException {
48 String input = email.getText();
49 if (input.length() < 1) {
50 throw new GeneratorException("Email must be present.");
52 Validators.validateEmail(input);
56 public Grid getWidget() {
60 table = new Grid(1, 2);
62 table.setText(0, 0, "Address");
63 table.setWidget(0, 1, email);
68 public void validate(Widget widget) throws GeneratorException {
69 if (widget == email) getEmailField();
72 public void setFocus() {