In barcode generaotor (zxing.appspot.com), generate barcode upon pressing enter. Issue 229: http://code.google.com/p/zxing/issues/detail?id=229.

git-svn-id: https://zxing.googlecode.com/svn/trunk@1113 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
leppoc 2009-11-18 23:15:52 +00:00
parent f919bbcba5
commit dcb68910a2
8 changed files with 47 additions and 15 deletions

View file

@ -16,6 +16,7 @@
package com.google.zxing.web.generator.client; package com.google.zxing.web.generator.client;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Element;
@ -59,9 +60,11 @@ public class CalendarEventGenerator implements GeneratorSource {
ListBox timeZones = new ListBox(); ListBox timeZones = new ListBox();
Date timePicker1PreviousDate = null; Date timePicker1PreviousDate = null;
public CalendarEventGenerator(final ChangeListener listener) { public CalendarEventGenerator(final ChangeListener listener,
KeyPressHandler keyListener) {
eventName.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED); eventName.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED);
eventName.addChangeListener(listener); eventName.addChangeListener(listener);
eventName.addKeyPressHandler(keyListener);
datePicker1.setAnimationEnabled(true); datePicker1.setAnimationEnabled(true);
datePicker2.setAnimationEnabled(true); datePicker2.setAnimationEnabled(true);
timePicker2 timePicker2
@ -70,6 +73,7 @@ public class CalendarEventGenerator implements GeneratorSource {
buildTimeZoneList(); buildTimeZoneList();
timeZones.setSelectedIndex(25); timeZones.setSelectedIndex(25);
timeZones.addKeyPressHandler(keyListener);
timePicker1.addChangeHandler(new ChangeHandler<Date>() { timePicker1.addChangeHandler(new ChangeHandler<Date>() {
public void onChange(ChangeEvent<Date> event) { public void onChange(ChangeEvent<Date> event) {
Date time = timePicker1PreviousDate; Date time = timePicker1PreviousDate;

View file

@ -16,6 +16,7 @@
package com.google.zxing.web.generator.client; package com.google.zxing.web.generator.client;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.user.client.ui.ChangeListener; import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.Grid; import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.TextBox;
@ -38,9 +39,11 @@ public class ContactInfoGenerator implements GeneratorSource {
TextBox memo = new TextBox(); TextBox memo = new TextBox();
TextBox[] widgets = {name, company, tel, url, email, address, address2, memo}; TextBox[] widgets = {name, company, tel, url, email, address, address2, memo};
public ContactInfoGenerator(ChangeListener changeListener) { public ContactInfoGenerator(ChangeListener changeListener,
KeyPressHandler keyListener) {
for (TextBox w: widgets) { for (TextBox w: widgets) {
w.addChangeListener(changeListener); w.addChangeListener(changeListener);
w.addKeyPressHandler(keyListener);
} }
} }

View file

@ -16,6 +16,7 @@
package com.google.zxing.web.generator.client; package com.google.zxing.web.generator.client;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.user.client.ui.ChangeListener; import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.Grid; import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.TextBox;
@ -30,9 +31,10 @@ public class EmailGenerator implements GeneratorSource {
Grid table = null; Grid table = null;
TextBox email = new TextBox(); TextBox email = new TextBox();
public EmailGenerator(ChangeListener listener) { public EmailGenerator(ChangeListener listener, KeyPressHandler keyListener) {
email.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED); email.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED);
email.addChangeListener(listener); email.addChangeListener(listener);
email.addKeyPressHandler(keyListener);
} }
public String getName() { public String getName() {

View file

@ -18,6 +18,8 @@ package com.google.zxing.web.generator.client;
import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.http.client.URL; import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.Button;
@ -103,14 +105,14 @@ public class Generator implements EntryPoint {
} }
private void loadGenerators() { private void loadGenerators() {
generators.add(new CalendarEventGenerator(changeListener)); generators.add(new CalendarEventGenerator(changeListener, keyPressHandler));
generators.add(new ContactInfoGenerator(changeListener)); generators.add(new ContactInfoGenerator(changeListener, keyPressHandler));
generators.add(new EmailGenerator(changeListener)); generators.add(new EmailGenerator(changeListener, keyPressHandler));
generators.add(new GeoLocationGenerator(changeListener)); generators.add(new GeoLocationGenerator(changeListener, keyPressHandler));
generators.add(new PhoneNumberGenerator(changeListener)); generators.add(new PhoneNumberGenerator(changeListener, keyPressHandler));
generators.add(new SmsAddressGenerator(changeListener)); generators.add(new SmsAddressGenerator(changeListener, keyPressHandler));
generators.add(new TextGenerator(changeListener)); generators.add(new TextGenerator(changeListener));
generators.add(new UrlGenerator(changeListener)); generators.add(new UrlGenerator(changeListener, keyPressHandler));
} }
public void setupLeftPanel() { public void setupLeftPanel() {
@ -237,4 +239,12 @@ public class Generator implements EntryPoint {
} }
}; };
public KeyPressHandler keyPressHandler = new KeyPressHandler() {
@Override
public void onKeyPress(KeyPressEvent event) {
if (event.getCharCode() == '\n' || event.getCharCode() == '\r') {
generate();
}
}
};
} }

View file

@ -16,6 +16,7 @@
package com.google.zxing.web.generator.client; package com.google.zxing.web.generator.client;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.http.client.URL; import com.google.gwt.http.client.URL;
import com.google.gwt.maps.client.MapWidget; import com.google.gwt.maps.client.MapWidget;
import com.google.gwt.maps.client.control.SmallMapControl; import com.google.gwt.maps.client.control.SmallMapControl;
@ -52,15 +53,19 @@ public class GeoLocationGenerator implements GeneratorSource, ChangeListener {
Marker mapMarker = null; Marker mapMarker = null;
private ChangeListener changeListener; private ChangeListener changeListener;
public GeoLocationGenerator(ChangeListener listener) { public GeoLocationGenerator(ChangeListener listener,
KeyPressHandler keyListener) {
this.changeListener = listener; this.changeListener = listener;
latitude.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED); latitude.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED);
longitude.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED);
latitude.addChangeListener(listener); latitude.addChangeListener(listener);
latitude.addChangeListener(this); latitude.addChangeListener(this);
latitude.addKeyPressHandler(keyListener);
longitude.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED);
longitude.addChangeListener(listener); longitude.addChangeListener(listener);
longitude.addChangeListener(this); longitude.addChangeListener(this);
longitude.addKeyPressHandler(keyListener);
query.addChangeListener(listener); query.addChangeListener(listener);
query.addKeyPressHandler(keyListener);
} }
public String getName() { public String getName() {

View file

@ -16,6 +16,7 @@
package com.google.zxing.web.generator.client; package com.google.zxing.web.generator.client;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.user.client.ui.ChangeListener; import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.Grid; import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.TextBox;
@ -30,9 +31,11 @@ public class PhoneNumberGenerator implements GeneratorSource {
Grid table = null; Grid table = null;
TextBox number = new TextBox(); TextBox number = new TextBox();
public PhoneNumberGenerator(ChangeListener listener) { public PhoneNumberGenerator(ChangeListener listener,
KeyPressHandler keyListener) {
number.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED); number.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED);
number.addChangeListener(listener); number.addChangeListener(listener);
number.addKeyPressHandler(keyListener);
} }
public String getName() { public String getName() {

View file

@ -16,6 +16,7 @@
package com.google.zxing.web.generator.client; package com.google.zxing.web.generator.client;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.user.client.ui.ChangeListener; import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.Grid; import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.TextArea; import com.google.gwt.user.client.ui.TextArea;
@ -33,9 +34,11 @@ public class SmsAddressGenerator implements GeneratorSource {
TextBox number = new TextBox(); TextBox number = new TextBox();
TextArea message = new TextArea(); TextArea message = new TextArea();
public SmsAddressGenerator(ChangeListener listener) { public SmsAddressGenerator(ChangeListener listener,
KeyPressHandler keyListener) {
number.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED); number.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED);
number.addChangeListener(listener); number.addChangeListener(listener);
number.addKeyPressHandler(keyListener);
message.addChangeListener(listener); message.addChangeListener(listener);
} }

View file

@ -16,6 +16,7 @@
package com.google.zxing.web.generator.client; package com.google.zxing.web.generator.client;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.user.client.ui.ChangeListener; import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.Grid; import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.TextBox;
@ -30,9 +31,10 @@ public class UrlGenerator implements GeneratorSource {
Grid table = null; Grid table = null;
TextBox url = new TextBox(); TextBox url = new TextBox();
public UrlGenerator(ChangeListener listener) { public UrlGenerator(ChangeListener listener, KeyPressHandler keyListener) {
url.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED); url.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED);
url.addChangeListener(listener); url.addChangeListener(listener);
url.addKeyPressHandler(keyListener);
} }
public Grid getWidget() { public Grid getWidget() {