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.event.dom.client.KeyPressHandler;
20 import com.google.gwt.user.client.ui.ChangeListener;
21 import com.google.gwt.user.client.ui.Grid;
22 import com.google.gwt.user.client.ui.TextBox;
23 import com.google.gwt.user.client.ui.Widget;
26 * A generator for URL addresses.
28 * @author Yohann Coppel
30 public class UrlGenerator implements GeneratorSource {
32 TextBox url = new TextBox();
34 public UrlGenerator(ChangeListener listener, KeyPressHandler keyListener) {
35 url.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED);
36 url.addChangeListener(listener);
37 url.addKeyPressHandler(keyListener);
40 public Grid getWidget() {
42 // early termination if the table has already been constructed
46 table = new Grid(1, 2);
47 table.getColumnFormatter().addStyleName(0, "firstColumn");
49 url.setText("http://");
51 table.setText(0, 0, "URL");
52 table.setWidget(0, 1, url);
57 public String getName() {
61 public String getText() throws GeneratorException {
65 private String getUrlField() throws GeneratorException {
66 String input = url.getText();
67 Validators.validateUrl(input);
71 public void validate(Widget widget) throws GeneratorException {
77 public void setFocus() {