X-Git-Url: http://git.rot13.org/?p=zxing.git;a=blobdiff_plain;f=zxing.appspot.com%2Fgenerator%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fweb%2Fgenerator%2Fclient%2FContactInfoGenerator.java;h=4cde3a9d82f90890a948c3f4b64f7ca9e7a0d71a;hp=d3d9934e1dcdecb2f6936ddb03a1202694a48b57;hb=af4057be35cd5e29872498541761dc11799a121e;hpb=999e861f9b7260521f9f2245ae2cc9fc645a0746 diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/ContactInfoGenerator.java b/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/ContactInfoGenerator.java index d3d9934e..4cde3a9d 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/ContactInfoGenerator.java +++ b/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/ContactInfoGenerator.java @@ -16,6 +16,7 @@ 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.Grid; import com.google.gwt.user.client.ui.TextBox; @@ -29,18 +30,20 @@ import com.google.gwt.user.client.ui.Widget; public class ContactInfoGenerator implements GeneratorSource { Grid table = null; TextBox name = new TextBox(); - TextBox company = new TextBox(); + //TextBox company = new TextBox(); TextBox tel = new TextBox(); TextBox url = new TextBox(); TextBox email = new TextBox(); TextBox address = new TextBox(); TextBox address2 = new TextBox(); TextBox memo = new TextBox(); - TextBox[] widgets = {name, company, tel, url, email, address, address2, memo}; + TextBox[] widgets = {name, tel, url, email, address, address2, memo}; - public ContactInfoGenerator(ChangeListener changeListener) { + public ContactInfoGenerator(ChangeListener changeListener, + KeyPressHandler keyListener) { for (TextBox w: widgets) { w.addChangeListener(changeListener); + w.addKeyPressHandler(keyListener); } } @@ -50,7 +53,7 @@ public class ContactInfoGenerator implements GeneratorSource { public String getText() throws GeneratorException { String name = getNameField(); - String company = getCompanyField(); + //String company = getCompanyField(); String tel = getTelField(); String url = getUrlField(); String email = getEmailField(); @@ -61,19 +64,19 @@ public class ContactInfoGenerator implements GeneratorSource { // Build the output with obtained data. // note that some informations may just be "" if they were not specified. //return getVCard(name, company, tel, url, email, address, memo); - return getMeCard(name, company, tel, url, email, address, address2, memo); + return getMeCard(name, tel, url, email, address, address2, memo); } - private String getMeCard(String name, String company, String tel, String url, + private String getMeCard(String name, String tel, String url, String email, String address, String address2, String memo) { StringBuilder output = new StringBuilder(); output.append("MECARD:"); + name = name.replace(",", ""); // remove commas -- reserved char in MECARD output.append("N:").append(name).append(';'); - maybeAppend(output, "ORG:", company); + //maybeAppend(output, "ORG:", company); // Not standard; don't generate maybeAppend(output, "TEL:", tel); maybeAppend(output, "URL:", url); maybeAppend(output, "EMAIL:", email); - maybeAppend(output, "ADR:", address); if (address.length() > 0 || address2.length() > 0) { output.append("ADR:"); if (address.length() > 0) { @@ -116,27 +119,31 @@ public class ContactInfoGenerator implements GeneratorSource { } */ - private static String parseTextField(TextBox textBox) throws GeneratorException { + private static String parseTextField(String name, TextBox textBox) throws GeneratorException { String input = textBox.getText(); if (input.length() < 1) { return ""; } if (input.contains("\n")) { - throw new GeneratorException("Field must not contain \\n characters."); + throw new GeneratorException(name + " field must not contain \\n characters."); } if (input.contains(";")) { - throw new GeneratorException("Field must not contains ; characters"); + throw new GeneratorException(name + " field must not contains ; characters"); } return input; } private String getNameField() throws GeneratorException { - return parseTextField(name); + String input = name.getText(); + if (input.length() < 1) { + throw new GeneratorException("Name must be at least 1 character."); + } + return parseTextField("Name", name); } - private String getCompanyField() throws GeneratorException { - return parseTextField(company); - } + //private String getCompanyField() throws GeneratorException { + // return parseTextField("Company", company); + //} private String getTelField() throws GeneratorException { String input = Validators.filterNumber(tel.getText()); @@ -171,15 +178,15 @@ public class ContactInfoGenerator implements GeneratorSource { } private String getAddressField() throws GeneratorException { - return parseTextField(address); + return parseTextField("Address", address); } private String getAddress2Field() throws GeneratorException { - return parseTextField(address2); + return parseTextField("Address 2", address2); } private String getMemoField() throws GeneratorException { - return parseTextField(memo); + return parseTextField("Memo", memo); } public Grid getWidget() { @@ -187,24 +194,22 @@ public class ContactInfoGenerator implements GeneratorSource { // early termination if the table has already been constructed return table; } - table = new Grid(8, 2); + table = new Grid(7, 2); table.setText(0, 0, "Name"); table.setWidget(0, 1, name); - table.setText(1, 0, "Company"); - table.setWidget(1, 1, company); - table.setText(2, 0, "Phone number"); - table.setWidget(2, 1, tel); - table.setText(3, 0, "Email"); - table.setWidget(3, 1, email); - table.setText(4, 0, "Address"); - table.setWidget(4, 1, address); - table.setText(5, 0, "Address 2"); - table.setWidget(5, 1, address2); - table.setText(6, 0, "Website"); - table.setWidget(6, 1, url); - table.setText(7, 0, "Memo"); - table.setWidget(7, 1, memo); + table.setText(1, 0, "Phone number"); + table.setWidget(1, 1, tel); + table.setText(2, 0, "Email"); + table.setWidget(2, 1, email); + table.setText(3, 0, "Address"); + table.setWidget(3, 1, address); + table.setText(4, 0, "Address 2"); + table.setWidget(4, 1, address2); + table.setText(5, 0, "Website"); + table.setWidget(5, 1, url); + table.setText(6, 0, "Memo"); + table.setWidget(6, 1, memo); name.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED); return table; @@ -212,7 +217,7 @@ public class ContactInfoGenerator implements GeneratorSource { public void validate(Widget widget) throws GeneratorException { if (widget == name) getNameField(); - if (widget == company) getCompanyField(); + //if (widget == company) getCompanyField(); if (widget == tel) getTelField(); if (widget == email) getEmailField(); if (widget == address) getAddressField();