diff --git a/build.properties b/build.properties index a7fcf7fc5..5787c83a7 100644 --- a/build.properties +++ b/build.properties @@ -15,5 +15,5 @@ version=2.0 # Uncomment and set this variable if building the zxing.appspot.com subdirectory. It points to the # location of the Google Web Toolkit (GWT) which can be downloaded here: # http://code.google.com/webtoolkit/ -# It builds against GWT 2.0.1 at the moment. +# It builds against GWT 2.4 at the moment. #GWT-home=/usr/local/gwt diff --git a/zxing.appspot.com/Generator.launch b/zxing.appspot.com/Generator.launch new file mode 100644 index 000000000..c08ce8fe8 --- /dev/null +++ b/zxing.appspot.com/Generator.launch @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/zxing.appspot.com/README b/zxing.appspot.com/README index 27812c3c4..08215b44b 100644 --- a/zxing.appspot.com/README +++ b/zxing.appspot.com/README @@ -1,14 +1,84 @@ -To compile: ----------- -Run 'ant' in this directory. You might get a lot of warnings with -[WARN] but you should not get any errors. +--- Generated by GWT WebAppCreator --- +Congratulations, you've successfully generated a starter project! What next? -To test: -------- -View the file "build/site/generator/index.html" in any browser. You can do -this from the commandline with: +-- Option A: Import your project into Eclipse (recommended) -- -firefox build/site/generator/index.html +If you use Eclipse, you can simply import the generated project into Eclipse. +We've tested against Eclipse 3.4 and 3.5. Later versions will likely also +work, earlier versions may not. -Now you can try out your changes. +If the directory containing this file does not have a .classpath or .project +file, generate them by running 'ant eclipse.generate' + +In Eclipse, go to the File menu and choose: + + File -> Import... -> Existing Projects into Workspace + + Browse to the directory containing this file, + select "Generator". + + Be sure to uncheck "Copy projects into workspace" if it is checked. + + Click Finish. + +You can now browse the project in Eclipse. + +To launch your web app in GWT development mode, go to the Run menu and choose: + + Run -> Open Debug Dialog... + + Under Java Application, you should find a launch configuration + named "Generator". Select and click "Debug". + + You can now use the built-in debugger to debug your web app in development mode. + +If you supplied the junit path when invoking webAppCreator, you should see +launch configurations for running your tests in development and production +mode. + +-- Option B: Build from the command line with Ant -- + +If you prefer to work from the command line, you can use Ant to build your +project. (http://ant.apache.org/) Ant uses the generated 'build.xml' file +which describes exactly how to build your project. This file has been tested +to work against Ant 1.7.1. The following assumes 'ant' is on your command +line path. + +To run development mode, just type 'ant devmode'. + +To compile your project for deployment, just type 'ant'. + +To compile and also bundle into a .war file, type 'ant war'. + +If you supplied the junit path when invoking webAppCreator, you can type 'ant +test' to run tests in development and production mode. + +For a full listing of other targets, type 'ant -p'. + +-- Option C: Using another IDE -- + +GWT projects can be run in other IDEs as well, but will require some manual +setup. If you go this route, be sure to: + +* Have your IDE build .class files into 'war/WEB-INF/classes'. +* Add gwt-user.jar and gwt-dev.jar to your project build path. +* When creating a launch configuration, add a classpath entry for your 'src' + folder (this is somewhat unusual but GWT needs access to your source files). + +If you get stuck, try to mimic what the Ant 'build.xml' would do. + +-- Option D: Using Maven -- + +If you have generated your project with the option '-maven', you have a 'pom.xml' +file ready to use. Assuming you have 'maven2' installed in your system, 'mvn' is +in your path, and you have access to maven repositories, you should be able to run: + +mvn clean # delete temporary stuff +mvn test # run all the tests (gwt and junit) +mvn gwt:run # run development mode +mvn gwt:compile # compile to javascript +mvn package # generate a .war package ready to deploy + +For more information about other available goals, read maven and gwt-maven-plugin +documentation (http://maven.apache.org, http://mojo.codehaus.org/gwt-maven-plugin) diff --git a/zxing.appspot.com/app.yaml b/zxing.appspot.com/app.yaml deleted file mode 100644 index 0463ea94d..000000000 --- a/zxing.appspot.com/app.yaml +++ /dev/null @@ -1,23 +0,0 @@ -application: zxing -version: 2 -runtime: python -api_version: 1 - -handlers: -- url: /generator - script: redirect.py - -- url: /scan - static_files: site/scan.html - upload: site/scan.html - -- url: /favicon.ico - static_files: static/favicon.ico - upload: static/favicon.ico - -- url: (.*)/ - static_files: site\1/index.html - upload: site/index.html - -- url: / - static_dir: site diff --git a/zxing.appspot.com/build.xml b/zxing.appspot.com/build.xml index efc01550f..c7502b7ad 100644 --- a/zxing.appspot.com/build.xml +++ b/zxing.appspot.com/build.xml @@ -14,66 +14,92 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - - + - - - - - - + - - + + - - - Creating output directories if needed... - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - Copying static files... - - - - + + + + + + + - - - Renaming generator output... - - + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + - - + + + + + + + + + diff --git a/zxing.appspot.com/generator/.classpath b/zxing.appspot.com/generator/.classpath deleted file mode 100644 index dba0fea7e..000000000 --- a/zxing.appspot.com/generator/.classpath +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/zxing.appspot.com/generator/.project b/zxing.appspot.com/generator/.project deleted file mode 100644 index 9eada68e6..000000000 --- a/zxing.appspot.com/generator/.project +++ /dev/null @@ -1,27 +0,0 @@ - - - BarcodeGenerator - BarcodeGenerator project - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.jdt.core.javanature - - - - gwt-user.jar - 1 - GWT_HOME/gwt-user.jar - - - gwt.jar - 1 - GWT_JAR - - - diff --git a/zxing.appspot.com/generator/Generator.launch b/zxing.appspot.com/generator/Generator.launch deleted file mode 100644 index 8e6da460c..000000000 --- a/zxing.appspot.com/generator/Generator.launch +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/zxing.appspot.com/generator/README b/zxing.appspot.com/generator/README deleted file mode 100644 index cb9891bcb..000000000 --- a/zxing.appspot.com/generator/README +++ /dev/null @@ -1,11 +0,0 @@ - - -To develop with Eclipse. - -Before importing the project, you need to define some variables. -- In Eclipse Preferences, go to General->Workspace->Linked Resources. -- Click New and add the 2 following variables: - - GWT_HOME that point to the directory containing gwt-user.jar - - GWT_JAR that point to the gwt-dev-XXX.jar file directly. (XXX will be linux, mac, etc) -- then you can import the project by File->Import...->Existing project into workspace. - diff --git a/zxing.appspot.com/generator/libs/gwt-maps.jar b/zxing.appspot.com/generator/libs/gwt-maps.jar deleted file mode 100644 index 67eb6a57b..000000000 Binary files a/zxing.appspot.com/generator/libs/gwt-maps.jar and /dev/null differ diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/Generator.gwt.xml b/zxing.appspot.com/generator/src/com/google/zxing/web/generator/Generator.gwt.xml deleted file mode 100644 index 145cedbb8..000000000 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/Generator.gwt.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - - - - - -
- - - - diff --git a/zxing.appspot.com/redirect.py b/zxing.appspot.com/redirect.py deleted file mode 100644 index ed1cccb61..000000000 --- a/zxing.appspot.com/redirect.py +++ /dev/null @@ -1,17 +0,0 @@ -from google.appengine.ext import webapp -from google.appengine.ext.webapp.util import run_wsgi_app - -class BlogHandler(webapp.RequestHandler): - def get(self, tail = ''): - self.redirect('/generator/'+tail, permanent = True) - -application = webapp.WSGIApplication( - [ - (r'^/generator$', BlogHandler) - ]) - -def main(): - run_wsgi_app(application) - -if __name__ == "__main__": - main() diff --git a/zxing.appspot.com/src/com/google/zxing/web/generator/Generator.gwt.xml b/zxing.appspot.com/src/com/google/zxing/web/generator/Generator.gwt.xml new file mode 100644 index 000000000..1f4f19df7 --- /dev/null +++ b/zxing.appspot.com/src/com/google/zxing/web/generator/Generator.gwt.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/CalendarEventGenerator.java b/zxing.appspot.com/src/com/google/zxing/web/generator/client/CalendarEventGenerator.java similarity index 70% rename from zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/CalendarEventGenerator.java rename to zxing.appspot.com/src/com/google/zxing/web/generator/client/CalendarEventGenerator.java index afa7ae90b..ebdf81a3f 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/CalendarEventGenerator.java +++ b/zxing.appspot.com/src/com/google/zxing/web/generator/client/CalendarEventGenerator.java @@ -16,68 +16,67 @@ package com.google.zxing.web.generator.client; +import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.event.dom.client.ChangeHandler; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.KeyPressHandler; +import com.google.gwt.event.logical.shared.ValueChangeEvent; +import com.google.gwt.event.logical.shared.ValueChangeHandler; +import com.google.gwt.gen2.picker.client.TimePicker; import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; -import com.google.gwt.user.client.ui.ChangeListener; import com.google.gwt.user.client.ui.CheckBox; -import com.google.gwt.user.client.ui.ClickListener; import com.google.gwt.user.client.ui.Grid; import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.Widget; -import com.google.gwt.widgetideas.client.event.ChangeEvent; -import com.google.gwt.widgetideas.client.event.ChangeHandler; -import com.google.gwt.widgetideas.datepicker.client.DateBox; -import com.google.gwt.widgetideas.datepicker.client.TimePicker; -import com.google.zxing.web.generator.client.TimeZoneList.TimeZoneInfo; +import com.google.gwt.user.datepicker.client.DatePicker; import java.util.Date; /** - * A Generator for calendar events. Output is in VCal format. + * A Generator for calendar events. * * @author Yohann Coppel */ -public class CalendarEventGenerator implements GeneratorSource { - public static final String[] FULL_DAY_ONLY_IDS = { "fullDayOnlyInfo1", - "fullDayOnlyInfo2", "fullDayOnlyInfo3", "fullDayOnlyInfo4" }; +public final class CalendarEventGenerator implements GeneratorSource { + + private static final String[] FULL_DAY_ONLY_IDS = + { "fullDayOnlyInfo1", "fullDayOnlyInfo2", "fullDayOnlyInfo3", "fullDayOnlyInfo4" }; private static final long ONE_HOUR = 60L * 60 * 1000; - Grid table = null; - TextBox eventName = new TextBox(); - CheckBox fullDay = new CheckBox(); - DateBox datePicker1 = new DateBox(); - DateBox datePicker2 = new DateBox(); - TimePicker timePicker1 = new TimePicker(new Date(), DateTimeFormat + private Grid table; + private final TextBox eventName = new TextBox(); + private final CheckBox fullDay = new CheckBox(); + private final DatePicker datePicker1 = new DatePicker(); + private final DatePicker datePicker2 = new DatePicker(); + private final TimePicker timePicker1 = new TimePicker(new Date(), DateTimeFormat .getFormat("a"), DateTimeFormat.getFormat("hh"), DateTimeFormat .getFormat("mm"), null); - TimePicker timePicker2 = new TimePicker(new Date(), DateTimeFormat + private final TimePicker timePicker2 = new TimePicker(new Date(), DateTimeFormat .getFormat("a"), DateTimeFormat.getFormat("hh"), DateTimeFormat .getFormat("mm"), null); - CheckBox summerTime = new CheckBox(); - ListBox timeZones = new ListBox(); - Date timePicker1PreviousDate = null; - TextBox location = new TextBox(); - TextBox description = new TextBox(); + private final CheckBox summerTime = new CheckBox(); + private final ListBox timeZones = new ListBox(); + private Date timePicker1PreviousDate = null; + private final TextBox location = new TextBox(); + private final TextBox description = new TextBox(); - public CalendarEventGenerator(final ChangeListener listener, - KeyPressHandler keyListener) { + public CalendarEventGenerator(final ChangeHandler handler, KeyPressHandler keyListener) { eventName.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED); - eventName.addChangeListener(listener); + eventName.addChangeHandler(handler); eventName.addKeyPressHandler(keyListener); - datePicker1.setAnimationEnabled(true); - datePicker2.setAnimationEnabled(true); - timePicker2 - .setDateTime(addMilliseconds(timePicker1.getDateTime(), ONE_HOUR)); + timePicker2.setDateTime(addMilliseconds(timePicker1.getDateTime(), ONE_HOUR)); timePicker1PreviousDate = timePicker1.getDateTime(); buildTimeZoneList(); timeZones.setSelectedIndex(25); timeZones.addKeyPressHandler(keyListener); - timePicker1.addChangeHandler(new ChangeHandler() { - public void onChange(ChangeEvent event) { + timePicker1.addValueChangeHandler(new ValueChangeHandler() { + @Override + public void onValueChange(ValueChangeEvent dateValueChangeEvent) { Date time = timePicker1PreviousDate; Date time1 = timePicker1.getDateTime(); Date time2 = timePicker2.getDateTime(); @@ -95,29 +94,40 @@ public class CalendarEventGenerator implements GeneratorSource { timePicker1PreviousDate = time1; } }); - timePicker2.addChangeHandler(new ChangeHandler() { - public void onChange(ChangeEvent event) { - listener.onChange(timePicker2); + timePicker2.addValueChangeHandler(new ValueChangeHandler() { + @Override + public void onValueChange(ValueChangeEvent dateValueChangeEvent) { + // Hack to stitch together these old and new APIs + ChangeEvent event = new ChangeEvent() { + @Override + public Object getSource() { + return timePicker2; + } + }; + handler.onChange(event); } }); } private void buildTimeZoneList() { for (TimeZoneInfo info : TimeZoneList.TIMEZONES) { - timeZones.addItem(info.GMTRelative + ' ' + info.abreviation, String.valueOf(info.gmtDiff)); + timeZones.addItem(info.getGMTRelative() + ' ' + info.getAbreviation(), + String.valueOf(info.getGmtDiff())); } } + @Override public String getName() { return "Calendar event"; } + @Override public Grid getWidget() { if (table != null) { return table; } - datePicker1.getDatePicker().setSelectedDate(new Date()); - datePicker2.getDatePicker().setSelectedDate(new Date()); + datePicker1.setValue(new Date()); + datePicker2.setValue(new Date()); table = new Grid(10, 2); table.setText(0, 0, "All day event"); @@ -155,24 +165,22 @@ public class CalendarEventGenerator implements GeneratorSource { table.getRowFormatter().getElement(6).setId(FULL_DAY_ONLY_IDS[2]); table.getRowFormatter().getElement(7).setId(FULL_DAY_ONLY_IDS[3]); - fullDay.addClickListener(new ClickListener() { - public void onClick(Widget sender) { - CheckBox cb = (CheckBox) sender; - setFullDay(cb.isChecked()); + fullDay.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + CheckBox cb = (CheckBox) event.getSource(); + for (String s : FULL_DAY_ONLY_IDS) { + Element element = DOM.getElementById(s); + String style = cb.getValue() ? "none" : ""; + DOM.setStyleAttribute(element, "display", style); + } } }); return table; } - private static void setFullDay(boolean fullDay) { - for (String s : FULL_DAY_ONLY_IDS) { - Element element = DOM.getElementById(s); - String style = fullDay ? "none" : ""; - DOM.setStyleAttribute(element, "display", style); - } - } - + @Override public String getText() throws GeneratorException { String eventName = getEventNameField(); String dates = getDateTimeFields(); @@ -194,14 +202,13 @@ public class CalendarEventGenerator implements GeneratorSource { throw new GeneratorException("Event name must be at least 1 character."); } if (inputName.contains("\n")) { - throw new GeneratorException( - "Event name should not contain \\n characters."); + throw new GeneratorException("Event name should not contain \\n characters."); } return "SUMMARY:" + inputName + "\r\n"; } private String getDateTimeFields() throws GeneratorException { - if (fullDay.isChecked()) { + if (fullDay.getValue()) { return getFullDayDateFields(); } return getDateTimeValues(); @@ -232,9 +239,9 @@ public class CalendarEventGenerator implements GeneratorSource { } private String getFullDayDateFields() throws GeneratorException { - Date date1 = datePicker1.getDatePicker().getSelectedDate(); - Date date2 = datePicker2.getDatePicker().getSelectedDate(); - if (null == date1 || null == date2) { + Date date1 = datePicker1.getValue(); + Date date2 = datePicker2.getValue(); + if (date1 == null || date2 == null) { throw new GeneratorException("Start and end dates must be set."); } if (date1.after(date2)) { @@ -252,27 +259,24 @@ public class CalendarEventGenerator implements GeneratorSource { } private String getDateTimeValues() throws GeneratorException { - Date date1 = datePicker1.getDatePicker().getSelectedDate(); - Date date2 = datePicker2.getDatePicker().getSelectedDate(); + Date date1 = datePicker1.getValue(); + Date date2 = datePicker2.getValue(); Date time1 = timePicker1.getDateTime(); Date time2 = timePicker2.getDateTime(); - if (null == date1 || null == date2 || null == time1 || null == time2) { + if (date1 == null || date2 == null || time1 == null || time2 == null) { throw new GeneratorException("Start and end dates/times must be set."); } String timezoneDelta = timeZones.getValue(timeZones.getSelectedIndex()); long diffTimeZone = Long.parseLong(timezoneDelta); - if (summerTime.isChecked()) { + if (summerTime.getValue()) { diffTimeZone += ONE_HOUR; } - Date dateTime1 = addMilliseconds(mergeDateAndTime(date1, time1), - -diffTimeZone); - Date dateTime2 = addMilliseconds(mergeDateAndTime(date2, time2), - -diffTimeZone); + Date dateTime1 = addMilliseconds(mergeDateAndTime(date1, time1), -diffTimeZone); + Date dateTime2 = addMilliseconds(mergeDateAndTime(date2, time2), -diffTimeZone); if (dateTime1.after(dateTime2)) { throw new GeneratorException("Ending date is after starting date."); } - DateTimeFormat isoFormatter = DateTimeFormat - .getFormat("yyyyMMdd'T'HHmmss'Z'"); + DateTimeFormat isoFormatter = DateTimeFormat.getFormat("yyyyMMdd'T'HHmmss'Z'"); StringBuilder output = new StringBuilder(); output.append("DTSTART:"); output.append(isoFormatter.format(dateTime1)); @@ -294,11 +298,11 @@ public class CalendarEventGenerator implements GeneratorSource { return merger.parse(d + t); } + @Override public void validate(Widget widget) throws GeneratorException { if (widget == eventName) { getEventNameField(); - } else if (widget == datePicker1 || widget == timePicker1 || widget == datePicker2 - || widget == timePicker2) { + } else if (widget == datePicker1 || widget == timePicker1 || widget == datePicker2 || widget == timePicker2) { getDateTimeFields(); } } @@ -307,6 +311,7 @@ public class CalendarEventGenerator implements GeneratorSource { return new Date(time1.getTime() + milliseconds); } + @Override public void setFocus() { eventName.setFocus(true); } diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/ContactInfoGenerator.java b/zxing.appspot.com/src/com/google/zxing/web/generator/client/ContactInfoGenerator.java similarity index 50% rename from zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/ContactInfoGenerator.java rename to zxing.appspot.com/src/com/google/zxing/web/generator/client/ContactInfoGenerator.java index 16f9ec874..9297f1553 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/ContactInfoGenerator.java +++ b/zxing.appspot.com/src/com/google/zxing/web/generator/client/ContactInfoGenerator.java @@ -16,9 +16,10 @@ package com.google.zxing.web.generator.client; +import com.google.gwt.event.dom.client.ChangeHandler; 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.ListBox; import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.Widget; @@ -27,30 +28,36 @@ import com.google.gwt.user.client.ui.Widget; * * @author Yohann Coppel */ -public class ContactInfoGenerator implements GeneratorSource { - Grid table = null; - TextBox name = 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}; - - public ContactInfoGenerator(ChangeListener changeListener, - KeyPressHandler keyListener) { +public final class ContactInfoGenerator implements GeneratorSource { + + private Grid table; + private final ListBox encoding = new ListBox(); + private final TextBox name = new TextBox(); + private final TextBox company = new TextBox(); + private final TextBox tel = new TextBox(); + private final TextBox url = new TextBox(); + private final TextBox email = new TextBox(); + private final TextBox address = new TextBox(); + private final TextBox address2 = new TextBox(); + private final TextBox memo = new TextBox(); + + public ContactInfoGenerator(ChangeHandler changeHandler, KeyPressHandler keyListener) { + TextBox[] widgets = {name, company, tel, url, email, address, address2, memo}; for (TextBox w: widgets) { - w.addChangeListener(changeListener); + w.addChangeHandler(changeHandler); w.addKeyPressHandler(keyListener); } + encoding.addItem("MECARD"); + encoding.addItem("vCard"); + encoding.setSelectedIndex(0); } + @Override public String getName() { return "Contact information"; } + @Override public String getText() throws GeneratorException { String name = getNameField(); String company = getCompanyField(); @@ -63,74 +70,69 @@ 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); + if ("vCard".equals(encoding.getValue(encoding.getSelectedIndex()))) { + return getVCard(name, company, tel, url, email, address, address2, memo); + } return getMeCard(name, company, tel, url, email, address, address2, memo); } - private String getMeCard(String name, String company, String tel, String url, - String email, String address, String address2, String memo) { - StringBuilder output = new StringBuilder(); + private static String getMeCard(String name, String company, String tel, String url, + String email, String address, String address2, String memo) { + StringBuilder output = new StringBuilder(100); output.append("MECARD:"); - name = name.replace(",", ""); // remove commas -- reserved char in MECARD - output.append("N:").append(name).append(';'); - maybeAppend(output, "ORG:", company); // Not standard; don't generate - maybeAppend(output, "TEL:", tel); - maybeAppend(output, "URL:", url); - maybeAppend(output, "EMAIL:", email); - if (address.length() > 0 || address2.length() > 0) { - output.append("ADR:"); - if (address.length() > 0) { - output.append(address); - } - if (address2.length() > 0) { - if (address.length() > 0) { - output.append(' '); - } - output.append(address2); - } - output.append(';'); - } - maybeAppend(output, "NOTE:", memo); + maybeAppendMECARD(output, "N", name.replace(",", "")); + maybeAppendMECARD(output, "ORG", company); + maybeAppendMECARD(output, "TEL", tel); + maybeAppendMECARD(output, "URL", url); + maybeAppendMECARD(output, "EMAIL", email); + maybeAppendMECARD(output, "ADR", buildAddress(address, address2)); + maybeAppendMECARD(output, "NOTE", memo); output.append(';'); return output.toString(); } + + private static String buildAddress(String address, String address2) { + if (address.length() > 0) { + if (address2.length() > 0) { + return address + ' ' + address2; + } + return address; + } + if (address2.length() > 0) { + return address2; + } + return ""; + } - private static void maybeAppend(StringBuilder output, String prefix, String value) { + private static void maybeAppendMECARD(StringBuilder output, String prefix, String value) { if (value.length() > 0) { - output.append(prefix).append(value).append(';'); + value = value.replaceAll("([:;])", "\\\\$1"); + value = value.replaceAll("\\n", ""); + output.append(prefix).append(':').append(value).append(';'); } } - /*// VCARD GENERATION. Keep this in case we want to go back to vcard format - // or have the option. - private String getVCard(String name, String company, String tel, String url, - String email, String address, String memo) { - String output = "BEGIN:VCARD\n"; - output += "N:" + name + "\n"; - output += company.length() > 0 ? "ORG:" + company + "\n" : ""; - output += tel.length() > 0 ? "TEL:" + tel + "\n" : ""; - output += url.length() > 0 ? "URL:" + url + "\n" : ""; - output += email.length() > 0 ? "EMAIL:" + email + "\n" : ""; - output += address.length() > 0 ? "ADR:" + address + "\n" : ""; - output += memo.length() > 0 ? "NOTE:" + memo + "\n" : ""; - output += "END:VCARD"; - - return output; + private static String getVCard(String name, String company, String tel, String url, + String email, String address, String address2, String memo) { + StringBuilder output = new StringBuilder(100); + output.append("BEGIN:VCARD\n"); + maybeAppendvCard(output, "N", name); + maybeAppendvCard(output, "ORG", company); + maybeAppendvCard(output, "TEL", tel); + maybeAppendvCard(output, "URL", url); + maybeAppendvCard(output, "EMAIL", email); + maybeAppendvCard(output, "ADR", buildAddress(address, address2)); + maybeAppendvCard(output, "NOTE", memo); + output.append("END:VCARD"); + return output.toString(); } - */ - - private static String parseTextField(String name, TextBox textBox) throws GeneratorException { - String input = textBox.getText(); - if (input.length() < 1) { - return ""; + + private static void maybeAppendvCard(StringBuilder output, String prefix, String value) { + if (value.length() > 0) { + value = value.replaceAll("([\\\\:;])", "\\\\$1"); + value = value.replaceAll("\\n", "\\\\n"); + output.append(prefix).append(':').append(value).append('\n'); } - if (input.contains("\n")) { - throw new GeneratorException(name + " field must not contain \\n characters."); - } - if (input.contains(";")) { - throw new GeneratorException(name + " field must not contains ; characters"); - } - return input; } private String getNameField() throws GeneratorException { @@ -138,11 +140,11 @@ public class ContactInfoGenerator implements GeneratorSource { if (input.length() < 1) { throw new GeneratorException("Name must be at least 1 character."); } - return parseTextField("Name", name); + return input; } - private String getCompanyField() throws GeneratorException { - return parseTextField("Company", company); + private String getCompanyField() { + return company.getText(); } private String getTelField() throws GeneratorException { @@ -177,24 +179,25 @@ public class ContactInfoGenerator implements GeneratorSource { return input; } - private String getAddressField() throws GeneratorException { - return parseTextField("Address", address); + private String getAddressField() { + return address.getText(); } - private String getAddress2Field() throws GeneratorException { - return parseTextField("Address 2", address2); + private String getAddress2Field() { + return address2.getText(); } - private String getMemoField() throws GeneratorException { - return parseTextField("Memo", memo); + private String getMemoField() { + return memo.getText(); } + @Override public Grid getWidget() { if (table != null) { // early termination if the table has already been constructed return table; } - table = new Grid(8, 2); + table = new Grid(9, 2); table.setText(0, 0, "Name"); table.setWidget(0, 1, name); @@ -212,22 +215,42 @@ public class ContactInfoGenerator implements GeneratorSource { table.setWidget(6, 1, url); table.setText(7, 0, "Memo"); table.setWidget(7, 1, memo); + table.setText(8, 0, "Encoding"); + table.setWidget(8, 1, encoding); name.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED); return table; } + @Override public void validate(Widget widget) throws GeneratorException { - if (widget == name) getNameField(); - if (widget == company) getCompanyField(); - if (widget == tel) getTelField(); - if (widget == email) getEmailField(); - if (widget == address) getAddressField(); - if (widget == address2) getAddress2Field(); - if (widget == url) getUrlField(); - if (widget == memo) getMemoField(); + if (widget == name) { + getNameField(); + } + if (widget == company) { + getCompanyField(); + } + if (widget == tel) { + getTelField(); + } + if (widget == email) { + getEmailField(); + } + if (widget == address) { + getAddressField(); + } + if (widget == address2) { + getAddress2Field(); + } + if (widget == url) { + getUrlField(); + } + if (widget == memo) { + getMemoField(); + } } + @Override public void setFocus() { name.setFocus(true); } diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/EmailGenerator.java b/zxing.appspot.com/src/com/google/zxing/web/generator/client/EmailGenerator.java similarity index 81% rename from zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/EmailGenerator.java rename to zxing.appspot.com/src/com/google/zxing/web/generator/client/EmailGenerator.java index 517a4ee7b..240e36322 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/EmailGenerator.java +++ b/zxing.appspot.com/src/com/google/zxing/web/generator/client/EmailGenerator.java @@ -16,8 +16,8 @@ package com.google.zxing.web.generator.client; +import com.google.gwt.event.dom.client.ChangeHandler; 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; import com.google.gwt.user.client.ui.Widget; @@ -27,23 +27,25 @@ import com.google.gwt.user.client.ui.Widget; * * @author Yohann Coppel */ -public class EmailGenerator implements GeneratorSource { - Grid table = null; - TextBox email = new TextBox(); +public final class EmailGenerator implements GeneratorSource { + + private Grid table; + private final TextBox email = new TextBox(); - public EmailGenerator(ChangeListener listener, KeyPressHandler keyListener) { + public EmailGenerator(ChangeHandler handler, KeyPressHandler keyListener) { email.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED); - email.addChangeListener(listener); + email.addChangeHandler(handler); email.addKeyPressHandler(keyListener); } + @Override public String getName() { return "Email address"; } + @Override public String getText() throws GeneratorException { - String email = getEmailField(); - return "mailto:"+email; + return "mailto:" + getEmailField(); } private String getEmailField() throws GeneratorException { @@ -55,24 +57,25 @@ public class EmailGenerator implements GeneratorSource { return input; } + @Override public Grid getWidget() { if (table != null) { return table; } table = new Grid(1, 2); - table.setText(0, 0, "Address"); table.setWidget(0, 1, email); - return table; } + @Override public void validate(Widget widget) throws GeneratorException { if (widget == email) { getEmailField(); } } + @Override public void setFocus() { email.setFocus(true); } diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/Generator.java b/zxing.appspot.com/src/com/google/zxing/web/generator/client/Generator.java similarity index 52% rename from zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/Generator.java rename to zxing.appspot.com/src/com/google/zxing/web/generator/client/Generator.java index 9f6bb3338..a25f8f7b8 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/Generator.java +++ b/zxing.appspot.com/src/com/google/zxing/web/generator/client/Generator.java @@ -17,77 +17,78 @@ package com.google.zxing.web.generator.client; import com.google.gwt.core.client.EntryPoint; -import com.google.gwt.dom.client.Element; +import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.event.dom.client.ChangeHandler; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; 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.user.client.DOM; +import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.Button; -import com.google.gwt.user.client.ui.ChangeListener; -import com.google.gwt.user.client.ui.ClickListener; import com.google.gwt.user.client.ui.Grid; import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HTMLTable; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.SimplePanel; +import com.google.gwt.user.client.ui.TextArea; import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; -import com.google.gwt.user.client.ui.HTMLTable.CellFormatter; import java.util.ArrayList; import java.util.List; -/** - * Entry point classes define onModuleLoad(). Setup the page, and loads - * all different generators. - * - * @author Yohann Coppel - */ -public class Generator implements EntryPoint { -// public static final StringConstants S = GWT.create(StringConstants.class); +public final class Generator implements EntryPoint { + private final List generators = new ArrayList(); - ListBox genList = new ListBox(); - ListBox sizeList = new ListBox(); - Image result = new Image("");//http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=http://google.com"); - Grid topPanel = new Grid(5, 1); - GeneratorSource selectedGenerator = null; - private Button generateButton; - VerticalPanel rightPanel = new VerticalPanel(); - TextBox urlResult = new TextBox(); - HTML downloadText = new HTML("Download or embed with this URL:"); - //Element errorElement = null; - + private final ListBox genList = new ListBox(); + private final ListBox sizeList = new ListBox(); + private final ListBox ecLevelList = new ListBox(); + private final ListBox encodingList = new ListBox(); + private final Image result = new Image(""); + private final HTMLTable topPanel = new Grid(5, 1); + private GeneratorSource selectedGenerator = null; + private final VerticalPanel rightPanel = new VerticalPanel(); + private final TextBox urlResult = new TextBox(); + private final Widget downloadText = + new HTML("Download or embed with this URL:"); + private final TextArea rawTextResult = new TextArea(); + + @Override public void onModuleLoad() { loadGenerators(); - + HorizontalPanel mainPanel = new HorizontalPanel(); setupLeftPanel(); topPanel.getElement().setId("leftpanel"); Widget leftPanel = topPanel; - + mainPanel.add(leftPanel); - + SimplePanel div = new SimplePanel(); SimplePanel div2 = new SimplePanel(); div2.add(result); div2.getElement().setId("innerresult"); div.add(div2); div.getElement().setId("imageresult"); - + urlResult.getElement().setId("urlresult"); + rawTextResult.getElement().setId("rawtextresult"); + rawTextResult.setCharacterWidth(50); + rawTextResult.setVisibleLines(8); downloadText.getElement().setId("downloadText"); rightPanel.add(div); rightPanel.add(downloadText); rightPanel.add(urlResult); + rightPanel.add(rawTextResult); mainPanel.add(rightPanel); mainPanel.getElement().setId("mainpanel"); RootPanel.get("ui").add(mainPanel); - //RootPanel.get().add(output); - //output.setHeight("200px"); - //output.setWidth("500px"); setWidget(1); invalidateBarcode(); } @@ -105,99 +106,119 @@ public class Generator implements EntryPoint { } private void loadGenerators() { - generators.add(new CalendarEventGenerator(changeListener, keyPressHandler)); - generators.add(new ContactInfoGenerator(changeListener, keyPressHandler)); - generators.add(new EmailGenerator(changeListener, keyPressHandler)); - generators.add(new GeoLocationGenerator(changeListener, keyPressHandler)); - generators.add(new PhoneNumberGenerator(changeListener, keyPressHandler)); - generators.add(new SmsAddressGenerator(changeListener, keyPressHandler)); - generators.add(new TextGenerator(changeListener)); - generators.add(new UrlGenerator(changeListener, keyPressHandler)); - generators.add(new WifiGenerator(changeListener, keyPressHandler)); + generators.add(new CalendarEventGenerator(changeHandler, keyPressHandler)); + generators.add(new ContactInfoGenerator(changeHandler, keyPressHandler)); + generators.add(new EmailGenerator(changeHandler, keyPressHandler)); + generators.add(new GeoLocationGenerator(changeHandler, keyPressHandler)); + generators.add(new PhoneNumberGenerator(changeHandler, keyPressHandler)); + generators.add(new SmsAddressGenerator(changeHandler, keyPressHandler)); + generators.add(new TextGenerator(changeHandler)); + generators.add(new UrlGenerator(changeHandler, keyPressHandler)); + generators.add(new WifiGenerator(changeHandler, keyPressHandler)); } - - public void setupLeftPanel() { + + void setupLeftPanel() { topPanel.setHTML(2, 0, ""); - + // fills up the list of generators for(GeneratorSource generator: generators) { genList.addItem(generator.getName()); setGridStyle(generator.getWidget()); } - sizeList.addItem("S", "120"); - sizeList.addItem("M", "230"); - sizeList.addItem("L", "350"); + sizeList.addItem("Small", "120"); + sizeList.addItem("Medium", "230"); + sizeList.addItem("Large", "350"); sizeList.setSelectedIndex(2); + + ecLevelList.addItem("L"); + ecLevelList.addItem("M"); + ecLevelList.addItem("Q"); + ecLevelList.addItem("H"); + ecLevelList.setSelectedIndex(0); - // updates the second row of the table with the content of the selected - // generator - genList.addChangeListener(new ChangeListener() { - public void onChange(Widget sender) { + encodingList.addItem("UTF-8"); + encodingList.addItem("ISO-8859-1"); + encodingList.addItem("Shift_JIS"); + encodingList.setSelectedIndex(0); + + // updates the second row of the table with the content of the selected generator + genList.addChangeHandler(new ChangeHandler() { + @Override + public void onChange(ChangeEvent Event) { int i = genList.getSelectedIndex(); setWidget(i); } }); // grid for the generator picker - Grid selectionTable = new Grid(1, 2); + HTMLTable selectionTable = new Grid(1, 2); selectionTable.setText(0, 0, "Contents"); selectionTable.setWidget(0, 1, genList); setGridStyle(selectionTable); - + topPanel.setWidget(0, 0, selectionTable); - + // grid for the generate button - Grid generateGrid = new Grid(1, 2); + HTMLTable generateGrid = new Grid(1, 2); setGridStyle(generateGrid); - - generateButton = new Button("Generate →"); - generateButton.addClickListener(new ClickListener() { - public void onClick(Widget sender) { + + Button generateButton = new Button("Generate →"); + generateButton.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { generate(); } }); - generateGrid.setWidget(0,1,generateButton); + generateGrid.setWidget(0, 1, generateButton); topPanel.setWidget(4, 0, generateGrid); - - Grid sizeTable = new Grid(1, 2); - sizeTable.setText(0, 0, "Barcode size"); - sizeTable.setWidget(0, 1, sizeList); - setGridStyle(sizeTable); - topPanel.setWidget(3, 0, sizeTable); + + HTMLTable configTable = new Grid(3, 2); + configTable.setText(0, 0, "Barcode size"); + configTable.setWidget(0, 1, sizeList); + configTable.setText(1, 0, "Error correction"); + configTable.setWidget(1, 1, ecLevelList); + configTable.setText(2, 0, "Character encoding"); + configTable.setWidget(2, 1, encodingList); + setGridStyle(configTable); + topPanel.setWidget(3, 0, configTable); } - protected void setGridStyle(Grid grid) { + private static void setGridStyle(HTMLTable grid) { grid.getColumnFormatter().addStyleName(0, "firstColumn"); grid.getColumnFormatter().addStyleName(1, "secondColumn"); - CellFormatter cellFormatter = grid.getCellFormatter(); - for(int i = 0; i < grid.getRowCount(); ++i) { + HTMLTable.CellFormatter cellFormatter = grid.getCellFormatter(); + for (int i = 0; i < grid.getRowCount(); ++i) { cellFormatter.addStyleName(i, 0, "firstColumn"); cellFormatter.addStyleName(i, 1, "secondColumn"); } } - protected String getUrl(int sizeX, int sizeY, String content) { - StringBuilder result = new StringBuilder(); - result.append("http://chart.apis.google.com/chart?cht=qr&chs="); - result.append(sizeX).append('x').append(sizeY); - result.append("&chl="); - result.append(URL.encodeComponent(content)); + private static String getUrl(int sizeX, int sizeY, String ecLevel, String encoding, String content) { + StringBuilder result = new StringBuilder(100); + result.append("http://chart.apis.google.com/chart?cht=qr"); + result.append("&chs=").append(sizeX).append('x').append(sizeY); + result.append("&chld=").append(ecLevel); + result.append("&choe=").append(encoding); + result.append("&chl=").append(URL.encodeQueryString(content)); return result.toString(); } - + private void generate() { try { String text = selectedGenerator.getText(); eraseErrorMessage(); - int size = Integer.parseInt(sizeList - .getValue(sizeList.getSelectedIndex())); - String url = getUrl(size, size, text); + int size = Integer.parseInt(sizeList.getValue(sizeList.getSelectedIndex())); + String ecLevel = ecLevelList.getValue(ecLevelList.getSelectedIndex()); + String encoding = encodingList.getValue(encodingList.getSelectedIndex()); + String url = getUrl(size, size, ecLevel, encoding, text); result.setUrl(url); result.setVisible(true); urlResult.setText(url); urlResult.setVisible(true); + rawTextResult.setText(text); + rawTextResult.setVisible(true); Element linkElement = DOM.getElementById("downloadlink"); linkElement.setAttribute("href", url); downloadText.setVisible(true); @@ -207,30 +228,33 @@ public class Generator implements EntryPoint { showErrorMessage(error); } } - - public void invalidateBarcode() { + + void invalidateBarcode() { result.setVisible(false); urlResult.setText(""); urlResult.setVisible(false); + rawTextResult.setText(""); + rawTextResult.setVisible(false); Element linkElement = DOM.getElementById("downloadlink"); linkElement.setAttribute("href", ""); downloadText.setVisible(false); } - - public void showErrorMessage(String error) { + + private static void showErrorMessage(String error) { Element errorElement = DOM.getElementById("errorMessageID"); errorElement.setInnerHTML(error); } - - public void eraseErrorMessage() { + + private static void eraseErrorMessage() { Element errorElement = DOM.getElementById("errorMessageID"); errorElement.setInnerHTML(" "); } - - public ChangeListener changeListener = new ChangeListener() { - public void onChange(Widget sender) { + + private final ChangeHandler changeHandler = new ChangeHandler() { + @Override + public void onChange(ChangeEvent event) { try { - selectedGenerator.validate(sender); + selectedGenerator.validate((Widget) event.getSource()); eraseErrorMessage(); } catch (GeneratorException ex) { String error = ex.getMessage(); @@ -239,8 +263,8 @@ public class Generator implements EntryPoint { } } }; - - public KeyPressHandler keyPressHandler = new KeyPressHandler() { + + private final KeyPressHandler keyPressHandler = new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { if (event.getCharCode() == '\n' || event.getCharCode() == '\r') { diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/GeneratorException.java b/zxing.appspot.com/src/com/google/zxing/web/generator/client/GeneratorException.java similarity index 90% rename from zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/GeneratorException.java rename to zxing.appspot.com/src/com/google/zxing/web/generator/client/GeneratorException.java index ede4d9f9b..9a7ba9554 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/GeneratorException.java +++ b/zxing.appspot.com/src/com/google/zxing/web/generator/client/GeneratorException.java @@ -23,8 +23,10 @@ package com.google.zxing.web.generator.client; * * @author Yohann Coppel */ -public class GeneratorException extends Exception { - public GeneratorException(String message) { +final class GeneratorException extends Exception { + + GeneratorException(String message) { super(message); } + } diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/GeneratorSource.java b/zxing.appspot.com/src/com/google/zxing/web/generator/client/GeneratorSource.java similarity index 100% rename from zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/GeneratorSource.java rename to zxing.appspot.com/src/com/google/zxing/web/generator/client/GeneratorSource.java diff --git a/zxing.appspot.com/src/com/google/zxing/web/generator/client/GeoLocationGenerator.java b/zxing.appspot.com/src/com/google/zxing/web/generator/client/GeoLocationGenerator.java new file mode 100644 index 000000000..50f6639c4 --- /dev/null +++ b/zxing.appspot.com/src/com/google/zxing/web/generator/client/GeoLocationGenerator.java @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2008 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.web.generator.client; + +import com.google.gwt.event.dom.client.ChangeHandler; +import com.google.gwt.event.dom.client.KeyPressHandler; +import com.google.gwt.user.client.ui.Grid; +import com.google.gwt.user.client.ui.TextBox; +import com.google.gwt.user.client.ui.Widget; + +/** + * A generator for geo location. It also accepts a google maps links and + * extracts the coordinates and query from the URL. + * + * @author Yohann Coppel + */ +public final class GeoLocationGenerator implements GeneratorSource { + + private static final String LON_REGEXP = "[+-]?[0-9]+(.[0-9]+)?"; + private static final String LAT_REGEXP = "[+-]?[0-9]+(.[0-9]+)?"; + + private Grid table; + private final TextBox latitude = new TextBox(); + private final TextBox longitude = new TextBox(); + private final TextBox query = new TextBox(); + + public GeoLocationGenerator(ChangeHandler handler, KeyPressHandler keyListener) { + latitude.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED); + latitude.addChangeHandler(handler); + latitude.addKeyPressHandler(keyListener); + longitude.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED); + longitude.addChangeHandler(handler); + longitude.addKeyPressHandler(keyListener); + query.addChangeHandler(handler); + query.addKeyPressHandler(keyListener); + } + + @Override + public String getName() { + return "Geo location"; + } + + @Override + public String getText() throws GeneratorException { + String que = getQueryField(); + if (que != null && que.length() > 0) { + if (getLatitudeField() == null) { + latitude.setText("0"); + } + if (getLongitudeField() == null) { + longitude.setText("0"); + } + } + String lat = getLatitudeField(); + String lon = getLongitudeField(); + + if (que != null && que.length() > 0) { + return "geo:" + lat + ',' + lon + "?q=" + que; + } + return "geo:" + lat + ',' + lon; + } + + private String getQueryField() { + String que = query.getText(); + que = que.replace("&", "%26"); + return que; + } + + private String getLongitudeField() throws GeneratorException { + String lon = longitude.getText(); + if (!lon.matches(LON_REGEXP)) { + throw new GeneratorException("Longitude is not a correct value."); + } + double val = Double.parseDouble(lon); + if (val < -180.0 || val > 180.0) { + throw new GeneratorException("Longitude must be in [-180:180]"); + } + return lon; + } + + private String getLatitudeField() throws GeneratorException { + String lat = latitude.getText(); + if (!lat.matches(LAT_REGEXP)) { + throw new GeneratorException("Latitude is not a correct value."); + } + double val = Double.parseDouble(lat); + if (val < -90.0 || val > 90.0) { + throw new GeneratorException("Latitude must be in [-90:90]"); + } + return lat; + } + + @Override + public Grid getWidget() { + if (table != null) { + return table; + } + table = new Grid(3, 2); + + table.setText(0, 0, "Latitude"); + table.setWidget(0, 1, latitude); + table.setText(1, 0, "Longitude"); + table.setWidget(1, 1, longitude); + table.setText(2, 0, "Query"); + table.setWidget(2, 1, query); + return table; + } + + @Override + public void validate(Widget widget) throws GeneratorException { + if (widget == latitude) { + getLatitudeField(); + } + if (widget == longitude) { + getLongitudeField(); + } + } + + @Override + public void setFocus() { + latitude.setFocus(true); + } + +} diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/PhoneNumberGenerator.java b/zxing.appspot.com/src/com/google/zxing/web/generator/client/PhoneNumberGenerator.java similarity index 83% rename from zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/PhoneNumberGenerator.java rename to zxing.appspot.com/src/com/google/zxing/web/generator/client/PhoneNumberGenerator.java index 17a78c53e..8c0dd41a5 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/PhoneNumberGenerator.java +++ b/zxing.appspot.com/src/com/google/zxing/web/generator/client/PhoneNumberGenerator.java @@ -16,8 +16,8 @@ package com.google.zxing.web.generator.client; +import com.google.gwt.event.dom.client.ChangeHandler; 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; import com.google.gwt.user.client.ui.Widget; @@ -27,21 +27,23 @@ import com.google.gwt.user.client.ui.Widget; * * @author Yohann Coppel */ -public class PhoneNumberGenerator implements GeneratorSource { - Grid table = null; - TextBox number = new TextBox(); +public final class PhoneNumberGenerator implements GeneratorSource { + + private Grid table; + private final TextBox number = new TextBox(); - public PhoneNumberGenerator(ChangeListener listener, - KeyPressHandler keyListener) { + public PhoneNumberGenerator(ChangeHandler handler, KeyPressHandler keyListener) { number.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED); - number.addChangeListener(listener); + number.addChangeHandler(handler); number.addKeyPressHandler(keyListener); } + @Override public String getName() { return "Phone number"; } + @Override public String getText() throws GeneratorException { String tel = getTelField(); return "tel:" + tel; @@ -57,6 +59,7 @@ public class PhoneNumberGenerator implements GeneratorSource { return input; } + @Override public Grid getWidget() { if (table != null) { return table; @@ -69,12 +72,14 @@ public class PhoneNumberGenerator implements GeneratorSource { return table; } + @Override public void validate(Widget widget) throws GeneratorException { if (widget == number) { getTelField(); } } + @Override public void setFocus() { number.setFocus(true); } diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/SmsAddressGenerator.java b/zxing.appspot.com/src/com/google/zxing/web/generator/client/SmsAddressGenerator.java similarity index 85% rename from zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/SmsAddressGenerator.java rename to zxing.appspot.com/src/com/google/zxing/web/generator/client/SmsAddressGenerator.java index f117e51e4..aa930552e 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/SmsAddressGenerator.java +++ b/zxing.appspot.com/src/com/google/zxing/web/generator/client/SmsAddressGenerator.java @@ -16,8 +16,8 @@ package com.google.zxing.web.generator.client; +import com.google.gwt.event.dom.client.ChangeHandler; 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.TextArea; import com.google.gwt.user.client.ui.TextBox; @@ -29,23 +29,25 @@ import com.google.gwt.user.client.ui.Widget; * * @author Yohann Coppel */ -public class SmsAddressGenerator implements GeneratorSource { - Grid table = null; - TextBox number = new TextBox(); - TextArea message = new TextArea(); +public final class SmsAddressGenerator implements GeneratorSource { - public SmsAddressGenerator(ChangeListener listener, - KeyPressHandler keyListener) { + private Grid table; + private final TextBox number = new TextBox(); + private final TextArea message = new TextArea(); + + public SmsAddressGenerator(ChangeHandler handler, KeyPressHandler keyListener) { number.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED); - number.addChangeListener(listener); + number.addChangeHandler(handler); number.addKeyPressHandler(keyListener); - message.addChangeListener(listener); + message.addChangeHandler(handler); } + @Override public String getName() { return "SMS"; } + @Override public String getText() throws GeneratorException { String inputNumber = getTelField(); String inputMessage = getMessageField(); @@ -77,6 +79,7 @@ public class SmsAddressGenerator implements GeneratorSource { return inputMessage; } + @Override public Grid getWidget() { if (table != null) { return table; @@ -92,6 +95,7 @@ public class SmsAddressGenerator implements GeneratorSource { return table; } + @Override public void validate(Widget widget) throws GeneratorException { if (widget == number) { getTelField(); @@ -101,6 +105,7 @@ public class SmsAddressGenerator implements GeneratorSource { } } + @Override public void setFocus() { number.setFocus(true); } diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/StylesDefs.java b/zxing.appspot.com/src/com/google/zxing/web/generator/client/StylesDefs.java similarity index 81% rename from zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/StylesDefs.java rename to zxing.appspot.com/src/com/google/zxing/web/generator/client/StylesDefs.java index 5be82ae73..162d6a307 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/StylesDefs.java +++ b/zxing.appspot.com/src/com/google/zxing/web/generator/client/StylesDefs.java @@ -21,7 +21,11 @@ package com.google.zxing.web.generator.client; * * @author Yohann Coppel */ -public class StylesDefs { - public static final String INPUT_FIELD_REQUIRED = "required"; - public static final String ERROR_MESSAGE = "errorMessage"; +final class StylesDefs { + + static final String INPUT_FIELD_REQUIRED = "required"; + static final String ERROR_MESSAGE = "errorMessage"; + + private StylesDefs() { + } } diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/TextGenerator.java b/zxing.appspot.com/src/com/google/zxing/web/generator/client/TextGenerator.java similarity index 79% rename from zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/TextGenerator.java rename to zxing.appspot.com/src/com/google/zxing/web/generator/client/TextGenerator.java index f9f217af4..1f3718569 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/TextGenerator.java +++ b/zxing.appspot.com/src/com/google/zxing/web/generator/client/TextGenerator.java @@ -16,7 +16,7 @@ package com.google.zxing.web.generator.client; -import com.google.gwt.user.client.ui.ChangeListener; +import com.google.gwt.event.dom.client.ChangeHandler; import com.google.gwt.user.client.ui.Grid; import com.google.gwt.user.client.ui.TextArea; import com.google.gwt.user.client.ui.Widget; @@ -26,25 +26,28 @@ import com.google.gwt.user.client.ui.Widget; * * @author Yohann Coppel */ -public class TextGenerator implements GeneratorSource { - TextArea text = new TextArea(); - Grid table = null; - String error = ""; - - public TextGenerator(ChangeListener listener) { +public final class TextGenerator implements GeneratorSource { + + private Grid table; + private final TextArea text = new TextArea(); + + public TextGenerator(ChangeHandler handler) { text.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED); - text.addChangeListener(listener); + text.addChangeHandler(handler); + text.setVisibleLines(5); } + @Override public String getName() { return "Text"; } + @Override public String getText() throws GeneratorException { return getTextField(); } - public String getTextField() throws GeneratorException { + String getTextField() throws GeneratorException { String input = text.getText(); if (input.length() == 0) { throw new GeneratorException("Text should be at least 1 character."); @@ -52,6 +55,7 @@ public class TextGenerator implements GeneratorSource { return input; } + @Override public Grid getWidget() { if (table != null) { // early termination if the table has already been constructed @@ -67,16 +71,18 @@ public class TextGenerator implements GeneratorSource { return table; } - public String getErrorMessage() { - return error; + public static String getErrorMessage() { + return ""; } + @Override public void validate(Widget widget) throws GeneratorException { if (widget == text) { getTextField(); } } + @Override public void setFocus() { text.setFocus(true); } diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/StringConstants.java b/zxing.appspot.com/src/com/google/zxing/web/generator/client/TimeZoneInfo.java similarity index 52% rename from zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/StringConstants.java rename to zxing.appspot.com/src/com/google/zxing/web/generator/client/TimeZoneInfo.java index 354c2db20..bab063ed1 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/StringConstants.java +++ b/zxing.appspot.com/src/com/google/zxing/web/generator/client/TimeZoneInfo.java @@ -16,10 +16,34 @@ package com.google.zxing.web.generator.client; -import com.google.gwt.i18n.client.Messages; +final class TimeZoneInfo { + + private final String abreviation; + private final String longName; + private final String GMTRelative; + private final long gmtDiff; + + TimeZoneInfo(String abreviation, String longName, String relative, long gmtDiff) { + GMTRelative = relative; + this.abreviation = abreviation; + this.gmtDiff = gmtDiff; + this.longName = longName; + } + + String getAbreviation() { + return abreviation; + } + + String getLongName() { + return longName; + } + + String getGMTRelative() { + return GMTRelative; + } + + long getGmtDiff() { + return gmtDiff; + } -// Not used yet. A first atempt to localization. -public interface StringConstants extends Messages { - String codeType(); - String generateButton(); } diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/TimeZoneList.java b/zxing.appspot.com/src/com/google/zxing/web/generator/client/TimeZoneList.java similarity index 60% rename from zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/TimeZoneList.java rename to zxing.appspot.com/src/com/google/zxing/web/generator/client/TimeZoneList.java index 298c7b9ad..6dcc157e3 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/TimeZoneList.java +++ b/zxing.appspot.com/src/com/google/zxing/web/generator/client/TimeZoneList.java @@ -22,57 +22,47 @@ package com.google.zxing.web.generator.client; * * @author Yohann Coppel */ -public class TimeZoneList { - public static class TimeZoneInfo { - String abreviation; - String longName; - String GMTRelative; - long gmtDiff; - public TimeZoneInfo(String abreviation, String longName, String relative, long gmtDiff) { - super(); - GMTRelative = relative; - this.abreviation = abreviation; - this.gmtDiff = gmtDiff; - this.longName = longName; - } +final class TimeZoneList { + + private TimeZoneList() { } + + private static final long ONE_HOUR = 60L * 60 * 1000; + private static final long THIRTY_MIN = 30L * 60 * 1000; - private static final long ONE_HOUR = 60L*60*1000; - private static final long THIRTY_MIN = 30L*60*1000; - - public static final TimeZoneInfo[] TIMEZONES = { - new TimeZoneInfo("GMT", "Greenwich Mean Time", "GMT", 0 * ONE_HOUR + 0 * THIRTY_MIN), // 0 - new TimeZoneInfo("UTC", "Universal Coordinated Time", "GMT", 0 * ONE_HOUR + 0 * THIRTY_MIN), - new TimeZoneInfo("ECT", "European Central Time", "GMT+1:00", 1 * ONE_HOUR + 0 * THIRTY_MIN), - new TimeZoneInfo("EET", "Eastern European Time", "GMT+2:00", 2 * ONE_HOUR + 0 * THIRTY_MIN), - new TimeZoneInfo("ART", "(Arabic) Egypt Standard Time", "GMT+2:00", 2 * ONE_HOUR + 0 * THIRTY_MIN), - new TimeZoneInfo("EAT", "Eastern African Time", "GMT+3:00", 3 * ONE_HOUR + 0 * THIRTY_MIN), // 5 - new TimeZoneInfo("MET", "Middle East Time", "GMT+3:30", 3 * ONE_HOUR + 1 * THIRTY_MIN), - new TimeZoneInfo("NET", "Near East Time", "GMT+4:00", 4 * ONE_HOUR + 0 * THIRTY_MIN), - new TimeZoneInfo("PLT", "Pakistan Lahore Time", "GMT+5:00", 5 * ONE_HOUR + 0 * THIRTY_MIN), - new TimeZoneInfo("IST", "India Standard Time", "GMT+5:30", 5 * ONE_HOUR + 1 * THIRTY_MIN), - new TimeZoneInfo("BST", "Bangladesh Standard Time", "GMT+6:00", 6 * ONE_HOUR + 0 * THIRTY_MIN), // 10 - new TimeZoneInfo("VST", "Vietnam Standard Time", "GMT+7:00", 7 * ONE_HOUR + 0 * THIRTY_MIN), - new TimeZoneInfo("CTT", "China Taiwan Time", "GMT+8:00", 8 * ONE_HOUR + 0 * THIRTY_MIN), - new TimeZoneInfo("JST", "Japan Standard Time", "GMT+9:00", 9 * ONE_HOUR + 0 * THIRTY_MIN), - new TimeZoneInfo("ACT", "Australia Central Time", "GMT+9:30", 9 * ONE_HOUR + 1 * THIRTY_MIN), - new TimeZoneInfo("AET", "Australia Eastern Time", "GMT+10:00", 10 * ONE_HOUR + 0 * THIRTY_MIN), // 15 - new TimeZoneInfo("SST", "Solomon Standard Time", "GMT+11:00", 11 * ONE_HOUR + 0 * THIRTY_MIN), - new TimeZoneInfo("NST", "New Zealand Standard Time", "GMT+12:00", 12 * ONE_HOUR + 0 * THIRTY_MIN), - new TimeZoneInfo("MIT", "Midway Islands Time", "GMT-11:00", -11 * ONE_HOUR - 0 * THIRTY_MIN), - new TimeZoneInfo("HST", "Hawaii Standard Time", "GMT-10:00", -10 * ONE_HOUR - 0 * THIRTY_MIN), - new TimeZoneInfo("AST", "Alaska Standard Time", "GMT-9:00", -9 * ONE_HOUR - 0 * THIRTY_MIN), // 20 - new TimeZoneInfo("PST", "Pacific Standard Time", "GMT-8:00", -8 * ONE_HOUR - 0 * THIRTY_MIN), - new TimeZoneInfo("PNT", "Phoenix Standard Time", "GMT-7:00", -7 * ONE_HOUR - 0 * THIRTY_MIN), - new TimeZoneInfo("MST", "Mountain Standard Time", "GMT-7:00", -7 * ONE_HOUR - 0 * THIRTY_MIN), - new TimeZoneInfo("CST", "Central Standard Time", "GMT-6:00", -6 * ONE_HOUR - 0 * THIRTY_MIN), - new TimeZoneInfo("EST", "Eastern Standard Time", "GMT-5:00", -5 * ONE_HOUR - 0 * THIRTY_MIN), // 25 - new TimeZoneInfo("IET", "Indiana Eastern Standard Time", "GMT-5:00", -5 * ONE_HOUR - 0 * THIRTY_MIN), - new TimeZoneInfo("PRT", "Puerto Rico and US Virgin Islands Time", "GMT-4:00", -4 * ONE_HOUR - 0 * THIRTY_MIN), - new TimeZoneInfo("CNT", "Canada Newfoundland Time", "GMT-3:30", -3 * ONE_HOUR - 1 * THIRTY_MIN), - new TimeZoneInfo("AGT", "Argentina Standard Time", "GMT-3:00", -3 * ONE_HOUR - 0 * THIRTY_MIN), - new TimeZoneInfo("BET", "Brazil Eastern Time", "GMT-3:00", -3 * ONE_HOUR - 0 * THIRTY_MIN), // 30 - new TimeZoneInfo("CAT", "Central African Time", "GMT-1:00", -1 * ONE_HOUR - 0 * THIRTY_MIN), + static final TimeZoneInfo[] TIMEZONES = { + new TimeZoneInfo("GMT", "Greenwich Mean Time", "GMT", 0), // 0 + new TimeZoneInfo("UTC", "Universal Coordinated Time", "GMT", 0), + new TimeZoneInfo("ECT", "European Central Time", "GMT+1:00", ONE_HOUR), + new TimeZoneInfo("EET", "Eastern European Time", "GMT+2:00", 2 * ONE_HOUR), + new TimeZoneInfo("ART", "(Arabic) Egypt Standard Time", "GMT+2:00", 2 * ONE_HOUR), + new TimeZoneInfo("EAT", "Eastern African Time", "GMT+3:00", 3 * ONE_HOUR), // 5 + new TimeZoneInfo("MET", "Middle East Time", "GMT+3:30", 3 * ONE_HOUR + THIRTY_MIN), + new TimeZoneInfo("NET", "Near East Time", "GMT+4:00", 4 * ONE_HOUR), + new TimeZoneInfo("PLT", "Pakistan Lahore Time", "GMT+5:00", 5 * ONE_HOUR), + new TimeZoneInfo("IST", "India Standard Time", "GMT+5:30", 5 * ONE_HOUR + THIRTY_MIN), + new TimeZoneInfo("BST", "Bangladesh Standard Time", "GMT+6:00", 6 * ONE_HOUR), // 10 + new TimeZoneInfo("VST", "Vietnam Standard Time", "GMT+7:00", 7 * ONE_HOUR), + new TimeZoneInfo("CTT", "China Taiwan Time", "GMT+8:00", 8 * ONE_HOUR), + new TimeZoneInfo("JST", "Japan Standard Time", "GMT+9:00", 9 * ONE_HOUR), + new TimeZoneInfo("ACT", "Australia Central Time", "GMT+9:30", 9 * ONE_HOUR + THIRTY_MIN), + new TimeZoneInfo("AET", "Australia Eastern Time", "GMT+10:00", 10 * ONE_HOUR), // 15 + new TimeZoneInfo("SST", "Solomon Standard Time", "GMT+11:00", 11 * ONE_HOUR), + new TimeZoneInfo("NST", "New Zealand Standard Time", "GMT+12:00", 12 * ONE_HOUR), + new TimeZoneInfo("MIT", "Midway Islands Time", "GMT-11:00", -11 * ONE_HOUR), + new TimeZoneInfo("HST", "Hawaii Standard Time", "GMT-10:00", -10 * ONE_HOUR), + new TimeZoneInfo("AST", "Alaska Standard Time", "GMT-9:00", -9 * ONE_HOUR), // 20 + new TimeZoneInfo("PST", "Pacific Standard Time", "GMT-8:00", -8 * ONE_HOUR), + new TimeZoneInfo("PNT", "Phoenix Standard Time", "GMT-7:00", -7 * ONE_HOUR), + new TimeZoneInfo("MST", "Mountain Standard Time", "GMT-7:00", -7 * ONE_HOUR), + new TimeZoneInfo("CST", "Central Standard Time", "GMT-6:00", -6 * ONE_HOUR), + new TimeZoneInfo("EST", "Eastern Standard Time", "GMT-5:00", -5 * ONE_HOUR), // 25 + new TimeZoneInfo("IET", "Indiana Eastern Standard Time", "GMT-5:00", -5 * ONE_HOUR), + new TimeZoneInfo("PRT", "Puerto Rico and US Virgin Islands Time", "GMT-4:00", -4 * ONE_HOUR), + new TimeZoneInfo("CNT", "Canada Newfoundland Time", "GMT-3:30", -3 * ONE_HOUR - THIRTY_MIN), + new TimeZoneInfo("AGT", "Argentina Standard Time", "GMT-3:00", -3 * ONE_HOUR), + new TimeZoneInfo("BET", "Brazil Eastern Time", "GMT-3:00", -3 * ONE_HOUR), // 30 + new TimeZoneInfo("CAT", "Central African Time", "GMT-1:00", -1 * ONE_HOUR), }; } diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/UrlGenerator.java b/zxing.appspot.com/src/com/google/zxing/web/generator/client/UrlGenerator.java similarity index 84% rename from zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/UrlGenerator.java rename to zxing.appspot.com/src/com/google/zxing/web/generator/client/UrlGenerator.java index baa4b340f..7d21f5f6e 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/UrlGenerator.java +++ b/zxing.appspot.com/src/com/google/zxing/web/generator/client/UrlGenerator.java @@ -16,8 +16,8 @@ package com.google.zxing.web.generator.client; +import com.google.gwt.event.dom.client.ChangeHandler; 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; import com.google.gwt.user.client.ui.Widget; @@ -27,16 +27,18 @@ import com.google.gwt.user.client.ui.Widget; * * @author Yohann Coppel */ -public class UrlGenerator implements GeneratorSource { - Grid table = null; - TextBox url = new TextBox(); +public final class UrlGenerator implements GeneratorSource { + + private Grid table; + private final TextBox url = new TextBox(); - public UrlGenerator(ChangeListener listener, KeyPressHandler keyListener) { + public UrlGenerator(ChangeHandler handler, KeyPressHandler keyListener) { url.addStyleName(StylesDefs.INPUT_FIELD_REQUIRED); - url.addChangeListener(listener); + url.addChangeHandler(handler); url.addKeyPressHandler(keyListener); } + @Override public Grid getWidget() { if (table != null) { // early termination if the table has already been constructed @@ -54,10 +56,12 @@ public class UrlGenerator implements GeneratorSource { return table; } + @Override public String getName() { return "URL"; } + @Override public String getText() throws GeneratorException { return getUrlField(); } @@ -68,12 +72,14 @@ public class UrlGenerator implements GeneratorSource { return input; } + @Override public void validate(Widget widget) throws GeneratorException { if (widget == url) { getUrlField(); } } + @Override public void setFocus() { url.setFocus(true); } diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/Validators.java b/zxing.appspot.com/src/com/google/zxing/web/generator/client/Validators.java similarity index 78% rename from zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/Validators.java rename to zxing.appspot.com/src/com/google/zxing/web/generator/client/Validators.java index ef6c62944..80fd14f2f 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/Validators.java +++ b/zxing.appspot.com/src/com/google/zxing/web/generator/client/Validators.java @@ -22,18 +22,22 @@ package com.google.zxing.web.generator.client; * * @author Yohann Coppel */ -public final class Validators { - public static String filterNumber(String number) { +final class Validators { + + private Validators() { + } + + static String filterNumber(String number) { return number.replaceAll("[ \\.,\\-\\(\\)]", ""); } - public static void validateNumber(String number) throws GeneratorException { + static void validateNumber(String number) throws GeneratorException { if (!number.matches("\\+?[0-9]+")) { throw new GeneratorException("Phone number must be digits only."); } } - public static void validateUrl(String url) throws GeneratorException { + static void validateUrl(String url) throws GeneratorException { if (!isBasicallyValidURI(url)) { throw new GeneratorException("URL is not valid."); } @@ -45,13 +49,10 @@ public final class Validators { } int period = uri.indexOf('.'); // Look for period in a domain but followed by at least a two-char TLD - if (period >= uri.length() - 2) { - return false; - } - return period >= 0 || uri.indexOf(':') >= 0; + return period < uri.length() - 2 && (period >= 0 || uri.indexOf(':') >= 0); } - public static void validateEmail(String email) throws GeneratorException { + static void validateEmail(String email) throws GeneratorException { //FIXME: we can have a better check for email here. if (!email.matches("^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}$")) { throw new GeneratorException("Email is not valid."); diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/WifiGenerator.java b/zxing.appspot.com/src/com/google/zxing/web/generator/client/WifiGenerator.java similarity index 80% rename from zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/WifiGenerator.java rename to zxing.appspot.com/src/com/google/zxing/web/generator/client/WifiGenerator.java index 05be7464d..debf4533d 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/WifiGenerator.java +++ b/zxing.appspot.com/src/com/google/zxing/web/generator/client/WifiGenerator.java @@ -16,9 +16,10 @@ package com.google.zxing.web.generator.client; +import com.google.gwt.event.dom.client.ChangeHandler; 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.HasText; import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.Widget; @@ -28,29 +29,30 @@ import com.google.gwt.user.client.ui.Widget; * * @author Vikram Aggarwal */ -public class WifiGenerator implements GeneratorSource { - Grid table = null; - TextBox ssid = new TextBox(); - TextBox password = new TextBox(); - final boolean multipleSelections = false; - ListBox networkType = new ListBox(multipleSelections); - TextBox[] widgets = {ssid, password }; - - public WifiGenerator(ChangeListener changeListener, KeyPressHandler keyListener) { - networkType.addItem("WEP", "WEP"); - networkType.addItem("WPA/WPA2", "WPA"); - networkType.addItem("No encryption", "nopass"); - +public final class WifiGenerator implements GeneratorSource { + + private Grid table; + private final TextBox ssid = new TextBox(); + private final TextBox password = new TextBox(); + private final ListBox networkType = new ListBox(false); + + public WifiGenerator(ChangeHandler handler, KeyPressHandler keyListener) { + networkType.addItem("WEP", "WEP"); + networkType.addItem("WPA/WPA2", "WPA"); + networkType.addItem("No encryption", "nopass"); + TextBox[] widgets = {ssid, password}; for (TextBox w: widgets) { - w.addChangeListener(changeListener); + w.addChangeHandler(handler); w.addKeyPressHandler(keyListener); } } + @Override public String getName() { return "Wifi network"; } + @Override public String getText() throws GeneratorException { String ssid = getSsidField(); String password = getPasswordField(); @@ -60,7 +62,7 @@ public class WifiGenerator implements GeneratorSource { return getWifiString(ssid, password, networkType); } - private String getWifiString(String ssid, String password, String type) { + private static String getWifiString(String ssid, String password, String type) { StringBuilder output = new StringBuilder(100); output.append("WIFI:"); output.append("S:").append(ssid).append(';'); @@ -76,7 +78,7 @@ public class WifiGenerator implements GeneratorSource { } } - private static String parseTextField(String name, TextBox textBox) throws GeneratorException { + private static String parseTextField(String name, HasText textBox) throws GeneratorException { String input = textBox.getText(); if (input.length() < 1) { return ""; @@ -107,6 +109,7 @@ public class WifiGenerator implements GeneratorSource { return networkType.getValue(networkType.getSelectedIndex()); } + @Override public Grid getWidget() { if (table != null) { // early termination if the table has already been constructed @@ -125,6 +128,7 @@ public class WifiGenerator implements GeneratorSource { return table; } + @Override public void validate(Widget widget) throws GeneratorException { if (widget == ssid) { getSsidField(); @@ -137,6 +141,7 @@ public class WifiGenerator implements GeneratorSource { } } + @Override public void setFocus() { ssid.setFocus(true); } diff --git a/zxing.appspot.com/static/scan.html b/zxing.appspot.com/static/scan.html deleted file mode 100644 index 332069e92..000000000 --- a/zxing.appspot.com/static/scan.html +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - Zebra Crossing - - - - - - - - - - - -
- - - A web page you are viewing would like to scan a barcode with your camera phone. To do - this, you need to install a new application. -

- If you are using an Android device, - click here to - install Barcode Scanner. Once installed, it will launch automatically the next time you - click on the hyperlink which brought you here. -

- For all other mobile devices, please see - these installation instructions. -

- - - - diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/public/Generator.css b/zxing.appspot.com/war/Generator.css similarity index 90% rename from zxing.appspot.com/generator/src/com/google/zxing/web/generator/public/Generator.css rename to zxing.appspot.com/war/Generator.css index f31e5f49e..3675a34e4 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/public/Generator.css +++ b/zxing.appspot.com/war/Generator.css @@ -47,18 +47,11 @@ body { position: relative; display: table; - #position: relative; } #innerresult { display: table-cell; vertical-align: middle; width: 100%; - #position: absolute; - #top: 50%; -} -#innerresult img { - #position: relative; - #top: -50%; } #downloadText { font-size: 11px; @@ -66,6 +59,9 @@ body { #urlresult { width: 350px; } +#rawtextresult { + width: 350px; +} .firstColumn { width: 100px; text-align: right; @@ -97,7 +93,7 @@ body { background-color: #fffbcc; } .required { - background: #ffffff url(required-field-bg.png) repeat-y; + background: #ffffff url(static/required-field-bg.png) repeat-y; } .errorMessage { padding-left: 110px; diff --git a/zxing.appspot.com/war/Generator.html b/zxing.appspot.com/war/Generator.html new file mode 100644 index 000000000..69c5a9bc5 --- /dev/null +++ b/zxing.appspot.com/war/Generator.html @@ -0,0 +1,29 @@ + + + + + + QR Code Generator from the ZXing Project + + + + + + + + +
+ + + + + diff --git a/zxing.appspot.com/generator/libs/gwt-incubator.jar b/zxing.appspot.com/war/WEB-INF/lib/gwt-incubator.jar similarity index 76% rename from zxing.appspot.com/generator/libs/gwt-incubator.jar rename to zxing.appspot.com/war/WEB-INF/lib/gwt-incubator.jar index 72ea69212..665078c77 100644 Binary files a/zxing.appspot.com/generator/libs/gwt-incubator.jar and b/zxing.appspot.com/war/WEB-INF/lib/gwt-incubator.jar differ diff --git a/zxing.appspot.com/war/WEB-INF/web.xml b/zxing.appspot.com/war/WEB-INF/web.xml new file mode 100644 index 000000000..dbfd97a10 --- /dev/null +++ b/zxing.appspot.com/war/WEB-INF/web.xml @@ -0,0 +1,10 @@ + + + + + index.html + + + \ No newline at end of file diff --git a/zxing.appspot.com/war/app.yaml b/zxing.appspot.com/war/app.yaml new file mode 100644 index 000000000..ae465bf80 --- /dev/null +++ b/zxing.appspot.com/war/app.yaml @@ -0,0 +1,21 @@ +application: zxing +version: 2 +runtime: python +api_version: 1 + +handlers: +- url: /generator + static_files: Generator.html + upload: Generator.html + +- url: /scan + static_files: scan.html + upload: scan.html + +- url: / + static_files: index.html + upload: index.html + +- url: /(.*) + static_files: \1 + upload: / \ No newline at end of file diff --git a/zxing.appspot.com/static/favicon.ico b/zxing.appspot.com/war/favicon.ico similarity index 100% rename from zxing.appspot.com/static/favicon.ico rename to zxing.appspot.com/war/favicon.ico diff --git a/zxing.appspot.com/static/index.html b/zxing.appspot.com/war/index.html similarity index 54% rename from zxing.appspot.com/static/index.html rename to zxing.appspot.com/war/index.html index 807ca481b..9a385792e 100644 --- a/zxing.appspot.com/static/index.html +++ b/zxing.appspot.com/war/index.html @@ -1,4 +1,4 @@ - + @@ -9,26 +9,22 @@
- + - Welcome to the Zebra Crossing site at zxing.appspot.com. -

- This site features a QR Code Generator, which +

Welcome to the Zebra Crossing site at zxing.appspot.com.

+

This site features a QR Code Generator, which allows you to create a two-dimensional barcode that can be scanned with a camera phone. These QR Codes can contain a URL, contact - information, a calendar event, and much more. -

- The ZXing Project exists - to provide an open source barcode scanner for a range of devices. You - can - download the software for your phone here. + information, a calendar event, and much more.

+

The ZXing Project exists + to provide an open source barcode scanner for a range of devices.

diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/public/required-field-bg.png b/zxing.appspot.com/war/required-field-bg.png similarity index 100% rename from zxing.appspot.com/generator/src/com/google/zxing/web/generator/public/required-field-bg.png rename to zxing.appspot.com/war/required-field-bg.png diff --git a/zxing.appspot.com/war/scan.html b/zxing.appspot.com/war/scan.html new file mode 100644 index 000000000..c9a3ebbde --- /dev/null +++ b/zxing.appspot.com/war/scan.html @@ -0,0 +1,35 @@ + + + + + + Zebra Crossing + + + + + + + + + + + +
+ + +

A web page you are viewing would like to scan a barcode with your camera phone. To do + this, you need to install a new application.

+

If you are using an Android device, + click here to + install Barcode Scanner. Once installed, it will launch automatically the next time you + click on the hyperlink which brought you here.

+
+ + + + diff --git a/zxing.appspot.com/static/style.css b/zxing.appspot.com/war/style.css similarity index 100% rename from zxing.appspot.com/static/style.css rename to zxing.appspot.com/war/style.css diff --git a/zxing.appspot.com/static/zxingicon.png b/zxing.appspot.com/war/zxingicon.png similarity index 100% rename from zxing.appspot.com/static/zxingicon.png rename to zxing.appspot.com/war/zxingicon.png diff --git a/zxing.appspot.com/static/zxingiconsmall.png b/zxing.appspot.com/war/zxingiconsmall.png similarity index 100% rename from zxing.appspot.com/static/zxingiconsmall.png rename to zxing.appspot.com/war/zxingiconsmall.png